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() => MongoDbAccessManager.Dicts.Find(FilterDefinition.Empty).ToList(); /// /// /// /// /// public override bool DeleteDict(IEnumerable value) { var list = new List>(); foreach (var id in value) { list.Add(new DeleteOneModel(Builders.Filter.Eq(md => md.Id, id))); } MongoDbAccessManager.Dicts.BulkWrite(list); return true; } /// /// /// /// /// public override bool SaveDict(BootstrapDict p) { if (p.Id == "0") { p.Id = null; MongoDbAccessManager.Dicts.InsertOne(p); return true; } else { MongoDbAccessManager.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) { MongoDbAccessManager.Dicts.FindOneAndUpdate(md => md.Category == dict.Category && md.Name == dict.Name, Builders.Update.Set(md => md.Code, dict.Code)); return true; } } }