예제 #1
0
        public OrderItem(ItemOrdered itemOrdered, decimal price, int quantity)
        {
            this.ItemOrdered = itemOrdered;

            this.Price    = price;
            this.Quantity = quantity;
        }
예제 #2
0
 private void UpdateGrandTotal()
 {
     if (ItemOrdered.Count() != 0 || ItemOrdered != null)
     {
         GrandTotal = ItemOrdered.Sum(item => item.TotalAmount);
     }
 }
예제 #3
0
        private void AddNewOrder(ItemOfMenu itemOrder, Table tableOrder, int numberUnit)
        {
            Order       newestOrder   = new Order(tableOrder);
            ItemOrdered tempItemOrder = new ItemOrdered(itemOrder, numberUnit);

            newestOrder.OrderDetail.Add(tempItemOrder);
            _shopOrder.OrderHistoryOfShop.ListOrders.Add(newestOrder);
        }
 internal void AmazonPlaceOrder(Order order)
 {
     foreach (var item in Mystock)
     {
         if (order.Name == item)
         {
             ItemOrdered?.Invoke(order);
         }
     }
 }
예제 #5
0
        public override async Task <ActionResult <CreateOrderResponse> > HandleAsync(CreateOrderRequest request, CancellationToken cancellationToken = default)
        {
            var response = new CreateOrderResponse(request.CorrelationId());

            if (request.Items.Count <= 0)
            {
                return(BadRequest("Items can't less than 1"));
            }

            var itemsSpecification = new ItemFilterSpecification(request.Items.Select(i => i.ItemId).ToArray());
            var items = await _itemRepository.ListAsync(itemsSpecification);

            if (items.Count <= 0)
            {
                return(BadRequest("Items doesn't exists"));
            }

            var orderedItems = items.Select(orderedItem =>
            {
                var item        = items.First(c => c.Id == orderedItem.Id);
                var units       = request.Items.FirstOrDefault(i => i.ItemId == item.Id).Units;
                var itemOrdered = new ItemOrdered(orderedItem.Id, orderedItem.Name, orderedItem.Description, orderedItem.PictureUri);
                var orderItem   = new OrderItem(itemOrdered, item.Price, units);

                return(orderItem);
            }).ToList();

            var order = new Order(request.CustomerUsername, orderedItems, request.Comment);
            await _orderRepository.AddAsync(order);

            response.Order = new OrderDto
            {
                CustomerUsername = order.CustomerId,
                Comment          = order.Comment,
                OrderDate        = order.OrderDate,
                TotalPrice       = order.GetTotalPrice()
            };

            foreach (var item in order.OrderItems)
            {
                response.Order.Items.Add(new ItemDto
                {
                    Id          = item.Id,
                    Description = item.OrderedItem.Description,
                    Name        = item.OrderedItem.Name,
                    PictureUri  = item.OrderedItem.PictureUri,
                    Price       = item.UnitPrice
                });
            }

            return(response);
        }
예제 #6
0
        public async Task CreateOrderAsync(string basketId, Address shippingAddress)
        {
            var basket = await _basketRepository.FindOneAsync(x => x.Id == ObjectId.Parse(basketId));

            //Guard.Against.NullBasket(basketId, basket);
            var items = new List <ItemOrdered>();

            foreach (var item in basket.Items)
            {
                //var catalogItem = _itemRepository.FindOne(x => x.SecondaryId == item.SecondaryId);
                var itemOrdered = new ItemOrdered(item.StoreId, item.SecondaryId, item.Name, _uriComposer.ComposePicUri(item.PictureUri), item.Price, item.Amount);
                //var orderItem = new OrderItem(itemOrdered, item.Price, item.Amount);
                items.Add(itemOrdered);
            }
            var order = new Order(basket.BuyerId, basket.StoreId, shippingAddress, items);

            await _orderRepository.InsertOneAsync(order);
        }
