public async Task <BaseApiResponse> SetGender(SetGenderRequest request) { request.CheckNotNull(nameof(request)); TryInitUserModel(); if (!"男,女,保密".IsIncludeItem(request.Gender)) { return(new BaseApiResponse { Code = 400, Message = "性别参数错误,非: 男/女/保密" }); } //更新 var command = new UpdateGenderCommand(request.Gender) { AggregateRootId = _user.Id }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } //更新缓存 _user.Gender = request.Gender; _apiSession.UpdateUserInfo(_user.Id.ToString(), _user); return(new BaseApiResponse()); }
public async Task <BaseApiResponse> SetGender([FromBody] SetGenderRequest request) { request.CheckNotNull(nameof(request)); var currentAccount = _contextService.GetCurrentAccount(HttpContext); if (!"男,女,保密".IsIncludeItem(request.Gender)) { return(new BaseApiResponse { Code = 400, Message = "性别参数错误,非: 男/女/保密" }); } //更新 var command = new UpdateGenderCommand(request.Gender) { AggregateRootId = currentAccount.UserId.ToGuid() }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } return(new BaseApiResponse()); }
public async Task <IActionResult> Put(int id, UpdateGenderCommand command) { if (id != command.Id) { return(BadRequest()); } return(Ok(await _mediator.Send(command))); }
public async Task <ActionResult <Result> > UpdateGender([FromBody] UpdateGenderCommand command) { var result = await Mediator.Send(command); if (!result.Succeeded) { return(BadRequest(result)); } return(Ok(result)); }
public ICommandResult Handle(UpdateGenderCommand command) { Gender gender = new Gender(command.Id, command.Title, command.Description); AddNotifications(gender.Notifications); if (Invalid) { return(new CommandResult(false, "Por favor, verifique se todos os campos estão preenchidos corretamente!", Notifications)); } bool result = _repository.Update(gender); if (!result) { return(new CommandResult(false, "Ocorreu um erro ao modificar o gênero!", Notifications)); } return(new CommandResult(true, "Gênero modificado com sucesso!")); }
public ICommandResult Update([FromBody] UpdateGenderCommand command) { return(_handler.Handle(command)); }
public void Handle(ICommandContext context, UpdateGenderCommand command) { context.Get <User>(command.AggregateRootId).UpdateGender(command.Gender); }