public async Task DeleteExpense(string accountName, long id) { accountName = Uri.UnescapeDataString(accountName); var cmd = new DeleteExpenseCommand { AccountName = accountName, Id = id }; await this.mediator.Send(cmd); }
public async Task <IActionResult> DeleteExpense(string id) { var command = new DeleteExpenseCommand(id); var foundAndDeleted = await _mediator.Send(command); if (!foundAndDeleted) { return(NotFound()); } return(Ok()); }
public async Task <IActionResult> DeleteExpense(int expenseId) { var command = new DeleteExpenseCommand(expenseId); var result = await Mediator.Send(command); if (result) { return(NoContent()); } throw new Exception("Error deleting the expense."); }
public ActionResult Delete(int id) { var command = new DeleteExpenseCommand { ExpenseId = id }; var result = commandBus.Submit(command); DateTime startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1); DateTime endDate = startDate.AddMonths(1).AddDays(-1); var expenses = expenseRepository.GetMany(exp => exp.Date >= startDate && exp.Date <= endDate); return(PartialView("_ExpenseList", expenses)); }
public async Task <ActionResult> DeleteExpense(int id) { var command = new DeleteExpenseCommand(id); var result = await _mediator.Send(command); if (result == null) { return(NotFound()); } else if (result == false) { return(BadRequest()); } return(NoContent()); }
public void ExpenseDeleteTest() { using (var lifetime = container.BeginLifetimeScope()) { IExpenseRepository expenseRepository = lifetime.Resolve <IExpenseRepository>(); DefaultCommandBus commandBus = lifetime.Resolve <DefaultCommandBus>(); IMappingEngine mapper = lifetime.Resolve <IMappingEngine>(); Expense expense = expenseRepository.Get(c => c.Amount == 150); Assert.IsNotNull(expense, "Error: Expense was not found"); DeleteExpenseCommand command = mapper.Map <DeleteExpenseCommand>(expense); ICommandHandler <DeleteExpenseCommand> commnadHandler = lifetime.Resolve <ICommandHandler <DeleteExpenseCommand> >(); ICommandResult result = commandBus.Submit(command, commnadHandler); Assert.IsNotNull(result, "Error: Expense was not deleted"); Assert.IsTrue(result.Success, "Error: Expense was not deleted"); } }