예제 #7
0
        public void OrderDrinksOrFoods(ItemOfMenu itemOrder, Table tableOrder, int numberUnit = 1)
        {
            int indexOrder = LastIndexOrderOfTable(tableOrder.TableNumber);

            if (indexOrder != -1)
            {
                Order newestOrder = _shopOrder.OrderHistoryOfShop.ListOrders[indexOrder];
                if (!newestOrder.IsPaid)
                {
                    string choice = string.Empty;
                    do
                    {
                        Console.Write($"Table {tableOrder.TableNumber} is using. Do you want to add more {itemOrder.Name} to this table? (Y/N): ");
                        choice = Console.ReadLine().Trim();
                    } while (choice == "" || (choice != "Y" && choice != "y" && choice != "N" && choice != "N"));
                    if (choice == "N" || choice == "n")
                    {
                        return;
                    }
                    int index = IsItemExistsInOrderDetail(newestOrder, itemOrder.Name);
                    if (index != -1)
                    {
                        newestOrder.OrderDetail[index].Quantity += numberUnit;
                    }
                    else
                    {
                        ItemOrdered tempItemOrder = new ItemOrdered(itemOrder, numberUnit);
                        newestOrder.OrderDetail.Add(tempItemOrder);
                    }
                }
                else
                {
                    AddNewOrder(itemOrder, tableOrder, numberUnit);
                }
            }
            else
            {
                AddNewOrder(itemOrder, tableOrder, numberUnit);
            }
        }
예제 #8
0
 public OrderItem(ItemOrdered item, decimal pricePerUnit, int units)
 {
     OrderedItem = item;
     UnitPrice   = pricePerUnit;
     Units       = units;
 }
