Files
mapo-core/MP.SPEC/Components/RecipeMan.razor.cs
T
Samuele Locatelli dde39d52dd SPEC:
- OK salvataggio ricetta in MongoDB
2023-02-08 18:52:38 +01:00

95 lines
2.5 KiB
C#

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<string, string> GetListByType(string DictType)
{
Dictionary<string, string> answ = new Dictionary<string, string>();
// 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
}
}