136 lines
5.1 KiB
C#
136 lines
5.1 KiB
C#
using Air.Model.AirAdminViewModel;
|
|
using Mini.Common;
|
|
using Mini.Services.Bas;
|
|
using Mini.Web.WebHelper.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Mini.Web.WebHelper
|
|
{
|
|
public class InitRightsToData
|
|
{
|
|
private readonly IBasRightService _basRightService ;
|
|
private readonly IBasRightToolButtonService _basRightToolButtonService ;
|
|
public InitRightsToData(IBasRightService basRightService, IBasRightToolButtonService basRightToolButtonService)
|
|
{
|
|
this._basRightService = basRightService;
|
|
this._basRightToolButtonService = basRightToolButtonService;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 平台权限
|
|
/// </summary>
|
|
/// <param name="errors"></param>
|
|
/// <returns></returns>
|
|
public bool Insert(ref ValidationErrors errors)
|
|
{
|
|
List<InnerRight> initRights = InitRights.getInitRights();
|
|
//create Right
|
|
List<InnerRight> dataRights = (from m in _basRightService.GetList() select new InnerRight() { RightId = m.RightId, RightName = m.RName }).ToList();
|
|
var InsertRights = initRights.Except(dataRights, new InitRightComPare()).ToList();
|
|
var bas_rights = new List<Bas_RightModel>();
|
|
foreach (InnerRight innerright in InsertRights)
|
|
{
|
|
var right = new Bas_RightModel();
|
|
right.RightId = innerright.RightId;
|
|
right.RName = innerright.RightName;
|
|
right.CTime = DateTime.Now;
|
|
right.CreateUser = 10000;
|
|
bas_rights.Add(right);
|
|
}
|
|
if (bas_rights.Count > 0)
|
|
{
|
|
_basRightService.CreateList(bas_rights);
|
|
//if (!rightResult)
|
|
//{
|
|
// errors.Add("添加权限失败。");
|
|
// return false;
|
|
//}
|
|
}
|
|
//Tool Bar
|
|
var toolBarBtns = new List<ToolBarBtn>();
|
|
foreach (InnerRight inRight in initRights)
|
|
{
|
|
toolBarBtns.AddRange(inRight.ToolBars);
|
|
}
|
|
List<ToolBarBtn> entitys = (from m in _basRightToolButtonService.GetList()
|
|
select new ToolBarBtn()
|
|
{
|
|
RightId = m.RightId,
|
|
ToolBarId = m.ButtonId,
|
|
ToolBarName = m.ButtonName,
|
|
ToolBarCode = m.ButtonCode
|
|
}
|
|
).ToList();
|
|
List<ToolBarBtn> CreateToolBtn = toolBarBtns.Except(entitys, new InitToolBarComPare()).ToList();
|
|
List<ToolBarBtn> DeleteToolBtn = entitys.Except(toolBarBtns, new InitToolBarComPare()).ToList();
|
|
//create
|
|
var listToolButton = new List<Bas_RightToolButtonModel>();
|
|
foreach (ToolBarBtn btn in CreateToolBtn)
|
|
{
|
|
var Right_ToolButton = new Bas_RightToolButtonModel();
|
|
Right_ToolButton.RightId = btn.RightId;
|
|
Right_ToolButton.ButtonId = btn.ToolBarId;
|
|
Right_ToolButton.ButtonName = btn.ToolBarName;
|
|
Right_ToolButton.ButtonCode = btn.ToolBarCode;
|
|
listToolButton.Add(Right_ToolButton);
|
|
}
|
|
if (listToolButton.Count > 0)
|
|
{
|
|
_basRightToolButtonService.CreateList(listToolButton);
|
|
//if (!isOk)
|
|
//{
|
|
// errors.Add("添加toolbutton失败。");
|
|
// return false;
|
|
//}
|
|
}
|
|
//delete
|
|
foreach (ToolBarBtn btn in DeleteToolBtn)
|
|
{
|
|
var model = new Bas_RightToolButtonModel() { RightId = btn.RightId, ButtonId = btn.ToolBarId, ButtonName = btn.ToolBarName, ButtonCode = btn.ToolBarCode };
|
|
_basRightToolButtonService.Delete(model);
|
|
//if (!isOk)
|
|
//{
|
|
// errors.Add("删除toolbutton失败。");
|
|
// return false;
|
|
//}
|
|
}
|
|
return true;
|
|
//}
|
|
//catch (Exception ex)
|
|
//{
|
|
// string message = ex.Message;
|
|
// return false;
|
|
//}
|
|
}
|
|
|
|
|
|
public class InitRightComPare : IEqualityComparer<InnerRight>
|
|
{
|
|
public bool Equals(InnerRight x, InnerRight y)
|
|
{
|
|
return x.RightId == y.RightId;
|
|
}
|
|
public int GetHashCode(InnerRight obj)
|
|
{
|
|
return obj.RightId.GetHashCode();
|
|
}
|
|
}
|
|
|
|
public class InitToolBarComPare : IEqualityComparer<ToolBarBtn>
|
|
{
|
|
public bool Equals(ToolBarBtn x, ToolBarBtn y)
|
|
{
|
|
return x.RightId == y.RightId && x.ToolBarId == y.ToolBarId;
|
|
}
|
|
public int GetHashCode(ToolBarBtn obj)
|
|
{
|
|
return obj.ToolBarId.GetHashCode();
|
|
}
|
|
}
|
|
}
|
|
}
|