public ResponseModelBase <RoleOutput> Update(RoleUpdateInput entity)
        {
            var roleEntity = Mapper.Map <Role>(entity);
            var result     = _roleService.Update(roleEntity);
            var roleOutput = Mapper.Map <RoleOutput>(result);

            return(new ResponseModelBase <RoleOutput>().OkResult(roleOutput, result.Validations.ErrorMessages));
        }
Esempio n. 2
0
        public ActionResult Update(RoleUpdateInput input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.ModelState.ToJsonResult());
            }
            AcDomain.Handle(input.ToCommand(AcSession));

            return(this.JsonResult(new ResponseData {
                success = true, id = input.Id
            }));
        }
Esempio n. 3
0
        /// <summary>
        /// 角色更新
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <bool> RoleUpdate(int id, RoleUpdateInput input)
        {
            var dbRole = await _roleRep.Select.IncludeMany(r => r.UserRoles)
                         .Where(x => !x.IsDeleted && x.Id == id)
                         .ToOneAsync();

            if (dbRole == null)
            {
                throw new Exception("未找到角色,请检查是否为当前租户的角色或角色是否启用");
            }
            {
                var res = Mapper.Map(input, dbRole);
                await _roleRep.UpdateAsync(res);

                var userIds = dbRole.UserRoles.Select(x => x.UserId);
                if (input.UserIds.Any())
                {
                    var(needAdd, needRemove) = AddAndRemove(input.UserIds, userIds);
                    var userRoleRep = UnitOfWork.GetRepository <UserRole>();
                    var userRole    = needAdd.Select(userId => new UserRole()
                    {
                        RoleId = res.Id, UserId = userId
                    }).ToList();
                    if (userRole.Any())
                    {
                        await userRoleRep.InsertAsync(userRole);
                    }
                    userRole.Clear();
                    userRole.AddRange(needRemove.Select(userId => new UserRole()
                    {
                        RoleId = res.Id, UserId = userId
                    }));
                    if (userRole.Any())
                    {
                        await userRoleRep.DeleteAsync(userRole);
                    }
                }
                try
                {
                    UnitOfWork.Commit();
                    return(true);
                }
                catch (Exception e)
                {
                    Logger.LogError(e.ToString());
                    UnitOfWork.Rollback();
                    return(false);
                }
            }
        }
Esempio n. 4
0
        public async Task <IResponseOutput> UpdateAsync(RoleUpdateInput input)
        {
            if (!(input?.Id > 0))
            {
                return(ResponseOutput.NotOk());
            }

            var entity = await _roleRepository.GetAsync(input.Id);

            if (!(entity?.Id > 0))
            {
                return(ResponseOutput.NotOk("½ÇÉ«²»´æÔÚ£¡"));
            }

            _mapper.Map(input, entity);
            await _roleRepository.UpdateAsync(entity);

            return(ResponseOutput.Ok());
        }
Esempio n. 5
0
        public async Task <IActionResult> UpdateRole([FromRoute] int id, [FromBody] RoleUpdateInput input)
        {
            if (input.Id != id)
            {
                return(BadRequest(Json(new { Error = "请求参数错误" })));
            }

            var role = await dbContext.Roles.FirstOrDefaultAsync(r => r.Id == id);

            if (role == null)
            {
                return(NotFound(Json(new { Error = "该角色不存在" })));
            }

            dbContext.Entry(role).CurrentValues.SetValues(input);
            await dbContext.SaveChangesAsync();

            return(new NoContentResult());
        }
Esempio n. 6
0
        public async Task <IResultModel> UpdateAsync(RoleUpdateInput input)
        {
            if (!(input?.Id > 0))
            {
                return(ResultModel.NotExists);
            }

            var entity = await _roleRepository.GetAsync(input.Id);

            if (!(entity?.Id > 0))
            {
                return(ResultModel.Failed("角色不存在!"));
            }
            _mapper.Map(input, entity);
            entity.ModifiedTime     = DateTime.UtcNow;
            entity.ModifiedUserId   = _user.Id;
            entity.ModifiedUserName = _user.Name;
            var result = await _roleRepository.UpdateAsync(entity);

            return(ResultModel.Result(result > 0));
        }
Esempio n. 7
0
 public async Task <IResultModel> Update([FromQuery] RoleUpdateInput input)
 {
     return(await _roleServices.UpdateAsync(input));
 }
 public ResponseModelBase <RoleOutput> Put([FromBody] RoleUpdateInput value)
 {
     return(_roleAppService.Update(value));
 }
Esempio n. 9
0
 public async Task <IActionResult> UpdateRolePage(int id, [FromBody] RoleUpdateInput input)
 {
     return(Ok(await _commonService.RoleUpdate(id, input)));
 }
Esempio n. 10
0
 public async Task <IResponseOutput> Update(RoleUpdateInput input)
 {
     return(await _roleServices.UpdateAsync(input));
 }
Esempio n. 11
0
        public ActionResult Update(RoleUpdateInput input)
        {
            if (!this.ModelState.IsValid)
            {
                return this.ModelState.ToJsonResult();
            }
            AcDomain.Handle(input.ToCommand(AcSession));

            return this.JsonResult(new ResponseData { success = true, id = input.Id });
        }