SPEC:
- OK salvataggio ricetta in MongoDB
This commit is contained in:
@@ -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");
|
||||
}
|
||||
/// <summary>
|
||||
/// Database corrente MongoDB
|
||||
/// </summary>
|
||||
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<RecipeModel>.Filter;
|
||||
var filter = filtBuilder.Eq<int>("IdxPODL", idxPODL);
|
||||
var collectionData = mongoDb.GetCollection<RecipeModel>("RecipeArchive");
|
||||
// recupero
|
||||
answ = collectionData.Find(filter).Project<RecipeModel>("{_id: 0}").FirstOrDefault<RecipeModel>();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Salva ricetta su MongoDB
|
||||
/// </summary>
|
||||
/// <param name="currRecord"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> RecipeSetByPODL(RecipeModel currRecord)
|
||||
{
|
||||
await Task.Delay(1);
|
||||
bool answ = false;
|
||||
try
|
||||
{
|
||||
// definisco filtro
|
||||
var filtBuilder = Builders<RecipeModel>.Filter;
|
||||
var filter = filtBuilder.Eq<int>("IdxPODL", currRecord.IdxPODL);
|
||||
var collectionData = mongoDb.GetCollection<RecipeModel>("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<RecipeConfig>(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<int, Dictionary<string, string>>()
|
||||
RowsVal = new Dictionary<string, Dictionary<string, KeyConfig>>()
|
||||
{
|
||||
{ 1, currRecipe.RowsConf.ListKeys}
|
||||
//{ "1", rigaBase }
|
||||
{ "1", RecipeModel.ConvertToObj(currRecipe.RowsConf.ListKeys)}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
return answ;
|
||||
|
||||
Reference in New Issue
Block a user