114 lines
3.6 KiB
C#
114 lines
3.6 KiB
C#
using System;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using WX.CRM.BLL.Util;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Base;
|
|
|
|
namespace WX.CRM.BLL.Base
|
|
{
|
|
public class BAS_INNERDEPARTMENT_BL : IBAS_INNERDEPARTMENT, IBAS_INNERDEPARTMENT_Q
|
|
{
|
|
#region 新增
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
/// <param name="errors"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.BAS_INNERDEPARTMENT model)
|
|
{
|
|
try
|
|
{
|
|
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
model.DEPTID = new SEQUENCES_BL().Seq_base_get();
|
|
db.BAS_INNERDEPARTMENT.Add(model);
|
|
return db.SaveChanges().GetResult();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
/// <param name="errors"></param>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public bool Delete(ref ValidationErrors errors, decimal id)
|
|
{
|
|
try
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
WX.CRM.Model.Entity.BAS_INNERDEPARTMENT entry = db.BAS_INNERDEPARTMENT.FirstOrDefault(m => m.DEPTID == id);
|
|
if (entry != null)
|
|
db.BAS_INNERDEPARTMENT.Remove(entry);
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 修改数据
|
|
/// <summary>
|
|
/// 修改数据
|
|
/// </summary>
|
|
/// <param name="errors"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public bool Update(ref ValidationErrors errors, WX.CRM.Model.Entity.BAS_INNERDEPARTMENT model)
|
|
{
|
|
try
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
db.BAS_INNERDEPARTMENT.Attach(model);
|
|
db.Entry<WX.CRM.Model.Entity.BAS_INNERDEPARTMENT>(model).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public WX.CRM.Model.Entity.BAS_INNERDEPARTMENT GetModel(decimal id)
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
WX.CRM.Model.Entity.BAS_INNERDEPARTMENT entry = db.BAS_INNERDEPARTMENT.FirstOrDefault(m => m.DEPTID == id);
|
|
return entry;
|
|
}
|
|
}
|
|
public WX.CRM.Model.Entity.BAS_INNERDEPARTMENT GetModel(string innerDeptCode)
|
|
{
|
|
using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext())
|
|
{
|
|
WX.CRM.Model.Entity.BAS_INNERDEPARTMENT entry = db.BAS_INNERDEPARTMENT.FirstOrDefault(m => m.INNERDEPTCODE == innerDeptCode);
|
|
return entry;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|