コード例 #1
0
 public void AddProductToCart(IProduct product)
 {
     if (product.Stock > 0)
     {
         ShoppingList.Add(product);
     }
 }
コード例 #2
0
        public OperationResult Post(ShoppingListItem item)
        {
            ShoppingList shoppingList = _shoppingListService.GetShoppingList();

            shoppingList.Add(item);
            return(new OperationResult.SeeOther()
            {
                RedirectLocation = shoppingList.CreateUri()
            });
        }
コード例 #3
0
        public void ExecuteAction(string actionName, string[] voiceInput = null)
        {
            switch (actionName)
            {
            case "AddToShoppingList": mShoppingList.Add(voiceInput); break;

            case "AddLasagnaIngredients": mShoppingList.AddLasagnaIngredients(); break;

            case "SpeakShoppingList": mShoppingList.SpeakShoppingList(); break;
            }
        }
コード例 #4
0
 public ShoppingListContext(DbContextOptions <ShoppingListContext> options)
     : base(options)
 {
     if (ShoppingList.Count() == 0)
     {
         ShoppingList.Add(new ShoppingItem {
             Title = "Google Pixel 3", Description = "A Google Product", Url = "https://images.idgesg.net/images/article/2018/10/pixel_3_xl_bigger_notch_long-100776124-large.jpg"
         });
         SaveChanges();
     }
 }
コード例 #5
0
ファイル: ShoppingManager.cs プロジェクト: HydeTu/FH.Recruit
        public IShoppingList CreateRandomShoppingList()
        {
            IShoppingList result = new ShoppingList(DateTime.Now);

            int count = _random.Next(3, _items.Count);

            for (int i = 0; i < count; i++)
            {
                result.Add(_items.ElementAt(_random.Next(_items.Count - 1)).Value, _random.Next(0, 10));
            }
            return(result);
        }
コード例 #6
0
        public IHttpActionResult Post(ShoppingItem value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var res = ShoppingList.Add(value.Item, value.Quantity);

            if (res)
            {
                return(CreatedAtRoute("GetItemById", new { id = value.Item.Id }, value));
            }
            return(BadRequest("Could not add to shopping list"));
        }
コード例 #7
0
        private void AddItemToShoppingList(SalesItem item)
        {
            var matchingItem = ShoppingList.Where(x => x.Name.Contains(item.Name)).FirstOrDefault();

            if (matchingItem != null)
            {
                matchingItem.Quantity += 1;
                var s = ShoppingList;
            }
            else
            {
                ShoppingList.Add(new SalesItem(item));
            }
        }
コード例 #8
0
ファイル: ViewModel.cs プロジェクト: perovsing/Database
        private void AddToShoppingList()
        {
            _user = new Consumer.Consumer(_unit);
            //ShoppingListItem _shoppingListItem = new ShoppingListItem();

            if (_user.DoesProductExsist(ShoppingListItem))
            {
                ShoppingList.Add(new ProduktInfo(ShoppingListItem));
            }
            else
            {
                MessageBox.Show("produktet findes ikke", "Error", MessageBoxButton.OK);
            }
        }
コード例 #9
0
ファイル: Tests.cs プロジェクト: damonmcminn/ShoppingList
        public void Add()
        {
            var pepsi        = new Drink(" Pepsi");
            var capitalPepsi = new Drink("PEPSI");
            var paddedPepsi  = new Drink("     pepsi       ");

            Assert.AreEqual(pepsi.Id, capitalPepsi.Id);
            Assert.AreEqual(capitalPepsi.Id, paddedPepsi.Id);

            Assert.True(ShoppingList.Add(pepsi));
            Assert.False(ShoppingList.Add(capitalPepsi));
            Assert.False(ShoppingList.Add(paddedPepsi));

            Assert.AreEqual("Pepsi", ShoppingList.Items.First().Name);
        }
