public async Task <ActionResult> DeleteProductionDateFromOrderProductAddress(DeleteProductionDateFromOrderProductAddressViewModel model) { OrderProductAddressProductionDate orderProductAddressProductionDate = await context.OrderProductAddressProductionDates .FindAsync(model.OrderProductAddress.OrderProduct.Order.Id, model.OrderProductAddress.OrderProduct.Product.Id, model.OrderProductAddress.Address.Id, model.ProductionDate); if (orderProductAddressProductionDate == null) { return(HttpNotFound()); } context.OrderProductAddressProductionDates.Remove(orderProductAddressProductionDate); try { await context.SaveChangesAsync(); } catch (Exception ex) { string errorMessage = ex.Message; while (ex != null) { errorMessage = ex.Message; ex = ex.InnerException; } ModelState.AddModelError("", errorMessage); return(View(model)); } return(RedirectToAction(nameof(Details), new { orderId = orderProductAddressProductionDate.OrderId, productId = orderProductAddressProductionDate.ProductId, addressId = orderProductAddressProductionDate.AddressId })); }
public async Task <ActionResult> DeleteProductionDateFromOrderProductAddress(int?orderId, int?productId, int?addressId, DateTime?productionDate) { if (orderId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (productId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (addressId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (productionDate == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OrderProductAddress orderProductAddress = await context.OrderProductAddresses .Include(opa => opa.OrderProduct.Order) .Include(opa => opa.OrderProduct.Product) .Include(opa => opa.Address) .FirstOrDefaultAsync(opa => opa.OrderId == orderId && opa.ProductId == productId && opa.AddressId == addressId); if (orderProductAddress == null) { return(HttpNotFound()); } DeleteProductionDateFromOrderProductAddressViewModel model = new DeleteProductionDateFromOrderProductAddressViewModel(orderProductAddress, productionDate.Value); return(View(model)); }