using MyCode.Project.Domain.Message.Response.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyCode.Project.Domain.Businesses.Menus
{
///
/// 菜单按钮选中
///
public class MenuButtonCheck
{
///
/// 页面按钮权限
///
public List> Page { get; set; } = new List>();
///
/// 分页列表按钮权限
///
public List> PageList { get; set; } = new List>();
///
/// 分页子列表按钮权限
///
public List> ChildrenList { get; set; } = new List>();
///
/// 初始化一个类型的实例
///
public MenuButtonCheck()
{
}
///
/// 初始化一个类型的实例
///
/// 菜单按钮
/// 是否加盟商
public MenuButtonCheck(MenuButton button, bool isCustomer)
{
if (button==null)
{
return;
}
if (button.Page.Any())
{
if (isCustomer)
{
button.Page = button.Page.Where(x => x.SysType == 0).ToList();
}
button.Page.ForEach(x =>
{
if (Page.All(y => y.Key != x.Name))
{
Page.Add(new KeyValuePair(x.Name, false));
}
});
}
if (button.PageList.Any())
{
if (isCustomer)
{
button.PageList = button.PageList.Where(x => x.SysType == 0).ToList();
}
button.PageList.ForEach(x =>
{
if (PageList.All(y => y.Key != x.Name))
{
PageList.Add(new KeyValuePair(x.Name, false));
}
});
}
if (button.ChildrenList.Any())
{
if (isCustomer)
{
button.ChildrenList = button.ChildrenList.Where(x => x.SysType == 0).ToList();
}
button.ChildrenList.ForEach(x =>
{
if (ChildrenList.All(y => y.Key != x.Name))
{
ChildrenList.Add(new KeyValuePair(x.Name, false));
}
});
}
//if (button.Page.Any())
//{
// button.Page.ForEach(x =>
// {
// if (Page.All(y => y.Key != x))
// {
// Page.Add(new KeyValuePair(x, false));
// }
// });
//}
//if (button.PageList.Any())
//{
// button.PageList.ForEach(x =>
// {
// if (PageList.All(y => y.Key != x))
// {
// PageList.Add(new KeyValuePair(x, false));
// }
// });
//}
//if (button.ChildrenList.Any())
//{
// button.ChildrenList.ForEach(x =>
// {
// if (ChildrenList.All(y => y.Key != x))
// {
// ChildrenList.Add(new KeyValuePair(x, false));
// }
// });
//}
}
///
/// 更新按钮
///
/// 菜单按钮
/// 是否加盟商
public void UpdateButton(MenuButton button, bool isCustomer)
{
if (button==null)
{
return;
}
if (button.Page.Any())
{
if (isCustomer)
{
button.Page = button.Page.Where(x => x.SysType == 0).ToList();
}
button.Page.ForEach(x =>
{
if (Page.All(y => y.Key != x.Name))
{
Page.Add(new KeyValuePair(x.Name, false));
}
});
}
if (button.PageList.Any())
{
if (isCustomer)
{
button.PageList = button.PageList.Where(x => x.SysType == 0).ToList();
}
button.PageList.ForEach(x =>
{
if (PageList.All(y => y.Key != x.Name))
{
PageList.Add(new KeyValuePair(x.Name, false));
}
});
}
if (button.ChildrenList.Any())
{
if (isCustomer)
{
button.ChildrenList = button.ChildrenList.Where(x => x.SysType == 0).ToList();
}
button.ChildrenList.ForEach(x =>
{
if (ChildrenList.All(y => y.Key != x.Name))
{
ChildrenList.Add(new KeyValuePair(x.Name, false));
}
});
}
//if (button.Page.Any())
//{
// button.Page.ForEach(x =>
// {
// if (Page.All(y => y.Key != x))
// {
// Page.Add(new KeyValuePair(x, false));
// }
// });
//}
//if (button.PageList.Any())
//{
// button.PageList.ForEach(x =>
// {
// if (PageList.All(y => y.Key != x))
// {
// PageList.Add(new KeyValuePair(x, false));
// }
// });
//}
//if (button.ChildrenList.Any())
//{
// button.ChildrenList.ForEach(x =>
// {
// if (ChildrenList.All(y => y.Key != x))
// {
// ChildrenList.Add(new KeyValuePair(x, false));
// }
// });
//}
}
///
/// 转换成菜单按钮
///
///
public MenuButtonView ToMenuButtonView()
{
MenuButtonView button = new MenuButtonView();
if (Page.Any())
{
button.Page = Page.Where(x => x.Value).Select(x => x.Key).ToList();
}
if (PageList.Any())
{
button.PageList = PageList.Where(x => x.Value).Select(x => x.Key).ToList();
}
if (ChildrenList.Any())
{
button.ChildrenList = ChildrenList.Where(x => x.Value).Select(x => x.Key).ToList();
}
return button;
}
}
}