public bool UpdateOrderDetail(OrderDetailUpdate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .OrderDetails
                    .Single(e => e.OrderDetailId == model.OrderDetailId);
                entity.ItemId   = model.ItemId;
                entity.Quantity = model.Quantity;
                entity.Filled   = model.Filled;

                bool success = true;
                try { ctx.SaveChanges(); }
                catch { success = false; }

                return(success);
            }
        }
Пример #2
0
        public OrderCrtUpdRtnStatus UpdatePulledItems(OrderHeaderDetail model, int orderId, bool isComplete)
        {
            OrderCrtUpdRtnStatus orderRtnStatus = new OrderCrtUpdRtnStatus
            {
                OrderHeaderCreated    = false,
                OrderAllDetailCreated = false,
                OrderId = 0
            };

            if (isComplete)
            {
                using (var ctx = new ApplicationDbContext())
                {
                    var entity =
                        ctx
                        .OrderHeaders
                        .Single(e => e.OrderId == model.OrderId);
                    entity.OrderCompletedAt = DateTimeOffset.Now;

                    try { ctx.SaveChanges(); }
                    catch { return(orderRtnStatus); }
                }
                orderRtnStatus.OrderHeaderCreated = true;
            }

            orderRtnStatus.OrderId = model.OrderId;

            // Assume all OrderDetail records will be created/updated/deleted - make false if any fail.
            orderRtnStatus.OrderAllDetailCreated = true;
            OrderDetailService orderDetailService = new OrderDetailService(_userId);

            // Add Order Detail
            foreach (var catagory in model.OrderDetailCategoryList)
            {
                foreach (var subCat in catagory.OrderDetailSubCatList)
                {
                    if (subCat.OrderDetailItemList != null)
                    {
                        foreach (var itm in subCat.OrderDetailItemList)
                        {
                            if (itm.Pulled != itm.PulledBefore)
                            {
                                // Marked as Pulled (or un-Pulled)
                                var orderDetail =
                                    new OrderDetailUpdate()
                                {
                                    OrderDetailId = itm.OrderDetailId,
                                    ItemId        = itm.ItemId,
                                    Quantity      = itm.Quantity,
                                    Filled        = itm.Pulled
                                };

                                if (!orderDetailService.UpdateOrderDetail(orderDetail))
                                {
                                    orderRtnStatus.OrderAllDetailCreated = false;
                                }
                            }
                        }
                    }
                }
            }
            return(orderRtnStatus);
        }
Пример #3
0
        public OrderCrtUpdRtnStatus UpdateOrder(OrderUpdate model)
        {
            OrderCrtUpdRtnStatus orderRtnStatus = new OrderCrtUpdRtnStatus
            {
                OrderHeaderCreated    = false,
                OrderAllDetailCreated = false,
                OrderId = 0
            };

            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .OrderHeaders
                    .Single(e => e.OrderId == model.OrderId);
                entity.CustId           = model.CustId;
                entity.SlotId           = model.SlotId;
                entity.MostWantedNotes  = model.MostWantedNotes;
                entity.FreezerNotes     = model.FreezerNotes;
                entity.ProduceNotes     = model.ProduceNotes;
                entity.NonFoodNotes     = model.NonFoodNotes;
                entity.Deliver          = model.Deliver;
                entity.PullStartedAt    = null;
                entity.PullStartedBy    = null;
                entity.OrderCompletedAt = null;

                try { ctx.SaveChanges(); }
                catch { return(orderRtnStatus); }
            }
            orderRtnStatus.OrderHeaderCreated = true;

            orderRtnStatus.OrderId = model.OrderId;

            // Assume all OrderDetail records will be created/updated/deleted - make false if any fail.
            orderRtnStatus.OrderAllDetailCreated = true;
            OrderDetailService orderDetailService = new OrderDetailService(_userId);

            // Add/Update/Delete Order Detail
            foreach (var catagory in model.OrderDetailCategoryList)
            {
                foreach (var subCat in catagory.OrderDetailSubCatList)
                {
                    if (subCat.OrderDetailItemList != null)
                    {
                        foreach (var itm in subCat.OrderDetailItemList)
                        {
                            if (itm.Quantity != itm.QuantityBefore)
                            {
                                if (itm.Quantity > 0 && itm.QuantityBefore > 0)
                                {
                                    // Quantity changed
                                    var orderDetail =
                                        new OrderDetailUpdate()
                                    {
                                        OrderDetailId = itm.OrderDetailId,
                                        ItemId        = itm.ItemId,
                                        Quantity      = itm.Quantity,
                                        Filled        = false
                                    };

                                    if (!orderDetailService.UpdateOrderDetail(orderDetail))
                                    {
                                        orderRtnStatus.OrderAllDetailCreated = false;
                                    }
                                }
                                else if (itm.Quantity > 0)
                                {
                                    // Add Detail
                                    var orderDetail =
                                        new OrderDetailCreate()
                                    {
                                        OrderId  = orderRtnStatus.OrderId,
                                        ItemId   = itm.ItemId,
                                        Quantity = itm.Quantity,
                                        Filled   = false
                                    };

                                    if (!orderDetailService.CreateOrderDetail(orderDetail))
                                    {
                                        orderRtnStatus.OrderAllDetailCreated = false;
                                    }
                                }
                                else if (itm.QuantityBefore > 0)
                                {
                                    if (!orderDetailService.DeleteOrderDetail(itm.OrderDetailId))
                                    {
                                        orderRtnStatus.OrderAllDetailCreated = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(orderRtnStatus);
        }