コード例 #1
0
 public OrderProductAddressDeliverySizeViewModel(OrderProductAddressDeliverySize orderProductAddressDeliverySize)
 {
     OrderProductAddressDelivery = new OrderProductAddressDeliveryViewModel(orderProductAddressDeliverySize.OrderProductAddressDelivery);
     Size               = new SizeViewModel(orderProductAddressDeliverySize.Size);
     DeliveryQuantity   = orderProductAddressDeliverySize.DeliveryQuantity;
     AcceptanceQuantity = orderProductAddressDeliverySize.AcceptanceQuantity;
 }
コード例 #2
0
        public async Task <ActionResult> Edit(EditOrderProductAddressDeliverySizeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(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());
            }

            orderProductAddressDeliverySize.DeliveryQuantity   = model.DeliveryQuantity;
            orderProductAddressDeliverySize.AcceptanceQuantity = model.AcceptanceQuantity;

            context.Entry(orderProductAddressDeliverySize).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 = orderProductAddressDeliverySize.OrderId,
                productId = orderProductAddressDeliverySize.ProductId,
                addressId = orderProductAddressDeliverySize.AddressId,
                deliveryId = orderProductAddressDeliverySize.DeliveryId,
                sizeId = orderProductAddressDeliverySize.SizeId
            }));
        }
コード例 #3
0
        public async Task <ActionResult> Edit(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));
            }

            OrderProductAddressDeliverySize orderProductAddressDeliverySize = await context.OrderProductAddressDeliverySizes
                                                                              .Include(opads => opads.OrderProductAddressDelivery.OrderProductAddress.OrderProduct.Order)
                                                                              .Include(opads => opads.OrderProductAddressDelivery.OrderProductAddress.OrderProduct.Product)
                                                                              .Include(opads => opads.OrderProductAddressDelivery.OrderProductAddress.Address)
                                                                              .Include(opads => opads.Size)
                                                                              .FirstOrDefaultAsync(opads => opads.OrderId == orderId &&
                                                                                                   opads.ProductId == productId &&
                                                                                                   opads.AddressId == addressId &&
                                                                                                   opads.DeliveryId == deliveryId &&
                                                                                                   opads.SizeId == sizeId);

            if (orderProductAddressDeliverySize == null)
            {
                return(HttpNotFound());
            }

            EditOrderProductAddressDeliverySizeViewModel model = new EditOrderProductAddressDeliverySizeViewModel();

            model.OrderProductAddressDelivery = new OrderProductAddressDeliveryViewModel(orderProductAddressDeliverySize.OrderProductAddressDelivery);
            model.Size               = new SizeViewModel(orderProductAddressDeliverySize.Size);
            model.DeliveryQuantity   = orderProductAddressDeliverySize.DeliveryQuantity;
            model.AcceptanceQuantity = orderProductAddressDeliverySize.AcceptanceQuantity;

            return(View(model));
        }
コード例 #4
0
        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
            }));
        }
コード例 #5
0
        private List <SelectListItem> GetAvailableSizes(OrderProductAddressDelivery orderProductAddressDelivery, int?sizeId = null)
        {
            List <SelectListItem> availableSizes = new List <SelectListItem>();

            if (context.Sizes.Any())
            {
                foreach (var size in context.Sizes
                         .Include(s => s.OrderProductAddressProductionDateSizes)
                         .Include(s => s.OrderProductAddressDeliverySizes))
                {
                    var orderProductAddressProductionDateSizes = size.OrderProductAddressProductionDateSizes
                                                                 .Where(opapds => opapds.OrderId == orderProductAddressDelivery.OrderId &&
                                                                        opapds.ProductId == orderProductAddressDelivery.ProductId &&
                                                                        opapds.AddressId == orderProductAddressDelivery.AddressId &&
                                                                        opapds.SizeId == size.Id)
                                                                 .GroupBy(opapds => opapds.SizeId);

                    OrderProductAddressDeliverySize orderProductAddressDeliverySize = size.OrderProductAddressDeliverySizes
                                                                                      .FirstOrDefault(opads => opads.OrderId == orderProductAddressDelivery.OrderId &&
                                                                                                      opads.ProductId == orderProductAddressDelivery.ProductId &&
                                                                                                      opads.AddressId == orderProductAddressDelivery.AddressId &&
                                                                                                      opads.DeliveryId == orderProductAddressDelivery.DeliveryId &&
                                                                                                      opads.SizeId == size.Id);


                    if (orderProductAddressProductionDateSizes.Any() && orderProductAddressDeliverySize == null)
                    {
                        availableSizes.Add(new SelectListItem
                        {
                            Value    = size.Id.ToString(),
                            Text     = size.Name,
                            Selected = size.Id == sizeId
                        });
                    }
                }
            }

            return(availableSizes);
        }