public async Task <ActionResult> DeleteSizeFromOrderProductAddressDelivery(int?orderId, int?productId, int?addressId, int?deliveryId, 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 (deliveryId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (sizeId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OrderProductAddressDelivery orderProductAddressDelivery = await context.OrderProductAddressDeliveries .Include(opad => opad.OrderProductAddress.OrderProduct.Order) .Include(opad => opad.OrderProductAddress.OrderProduct.Product) .Include(opad => opad.OrderProductAddress.Address) .FirstOrDefaultAsync(opad => opad.OrderId == orderId && opad.ProductId == productId && opad.AddressId == addressId && opad.DeliveryId == deliveryId); if (orderProductAddressDelivery == null) { return(HttpNotFound()); } Size size = await context.Sizes.FindAsync(sizeId); if (size == null) { return(HttpNotFound()); } DeleteSizeFromOrderProductAddressDeliveryViewModel model = new DeleteSizeFromOrderProductAddressDeliveryViewModel(orderProductAddressDelivery, size); return(View(model)); }
public async Task <ActionResult> DeleteSizeFromOrderProductAddressDelivery(DeleteSizeFromOrderProductAddressDeliveryViewModel model) { OrderProductAddressDeliverySize orderProductAddressDeliverySize = await context.OrderProductAddressDeliverySizes .FindAsync(model.OrderProductAddressDelivery.OrderProductAddress.OrderProduct.Order.Id, model.OrderProductAddressDelivery.OrderProductAddress.OrderProduct.Product.Id, model.OrderProductAddressDelivery.OrderProductAddress.Address.Id, model.OrderProductAddressDelivery.DeliveryId, model.Size.Id); if (orderProductAddressDeliverySize == null) { return(HttpNotFound()); } context.OrderProductAddressDeliverySizes.Remove(orderProductAddressDeliverySize); 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 = orderProductAddressDeliverySize.OrderId, productId = orderProductAddressDeliverySize.ProductId, addressId = orderProductAddressDeliverySize.AddressId, deliveryId = orderProductAddressDeliverySize.DeliveryId })); }