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 (p.Id == "0")
{
p.Id = null;
DbManager.Dicts.InsertOne(p);
return true;
}
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;
}
}
}