コード例 #10
0
        /// <summary>
        /// Load the current sync file if available
        /// </summary>
        public static void ReadShoppingSyncFile()
        {
            string syncText     = "";
            string emailAddress = GetSettingsValue("SYNC_EMAIL");

            Debug.WriteLine("Reading Cloud Shopping file....");

            try
            {
                if (Debugger.IsAttached || Global.isOnWifi()) // only try on WiFi (most data will block this)
                {
                    Debug.WriteLine("WIFI DETECTED!");
                    List <string> lines = new List <string>();
                    // Copy local repository to FTP Server
                    if (Device.OS == TargetPlatform.Android || Device.OS == TargetPlatform.iOS)
                    {
                        // Read from FTP File
                        //string[] lines = GetFileContent(emailAddress + SyncFileName)
                        lines = AESGCM
                                .SimpleDecryptWithPassword(
                            DependencyService.Get <IFtpWebRequest>().FTPRead(emailAddress + ShoppingListFileName), AESGCMKey)
                                .Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
                    }

                    // Only load orders
                    foreach (string line in lines)
                    {
                        Debug.WriteLine("line: " + line);
                        // if is already synced, append "[ISSYNCED]=1" if contains this in sync file (the desktop application will append this AFTER it syncs)
                        if (line.Length > 5 && line.Contains("[SI_NA_]="))
                        {
                            string name     = Parse_Line_Information(line, "SI_NA_");
                            string category = Parse_Line_Information(line, "SI_CA_");

                            if (!ShoppingList.Any(x => x.Name == name && x.Category == category)) // only add items that are not already there
                            {
                                ShoppingList.Add(new ShopItem(name, category));
                            }
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                Debug.WriteLine("No file found: " + Ex);
            }
            Debug.WriteLine("Done reading....");
        }
        private void AddShoppingListItem(Item item)
        {
            var matchedItems = ShoppingList.Where(x => x.InventoryModel.InventoryId == item.InventoryModel.InventoryId).ToList();

            if (matchedItems.Count > 0)
            {
                var matchedItemIndex = ShoppingList.IndexOf(matchedItems.FirstOrDefault());
                ShoppingList[matchedItemIndex].InventoryModel.Quantity += item.InventoryModel.Quantity;

                ShoppingList = new ObservableCollection <Item>(ShoppingList);
            }
            else
            {
                ShoppingList.Add(item);
            }

            CalculateTotalPrice();
        }
コード例 #12
0
        public async void OnNavigatedTo(NavigationParameters parameters)
        {
            if (first)
            {
                await GetDataFromServer();

                first = false;
            }

            if (parameters.ContainsKey("AddCategory"))
            {
                ShoppingList.Add((ShoppingCategoryViewModel)parameters["AddCategory"]);
            }
            else
            {
                ShoppingList = new ObservableCollection <ShoppingCategoryViewModel>
                {
                    new ShoppingCategoryViewModel()
                    {
                        Name            = "Juice",
                        Quantity        = 2,
                        ScannedQuantity = 0,
                    },
                    new ShoppingCategoryViewModel()
                    {
                        Name            = "Umbrella",
                        Quantity        = 1,
                        ScannedQuantity = 0,
                    },
                    new ShoppingCategoryViewModel()
                    {
                        Name            = "Raspberry Pi",
                        Quantity        = 1,
                        ScannedQuantity = 0,
                    }
                };
            }
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: mrockey28/CutListCalculator
        private void CalculateResults(bool doCutList)
        {
            double g_maxTransportableInches;

            if (!Double.TryParse(maxTransportBox.Text, out g_maxTransportableInches))
            {
                MessageBox.Show("Max inches must be numeric.", "Parsing error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Clone the permanent list, and then:
            //Remove length/costs exceeding specified max transportable length
            //We clone the list first, so that the size can be changed without reloading the program.
            List <List <BoardCost> > localBrdFootCost = new List <List <BoardCost> >(g_brdFootCost);

            for (int i = 0; i < localBrdFootCost.Count; i++)
            {
                localBrdFootCost[i].RemoveAll(x => x.GetInches() > g_maxTransportableInches);
            }

            //Sort
            List <ShoppingList> cutLists = new List <ShoppingList>();

            for (int i = 0; i < lengthsNeeded.Count; i++)
            {
                //Make sure we're looking at the longest needed length first.
                lengthsNeeded[i].Sort((x, y) => y.CompareTo(x));

                //Make sure that we can meet the needs of the longest board with our current length restriction.
                if (localBrdFootCost[i].Count == 0 && lengthsNeeded[i].Count > 0)
                {
                    MessageBox.Show(string.Format("No prices for requested board dimension {0}", i), "Parsing error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ShoppingList optimalCutList = new ShoppingList();
                for (int j = 0; j < localBrdFootCost[i].Count; j++)
                {
                    //Make a temporary copy of the lengths needed list, so we can play with it multiple times.
                    List <double> currentNeededLengths = new List <double>(lengthsNeeded[i]);

                    //This is where we will stick the current list of cuts, based on the current starting length.
                    //We will then try and figure out whether this list is optimal for this board type.
                    ShoppingList dimensionedCutLists = new ShoppingList();
                    while (currentNeededLengths.Count > 0)
                    {
                        //We may need to change the current default board length, based on how long the cut needs to be.
                        int k = j;
                        while (currentNeededLengths[0] > (localBrdFootCost[i][k].GetInches()))
                        {
                            //Here we rely on performing the first operation first -- we check and make sure we can iterate backwards
                            //(the list is sorted largest to smallest). If we can -- we do, in the second operation, and then verify that
                            //this new length isn't greater than what we can transport. If it is..... exit. We can't achieve a solution.
                            if (k == 0)
                            {
                                MessageBox.Show(string.Format("Error! Requested board length larger than transportable size: {0} {1}", currentNeededLengths[0], g_maxTransportableInches), "Runtime error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            k--;
                        }

                        List <double> cutList   = new List <double>();
                        double        remainder = FindMostEfficientUse(ref cutList, ref currentNeededLengths, localBrdFootCost[i][k].GetInches(), 0);

                        while (k < localBrdFootCost[i].Count - 1 && ((localBrdFootCost[i][k].GetInches() - localBrdFootCost[i][k + 1].GetInches()) <= remainder))
                        {
                            k++;
                        }

                        dimensionedCutLists.Add(new BoardCuts(localBrdFootCost[i][k], cutList));
                        foreach (double item in cutList)
                        {
                            currentNeededLengths.Remove(item);
                        }
                    }

                    //If the optimal list is empty, or the list just generated is lower in price than the current optimal list...
                    //replace the optimal list.
                    if (optimalCutList.Empty() || (dimensionedCutLists.GetCost() < optimalCutList.GetCost()))
                    {
                        optimalCutList = dimensionedCutLists;
                    }
                }

                cutLists.Add(optimalCutList);
            }

            double totalCost = 0;

            resultBox.Text = "";
            for (int i = 0; i < cutLists.Count; i++)
            {
                if (cutLists[i].GetBoards().Count == 0)
                {
                    continue;
                }

                if (doCutList)
                {
                    for (int j = 0; j < cutLists[i].GetBoards().Count; j++)
                    {
                        resultBox.Text += string.Format("{0}x{1}': ", GetEnumDescription((boardType)i), cutLists[i].GetBoards()[j].GetFeet());
                        foreach (double itr in cutLists[i].GetBoards()[j].GetCuts())
                        {
                            resultBox.Text += string.Format("{0} ", itr);
                        }
                        resultBox.Text += "\n";
                    }
                }
                else
                {
                    int lastFeet  = 0;
                    int lastTotal = 0;
                    for (int j = 0; j < cutLists[i].GetBoards().Count; j++)
                    {
                        totalCost += cutLists[i].GetBoards()[j].GetCost();
                        if (cutLists[i].GetBoards()[j].GetFeet() != lastFeet)
                        {
                            if (lastFeet != 0)
                            {
                                resultBox.Text += string.Format("{0}x{1}' boards: {2}\n", GetEnumDescription((boardType)i), lastFeet, lastTotal);
                            }
                            lastFeet  = cutLists[i].GetBoards()[j].GetFeet();
                            lastTotal = 1;
                        }
                        else
                        {
                            lastTotal++;
                        }
                    }
                    resultBox.Text += string.Format("{0}x{1}' boards: {2}\n", GetEnumDescription((boardType)i), lastFeet, lastTotal);
                }
            }
            if (!doCutList)
            {
                resultBox.Text += string.Format("Total cost is {0}", totalCost);
            }
        }
コード例 #14
0
        // need to validate quantity not exist or >= 1
        // ideally this would be shared across methods: decorator?
        // name must be required
        public IActionResult Post([FromBody] Drink drink)
        {
            var successfullyAdded = ShoppingList.Add(drink);

            return(successfullyAdded ? (IActionResult)Ok(drink) : BadRequest());
        }
コード例 #15
0
        //=========================== LOAD FILES ==============================

        /// <summary>
        /// Load all local information from configuration file
        /// </summary>
        public static string LoadLocalInformation()
        {
            ResetParameters();

            try
            {
                string[] lines = GetFileContent(ConfigFileName)
                                 .Split(new [] { Environment.NewLine }, StringSplitOptions.None);

                List <string> tempLocation   = new List <string>();
                List <string> tempPayment    = new List <string>();
                List <string> tempCategories = new List <string>();

                foreach (string line in lines)
                {
                    #region Load Local Settings

                    if (line.Contains("[PE_SE]"))
                    {
                        SetSettingsValue("SYNC_EMAIL", Parse_Line_Information(line, "SYNC_EMAIL"));
                        SetSettingsValue("EMAIL_VALIDATED", Parse_Line_Information(line, "EMAIL_VALIDATED"));
                    }

                    #endregion

                    #region Load Locations

                    if (line.Contains("[LO_NA_]="))
                    {
                        tempLocation.Add(Parse_Line_Information(line, "LO_NA_"));
                    }

                    #endregion

                    #region Load Payments

                    if (line.Contains("[PA_NA_]="))
                    {
                        tempPayment.Add(Parse_Line_Information(line, "PA_NA_"));
                    }

                    #endregion

                    #region Load Categories

                    if (line.Contains("[CA_NA_]="))
                    {
                        tempCategories.Add(Parse_Line_Information(line, "CA_NA_"));
                    }

                    #endregion

                    #region Load Items

                    if (line.Contains("[LT_NA_]="))
                    {
                        MasterItemList.Add(new Item(
                                               Parse_Line_Information(line, "LT_NA_"),
                                               Convert.ToDouble(Parse_Line_Information(line, "LT_PR_")),
                                               Convert.ToInt32(Parse_Line_Information(line, "LT_QU_")),
                                               Parse_Line_Information(line, "LT_CA_"),
                                               Parse_Line_Information(line, "LT_ID_")
                                               ));
                    }

                    #endregion

                    #region Load Orders

                    if (line.Contains("[LR_LO_]="))
                    {
                        OrderList.Add(new Order(
                                          Parse_Line_Information(line, "LR_LO_"),
                                          //Convert.ToDouble(Parse_Line_Information(line, "PRETAX_PRICE")),
                                          Parse_Line_Information(line, "LR_PA_"),
                                          Convert.ToDateTime(Parse_Line_Information(line, "LR_DA_")),
                                          Parse_Line_Information(line, "LR_SY_") == "1",
                                          Parse_Line_Information(line, "LR_ID_")
                                          ));
                    }

                    #endregion

                    #region Load ShopItem List

                    if (line.Contains("[SI_NA_]="))
                    {
                        ShoppingList.Add(new ShopItem(Parse_Line_Information(line, "SI_NA_"), Parse_Line_Information(line, "SI_CA_")
                                                      ));
                    }

                    #endregion

                    #region Load Global Items
                    if (line.Contains("||[IT_LO]="))
                    {
                        Item New_Item = new Item();
                        New_Item.Name           = Parse_Line_Information(line, "IT_DE_");
                        New_Item.Status         = Parse_Line_Information(line, "IT_ST_") == "" ? "0" : Parse_Line_Information(line, "IT_ST_");
                        New_Item.RefundAlert    = Parse_Line_Information(line, "IT_RE_") == "1" ? true : false;
                        New_Item.consumedStatus = Convert.ToInt32(Parse_Line_Information(line, "IT_CO_", "||", "2"));
                        New_Item.Location       = Parse_Line_Information(line, "IT_LO");
                        New_Item.Payment_Type   = Parse_Line_Information(line, "IT_PA_");
                        New_Item.Category       = Parse_Line_Information(line, "IT_CA_");
                        New_Item.Discount_Amt   = Convert.ToDouble(Parse_Line_Information(line, "IT_DI_", "||", "0"));
                        New_Item.Price          = Convert.ToDouble(Parse_Line_Information(line, "IT_PR_"));
                        New_Item.Quantity       = Convert.ToInt32(Parse_Line_Information(line, "IT_QU_"));
                        New_Item.Date           = Convert.ToDateTime(Parse_Line_Information(line, "IT_DA_"));
                        New_Item.Refund_Date    = Parse_Line_Information(line, "IT_RD_").Length > 0 ? Convert.ToDateTime(Parse_Line_Information(line, "IT_RD_")) : DateTime.Now;
                        New_Item.Memo           = Parse_Line_Information(line, "IT_ME_");
                        New_Item.OrderID        = Parse_Line_Information(line, "IT_ID_");

                        GlobalItemList.Add(New_Item);
                    }
                    #endregion

                    #region Load Global Orders
                    // Load orders
                    else if (line.Contains("||[OR_QU_]="))
                    {
                        Order New_Order = new Order();
                        New_Order.Location            = Parse_Line_Information(line, "OR_LO_");
                        New_Order.OrderMemo           = Parse_Line_Information(line, "OR_ME_");
                        New_Order.Payment             = Parse_Line_Information(line, "OR_PA_");
                        New_Order.Tax_Overridden      = (Parse_Line_Information(line, "OR_TO_") == "1");
                        New_Order.Order_Total_Pre_Tax = Convert.ToDouble(Parse_Line_Information(line, "OR_PP_"));
                        New_Order.GC_Amount           = Convert.ToDouble(Parse_Line_Information(line, "OR_GC_", "||", "0"));
                        New_Order.Order_Taxes         = Convert.ToDouble(Parse_Line_Information(line, "OR_TA_"));
                        New_Order.Order_Discount_Amt  = Convert.ToDouble(Parse_Line_Information(line, "OR_DI_", "||", "0"));
                        New_Order.Order_Quantity      = Convert.ToInt32(Parse_Line_Information(line, "OR_QU_"));
                        New_Order.Date    = Convert.ToDateTime(Parse_Line_Information(line, "OR_DA_"));
                        New_Order.OrderID = Parse_Line_Information(line, "OR_ID_");

                        GlobalOrderList.Add(New_Order);
                    }
                    #endregion
                }

                // Load all synced orders
                LoadSyncFile();

                // Sort locations
                LocationList = new ObservableCollection <string>(tempLocation.OrderBy(x => x));
                PaymentList  = new ObservableCollection <string>(tempPayment.OrderBy(x => x));
                CategoryList = new ObservableCollection <string>(tempCategories.OrderBy(x => x));

                // Remove synced orders from current orders
                return(RemoveSyncedOrders());
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error with loading file: " + ex);
            }
            return("");
        }