182 lines
5.8 KiB
C#
182 lines
5.8 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data.Entity.Validation;
|
||
using System.Linq;
|
||
using System.Linq.Expressions;
|
||
using WX.CRM.BLL.Base;
|
||
using WX.CRM.BLL.Util;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.IBLL.Res;
|
||
using WX.CRM.Model.Entity;
|
||
|
||
namespace WX.CRM.BLL.Res
|
||
{
|
||
public class RES_DISTRIBUTE_DETAIL_BL : IRES_DISTRIBUTE_DETAIL
|
||
{
|
||
#region 添加
|
||
|
||
/// <summary>
|
||
/// 添加
|
||
/// </summary>
|
||
/// <param name="errors"></param>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.RES_DISTRIBUTE_DETAIL model)
|
||
{
|
||
try
|
||
{
|
||
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
||
{
|
||
model.LOGID = new SEQUENCES_BL().Seq_base_get();
|
||
db.RES_DISTRIBUTE_DETAIL.Add(model);
|
||
return db.SaveChanges().GetResult();
|
||
}
|
||
}
|
||
catch (DbEntityValidationException dbEx)
|
||
{
|
||
var ex1 = dbEx.EntityValidationErrors.FirstOrDefault();
|
||
if (ex1 != null)
|
||
{
|
||
var ex2 = ex1.ValidationErrors.FirstOrDefault();
|
||
if (ex2 != null)
|
||
{
|
||
errors.Add(ex2.ErrorMessage);
|
||
}
|
||
else
|
||
errors.Add(dbEx.Message);
|
||
}
|
||
else
|
||
errors.Add(dbEx.Message);
|
||
return false;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
errors.Add(ex.Message);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public bool BatchAdd(ref ValidationErrors errors, IList<RES_DISTRIBUTE_DETAIL> list)
|
||
{
|
||
try
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
IList<RES_DISTRIBUTEDETAIL_HIS> his = new List<RES_DISTRIBUTEDETAIL_HIS>();
|
||
|
||
foreach (var model in list)
|
||
{
|
||
model.LOGID = new SEQUENCES_BL().Seq_base_get(Model.Enum.PKIDType.LargeTable);
|
||
//db.RES_DISTRIBUTE_DETAIL.Add(model);
|
||
his.Add(new RES_DISTRIBUTEDETAIL_HIS() { LOGID = model.LOGID, RESID = model.RESID, DISTRIBUTEID = model.DISTRIBUTEID, SALESID = model.SALESID, CTIME = model.CTIME });
|
||
}
|
||
|
||
db.RES_DISTRIBUTE_DETAIL.AddRange(list);
|
||
|
||
db.RES_DISTRIBUTEDETAIL_HIS.AddRange(his);
|
||
|
||
return db.SaveChanges().GetResult();
|
||
}
|
||
}
|
||
catch (DbEntityValidationException dbEx)
|
||
{
|
||
LogHelper.Error("分配资源异常:" + dbEx.Message);
|
||
var ex1 = dbEx.EntityValidationErrors.FirstOrDefault();
|
||
if (ex1 != null)
|
||
{
|
||
var ex2 = ex1.ValidationErrors.FirstOrDefault();
|
||
if (ex2 != null)
|
||
{
|
||
LogHelper.Error("分配资源ex2:" + ex2.ErrorMessage);
|
||
errors.Add(ex2.ErrorMessage);
|
||
return false;
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Error("分配资源dbEx0:" + dbEx.Message);
|
||
errors.Add(dbEx.Message);
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
LogHelper.Error("分配资源dbEx1:" + dbEx.Message);
|
||
errors.Add(dbEx.Message); return false;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
errors.Add("分配资源ex:" + ex.Message);
|
||
LogHelper.Error("分配资源ex:" + ex);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public void BatchRemove(List<decimal> list)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
foreach (var item in list)
|
||
{
|
||
var model = db.RES_DISTRIBUTE_DETAIL.FirstOrDefault(p => p.LOGID == item);
|
||
if (model != null)
|
||
db.RES_DISTRIBUTE_DETAIL.Remove(model);
|
||
}
|
||
db.SaveChanges();
|
||
}
|
||
}
|
||
public void BatchUpdate(List<string> list)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
foreach (var item in list)
|
||
{
|
||
var model = db.CACHE_RES_RESOURCE_COUNT.FirstOrDefault(p => p.RESID == item);
|
||
if (model != null)
|
||
{
|
||
model.HASACTIVE = 0;
|
||
}
|
||
}
|
||
db.SaveChanges();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 修改
|
||
|
||
/// <summary>
|
||
/// 数据的修改
|
||
/// </summary>
|
||
/// <param name="errors"></param>
|
||
/// <param name="model"></param>
|
||
/// <returns></returns>
|
||
public bool Update(ref ValidationErrors errors, WX.CRM.Model.Entity.RES_DISTRIBUTE_DETAIL model)
|
||
{
|
||
return false;
|
||
}
|
||
#endregion
|
||
|
||
#region 删除
|
||
|
||
/// <summary>
|
||
/// 删除
|
||
/// </summary>
|
||
/// <param name="errors"></param>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public bool Delete(ref ValidationErrors errors, decimal id)
|
||
{
|
||
return false;
|
||
}
|
||
#endregion
|
||
|
||
public IList<RES_DISTRIBUTE_DETAIL> GetList(Expression<Func<RES_DISTRIBUTE_DETAIL, bool>> where)
|
||
{
|
||
using (var db = new crmContext())
|
||
{
|
||
return db.RES_DISTRIBUTE_DETAIL.Where(where).ToList();
|
||
}
|
||
}
|
||
}
|
||
}
|