135 lines
4.6 KiB
C#
135 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Base;
|
|
using WX.CRM.Model.Entity;
|
|
|
|
namespace WX.CRM.BLL.Base
|
|
{
|
|
public class BAS_INNERUSERGROUP_BL : IBAS_INNERUSERGROUP, IBAS_INNERUSERGROUP_Q
|
|
{
|
|
#region 新增
|
|
/// <summary>
|
|
/// 新增数据
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.BAS_INNERUSERGROUP model)
|
|
{
|
|
try
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
db.Configuration.ValidateOnSaveEnabled = false;
|
|
model.CTIME = DateTime.Now;
|
|
|
|
BAS_INNERGROUP group = db.BAS_INNERGROUP.FirstOrDefault(m => m.GID == model.GID);
|
|
if (group == null)
|
|
{
|
|
errors.Add("组别有误!");
|
|
return false;
|
|
}
|
|
model.DEPTID = group.SALEDEPTID;
|
|
var dept = db.BAS_SALESDEPARTMENT.FirstOrDefault(p => p.SALEDEPTID == group.SALEDEPTID);
|
|
if (dept == null)
|
|
{
|
|
errors.Add("部门有误!");
|
|
return false;
|
|
}
|
|
model.COMPANYID = dept.COMPANYID;
|
|
|
|
db.BAS_INNERUSERGROUP.Add(model);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
#endregion
|
|
|
|
#region 修改
|
|
/// <summary>
|
|
/// 修改数据
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public bool Update(ref ValidationErrors errors, WX.CRM.Model.Entity.BAS_INNERUSERGROUP model)
|
|
{
|
|
try
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
db.Configuration.ValidateOnSaveEnabled = false;
|
|
WX.CRM.Model.Entity.BAS_INNERUSERGROUP entry = db.BAS_INNERUSERGROUP.FirstOrDefault(m => m.INNERUSERID == model.INNERUSERID);
|
|
if (entry == null)
|
|
return false;
|
|
//entry.DEPTID = model.DEPTID;
|
|
entry.GID = model.GID;
|
|
entry.UTIME = DateTime.Now;
|
|
entry.UPDATEUSER = model.UPDATEUSER;
|
|
|
|
var dept = db.BAS_SALESDEPARTMENT.FirstOrDefault(p => p.SALEDEPTID == entry.DEPTID);
|
|
if (dept == null)
|
|
{
|
|
errors.Add("部门有误!");
|
|
return false;
|
|
}
|
|
entry.COMPANYID = dept.COMPANYID;
|
|
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
#endregion
|
|
|
|
#region 获取实体
|
|
/// <summary>
|
|
/// 获取实体
|
|
/// </summary>
|
|
/// <param name="inneruserId"></param>
|
|
/// <returns></returns>
|
|
public WX.CRM.Model.Entity.BAS_INNERUSERGROUP GetModel(decimal inneruserId)
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
return db.BAS_INNERUSERGROUP.FirstOrDefault(m => m.INNERUSERID == inneruserId);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public bool Save(ref ValidationErrors errors, WX.CRM.Model.Entity.BAS_INNERUSERGROUP model)
|
|
{
|
|
try
|
|
{
|
|
WX.CRM.Model.Entity.BAS_INNERUSERGROUP entry = GetModel(model.INNERUSERID);
|
|
if (entry == null || entry.INNERUSERID == 0)
|
|
return Create(ref errors, model);
|
|
else
|
|
return Update(ref errors, model);
|
|
}
|
|
catch (Exception ex) { errors.Add(ex.Message); return false; }
|
|
}
|
|
|
|
|
|
public List<BAS_INNERUSERGROUP> GetList()
|
|
{
|
|
using (crmContext db = new crmContext())
|
|
{
|
|
return db.BAS_INNERUSERGROUP.ToList();
|
|
}
|
|
}
|
|
|
|
public List<BAS_INNERUSERGROUP> GetList(Expression<Func<BAS_INNERUSERGROUP, bool>> where)
|
|
{
|
|
using (var db = new crmContext())
|
|
{
|
|
return db.BAS_INNERUSERGROUP.Where(where).ToList();
|
|
}
|
|
}
|
|
}
|
|
}
|