using Microsoft.AspNetCore.Components; using MP.Data.MgModels; using MP.SPEC.Data; namespace MP.SPEC.Components { public partial class RecipeMan { #region Public Properties [Parameter] public int IdxPODL { get; set; } = 0; [Parameter] public string RecipePath { get; set; } = ""; #endregion Public Properties #region Protected Fields protected bool isLoading = false; #endregion Protected Fields #region Protected Properties protected RecipeModel? CurrRecipe { get; set; } = null; [Inject] protected MpDataService MDService { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected async Task CancelHeadData() { await ReloadData(); } protected Dictionary GetListByType(string DictType) { Dictionary answ = new Dictionary(); // inn primis il "selezionare" answ.Add("", "--- Selezionare ---"); // cerco tipo in enums... if (CurrRecipe != null && CurrRecipe.HeadConf.EnumVal.ContainsKey(DictType)) { foreach (var item in CurrRecipe.HeadConf.EnumVal[DictType]) { answ.Add(item.Key, item.Value); } } return answ; } protected override async Task OnParametersSetAsync() { await ReloadData(); } protected async Task SaveHeadData() { if (CurrRecipe != null) { await MDService.RecipeSetByPODL(CurrRecipe); } } #endregion Protected Methods #region Private Methods private async Task ReloadData() { await Task.Delay(1); isLoading = true; if (IdxPODL != 0 && !string.IsNullOrEmpty(RecipePath)) { CurrRecipe = new RecipeModel(); // effettua ricerca ricetta su MongoDb CurrRecipe = await MDService.RecipeGetByPODL(IdxPODL); // se non trova crea nuova... if (CurrRecipe == null || string.IsNullOrEmpty(CurrRecipe.Id)) { CurrRecipe = MDService.InitRecipe(IdxPODL, RecipePath); } } await Task.Delay(1); isLoading = false; } #endregion Private Methods } }