public async Task <ActionResult> Edit(EditOrderProductAddressProductionDateSizeViewModel model) { if (!ModelState.IsValid) { return(View(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()); } orderProductAddressProductionDateSize.Quantity = model.Quantity; context.Entry(orderProductAddressProductionDateSize).State = EntityState.Modified; 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, sizeId = orderProductAddressProductionDateSize.SizeId })); }
public async Task <ActionResult> Edit(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)); } OrderProductAddressProductionDateSize orderProductAddressProductionDateSize = await context.OrderProductAddressProductionDateSizes .Include(opapds => opapds.OrderProductAddressProductionDate.OrderProductAddress.OrderProduct.Order) .Include(opapds => opapds.OrderProductAddressProductionDate.OrderProductAddress.OrderProduct.Product) .Include(opapds => opapds.OrderProductAddressProductionDate.OrderProductAddress.Address) .Include(opapds => opapds.Size) .FirstOrDefaultAsync(opapds => opapds.OrderId == orderId && opapds.ProductId == productId && opapds.AddressId == addressId && opapds.ProductionDate == productionDate && opapds.SizeId == sizeId); if (orderProductAddressProductionDateSize == null) { return(HttpNotFound()); } EditOrderProductAddressProductionDateSizeViewModel model = new EditOrderProductAddressProductionDateSizeViewModel(); model.OrderProductAddressProductionDate = new OrderProductAddressProductionDateViewModel(orderProductAddressProductionDateSize.OrderProductAddressProductionDate); model.Size = new SizeViewModel(orderProductAddressProductionDateSize.Size); model.Quantity = orderProductAddressProductionDateSize.Quantity; 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 })); }
private List <SelectListItem> GetAvailableSizes(OrderProductAddressProductionDate orderProductAddressProductionDate, int?sizeId = null) { List <SelectListItem> availableSizes = new List <SelectListItem>(); if (context.Sizes.Any()) { foreach (var size in context.Sizes .Include(s => s.OrderProductAddressSizes) .Include(s => s.OrderProductAddressProductionDateSizes)) { OrderProductAddressSize orderProductAddressSize = size.OrderProductAddressSizes .FirstOrDefault(opas => opas.OrderId == orderProductAddressProductionDate.OrderId && opas.ProductId == orderProductAddressProductionDate.ProductId && opas.AddressId == orderProductAddressProductionDate.AddressId && opas.SizeId == size.Id); OrderProductAddressProductionDateSize orderProductAddressProductionDateSize = size.OrderProductAddressProductionDateSizes .FirstOrDefault(opapds => opapds.OrderId == orderProductAddressProductionDate.OrderId && opapds.ProductId == orderProductAddressProductionDate.ProductId && opapds.AddressId == orderProductAddressProductionDate.AddressId && opapds.ProductionDate == orderProductAddressProductionDate.ProductionDate && opapds.SizeId == size.Id); if (orderProductAddressSize != null && orderProductAddressProductionDateSize == null) { availableSizes.Add(new SelectListItem { Value = size.Id.ToString(), Text = size.Name, Selected = size.Id == sizeId }); } } } return(availableSizes); }
public OrderProductAddressProductionDateSizeViewModel(OrderProductAddressProductionDateSize orderProductAddressProductionDateSize) { OrderProductAddressProductionDate = new OrderProductAddressProductionDateViewModel(orderProductAddressProductionDateSize.OrderProductAddressProductionDate); Size = new SizeViewModel(orderProductAddressProductionDateSize.Size); Quantity = orderProductAddressProductionDateSize.Quantity; }