public IActionResult DeleteExpenses([FromBody] int[] ids) { var isDeleted = _expenseRepository.DeleteExpenses(ids); if (isDeleted) { return(Ok()); } else { return(StatusCode(304)); } }
public IActionResult Delete(int id) { var users = _userRepository.GetAllUsers(); var expenseName = _expenseNameRepository.GetExpenseNameById(id); decimal sum = 0; decimal tookPart = 0; foreach (var expense in expenseName.Expenses) { sum += expense.Paid; tookPart++; } var usersToModify = new List <User>(); var toPay = sum / tookPart; foreach (var expense in expenseName.Expenses) { usersToModify.Add(new User() { Name = expense.User.Name, Paid = -(toPay - expense.Paid) }); } _userRepository.UpdateUsers(usersToModify); _expenseRepository.DeleteExpenses(expenseName.Expenses); _expenseNameRepository.DeleteExpenseName(expenseName); var viewModel = new IndexViewModel() { AllUsers = _userRepository.GetAllUsers(), Expenses = _expenseNameRepository.GetAllExpenses() }; return(View("~/Views/Home/Index.cshtml", viewModel)); }