public IActionResult Delete(Guid id, IFormCollection collection) { try { // TODO: Add delete logic here _expenseRepo.Delete(id); return(RedirectToAction(nameof(Index)).WithSuccess("Supprimer", "vous avez supprimé avec succès ")); } catch (SupprimerException e) { return(View().WithDanger("ERREUR", e.Message)); } }
public Result Delete(Expenses Expenses) { var result = new Result(); try { ExpensesService ExpensesService = new ExpensesService(); ExpensesService.Delete(Expenses); result.IsSuccess = true; } catch (Exception exception) { result.IsSuccess = false; result.ExceptionInfo = exception; } return(result); }
public void DeleteExpenseWithCommentsShouldDeleteExpenseAndComments() { var options = new DbContextOptionsBuilder <ExpensesDbContext>() .UseInMemoryDatabase(databaseName: nameof(DeleteExpenseWithCommentsShouldDeleteExpenseAndComments)) .Options; using (var context = new ExpensesDbContext(options)) { var expensesService = new ExpensesService(context); var expected = new ExpensePostModel() { Description = "Variable", Type = "5", Location = "Sibiu", Date = Convert.ToDateTime("2019-05-05T11:11:11"), Currency = "USD", Sum = 555.77, Comments = new List <Comment>() { new Comment { Important = true, Text = "Very important expense", Owner = null } }, }; var actual = expensesService.Create(expected, null); var afterDelete = expensesService.Delete(actual.Id); int numberOfCommentsInDb = context.Comments.CountAsync().Result; var resultExpense = context.Expenses.Find(actual.Id); Assert.IsNotNull(afterDelete); Assert.IsNull(resultExpense); Assert.AreEqual(0, numberOfCommentsInDb); } }
public async Task <ActionResult> DeleteConfirmed(int id) { await _service.Delete(id); return(RedirectToAction("Index")); }