Exemplo n.º 1
0
        /// <summary>
        /// Lấy danh sách thao tác theo User
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>

        public List <ModuleMenuDTO> GetListOperationOfUser(long userId)
        {
            var listOperation    = new List <ModuleMenuDTO>();
            var listRoleIdOfUser = (from userRole in _userRoleRepository.GetAllAsQueryable().Where(x => x.UserId == userId)
                                    join role in _roleRepository.GetAllAsQueryable()
                                    on userRole.RoleId equals role.Id
                                    select role).Select(x => x.Id).ToList();

            if (listRoleIdOfUser != null && listRoleIdOfUser.Any())
            {
                listOperation = (from operationId in _roleOperationRepository.GetAllAsQueryable().Where(x => x.IsAccess == 1 && listRoleIdOfUser.Contains(x.RoleId)).Select(x => x.OperationId)
                                 join operation in _operationRepository.GetAllAsQueryable() on operationId equals operation.Id
                                 group operation by operation.ModuleId into groupMenu
                                 join module in _moduleRepository.GetAllAsQueryable() on groupMenu.Key equals module.Id
                                 select new ModuleMenuDTO()
                {
                    Id = groupMenu.Key,
                    ClassCss = module.ClassCss,
                    Code = module.Code,
                    CreatedBy = module.CreatedBy,
                    Icon = module.Icon,
                    CreatedDate = module.CreatedDate,
                    IsShow = module.IsShow,
                    Link = module.Link,
                    Name = module.Name,
                    Order = module.Order,
                    StyleCss = module.StyleCss,
                    UpdatedBy = module.UpdatedBy,
                    UpdatedDate = module.UpdatedDate,
                    ListOperation = groupMenu.OrderBy(x => x.Order).ThenBy(x => x.Id).ToList()
                })
                                .ToList();
            }
            return(listOperation);
        }