Example #1
0
        public async Task <RESTResult> GetDigitalAssets(UserDataTransferObject currentUser, int pageIndex, int pageSize)
        {
            RESTResult result = new RESTResult();
            IEnumerable <DigitalAssetItem> digitalAssetItems = null;

            if (currentUser.Roles.Where(item => item.Level == Common.RoleLevelStatus.SupperAdmin).Count() > 0)
            {
                digitalAssetItems = (await _digitalAssetRepository.GetAllListAsync()).Skip((pageIndex - 1) * pageSize).Take(pageSize);
            }
            var userDepartmentList = await _userDepartmentReposiotry.GetAllListAsync(o => o.UserId == currentUser.Id);

            if (userDepartmentList.Count > 0)
            {
                var users = await _userDepartmentReposiotry.GetAllListAsync(o => o.DepartmentId == userDepartmentList.First().DepartmentId);

                List <Guid> userIds = new List <Guid>();
                foreach (var user in users)
                {
                    userIds.Add(user.UserId);
                }

                digitalAssetItems = _digitalAssetRepository.GetAllList(d => d.IsDeleted == false && d.Status == DigitalAssetItemStatus.Public && userIds.Contains(d.CreateByUserId)).Skip((pageIndex - 1) * pageSize).Take(pageSize);
            }

            result.Code = Common.RESTStatus.Success;
            result.Data = digitalAssetItems;

            return(result);
        }
Example #2
0
        public async Task <RESTResult> GetDepartmentsAsync(UserDataTransferObject currentUser, int pageIndex, int pageSize)
        {
            RESTResult result = new RESTResult {
                Code = RESTStatus.Success
            };

            if (currentUser.Roles.Where(item => item.Level.Equals(RoleLevelStatus.SupperAdmin)).Count() > 0)
            {
                var departmentList = await _departmentReposiotry.GetAllListAsync(item => item.IsDeleted.Equals(false));

                var pagingDepartmentList = departmentList.Skip(pageSize * (pageIndex - 1)).Take(pageSize);
                result.Data = pagingDepartmentList.Select(item =>
                {
                    var departmentDTO = Mapper.Map <Department, DepartmentDataTransferObject>(item);
                    return(departmentDTO);
                });
            }
            else
            {
                if (currentUser.Department != null)
                {
                    var departmentModel = await _departmentReposiotry.GetAllListAsync(item => item.Id.Equals(currentUser.Department.Id) && item.IsDeleted.Equals(false));

                    result.Data = departmentModel.Skip(pageSize * (pageIndex - 1)).Take(pageSize);
                }
                else
                {
                    result.Code = RESTStatus.NotData;
                }
            }
            return(result);
        }
Example #3
0
        public async Task <RESTResult> GetRoles(UserDataTransferObject currentUser, int pageIndex, int pageSize)
        {
            RESTResult result = new RESTResult {
                Code = RESTStatus.Success
            };
            List <RoleDataTransferObject> rolesDataobjects = new List <RoleDataTransferObject>();

            if (currentUser.Roles.Where(item => item.Level.Equals(RoleLevelStatus.SupperAdmin)).Count() > 0)
            {
                var roles = _roleRepository.GetAllList(item => item.IsDeleted.Equals(false) && !item.Level.Equals(RoleLevelStatus.SupperAdmin)).Skip(pageSize * (pageIndex - 1)).Take(pageSize);
                foreach (var role in roles)
                {
                    //TODO:Get role permissions
                    var roleDataObject  = Mapper.Map <Role, RoleDataTransferObject>(role);
                    var rolePermissions = await _rolePermissionRepository.GetAllListAsync(item => role.Id.Equals(item.RoleId));

                    var permissions = await _permissionRepository.GetAllListAsync(item => rolePermissions.Select(c => c.PermissionId).Contains(item.Id));

                    permissions.ForEach(item => roleDataObject.Permissions.Add(Mapper.Map <Permission, PermissionTransferDataObject>(item)));
                    rolesDataobjects.Add(roleDataObject);
                }
                result.Data = rolesDataobjects;
            }
            else
            {
                //Get curretnt role under the department.
                var roles = (await GetRolesWithCurrentUser(currentUser.Id.Value, currentUser.Department.Id.Value)).Where(c => c.Level.Equals(RoleLevelStatus.Other)).Skip(pageSize * (pageIndex - 1)).Take(pageSize);
                foreach (var role in roles)
                {
                    //TODO:Get role permissions
                    var roleDataObject  = Mapper.Map <Role, RoleDataTransferObject>(role);
                    var rolePermissions = await _rolePermissionRepository.GetAllListAsync(item => role.Id.Equals(item.RoleId));

                    var permissions = await _permissionRepository.GetAllListAsync(item => rolePermissions.Select(c => c.PermissionId).Contains(item.Id));

                    permissions.ForEach(item => roleDataObject.Permissions.Add(Mapper.Map <Permission, PermissionTransferDataObject>(item)));
                    rolesDataobjects.Add(roleDataObject);
                }
                result.Data = rolesDataobjects;
            }

            return(result);
        }
Example #4
0
        public async Task <RESTResult> GetUsers(UserDataTransferObject currentUser, int pageIndex, int pageSize)
        {
            RESTResult result = new RESTResult {
                Code = RESTStatus.Success
            };
            List <UserDataTransferObject> userDTOs = new List <UserDataTransferObject>();

            //TODO: Super admin
            if (currentUser.Roles.Where(item => item.Level.Equals(RoleLevelStatus.SupperAdmin)).Count() > 0)
            {
                var allUserCount = await _userRepository.CountAsync();

                var allUser = (await _userRepository.GetAllListAsync()).Take(pageIndex * pageSize).Skip(pageSize * (pageIndex - 1));
                allUser.ToList().ForEach(item => userDTOs.Add(Mapper.Map <User, UserDataTransferObject>(item)));
                result.Data = new { users = userDTOs, Count = allUserCount };
                return(result);
            }
            if (currentUser.Department == null || currentUser.Permissions == null)
            {
                result.Code = RESTStatus.NotData;
                return(result);
            }
            var allUserIds = await _userDepartmentReposiotry.GetAllListAsync(item => item.DepartmentId.Equals(currentUser.Department.Id));

            var userModels = _userRepository.GetAllList(item => allUserIds.Select(c => c.UserId).Contains(item.Id) && item.IsDeleted.Equals(false)).Take(pageIndex * pageSize).Skip(pageSize * (pageIndex - 1));

            //TODO:Mapping, DOT NOT USE THE .ToList()
            foreach (var item in userModels)
            {
                userDTOs.Add(Mapper.Map <User, UserDataTransferObject>(item));
            }
            var userCount = await _userRepository.CountAsync(item => item.IsDeleted.Equals(false));

            result.Data = new { users = userDTOs, Count = userCount };
            return(result);
        }
 public MimeoOAIdentity(UserDataTransferObject currentUser)
 {
     this.CurrentUser = currentUser;
 }