using System.Collections.ObjectModel;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
public static class utils{
public static string ToDescription<TEnum>(this TEnum value)
var enumFields = value.GetType().GetField(value.ToString());
var attributes = (DescriptionAttribute[])enumFields
.GetCustomAttributes(typeof(DescriptionAttribute),
return attributes.Length > 0 ? attributes[0].Description : value.ToString();
public partial class RecordsCreate{
public string ReturnUrl { get; set; }
public ObservableCollection<Record> Records { get; }
private Record NewRecord { get; set;}
private Dictionary<int, string> _ServiceTypes { get; set; }
private EditContext EditContext;
public string? SuccessMessage { get; set; }
public string? ErrorMessage { get; set; }
EditContext = new EditContext(NewRecord);
protected override async Task OnInitializedAsync()
ServiceType cst = ServiceType.NotSet;
_ServiceTypes = Enum.GetValues(cst.GetType())
.ToDictionary(t => (int)(object)t, t => t.ToDescription());
EditContext = new EditContext(NewStoreMapping);
private async void AddRecord()
sm.Name == NewRecord.Name &&
sm.ServiceType == Records.ServiceType))
ErrorMessage = "Such a Record and ServiceType already exist";
Records.Add(NewStoreMapping);
NavigationManager.NavigateTo(ReturnUrl ?? "/records", forceLoad: false);
catch (Exception exception)
ErrorMessage = "Exception encountered while attempting to create a new record: {exception.Message}";
private async void AddMerchantFailed()
ErrorMessage = "Please fix highlightes errors first or cancel addition.";
await Task.FromResult(0);
private async Task LoadMerchants()
Records.Add(new Record(){ Name="Existing 1", ServiceType = 1});
catch (Exception exception)
ErrorMessage = "Exception encountered while attempting to load record details: {exception.Message}";