public async Task <ActionResult> DeleteSizeFromOrderProductAddressProductionDate(int?orderId, int?productId, int?addressId, DateTime?productionDate, int?sizeId) { 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)); } if (sizeId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OrderProductAddressProductionDate orderProductAddressProductionDate = await context.OrderProductAddressProductionDates .Include(opapd => opapd.OrderProductAddress.OrderProduct.Order) .Include(opapd => opapd.OrderProductAddress.OrderProduct.Product) .Include(opapd => opapd.OrderProductAddress.Address) .FirstOrDefaultAsync(opapd => opapd.OrderId == orderId && opapd.ProductId == productId && opapd.AddressId == addressId && opapd.ProductionDate == productionDate); if (orderProductAddressProductionDate == null) { return(HttpNotFound()); } Size size = await context.Sizes.FindAsync(sizeId); if (size == null) { return(HttpNotFound()); } DeleteSizeFromOrderProductAddressProductionDateViewModel model = new DeleteSizeFromOrderProductAddressProductionDateViewModel(orderProductAddressProductionDate, size); return(View(model)); }
public async Task <ActionResult> DeleteSizeFromOrderProductAddressProductionDate(DeleteSizeFromOrderProductAddressProductionDateViewModel model) { OrderProductAddressProductionDateSize orderProductAddressProductionDateSize = await context.OrderProductAddressProductionDateSizes .FindAsync(model.OrderProductAddressProductionDate.OrderProductAddress.OrderProduct.Order.Id, model.OrderProductAddressProductionDate.OrderProductAddress.OrderProduct.Product.Id, model.OrderProductAddressProductionDate.OrderProductAddress.Address.Id, model.OrderProductAddressProductionDate.ProductionDate, model.Size.Id); if (orderProductAddressProductionDateSize == null) { return(HttpNotFound()); } context.OrderProductAddressProductionDateSizes.Remove(orderProductAddressProductionDateSize); 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 = orderProductAddressProductionDateSize.OrderId, productId = orderProductAddressProductionDateSize.ProductId, addressId = orderProductAddressProductionDateSize.AddressId, productionDate = orderProductAddressProductionDateSize.ProductionDate })); }