Ejemplo n.º 1
0
        public decimal Dequeue()
        {
            decimal sum  = 0;
            var     cart = Queue.Dequeue();

            if (cart != null)
            {
                var check = new Check()
                {
                    SellerID   = Seller.SellerID,
                    Seller     = Seller,
                    CustomerID = cart.Customer.CustomerID,
                    Customer   = cart.Customer,
                    Created    = DateTime.Now
                };
                if (!IsModel)
                {
                    db.Checks.Add(check);
                    db.SaveChanges();
                }
                else
                {
                    check.CheckID = 0;
                }
                var sells = new List <Sell>();
                foreach (Product p in cart)
                {
                    if (p.Count > 0)
                    {
                        var sell = new Sell()
                        {
                            CheckOD   = check.CheckID,
                            Check     = check,
                            ProductID = p.ProductID,
                            Product   = p
                        };
                        sells.Add(sell);
                        if (!IsModel)
                        {
                            db.Sells.Add(sell);
                        }
                        p.Count--;
                        sum += p.Price;
                    }
                }
                if (!IsModel)
                {
                    db.SaveChanges();
                }
            }
            return(sum);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Извлечение корзин(товаров) из очереди
        /// </summary>
        public decimal Dequeue()
        {
            decimal sum = 0;

            if (Queue.Count == 0)
            {
                return(0);
            }

            var card = Queue.Dequeue();

            if (card != null)
            {
                var chek = new Check()
                {
                    SellerId   = Seller.SellerId,
                    Seller     = Seller,
                    CustomerId = card.Customer.CustomerId,
                    Customer   = card.Customer,
                    Created    = DateTime.Now
                };

                if (!IsModel)
                {
                    context.Checks.Add(chek);
                    context.SaveChanges();
                }
                else
                {
                    chek.CheckId = 0;
                }

                var sells = new List <Sell>();

                foreach (Product product in card)
                {
                    if (product.Count > 0)
                    {
                        var sell = new Sell()
                        {
                            CheckId   = chek.CheckId,
                            Check     = chek,
                            ProductId = product.ProductId,
                            Product   = product
                        };
                        sells.Add(sell);

                        if (!IsModel)
                        {
                            context.Sells.Add(sell);
                        }
                        product.Count--;
                        sum += product.Price;
                    }
                }

                chek.Price = sum;

                if (!IsModel)
                {
                    context.SaveChanges();
                }

                CheckClosed?.Invoke(this, chek);
            }
            return(sum);
        }
Ejemplo n.º 3
0
        public decimal Dequeue()
        {
            if (Queue.Count == 0)
            {
                return(0);
            }

            decimal fullPrice = 0;
            var     cart      = Queue.Dequeue();

            if (cart != null)
            {
                var check = new Check()
                {
                    SellerId   = Seller.SellerId,
                    Seller     = Seller,
                    CustomerId = cart.Customer.CustomerId,
                    Customer   = cart.Customer,
                    Created    = DateTime.Now
                };

                if (!IsModel)
                {
                    dbContext.Checks.Add(check);
                    dbContext.SaveChanges();
                }
                else
                {
                    check.CheckId = 0;
                }

                var sells = new List <Sell>();

                foreach (var product in cart)
                {
                    if (product.Count > 0)
                    {
                        var sell = new Sell()
                        {
                            CheckId   = check.CheckId,
                            Check     = check,
                            ProductId = product.ProductId,
                            Product   = product
                        };

                        sells.Add(sell);
                        if (!IsModel)
                        {
                            dbContext.Sells.Add(sell);
                        }

                        product.Count--;
                        fullPrice += product.Price;
                    }
                }
                check.Price = fullPrice;
                if (!IsModel)
                {
                    dbContext.SaveChanges();
                }

                CheckClosed?.Invoke(this, check);
            }
            return(fullPrice);
        }
Ejemplo n.º 4
0
        public decimal Dequeue()
        {
            decimal sum = 0; // сумма покупки

            if (Queue.Count == 0)
            {
                return(0);
            }
            var card = Queue.Dequeue();

            if (card != null)
            {
                var check = new Check()
                {
                    SellerID   = Seller.SellerId,
                    Seller     = Seller,
                    CustomerId = card.Customer.CustomerId,
                    Customer   = card.Customer,
                    Created    = DateTime.Now,
                };

                if (!IsModel)
                {
                    db.Checks.Add(check);
                    db.SaveChanges();
                }
                else
                {
                    check.CheckId = 0;
                }

                var sells = new List <Sell>();    //вспомогательный список

                foreach (Product product in card) // достаем из корзины
                {
                    if (product.Count > 0)
                    {
                        var sell = new Sell()
                        {
                            CheckId   = check.CheckId,
                            Check     = check,
                            ProductId = product.ProductId,
                            Product   = product
                        };

                        sells.Add(sell);  // добавляем продажу

                        if (!IsModel)
                        {
                            db.Sells.Add(sell);
                        }

                        product.Count--;      // уменьшаем кол-во товара
                        sum += product.Price; // формируем тоговую стоимость
                    }
                }

                check.Price = sum;

                if (!IsModel)
                {
                    db.SaveChanges();
                }

                CheckClosed?.Invoke(this, check); // генерируем событие (? - проверка на null)
            }
            return(sum);
        }