//Checks if Item is in basket
        public bool IsProductInBasket(string productName)
        {
            bool      inBasket = false;
            OrderItem item     = OrderItems.Find(x => x.ProductName == productName);

            if (item != null)
            {
                inBasket = true;
            }
            return(inBasket);
        }
Example #2
0
        public void Sell(string name, int count)
        {
            if (count <= 0)
            {
                return;
            }
            OrderItem orderItem = OrderItems.Find(o => o.MenuItem.Name.Equals(name));

            if (orderItem == null)
            {
                return;
            }
            orderItem.Count    = count;
            this._totalAmount += count * orderItem.MenuItem.Price;
        }
        //Remove product and amount of quanitity.
        public void RemoveProduct(string productName, int quantOfProducts)
        {
            OrderItem item = OrderItems.Find(x => x.ProductName == productName);

            if (item != null)
            {
                item.RemoveItems(quantOfProducts);
                if (item.Quantity <= 0)
                {
                    OrderItems.Remove(item);
                }
            }
            else
            {
                throw new KeyNotFoundException("Product Name Not Found");
            }
        }
 //Add product, price of product and quanitity.
 public bool AddProduct(string productName, decimal latestProductValue, int quantOfProducts)
 {
     //Check if values entered are null.
     if (!string.IsNullOrEmpty(productName) && quantOfProducts > 0)
     {
         // Check if product exists
         OrderItem oi = OrderItems.Find(x => x.ProductName == productName);
         if (oi == null)
         {
             OrderItem item = new OrderItem(productName, latestProductValue, quantOfProducts);
             OrderItems.Add(item);
             return(true);
         }
         else
         {
             oi.AddItems(latestProductValue, quantOfProducts);
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
        //Edits Product name.
        public void EditProduct(string oldProductName, string editedProductName, decimal editedPrice, int editedQuantity, OrderItem newItem)
        {
            OrderItem oi = OrderItems.Find(x => x.ProductName == oldProductName);

            if (oi != null)
            {
                if (oldProductName == editedProductName)
                {
                    oi.ChangeItems(editedProductName, editedPrice, editedQuantity);
                    OrderItems.Insert(FindIndex(oldProductName), oi);
                    OrderItems.RemoveAt(FindIndex(oldProductName));
                }
                else if (IsProductInBasket(editedProductName))
                {
                    RemoveProduct(oldProductName, oi.Quantity);
                    RemoveProduct(editedProductName);
                    AddProduct(editedProductName, editedPrice, editedQuantity);
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Edited item does not exist in list. First please add to list");
                }
            }
        }
Example #6
0
        public static void LoadLogs()
        {
            var     vidlog      = new VideoLog();
            dynamic productions = new Productions();
            dynamic episodes    = new Episodes();
            dynamic orderItems  = new OrderItems();
            dynamic channels    = new Channels();
            var     orders      = new Orders();

            var rand = new Random();

            Console.WriteLine("Deleting logs...");
            vidlog.Delete();

            foreach (var order in orders.All())
            {
                //pull the orderItems
                var items = orderItems.Find(OrderID: order.ID);

                //loop the items
                foreach (var item in items)
                {
                    var slug = item.SKU;
                    if (slug == "yearly")
                    {
                        Console.WriteLine("Loading Productions and Episodes for Annual...");

                        //create a download log for each production and episode
                        foreach (var p in productions.All())
                        {
                            var eps = episodes.Find(ProductionID: p.ID);
                            foreach (var e in eps)
                            {
                                var log = new {
                                    Slug          = item.SKU,
                                    EpisodeNumber = e.Number,
                                    Email         = order.Email,
                                    //the download file for the episode
                                    FileName = p.Slug + "_" + e.Number + ".zip",
                                    FileSize = e.HDFileSize,
                                    //1 day lag
                                    LogDate     = order.CreatedAt.AddDays(1),
                                    OrderItemID = item.ID
                                };
                                vidlog.Insert(log);
                            }
                        }
                    }
                    else if (slug == "monthly")
                    {
                        //create a stream log for each production and episode
                        Console.WriteLine("Loading Productions and Episodes for Monthly...");
                        foreach (var p in productions.All())
                        {
                            var eps = episodes.Find(ProductionID: p.ID);
                            foreach (var e in eps)
                            {
                                var log = new {
                                    Slug          = item.SKU,
                                    EpisodeNumber = e.Number,
                                    Email         = order.Email,
                                    //the download file for the episode
                                    FileName = p.Slug + "_" + e.Number + ".flv",
                                    FileSize = e.StreamFileSize,
                                    //1 day lag
                                    LogDate     = order.CreatedAt.AddDays(1),
                                    OrderItemID = item.ID
                                };
                                vidlog.Insert(log);
                            }
                        }
                    }
                    else
                    {
                        var p   = productions.First(Slug: item.SKU);
                        var eps = episodes.Find(ProductionID: p.ID);
                        Console.WriteLine("Loading log for {0}...", p.Slug);
                        foreach (var e in eps)
                        {
                            var log = new {
                                Slug          = item.SKU,
                                EpisodeNumber = e.Number,
                                Email         = order.Email,
                                //the download file for the episode
                                FileName = p.Slug + "_" + e.Number + ".zip",
                                FileSize = e.HDFileSize,
                                //1 day lag
                                LogDate     = order.CreatedAt.AddDays(1),
                                OrderItemID = item.ID
                            };
                            vidlog.Insert(log);
                        }
                    }
                }
            }
        }