public async Task <ActionResult> DeletePackage(int id) { var result = await declarationRepository.Delete(id); if (result) { return(Json(new { success = true })); } return(Json(new { success = false })); }
public async Task <ActionResult> DeleteAdmin(string id) { var user = await userManager.FindByIdAsync(id); var balances = await balanceRepository.GetAll(); //Delete user balance var userBalance = balances.FirstOrDefault(b => b.UserId == user.Id); if (userBalance != null) { var deleteBalanceResult = await balanceRepository.Delete(userBalance.Id); } //Delete user orders var orders = await orderRepository.GetAll(); var userOrders = orders.Where(o => o.UserId == user.Id).ToList(); if (userOrders.Count > 0) { foreach (var order in userOrders) { await orderRepository.Delete(order.Id); } } //Delete user declares var declares = await declarationRepository.GetAll(); var userDeclares = declares.Where(o => o.UserId == user.Id).ToList(); if (userDeclares.Count > 0) { foreach (var declaration in userDeclares) { await declarationRepository.Delete(declaration.Id); } } //Delete user var result = await userManager.DeleteAsync(user); if (result.Succeeded) { return(Json(new { success = true, message = "Deleted !" })); } return(Json(new { success = false, message = "Error appeared !" })); }