public async Task <ActionResult> DeleteSizeFromOrderProductAddress(int?orderId, int?productId, int?addressId, 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 (sizeId == 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()); } Size size = await context.Sizes.FindAsync(sizeId); if (size == null) { return(HttpNotFound()); } DeleteSizeFromOrderProductAddressViewModel model = new DeleteSizeFromOrderProductAddressViewModel(orderProductAddress, size); return(View(model)); }
public async Task <ActionResult> DeleteSizeFromOrderProductAddress(DeleteSizeFromOrderProductAddressViewModel model) { OrderProductAddressSize orderProductAddressSize = await context.OrderProductAddressSizes .FindAsync(model.OrderProductAddress.OrderProduct.Order.Id, model.OrderProductAddress.OrderProduct.Product.Id, model.OrderProductAddress.Address.Id, model.Size.Id); if (orderProductAddressSize == null) { return(HttpNotFound()); } context.OrderProductAddressSizes.Remove(orderProductAddressSize); 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 = orderProductAddressSize.OrderId, productId = orderProductAddressSize.ProductId, addressId = orderProductAddressSize.AddressId })); }