78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
namespace YLErp.Modules.UnderlyingModule
|
|
{
|
|
/// <summary>
|
|
/// 板块性质服务
|
|
/// </summary>
|
|
public class UnderlyingBlockService : YLBaseService
|
|
{
|
|
public UnderlyingBlockService(OptUserInfo userInfo) : base(userInfo)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有板块名称
|
|
/// </summary>
|
|
public IEnumerable<UnderlyingBlockConfig> GetBlocks(int? group)
|
|
{
|
|
var predicate = PredicateBuilder.Create<UnderlyingBlockConfig>(n => n.Group > 0);
|
|
if (group.HasValue)
|
|
{
|
|
predicate = predicate.And(n => n.Group == group.Value);
|
|
}
|
|
return DbContext.UnderlyingBlockConfig.AsNoTracking()
|
|
.Where(predicate).OrderByDescending(n => n.id).ToArray();
|
|
}
|
|
|
|
public int SaveData(UnderlyingBlockConfig model)
|
|
{
|
|
UnderlyingBlockConfig dbModel;
|
|
|
|
if (model.id > 0)
|
|
{
|
|
dbModel = DbContext.UnderlyingBlockConfig.Find(model.id);
|
|
if (DbContext.UnderlyingBlockConfig.Any(n => n.id != model.id && n.Group == dbModel.Group && n.Name == model.Name))
|
|
{
|
|
throw new ServiceException("板块性质名称不能重复");
|
|
}
|
|
if (dbModel == null)
|
|
{
|
|
throw new ServiceException("数据不存在");
|
|
}
|
|
dbModel.Name = model.Name;
|
|
dbModel.OptId = model.OptId;
|
|
dbModel.OptName = model.OptName;
|
|
}
|
|
else if (model.Group < 1 || model.Group > 5)
|
|
{
|
|
throw new ServiceException("group参数无效:" + model.Group);
|
|
}
|
|
else if (DbContext.UnderlyingBlockConfig.Any(n => n.id != model.id && n.Group == model.Group && n.Name == model.Name))
|
|
{
|
|
throw new ServiceException("板块性质名称不能重复");
|
|
}
|
|
else
|
|
{
|
|
DbContext.UnderlyingBlockConfig.Add(dbModel = model);
|
|
}
|
|
|
|
dbModel.OptDate = DateTime.Now;
|
|
|
|
return DbContext.SaveChanges();
|
|
}
|
|
|
|
public int RemoveDatas(int optId, string optName, params int[] ids)
|
|
{
|
|
if (ids == null || !ids.Any()) return 0;
|
|
var datas = DbContext.UnderlyingBlockConfig.Where(n => ids.Contains(n.id)).ToArray();
|
|
foreach (var data in datas)
|
|
{
|
|
data.Group = -1;
|
|
data.OptId = optId;
|
|
data.OptName = optName;
|
|
data.OptDate = DateTime.Now;
|
|
}
|
|
return DbContext.SaveChanges();
|
|
}
|
|
}
|
|
}
|