예제 #9
0
        public void RetrieveResponses(FormCollection collection)
        {
            List <QuestVal>   questvals  = new List <QuestVal>();
            List <ItemCounts> icounts    = new List <ItemCounts>();
            List <string>     shownItems = new List <string>();
            List <string>     setKeyIDs  = new List <string>();
            List <string>     QuestionsShown;

            //Request.Form
            try
            {
                QuestionsShown = Regex.Split(Request.Form["SectionLayout"].ToString(), ",").ToList();
            }
            catch
            {
                return;
            }
            string setKey = "";

            foreach (string key in Request.Form.Keys)
            {
                if (key.StartsWith("SPQuestion_") && !key.Contains("_ddl") && !key.Contains("_mddl"))
                {
                    QuestVal QV     = new QuestVal();
                    var      value  = collection[key];
                    string   Qindex = Regex.Split(key, "_")[1];
                    QV.QuestionID = Qindex;
                    QV.Response   = (string)value;

                    if (Request.Form.AllKeys.Contains(key + "_ddl"))
                    {
                        QV.DisplayResponse = collection[key + "_ddl"];
                    }

                    if (Request.Form.AllKeys.Contains(key + "_mddl"))
                    {
                        QV.Response        = QV.Response.Replace(",", "~");
                        QV.DisplayResponse = collection[key + "_mddl"];
                    }

                    questvals.Add(QV);

                    int listloc = 0;

                    foreach (string qid in QuestionsShown)
                    {
                        if (qid == QV.QuestionID)
                        {
                            QuestionsShown.RemoveAt(listloc);
                            break;
                        }
                        listloc++;
                    }
                }

                if (key.StartsWith("SPsetKey_"))
                {
                    string val = collection[key];
                    string cid = key.Remove(0, 9);
                    setKeyIDs.Add(cid);
                }

                if (key.StartsWith("SPShownItemCollection_"))
                {
                    string collectItems = collection[key];

                    shownItems.AddRange(Regex.Split(collectItems, "~~").ToList());
                }

                if (key.StartsWith("SPselectItemValues"))
                {
                    string thevalues    = collection[key];
                    string itemSelector = Regex.Split(key, "_")[2];
                    string ind          = Regex.Split(key, "_")[1];
                    if (thevalues != "~NoActivity~")
                    {
                        if (thevalues.StartsWith("~~"))
                        {
                            thevalues = thevalues.Remove(0, 2);
                        }
                        List <string> selectedVals = Regex.Split(thevalues, "~~").ToList();
                        foreach (string item in selectedVals)
                        {
                            ItemCounts IC = new ItemCounts();
                            IC.itemCode     = item;
                            IC.itemQuantity = 1;
                            IC.ownerOIS     = itemSelector;
                            icounts.Add(IC);
                        }
                        string collectItemsx = collection["SPSelectItemCollection_" + ind + "_" + itemSelector];

                        shownItems.AddRange(Regex.Split(collectItemsx, "~~").ToList());
                    }
                }
                if (key.StartsWith("SPitemcheck_"))
                {
                    string     itemSelector = Regex.Split(key, "_")[2];
                    string     itemCode     = key.Remove(0, 12 + itemSelector.Length + 3);
                    string     retval       = collection[key];
                    Int32      quant        = (retval == "on") ? 1 : 0;
                    ItemCounts IC           = new ItemCounts();
                    IC.itemCode     = itemCode;
                    IC.itemQuantity = quant;
                    IC.ownerOIS     = itemSelector;
                    icounts.Add(IC);
                }
                if (key.StartsWith("SPitemquant_"))
                {
                    string     itemSelector = Regex.Split(key, "_")[2];
                    string     itemCode     = key.Remove(0, 12 + itemSelector.Length + 3);
                    Int32      quant        = Convert.ToInt32(collection[key]);
                    ItemCounts IC           = new ItemCounts();
                    IC.itemCode     = itemCode;
                    IC.itemQuantity = quant;
                    IC.ownerOIS     = itemSelector;
                    icounts.Add(IC);
                }

                if (key == "SP_Notes")
                {
                    collection[key] = collection[key].Replace("\r", "");
                    collection[key] = collection[key].Replace("\n", "");
                    SessionManager.StoreContactNotes(HttpContext.Session, collection[key]);
                }
            }

            foreach (string qid in QuestionsShown)
            {
                QuestVal QV = new QuestVal();
                QV.QuestionID = qid;
                QV.Response   = "";
                questvals.Add(QV);
            }

            foreach (string item in shownItems)
            {
                bool foundit = false;
                foreach (ItemCounts iC in icounts)
                {
                    if (item == iC.itemCode)
                    {
                        foundit = true;
                        break;
                    }
                }
                if (!foundit)
                {
                    ItemCounts IC = new ItemCounts();
                    IC.itemCode     = item;
                    IC.itemQuantity = 0;
                    icounts.Add(IC);
                }
            }

            List <ItemOrdered> iOrd = new List <ItemOrdered>();

            foreach (ItemCounts iC in icounts)
            {
                ItemOrdered io = new ItemOrdered();
                io.ItemCode     = iC.itemCode;
                io.ItemQuantity = iC.itemQuantity;
                io.setKey       = (setKeyIDs.Exists(item => item == iC.ownerOIS)) ? true : false;
                io.oiOwner      = Convert.ToInt32(iC.ownerOIS);
                iOrd.Add(io);
            }


            SessionManager.AddUpdateOrderedItems(iOrd, HttpContext.Session);

            if (questvals.Count > 0)
            {
                SessionManager.AddUpdateQuestions(questvals, HttpContext.Session);
            }
        }
