public async Task <ActionResult> ListingDelete(int id) { var item = await _listingService.FindAsync(id); var orderQuery = await _orderService.Query(x => x.ListingID == id).SelectAsync(); // Delete item if no orders associated with it if (item.Orders.Count > 0) { var resultFailed = new { Success = false, Message = "You cannot delete item with orders! You can deactivate it instead." }; return(Json(resultFailed, JsonRequestBehavior.AllowGet)); } await _listingService.DeleteAsync(id); await _unitOfWorkAsync.SaveChangesAsync(); var result = new { Success = true, Message = "Your listing has been deleted." }; return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> ListingDelete(int id) { var item = await _listingService.FindAsync(id); var orderQuery = await _orderService.Query(x => x.ListingID == id).SelectAsync(); // Delete item if no orders associated with it if (item.Orders.Count > 0) { TempData[TempDataKeys.UserMessageAlertState] = "bg-danger"; TempData[TempDataKeys.UserMessage] = "[[[You cannot delete item with orders! You can deactivate it instead.]]]"; return(RedirectToAction("Listings")); } await _listingService.DeleteAsync(id); await _unitOfWorkAsync.SaveChangesAsync(); TempData[TempDataKeys.UserMessage] = "[[[The listing has been deleted.]]]"; return(RedirectToAction("Listings")); }