79 lines
3.0 KiB
C#
79 lines
3.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Air.Model;
|
|
using Air.Model.AirAdminViewModel;
|
|
using Mini.Common;
|
|
using Mini.Model;
|
|
using Mini.Model.Entity;
|
|
|
|
namespace Mini.Services.Bas
|
|
{
|
|
public class BasRoleRightResourceService : IBasRoleRightResourceService
|
|
{
|
|
private readonly IAdminRepository<Bas_RoleRightResource> _basRoleRightResourceRepository;
|
|
public BasRoleRightResourceService(IAdminRepository<Bas_RoleRightResource> basRoleRgihtResourceRepository)
|
|
{
|
|
this._basRoleRightResourceRepository = basRoleRgihtResourceRepository;
|
|
}
|
|
|
|
public object GetObjectByRoleId(int roleId)
|
|
{
|
|
object obj = (
|
|
from a in _basRoleRightResourceRepository.GetList(m => m.RoleId == roleId).ToList()
|
|
select new { id = a.RightId, toolValue = a.ToolBarvalue }
|
|
);
|
|
return obj;
|
|
}
|
|
|
|
public IList<Bas_RoleRightResource> GetRoleRightResourceByRoleId(int[] userRoleId)
|
|
{
|
|
return _basRoleRightResourceRepository.GetList(p => userRoleId.Contains(p.RoleId)).ToList();
|
|
}
|
|
|
|
public bool Save(int roleId, string rightIds, int createUser)
|
|
{
|
|
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 = _basRoleRightResourceRepository.GetList(m => m.RoleId == roleId).ToList();
|
|
Bas_RoleRightResource model = null;
|
|
|
|
foreach (var right in rightsAndButtons)
|
|
{
|
|
var entry = _basRoleRightResourceRepository.Get(m => m.RightId == right.rightId && m.RoleId == roleId);
|
|
if (entry == null)//没有数据
|
|
{
|
|
model = new Bas_RoleRightResource();
|
|
model.RoleId = roleId;
|
|
model.RightId = right.rightId;
|
|
model.ToolBarvalue = right.buttons;
|
|
model.CTime = DateTime.Now;
|
|
model.CreateUser = createUser;
|
|
_basRoleRightResourceRepository.Add(model);
|
|
}
|
|
else
|
|
{
|
|
if (!entry.ToolBarvalue.HasValue || (entry.ToolBarvalue.Value != right.buttons))
|
|
{
|
|
entry.ToolBarvalue = right.buttons;
|
|
bool x = _basRoleRightResourceRepository.Update(entry);
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
foreach (var entry in (from d in entryList where !rightIdList.Contains(d.RightId) select d))//将已经没有了的rightID数据删除
|
|
{
|
|
_basRoleRightResourceRepository.Delete(entry);
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|