예제 #10
0
        public static bool AddUpdateOrderItem(ItemOrdered Item, HttpSessionStateBase Session)
        {
            List <ItemOrdered> Items = (List <ItemOrdered>)Session["ItemsOrdered"];

            int foundindex   = -1;
            int currentcount = 0;

            if (Items != null)
            {
                foreach (ItemOrdered IO2 in Items)
                {
                    if (Item.ItemCode == IO2.ItemCode)
                    {
                        foundindex = currentcount;
                        break;
                    }
                    currentcount++;
                }
            }
            else
            {
                Items = new List <ItemOrdered>();
            }

            if (foundindex >= 0)
            {
                ItemOrdered IOS = Items[foundindex];
                IOS.ItemQuantity = Item.ItemQuantity;

                Items.RemoveAt(foundindex);

                if (IOS.ItemQuantity > 0)
                {
                    Items.Add(IOS);

                    if (IOS.setKey)
                    {
                        List <string> KeyList = Regex.Split(IOS.SetKeys, ",").ToList();
                        SetItemKeys(Session, KeyList, "I");
                    }
                }
                StoreItemsOrdered(Session, Items);

                //Session["ItemsOrdered"] = Items;

                return(true);
            }

            try
            {
                if (Item.ItemQuantity == 0)
                {
                    return(true);
                }

                ScreenViewer.API.ItemController IC = new API.ItemController();
                var             actionResult       = IC.GetScriptItemByCode(Item.ItemCode);
                var             response           = actionResult as OkNegotiatedContentResult <Data.ScriptItem>;
                Data.ScriptItem SI = response.Content;

                ItemOrdered newitem = new ItemOrdered();

                newitem.ItemCode     = SI.ItemCode;
                newitem.Category     = SI.ItemCategory;
                newitem.SubCategory  = SI.ItemSubCategory;
                newitem.ItemDesc     = SI.ItemDesc;
                newitem.ItemName     = SI.ItemName;
                newitem.ItemPrice    = (decimal)SI.ItemPrice;
                newitem.ItemQuantity = Item.ItemQuantity;
                newitem.ItemShipping = (decimal)SI.ItemShippingPrice;
                newitem.setKey       = Item.setKey;
                //newitem.SetKeys = SI.ItemSetKeys; ??
                newitem.oiOwner = Item.oiOwner;
                Items.Add(newitem);

                StoreItemsOrdered(Session, Items);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #11
0
 public OrderItem(ItemOrdered itemOrdered, decimal unitPrice, int units)
 {
     ItemOrdered = itemOrdered;
     UnitPrice   = unitPrice;
     Units       = units;
 }
예제 #12
0
        public async Task <Order> CreateOrderAsync(string buyerEmail, int deliveryMethodId, string basketId,
                                                   string shippingAddress)
        {
            // get basket from repo
            var basket = await _basketRepo.GetBasketAsync(basketId);

            // get items from the product and part repo
            var items = new List <OrderItem>();

            foreach (var item in basket.ProductItems)
            {
                var spec        = new ProductWithPhotosSpecification(item.Id);
                var productItem = await _unitOfWork.Repository <Product>().GetEntityWithSpecAsync(spec);

                var itemOrdered = new ItemOrdered(productItem.Id, productItem.Name,
                                                  productItem.Photos.FirstOrDefault(x => x.IsMain).Url);
                var orderItem = new OrderItem(itemOrdered, productItem.Price, item.Quantity);
                items.Add(orderItem);
            }
            foreach (var item in basket.PartItems)
            {
                var spec     = new PartsSpecification(item.Id);
                var partItem = await _unitOfWork.Repository <Part>().GetEntityWithSpecAsync(spec);

                var itemOrdered = new ItemOrdered(partItem.Id, partItem.Name,
                                                  partItem.Photos.FirstOrDefault(x => x.IsMain).Url);
                var orderItem = new OrderItem(itemOrdered, partItem.Price, item.Quantity);
                items.Add(orderItem);
            }

            //get delivery method from repo
            var deliveryMethod = await _unitOfWork.Repository <DeliveryMethod>().GetByIdAsync(deliveryMethodId);

            // calc subtotal
            var subtotal = items.Sum(item => item.Price * item.Quantity);

            //check to see if order exists
            var orderSpec      = new OrderByPaymentIntentIdSpecification(basket.PaymentIntentId);
            var exisitingOrder = await _unitOfWork.Repository <Order>().GetEntityWithSpecAsync(orderSpec);

            if (exisitingOrder != null)
            {
                _unitOfWork.Repository <Order>().Delete(exisitingOrder);
                await _paymentService.CreateOrUpdatePaymentIntent(basket.PaymentIntentId);
            }

            // create order
            var order = new Order(items, buyerEmail, shippingAddress, deliveryMethod, subtotal,
                                  basket.PaymentIntentId);

            _unitOfWork.Repository <Order>().Add(order);

            // TODO: save to db
            var result = await _unitOfWork.Complete();

            if (result <= 0)
            {
                return(null);
            }



            // return order
            return(order);
        }