public async Task <IActionResult> Put(Guid?id, [FromBody] ValueViewModel vm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!id.HasValue || id == Guid.Empty || vm == null || vm.Version == null) { return(CreateInvalidRequestResult()); } var updateCommand = new UpdateValueCommand { Id = id.GetValueOrDefault(), Version = vm.Version.Value.GetValueOrDefault(), UpdateNameCmd = vm.Name != null ? new UpdateNameChildCmd(vm.Name.Value) : null, UpdateValueCmd = vm.Value != null ? new UpdateValueChildCmd(vm.Value.Value) : null, // NOTE: Let the user not modify the code directly, // TODO: We should provide an alternative way to modify the value code //UpdateCodeCmd = vm.Code != null ? new UpdateCodeChildCmd(vm.Code.Value) : null, }; var result = await _mediator.Send(updateCommand); if (result.Success) { var updatedVm = ToViewModel(result.Model); return(Ok(updatedVm)); } else { return(CreateBadRequestResult(result)); } }
public async Task Put(int id, [FromBody] string value) { var updateValueCommand = new UpdateValueCommand() { Id = id, Value = value }; await _commandDispatcher.DispatchAsync(updateValueCommand); }
public async Task <IActionResult> Update(int id, [FromBody] UpdateValueCommand command) { await _mediator.Dispatch <UpdateValueCommand.WithId>(_mapper.Map <UpdateValueCommand.WithId>(command).With(_ => _.Id = id)); return(NoContent()); }