2018-10-30 13:07:29 +08:00
|
|
|
|
using Bootstrap.Security;
|
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess.MongoDB
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Dict : DataAccess.Dict
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2019-01-15 12:52:09 +08:00
|
|
|
|
public override IEnumerable<BootstrapDict> RetrieveDicts() => DbManager.Dicts.Find(FilterDefinition<BootstrapDict>.Empty).ToList();
|
2018-10-31 17:32:19 +08:00
|
|
|
|
|
2018-10-30 23:01:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public override bool Delete(IEnumerable<string> value)
|
2018-10-30 13:07:29 +08:00
|
|
|
|
{
|
2018-10-30 23:01:36 +08:00
|
|
|
|
var list = new List<WriteModel<BootstrapDict>>();
|
|
|
|
|
foreach (var id in value)
|
|
|
|
|
{
|
|
|
|
|
list.Add(new DeleteOneModel<BootstrapDict>(Builders<BootstrapDict>.Filter.Eq(md => md.Id, id)));
|
|
|
|
|
}
|
2019-01-15 12:52:09 +08:00
|
|
|
|
DbManager.Dicts.BulkWrite(list);
|
2018-10-30 23:01:36 +08:00
|
|
|
|
return true;
|
2018-10-30 13:07:29 +08:00
|
|
|
|
}
|
2018-10-31 17:32:19 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="p"></param>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public override bool Save(BootstrapDict p)
|
2018-10-31 17:32:19 +08:00
|
|
|
|
{
|
2019-05-14 15:08:46 +08:00
|
|
|
|
if (string.IsNullOrEmpty(p.Id))
|
2018-10-31 17:32:19 +08:00
|
|
|
|
{
|
|
|
|
|
p.Id = null;
|
2019-01-15 12:52:09 +08:00
|
|
|
|
DbManager.Dicts.InsertOne(p);
|
2019-05-18 21:21:03 +08:00
|
|
|
|
p.Id = DbManager.Dicts.Find(d => d.Name == p.Name && d.Category == p.Category && d.Define == p.Define && d.Code == p.Code).FirstOrDefault().Id;
|
2018-10-31 17:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-01-15 12:52:09 +08:00
|
|
|
|
DbManager.Dicts.UpdateOne(md => md.Id == p.Id, Builders<BootstrapDict>.Update.Set(md => md.Category, p.Category)
|
2018-10-31 17:32:19 +08:00
|
|
|
|
.Set(md => md.Define, p.Define)
|
|
|
|
|
.Set(md => md.Name, p.Name)
|
|
|
|
|
.Set(md => md.Code, p.Code));
|
|
|
|
|
}
|
2019-05-18 21:21:03 +08:00
|
|
|
|
return true;
|
2018-10-31 17:32:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dict"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override bool SaveSettings(BootstrapDict dict)
|
|
|
|
|
{
|
2019-01-15 12:52:09 +08:00
|
|
|
|
DbManager.Dicts.FindOneAndUpdate(md => md.Category == dict.Category && md.Name == dict.Name, Builders<BootstrapDict>.Update.Set(md => md.Code, dict.Code));
|
2018-10-31 17:32:19 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-10-30 13:07:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|