using System; using System.Collections.Generic; 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_ROLE_BL : IBAS_ROLE, IBAS_ROLE_Q { #region 新增 /// /// 新增 /// /// /// /// public bool Create(ref ValidationErrors errors, WX.CRM.Model.Entity.BAS_ROLE model) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { model.ROLEID = new SEQUENCES_BL().Seq_base_get(); db.BAS_ROLE.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_ROLE entry = db.BAS_ROLE.FirstOrDefault(m => m.ROLEID == id); if (entry == null) { errors.Add("数据已删除!"); return false; } db.BAS_ROLE.Remove(entry); return db.SaveChanges().GetResult(); } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion #region 修改数据 /// /// 修改数据 /// /// /// /// public bool Update(ref ValidationErrors errors, WX.CRM.Model.Entity.BAS_ROLE model) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { WX.CRM.Model.Entity.BAS_ROLE entry = db.BAS_ROLE.FirstOrDefault(m => m.ROLEID == model.ROLEID); entry.RNAME = model.RNAME; entry.SORTID = model.SORTID; entry.UPDATEUSER = model.UPDATEUSER; entry.UTIME = model.UTIME; entry.CODE = model.CODE; entry.REMARK = model.REMARK; db.SaveChanges(); //db.bas_role.Attach(model); //db.Entry(model).State = EntityState.Modified; return true; } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion #region 获取单个实体 /// /// 获取单个实体 /// /// /// public WX.CRM.Model.Entity.BAS_ROLE GetModel(decimal id) { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return db.BAS_ROLE.SingleOrDefault(m => m.ROLEID == id); } } #endregion #region 获取列表 /// /// 获取列表 /// /// public List GetList() { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return db.BAS_ROLE.OrderBy(m => m.SORTID).ToList(); } } #endregion #region 批量修改顺序 /// /// 批量修改顺序 /// /// 角色ID /// 排序号 /// public bool Sort(ref ValidationErrors errors, string roleIdStr, string sortIdStr) { try { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { string[] roleIds = roleIdStr.Split(','); string[] sortIds = sortIdStr.Split(','); for (int i = 0; i < roleIds.Length; i++) { decimal roleid = Convert.ToDecimal(roleIds[i]); decimal sortid = Convert.ToDecimal(sortIds[i]); WX.CRM.Model.Entity.BAS_ROLE model = db.BAS_ROLE.FirstOrDefault(m => m.ROLEID == roleid); if (model != null) model.SORTID = sortid; } db.SaveChanges(); return true; } } catch (Exception ex) { errors.Add(ex.Message); return false; } } #endregion #region 获取角色树形 /// /// 获取角色树形 /// /// public object GetRoleTree() { using (WX.CRM.Model.Entity.crmContext db = new WX.CRM.Model.Entity.crmContext()) { return (from model in db.BAS_ROLE.OrderBy(m => m.SORTID) select new { id = model.ROLEID, text = model.RNAME, iconCls = "icon-man" }).ToList(); } } #endregion } }