Example #1
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);
        }
Example #2
0
        public OrderCrtUpdRtnStatus CreateOrder(OrderCreate model)
        {
            OrderCrtUpdRtnStatus orderRtnStatus = new OrderCrtUpdRtnStatus
            {
                OrderHeaderCreated    = false,
                OrderAllDetailCreated = false,
                OrderId = 0
            };
            var entity =
                new OrderHeader()
            {
                CustId           = model.CustId,
                SlotId           = model.SlotId,
                MostWantedNotes  = model.MostWantedNotes,
                FreezerNotes     = model.FreezerNotes,
                ProduceNotes     = model.ProduceNotes,
                NonFoodNotes     = model.NonFoodNotes,
                Deliver          = model.Deliver,
                PullStartedAt    = null,
                PullStartedBy    = null,
                OrderCompletedAt = null,
                CreateBy         = _userId,
                CreatedAt        = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.OrderHeaders.Add(entity);

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

                orderRtnStatus.OrderHeaderCreated = true;
                orderRtnStatus.OrderId            = entity.OrderId;

                // Assume all OrderDetail records will be written - 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.Quantity > 0)
                                {
                                    var orderDetail =
                                        new OrderDetailCreate()
                                    {
                                        OrderId        = orderRtnStatus.OrderId,
                                        ItemId         = itm.ItemId,
                                        Quantity       = itm.Quantity,
                                        QuantityBefore = itm.Quantity,
                                        Filled         = false
                                    };

                                    if (!orderDetailService.CreateOrderDetail(orderDetail))
                                    {
                                        orderRtnStatus.OrderAllDetailCreated = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(orderRtnStatus);
        }
Example #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);
        }
Example #4
0
        public List <OrderDetailCategory> GetOrderDetailByOrderId(int id, string userId, bool shortList)
        {
            List <OrderDetailCategory> catDtlList = new List <OrderDetailCategory>();

            var catService = new CategoryService(userId);

            var newCategoryList = catService.GetCategories().OrderBy(o => o.CategoryName);

            foreach (CareModels.Catagories.CategoryList cat in newCategoryList)
            {
                List <OrderDetailSubCat> subCatDtlList = new List <OrderDetailSubCat>();
                var subCatService = new SubCatService(userId);

                bool subCatAdded   = false;
                var  newSubCatList = subCatService.GetSubCatsByCatId(cat.CategoryId);
                foreach (CareModels.SubCategories.SubCatListShort subCat in newSubCatList)
                {
                    List <OrderDetailItem> itemDtl = new List <OrderDetailItem>();
                    var itemService = new ItemService(userId);

                    var  newItemList = itemService.GetItemsBySubCatId(subCat.SubCatId);
                    bool itemAdded   = false;
                    foreach (CareModels.Items.ItemListShort itm in newItemList)
                    {
                        //OrderDetailItem snglItemDtl = new OrderDetailItem();
                        var orderDetailService = new OrderDetailService(userId);

                        var newItemDtl = orderDetailService.GetOrderDetailByOrderIdAndItemId(id, itm.ItemId);

                        if ((shortList && newItemDtl.ItemId > 0) || !shortList)
                        {
                            OrderDetailItem itmDtl = new OrderDetailItem
                            {
                                OrderDetailId  = newItemDtl.OrderDetailId,
                                ItemId         = itm.ItemId,
                                ItemName       = itm.ItemName,
                                AisleNumber    = itm.AisleNumber,
                                MaxAllowed     = itm.MaxAllowed,
                                PointCost      = itm.PointCost,
                                Quantity       = newItemDtl.Quantity,
                                QuantityBefore = newItemDtl.Quantity,
                                Pulled         = newItemDtl.Pulled,
                                PulledBefore   = newItemDtl.Pulled
                            };
                            itemDtl.Add(itmDtl);
                            itemAdded = true;
                        }
                    }
                    if (itemAdded)
                    {
                        OrderDetailSubCat dtlSubCat = new OrderDetailSubCat
                        {
                            SubCatId            = subCat.SubCatId,
                            CategoryId          = cat.CategoryId,
                            SubCatName          = subCat.SubCatName,
                            SubCatMaxAllowed    = subCat.SubCatMaxAllowed,
                            OrderDetailItemList = itemDtl
                        };
                        subCatDtlList.Add(dtlSubCat);
                        subCatAdded = true;
                    }
                }
                if (subCatAdded)
                {
                    OrderDetailCategory dtlCat = new OrderDetailCategory
                    {
                        CategoryId            = cat.CategoryId,
                        CategoryName          = cat.CategoryName,
                        OrderDetailSubCatList = subCatDtlList
                    };
                    catDtlList.Add(dtlCat);
                }
            }

            return(catDtlList);
        }