110 lines
4.0 KiB
C#
110 lines
4.0 KiB
C#
using BLL.Helper;
|
|
using CRM.Core.Model.Entity;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using WX.CRM.Common;
|
|
|
|
namespace CRM.Core.BLL.Base
|
|
{
|
|
public class BAS_ROLERIGHTRESOURCE_BL
|
|
{
|
|
public List<BAS_ROLERIGHTRESOURCE> GetRoleRightResourceByRoleId(int[] RoleId)
|
|
{
|
|
using (zxdContext db = new zxdContext())
|
|
{
|
|
return db.BAS_ROLERIGHTRESOURCE.Where(p => RoleId.Contains(p.ROLEID)).ToList();
|
|
}
|
|
}
|
|
|
|
public List<BAS_ROLERIGHTRESOURCE> GetRoleRightResourceByRoleId(int roleId)
|
|
{
|
|
return GetRoleRightResourceByRoleId(new int[] { roleId });
|
|
}
|
|
|
|
public bool Save(int roleId, string rightIds, decimal createUser)
|
|
{
|
|
try
|
|
{
|
|
using (var db = new zxdContext())
|
|
{
|
|
var rightsAndButtons = new List<RightAndButton>();
|
|
if (!string.IsNullOrEmpty(rightIds))
|
|
{
|
|
rightsAndButtons = Utility.JSONToObject<List<RightAndButton>>(rightIds);
|
|
}
|
|
string[] rightIdList = rightsAndButtons.Select(p => p.rightId).ToArray();
|
|
var entryList = db.BAS_ROLERIGHTRESOURCE.Where(m => m.ROLEID == roleId).ToList();
|
|
BAS_ROLERIGHTRESOURCE model = null;
|
|
|
|
foreach (var right in rightsAndButtons)
|
|
{
|
|
var entry = entryList.Where(m => m.RIGHTID == right.rightId).FirstOrDefault();
|
|
if (entry == null)//没有数据
|
|
{
|
|
model = new BAS_ROLERIGHTRESOURCE
|
|
{
|
|
ROLEID = roleId,
|
|
RIGHTID = right.rightId,
|
|
TOOLBARVALUE = right.buttons,
|
|
CTIME = DateTime.Now,
|
|
CREATEUSER = createUser
|
|
};
|
|
db.BAS_ROLERIGHTRESOURCE.Add(model);
|
|
}
|
|
else
|
|
{
|
|
if (!entry.TOOLBARVALUE.HasValue || (entry.TOOLBARVALUE.Value != right.buttons))
|
|
{
|
|
entry.TOOLBARVALUE = right.buttons;
|
|
}
|
|
}
|
|
}
|
|
foreach (var entry in (from d in entryList where !rightIdList.Contains(d.RIGHTID) select d))//将已经没有了的rightID数据删除
|
|
{
|
|
db.BAS_ROLERIGHTRESOURCE.Remove(entry);
|
|
}
|
|
return db.SaveChanges() > 0;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
public IList<IDictionary<string, object>> QueryData(string sql,int t=0){
|
|
IList<IDictionary<string, object>> reslut = new List<IDictionary<string, object>>();
|
|
try
|
|
{
|
|
MySqlHelper hl = new MySqlHelper();
|
|
if (t == 0)
|
|
{
|
|
reslut = hl.QueryDicList(sql,null);
|
|
}
|
|
else
|
|
{
|
|
var i = hl.ExecuteNonQuery(sql, null);
|
|
Dictionary<string, object> r = new Dictionary<string, object>();
|
|
r.Add("结果", "成功!");
|
|
reslut.Add(r);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Dictionary<string, object> r = new Dictionary<string, object>();
|
|
r.Add("结果", "失败!");
|
|
r.Add("错误", ex.Message);
|
|
reslut.Add(r);
|
|
}
|
|
return reslut;
|
|
}
|
|
|
|
}
|
|
|
|
public class RightAndButton
|
|
{
|
|
public string rightId { get; set; }
|
|
public decimal buttons { get; set; }
|
|
}
|
|
}
|