187 lines
6.0 KiB
C#
187 lines
6.0 KiB
C#
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 新增
|
|
/// <summary>
|
|
/// 新增
|
|
/// </summary>
|
|
/// <param name="errors"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
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 删除
|
|
/// <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_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 修改数据
|
|
/// <summary>
|
|
/// 修改数据
|
|
/// </summary>
|
|
/// <param name="errors"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
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<bas_role>(model).State = EntityState.Modified;
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
errors.Add(ex.Message);
|
|
return false;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 获取单个实体
|
|
/// <summary>
|
|
/// 获取单个实体
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
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 获取列表
|
|
/// <summary>
|
|
/// 获取列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<WX.CRM.Model.Entity.BAS_ROLE> 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 批量修改顺序
|
|
/// <summary>
|
|
/// 批量修改顺序
|
|
/// </summary>
|
|
/// <param name="roleIds">角色ID</param>
|
|
/// <param name="sortIds">排序号</param>
|
|
/// <returns></returns>
|
|
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 获取角色树形
|
|
/// <summary>
|
|
/// 获取角色树形
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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
|
|
}
|
|
}
|