public Task <bool> Handle(UpdateExpenseCommand command) { var entity = _expenseRepository.Get(command.Id); if (entity == null) { AddNotification("despesa", "Despesa não localizada"); return(Task.FromResult(false)); } entity.Update( new Description(command.Description), _favoredRepository.Get(command.Favored), new Money(command.Value) ); AddNotifications(entity); if (Invalid) { return(Task.FromResult(false)); } _expenseRepository.Update(entity); _uow.Commit(); return(Task.FromResult(true)); }
public async Task Update(string accountName, long id, [FromBody] UpdateExpenseCommand cmd) { accountName = Uri.UnescapeDataString(accountName); cmd.AccountName = accountName; cmd.UserName = this.currentUser.Name; cmd.Id = id; await this.mediator.Send(cmd); }
public async Task <IActionResult> UpdateExpense([FromRoute] long id, [FromBody] UpdateExpenseCommand command) { command.Id = id; var response = await _mediator.Send <ResultResponse <ExpenseDTO> >(command); if (response.IsSuccess) { return(Ok(response.Result)); } return(BadRequest(response.ErrorMessage)); }
public async Task <IActionResult> Update(int id, [FromBody] UpdateExpenseCommand command) { var result = await _handler.Handle(command); if (!_handler.Valid) { return(BadRequest(_handler.Notifications)); } return(Ok(result)); }
public async Task <IActionResult> PatchExpense(string id, UpdateExpenseCommand expense) { if (id != expense.Id) { return(BadRequest()); } await _mediator.Send(expense); return(NoContent()); }
public async Task <IActionResult> UpdateExpense(int expenseId, ExpenseForUpdateDto expenseForUpdateDto) { var command = new UpdateExpenseCommand(expenseId, expenseForUpdateDto); var result = await Mediator.Send(command); if (result) { return(NoContent()); } throw new Exception($"Update Expense {expenseId} failed on save."); }
public async Task <ActionResult> UpdateExpense(int id, ExpenseCreateUpdateDto dto) { var command = new UpdateExpenseCommand(id, dto); var result = await _mediator.Send(command); if (result == null) { return(NotFound()); } else if (result == false) { return(BadRequest()); } return(NoContent()); }
public async Task <ActionResult <Guid> > UpdateExpense([FromRoute] Guid id, [FromBody] UpdateExpenseCommand updateExpenseCommand, CancellationToken cancellationToken) { var userId = User.GetClaim("id"); if (userId == null) { return(Forbid()); } updateExpenseCommand.Id = id; updateExpenseCommand.OwnerId = new Guid(userId.Value); var result = await _mediator.Send(updateExpenseCommand, cancellationToken); return(Ok(result)); }
public async Task <ICommandResult> Handle(UpdateExpenseCommand command) { ICommandResult result = null; try { var expense = await _expenseRepository.GetById(command.Id); command.Adapt(expense); await _expenseRepository.Update(expense); return(new MessageResult("Item updated")); } catch (Exception ex) { AddNotification("UpdateExpenseCommand", ex.Message); } return(result); }
public async Task <IActionResult> Put(UpdateExpenseCommand command, CancellationToken cancellationToken) { var result = await _mediator.Send(command, cancellationToken); return(Ok(result)); }
public async Task <ActionResult> Update(UpdateExpenseCommand command) { await Mediator.Send(command); return(NoContent()); }