diff --git a/MP.Data/Conf/RecipeBlockConfig.cs b/MP.Data/Conf/RecipeBlockConfig.cs
index 3cc966dc..8c400c81 100644
--- a/MP.Data/Conf/RecipeBlockConfig.cs
+++ b/MP.Data/Conf/RecipeBlockConfig.cs
@@ -13,13 +13,14 @@ namespace MP.Data.Conf
{
///
/// Dizionario delle chiavi, differenziate dai primi caratteri:
- /// [C] --> Calcolato
- /// [F] --> Fixed (NON modificabile)
- /// [E] --> Enum: modificabile ma da dizionario valori seguente
+ /// C: --> Calcolato
+ /// E: --> Enum: modificabile ma da dizionario valori seguente
+ /// F: --> Fixed (NON modificabile)
/// "" --> editabile
///
public Dictionary ListKeys { get; set; } = new Dictionary();
+
///
/// Dizionario degli enum permessi
///
@@ -31,9 +32,9 @@ namespace MP.Data.Conf
public class CalcDetail
{
- public string Description { get; set; } = null!;
- public string Type { get; set; } = null!;
- public string Format { get; set; } = null!;
+ public string Description { get; set; } = "";
+ public string Type { get; set; } = "";
+ public string Format { get; set; } = "";
}
}
}
diff --git a/MP.Data/Controllers/MpMongoController.cs b/MP.Data/Controllers/MpMongoController.cs
index b148332a..7d371c81 100644
--- a/MP.Data/Controllers/MpMongoController.cs
+++ b/MP.Data/Controllers/MpMongoController.cs
@@ -12,6 +12,7 @@ using MP.Data.MgModels;
using System.IO;
using MP.Data.Conf;
using Newtonsoft.Json;
+using static MP.Data.MgModels.RecipeModel;
namespace MP.Data.Controllers
{
@@ -23,8 +24,13 @@ namespace MP.Data.Controllers
_configuration = configuration;
string mongoConf = _configuration.GetConnectionString("MongoConnect");
client = new MongoClient(mongoConf);
+ mongoDb = client.GetDatabase("MAPO");
Log.Info("Avviata classe MpMongoController");
}
+ ///
+ /// Database corrente MongoDB
+ ///
+ private IMongoDatabase mongoDb;
public void Dispose()
{
@@ -41,12 +47,45 @@ namespace MP.Data.Controllers
{
await Task.Delay(1);
RecipeModel answ = new RecipeModel();
+ try
+ {
+ // definisco filtro
+ var filtBuilder = Builders.Filter;
+ var filter = filtBuilder.Eq("IdxPODL", idxPODL);
+ var collectionData = mongoDb.GetCollection("RecipeArchive");
+ // recupero
+ answ = collectionData.Find(filter).Project("{_id: 0}").FirstOrDefault();
+ }
+ catch
+ { }
return answ;
}
+ ///
+ /// Salva ricetta su MongoDB
+ ///
+ ///
+ ///
public async Task RecipeSetByPODL(RecipeModel currRecord)
{
await Task.Delay(1);
bool answ = false;
+ try
+ {
+ // definisco filtro
+ var filtBuilder = Builders.Filter;
+ var filter = filtBuilder.Eq("IdxPODL", currRecord.IdxPODL);
+ var collectionData = mongoDb.GetCollection("RecipeArchive");
+ // elimino old
+ collectionData.DeleteMany(filter);
+ // aggiungo
+ collectionData.InsertOne(currRecord);
+ answ = true;
+ }
+ catch(Exception exc)
+ {
+ Log.Error($"Eccezione in RecipeSetByPODL{Environment.NewLine}{exc}");
+ }
+
return answ;
}
@@ -65,6 +104,8 @@ namespace MP.Data.Controllers
{
string rawData = File.ReadAllText(fullPath);
var currRecipe = JsonConvert.DeserializeObject(rawData);
+ //// calcolo obj riga base (ne aggiungo1...)
+ //var rigaBase = RecipeModel.ConvertToObj(currRecipe.RowsConf.ListKeys);
// copio la mia ricetta come conf...
answ = new RecipeModel()
{
@@ -72,14 +113,16 @@ namespace MP.Data.Controllers
TemplateFile = currRecipe.TemplateFile,
HeadConf = currRecipe.HeadConf,
RowsConf = currRecipe.RowsConf,
- HeadVal = currRecipe.HeadConf.ListKeys,
+ //HeadVal = currRecipe.HeadConf.ListKeys,
+ HeadVal = RecipeModel.ConvertToObj(currRecipe.HeadConf.ListKeys),
// aggiungo 1 riga...
- RowsVal = new Dictionary>()
+ RowsVal = new Dictionary>()
{
- { 1, currRecipe.RowsConf.ListKeys}
+ //{ "1", rigaBase }
+ { "1", RecipeModel.ConvertToObj(currRecipe.RowsConf.ListKeys)}
}
};
-
+
}
return answ;
diff --git a/MP.Data/MgModels/RecipeModel.cs b/MP.Data/MgModels/RecipeModel.cs
index 13e3de31..a81a8cd8 100644
--- a/MP.Data/MgModels/RecipeModel.cs
+++ b/MP.Data/MgModels/RecipeModel.cs
@@ -6,9 +6,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MP.Data.Conf;
+using System.ComponentModel.DataAnnotations.Schema;
namespace MP.Data.MgModels
{
+ [BsonIgnoreExtraElements]
public class RecipeModel : RecipeConfig
{
[BsonId]
@@ -19,15 +21,93 @@ namespace MP.Data.MgModels
public int IdxODL { get; set; } = 0;
+ /////
+ ///// Dizionario chiavi/valori campi header
+ /////
+ //public Dictionary HeadVal { get; set; } = new Dictionary();
+
+ /////
+ ///// Elenco righe ricetta (ogni riga dizionario chiavi/valori)
+ /////
+ //public Dictionary> RowsVal { get; set; } = new Dictionary>();
+
+
+
///
- /// Dizionario chiavi/valori campi header
+ /// Dizionario chiavi/valori estesi campi header
///
- public Dictionary HeadVal { get; set; } = new Dictionary();
+ public Dictionary HeadVal { get; set; } = new Dictionary();
+
///
/// Elenco righe ricetta (ogni riga dizionario chiavi/valori)
///
- public Dictionary> RowsVal { get; set; } = new Dictionary>();
+ public Dictionary> RowsVal { get; set; } = new Dictionary>();
+ ///
+ /// Inizializza la ListObj da ListKeys
+ ///
+ public static Dictionary ConvertToObj(Dictionary ListKeys)
+ {
+ Dictionary ListObj = ListKeys.ToDictionary(x => x.Key, x => new KeyConfig(x.Value));
+ return ListObj;
+ }
+
+ public class KeyConfig
+ {
+ ///
+ /// Init classe da valore raw
+ ///
+ ///
+ public KeyConfig(string rawValue)
+ {
+ this.OrigVal = rawValue;
+ this.Value = rawValue;
+ // cerco se ho uno dei 3 caratteri (C/E/F):
+ if (rawValue.Length >= 2 && rawValue.Substring(1, 1) == ":")
+ {
+ string selTipo = rawValue.Substring(0, 2);
+ switch (selTipo)
+ {
+ case "C:":
+ this.Type = KeyType.Calc;
+ this.Value = rawValue.Substring(2);
+ break;
+ case "E:":
+ this.Type = KeyType.Enum;
+ this.Value = "";
+ this.EnumType = rawValue.Substring(2);
+ break;
+ case "F:":
+ this.Type = KeyType.Fixed;
+ this.Value = rawValue.Substring(2);
+ break;
+ default:
+ this.Type = KeyType.None;
+ break;
+ }
+ }
+ else
+ {
+ this.Type = KeyType.Free;
+ }
+ }
+ [NotMapped]
+ public KeyType Type { get; set; } = KeyType.None;
+ [NotMapped]
+ public string Value { get; set; } = "";
+ [NotMapped]
+ public string EnumType { get; set; } = "";
+ public string OrigVal { get; set; } = "";
+ }
+
+ public enum KeyType
+ {
+ None = 0,
+ Calc,
+ Enum,
+ Fixed,
+ Free
+ }
public string RawRecipe { get; set; } = "";
diff --git a/MP.SPEC/Components/RecipeMan.razor b/MP.SPEC/Components/RecipeMan.razor
index 86e9e2ff..e0aaedc2 100644
--- a/MP.SPEC/Components/RecipeMan.razor
+++ b/MP.SPEC/Components/RecipeMan.razor
@@ -4,25 +4,54 @@
}
else
{
-