Esempio n. 1
0
        public async Task <IResultModel> Query(AccountQueryModel model)
        {
            var result = new QueryResultModel <AccountEntity>
            {
                Rows  = await _accountRepository.Query(model),
                Total = model.TotalCount
            };

            foreach (var item in result.Rows)
            {
                var roles = await _accountRoleRepository.QueryRole(item.Id);

                item.Roles = roles.Select(r => new OptionResultModel {
                    Label = r.Name, Value = r.Id
                }).ToList();
            }

            return(ResultModel.Success(result));
        }
Esempio n. 2
0
        public async Task <IResultModel> Query(AccountQueryModel model)
        {
            var result = new QueryResultModel <AccountQueryResultModel>();
            var paging = model.Paging();
            var list   = await _accountRepository.Query(paging, model.UserName, model.Name, model.Phone, model.Email);


            result.Rows  = _mapper.Map <List <AccountQueryResultModel> >(list);
            result.Total = paging.TotalCount;

            Parallel.ForEach(result.Rows, async item =>
            {
                var roles  = await _accountRoleRepository.QueryRole(item.Id);
                item.Roles = roles.Select(r => new OptionResultModel {
                    Label = r.Name, Value = r.Id
                }).ToList();
            });

            return(ResultModel.Success(result));
        }
Esempio n. 3
0
        public async Task <IResultModel> Edit(Guid id)
        {
            var entity = await _repository.GetAsync(id);

            if (entity == null)
            {
                return(ResultModel.NotExists);
            }

            var model = _mapper.Map <UserUpdateModel>(entity);

            if (!model.DepartmentId.IsEmpty())
            {
                model.DeptFullPath = await _departmentService.GetFullPath(entity.DepartmentId);
            }

            var roles = await _accountRoleRepository.QueryRole(entity.AccountId);

            model.Roles = roles.Select(m => m.Id).ToList();

            return(ResultModel.Success(model));
        }
Esempio n. 4
0
        /// <summary>
        /// 账户编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IResultModel> EditAccount(int id)
        {
            var employee = await _repository.GetAsync(id);

            if (employee == null)
            {
                return(ResultModel.NotExists);
            }

            var accountTask = _accountRepository.GetAsync(employee.AccountId);
            var rolesTask   = _accountRoleRepository.QueryRole(employee.AccountId);

            var account = await accountTask;
            var roles   = await rolesTask;

            var model = new EmployeeAccountUpdateModel
            {
                Id       = id,
                UserName = account.UserName,
                Roles    = roles.Select(m => m.Id).ToList()
            };

            return(ResultModel.Success(model));
        }