Пример #1
0
        public async Task <MenuAccountOuput> GetListMenuAccountAsync(string idAccount)
        {
            try
            {
                var listMenuGroud = await _context.MenuFunctionGroup.Where(c => c.Status == (int)AtRowStatus.Normal).AsNoTracking().ToListAsync();

                var listMenu = await _context.MenuFunctionSubGroup.Where(c => c.Status == (int)AtRowStatus.Normal).Select(c =>
                                                                                                                          new ListSubMenuFuntion
                {
                    IdMenuGroud = c.FK_MenuGroup,
                    NameGroup   = c.FK_MenuGroupNavigation.GroupName,

                    IdSubMenu   = c.Id,
                    NameSubName = c.SubGroupName,

                    MenuFunctions = c.MenuFunction.Where(c => c.Status == (int)AtRowStatus.Normal).Select(lc => new ListMenuFuntion
                    {
                        IdMenuFuntion   = lc.Id,
                        NameMenuFuntion = lc.Title,
                        IsCheck         = false
                    }).ToList()
                }).AsNoTracking()
                               .ToListAsync();

                var MenuFuntion = new MenuAccountOuput();
                MenuFuntion.ListMenuChucNang = new List <GroupMenuChucNang>();

                foreach (var itemGroud in listMenuGroud)
                {
                    var menuFuntion = new GroupMenuChucNang();
                    menuFuntion.IdMenuGroud  = itemGroud.Id;
                    menuFuntion.NameGroup    = itemGroud.GroupName;
                    menuFuntion.SubFunctions = listMenu.Where(c => c.IdMenuGroud == itemGroud.Id).ToList();
                    MenuFuntion.ListMenuChucNang.Add(menuFuntion);
                }

                var listID_MenuFuntionAccount = await _context.MenuFunction_Account
                                                .Where(c => c.FK_AccountObject == idAccount)
                                                .Select(c => c.FK_MenuFunction)
                                                .AsNoTracking()
                                                .ToListAsync();

                foreach (var item in listID_MenuFuntionAccount)
                {
                    foreach (var itemMenu in MenuFuntion.ListMenuChucNang)
                    {
                        foreach (var itemSub in itemMenu.SubFunctions)
                        {
                            foreach (var itemFun in itemSub.MenuFunctions)
                            {
                                if (item == itemFun.IdMenuFuntion)
                                {
                                    itemFun.IsCheck = true;
                                }
                            }
                        }
                    }
                }


                MenuFuntion.IdAccount = idAccount;
                return(MenuFuntion);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public async Task <MenuRoleOuput> GetListMenuRoleAsync(string idRole)
        {
            var listMenuGroud = await _context.MenuFunctionGroup.Where(c => c.Status == (int)AtRowStatus.Normal).AsNoTracking().ToListAsync();

            var listMenu = await _context.MenuFunctionSubGroup.Where(c => c.Status == (int)AtRowStatus.Normal).Select(c =>
                                                                                                                      new ListSubMenuFuntion
            {
                IdMenuGroud = c.FK_MenuGroup,
                NameGroup   = c.FK_MenuGroupNavigation.GroupName,

                IdSubMenu   = c.Id,
                NameSubName = c.SubGroupName,

                MenuFunctions = c.MenuFunction.Where(c => c.Status == (int)AtRowStatus.Normal).Select(lc => new ListMenuFuntion
                {
                    IdMenuFuntion   = lc.Id,
                    NameMenuFuntion = lc.Title,
                    IsCheck         = false
                }).ToList()
            }).AsNoTracking()
                           .ToListAsync();

            var MenuFuntion = new MenuRoleOuput();

            MenuFuntion.ListMenuChucNang = new List <GroupMenuChucNang>();

            foreach (var itemGroud in listMenuGroud)
            {
                var menuFuntion = new GroupMenuChucNang();
                menuFuntion.IdMenuGroud  = itemGroud.Id;
                menuFuntion.NameGroup    = itemGroud.GroupName;
                menuFuntion.SubFunctions = listMenu.Where(c => c.IdMenuGroud == itemGroud.Id).ToList();
                MenuFuntion.ListMenuChucNang.Add(menuFuntion);
            }

            var list_MenuFuntionRole = await _context.MenuFunction_Role
                                       .Where(c => c.FK_Role == idRole)
                                       .Select(c => c.FK_MenuFunction)
                                       .AsNoTracking()
                                       .ToListAsync();

            foreach (var item in list_MenuFuntionRole)
            {
                foreach (var itemMenu in MenuFuntion.ListMenuChucNang)
                {
                    foreach (var itemSub in itemMenu.SubFunctions)
                    {
                        foreach (var itemFun in itemSub.MenuFunctions)
                        {
                            if (item == itemFun.IdMenuFuntion)
                            {
                                itemFun.IsCheck = true;
                            }
                        }
                    }
                }
            }

            MenuFuntion.IdRole = idRole;

            var roleName = await _context.Role.FirstOrDefaultAsync(c => c.Id == idRole);

            MenuFuntion.NameRole = roleName.RoleName;

            return(MenuFuntion);
        }