using Bootstrap.Security;
using MongoDB.Driver;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.DataAccess.MongoDB
{
///
///
///
public class Dict : DataAccess.Dict
{
///
///
///
///
public override IEnumerable RetrieveDicts() => DbManager.Dicts.Find(FilterDefinition.Empty).ToList();
///
///
///
///
///
public override bool Delete(IEnumerable value)
{
var list = new List>();
foreach (var id in value)
{
list.Add(new DeleteOneModel(Builders.Filter.Eq(md => md.Id, id)));
}
DbManager.Dicts.BulkWrite(list);
return true;
}
///
///
///
///
///
public override bool Save(BootstrapDict p)
{
if (string.IsNullOrEmpty(p.Id))
{
p.Id = null;
DbManager.Dicts.InsertOne(p);
p.Id = DbManager.Dicts.Find(d => d.Name == p.Name && d.Category == p.Category && d.Define == p.Define && d.Code == p.Code).FirstOrDefault().Id;
}
else
{
DbManager.Dicts.UpdateOne(md => md.Id == p.Id, Builders.Update.Set(md => md.Category, p.Category)
.Set(md => md.Define, p.Define)
.Set(md => md.Name, p.Name)
.Set(md => md.Code, p.Code));
}
return true;
}
///
///
///
///
///
public override bool SaveSettings(BootstrapDict dict)
{
DbManager.Dicts.FindOneAndUpdate(md => md.Category == dict.Category && md.Name == dict.Name, Builders.Update.Set(md => md.Code, dict.Code));
return true;
}
}
}