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 新增 /// /// 新增 /// /// /// /// 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 删除 /// /// 删除 /// /// /// /// 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 修改数据 /// /// 修改数据 /// /// /// /// 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(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; } } } }