public async Task <IActionResult> Edit(int id, [Bind("BidID,Quantity,ProductID")] BidProduct bidProduct)
        {
            if (id != bidProduct.BidID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bidProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BidProductExists(bidProduct.BidID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BidID"]     = new SelectList(_context.Bids, "ID", "ID", bidProduct.BidID);
            ViewData["ProductID"] = new SelectList(_context.Products, "ID", "Code", bidProduct.ProductID);
            return(View(bidProduct));
        }
        public async Task <IActionResult> Create([Bind("BidID,Quantity,ProductID")] BidProduct bidProduct)
        {
            if (ModelState.IsValid)
            {
                _context.Add(bidProduct);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BidID"]     = new SelectList(_context.Bids, "ID", "ID", bidProduct.BidID);
            ViewData["ProductID"] = new SelectList(_context.Products, "ID", "Code", bidProduct.ProductID);
            return(View(bidProduct));
        }
Example #3
0
        public void PostProducts(string product)
        {
            List <ProductDeserialize> ProductsToAdd = JsonConvert.DeserializeObject <List <ProductDeserialize> >(product);
            int BidId = _context.Bids.OrderByDescending(p => p.ID).FirstOrDefault().ID;

            //loop over the object
            foreach (var i in ProductsToAdd)
            {
                // create a new bidProduct Object and assign the values
                var a = new BidProduct
                {
                    ProductID = i.ProductID,
                    Quantity  = i.Quantity,
                    BidID     = BidId
                };

                //                    Add the object to the context

                _context.BidProducts.Add(a);
                //                  Save changes

                _context.SaveChangesAsync();
            }
        }
Example #4
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            string bidNumber = tbBidNumber.Text;
            string vendorCode = tbVendorCode.Text;
            int    count = 0, price = 0;

            int.TryParse(tbCount.Text, out count);
            int.TryParse(tbPrice.Text, out price);

            if (count <= 0)
            {
                MessageBox.Show("Количество товара введено неверно", "Информация");
                return;
            }
            if (price <= 0)
            {
                MessageBox.Show("Цена товара введена неверно", "Информация");
            }

            using (DBCtx db = new DBCtx())
            {
                Bid bid = (from b in db.Bid
                           where b.bid_number == bidNumber
                           select b).FirstOrDefault();

                if (bid == null)
                {
                    MessageBox.Show("Указанная заявка не найдена", "Информация");
                    return;
                }

                Dictionary status = (from d in db.Dictionary
                                     where d.id == bid.status_id
                                     select d).FirstOrDefault();

                if (status == null)
                {
                    MessageBox.Show("Ошибка получения статуса", "Информация");
                    return;
                }

                if (status.term_name == "Закрыт")
                {
                    MessageBox.Show("Нельзя изменять товар в закрытой заявке", "Информация");
                    return;
                }


                Product product = (from p in db.Product
                                   where p.vendor_code == vendorCode && p.deleted == null
                                   select p).FirstOrDefault();

                if (product == null)
                {
                    MessageBox.Show("Указанный товар не найден", "Информация");
                    return;
                }

                BidProduct bp = (from _bp in db.BidProduct
                                 where _bp.bid_id == bid.id && _bp.product_id == product.id && _bp.product_count == prevCount && _bp.product_price == prevPrice
                                 select _bp).FirstOrDefault();

                if (bp == null)
                {
                    MessageBox.Show("Указанная позиция не найдена", "Информация");
                    return;
                }

                if (product.remainder < count - prevCount)
                {
                    MessageBox.Show("Количество товара на складе меньше чем указано, указать такое большое количество товара нельзя", "Информация");
                    return;
                }

                if (price != product.recommended_price)
                {
                    DialogResult result = MessageBox.Show("Рекомендованная цена отличается от введенной, оставить цену такой (нажмите да) или изменить (нажмите нет)", "Информация", MessageBoxButtons.YesNo);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }

                bp.product_count = count;
                bp.product_price = price;

                product.remainder -= count - prevCount;

                Logs log = new Logs();
                log.username = username;
                log.acttime  = DateTime.Now;
                log.action   = String.Format("Modify product to bid: bidNumber - {0}, vendorCode - {1}, count - {2}, price - {3}, prevCount - {4}, prevPrice - {5}",
                                             bid.bid_number, product.vendor_code, count, price, prevCount, prevPrice);
                db.Logs.Add(log);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    MessageBox.Show("Произошла ошибка, товар в заявке не был обновлен", "Информация");
                    return;
                }

                this.productTableAdapter.Fill(this.product._Product);

                MessageBox.Show("Товар в заявке был успешно обновлен", "Информация");
                this.Close();
            }
        }
Example #5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string bidNumber = tbBidNumber.Text;
            string vendorCode = tbVendorCode.Text;
            int    count = 0, price = 0;

            int.TryParse(tbCount.Text, out count);
            int.TryParse(tbPrice.Text, out price);

            if (count <= 0)
            {
                MessageBox.Show("Количество товара введено неверно", "Информация");
                return;
            }
            if (price <= 0)
            {
                MessageBox.Show("Цена товара введена неверно", "Информация");
            }

            using (DBCtx db = new DBCtx())
            {
                Bid bid = (from b in db.Bid
                           where b.bid_number == bidNumber
                           select b).FirstOrDefault();

                if (bid == null)
                {
                    MessageBox.Show("Указанная заявка не найдена", "Информация");
                    return;
                }

                Dictionary status = (from d in db.Dictionary
                                     where d.id == bid.status_id
                                     select d).FirstOrDefault();

                if (status == null)
                {
                    MessageBox.Show("Ошибка получения статуса", "Информация");
                    return;
                }

                if (status.term_name == "Закрыт")
                {
                    MessageBox.Show("Нельзя удалять товар из закрытой заявки", "Информация");
                    return;
                }

                Product product = (from p in db.Product
                                   where p.vendor_code == vendorCode && p.deleted == null
                                   select p).FirstOrDefault();

                if (product == null)
                {
                    MessageBox.Show("Указанный товар не найден", "Информация");
                    return;
                }

                BidProduct bp = (from _bp in db.BidProduct
                                 where _bp.bid_id == bid.id && _bp.product_id == product.id && _bp.product_count == count && _bp.product_price == price
                                 select _bp).FirstOrDefault();

                if (bp == null)
                {
                    MessageBox.Show("Указанная позиция не найдена", "Информация");
                    return;
                }

                product.remainder += bp.product_count;
                db.BidProduct.Remove(bp);

                Logs log = new Logs();
                log.username = username;
                log.acttime  = DateTime.Now;
                log.action   = String.Format("Remove product from bid: bidNumber - {0}, vendorCode - {1}, count - {2}, price - {3}",
                                             bidNumber, vendorCode, count, price);
                db.Logs.Add(log);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    MessageBox.Show("Произошла ошибка, товар в заявке не был удален", "Информация");
                    return;
                }

                MessageBox.Show("Товар в заявке был успешно удален", "Информация");
                this.Close();
            }
        }
Example #6
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string bidNumber = tbBidNumber.Text;
            string vendorCode = tbVendorCode.Text;
            int    count = 0, price = 0;

            int.TryParse(tbCount.Text, out count);
            int.TryParse(tbPrice.Text, out price);

            if (count <= 0)
            {
                MessageBox.Show("Количество товара введено неверно", "Информация");
                return;
            }
            if (price <= 0)
            {
                MessageBox.Show("Цена товара введена неверно", "Информация");
                return;
            }

            using (DBCtx db = new DBCtx())
            {
                Bid bid = (from b in db.Bid
                           where b.bid_number == bidNumber
                           select b).FirstOrDefault();

                if (bid == null)
                {
                    MessageBox.Show("Заявка не найдена", "Информация");
                    return;
                }

                Dictionary status = (from d in db.Dictionary
                                     from _e in db.Entity
                                     where d.id == bid.status_id && d.target == "STATUS" && _e.id == d.entity_id && _e.name == "bid" && d.deleted == null
                                     select d).FirstOrDefault();

                if (status == null)
                {
                    MessageBox.Show("Статус заявки не найден", "Информация");
                    return;
                }

                if (status.term_name == "Закрыт")
                {
                    MessageBox.Show("Нельзя добавлять товар в закрытую заявку", "Информация");
                    return;
                }

                Product product = (from p in db.Product
                                   where p.vendor_code == vendorCode && p.deleted == null
                                   select p).FirstOrDefault();

                if (product == null)
                {
                    MessageBox.Show("Товар с указанным артикулом не найден", "Информация");
                    return;
                }

                if (product.remainder < count)
                {
                    MessageBox.Show("Количество товара на складе меньше чем указано, добавить такое большое количество товара нельзя", "Информация");
                    return;
                }

                if (price != product.recommended_price)
                {
                    DialogResult result = MessageBox.Show("Рекомендованная цена отличается от введенной, оставить цену такой (нажмите да) или изменить (нажмите нет)", "Информация", MessageBoxButtons.YesNo);
                    if (result == DialogResult.No)
                    {
                        return;
                    }
                }

                BidProduct bp = new BidProduct();
                bp.bid_id        = bid.id;
                bp.product_id    = product.id;
                bp.product_count = count;
                bp.product_price = price;

                product.remainder -= count;

                db.BidProduct.Add(bp);

                Logs log = new Logs();
                log.username = username;
                log.acttime  = DateTime.Now;
                log.action   = String.Format("Add product to bid: bidNumber - {0}, vendorCode - {1}, count - {2}, price - {3}",
                                             bid.bid_number, product.vendor_code, count, price);
                db.Logs.Add(log);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    MessageBox.Show("Произошла ошибка, товар не был добавлен в заявку", "Информация");
                    return;
                }

                this.productTableAdapter.Fill(this.product._Product);
                this.bidTableAdapter.Fill(this.bid._Bid);

                MessageBox.Show("Товар был успешно добавлен в заявку", "Информация");
                this.Close();
            }
        }
Example #7
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            Random random = new Random();

            string[] baconNotes = new string[] { "Bacon ipsum dolor amet meatball corned beef kevin, alcatra kielbasa biltong drumstick strip steak spare ribs swine. Pastrami shank swine leberkas bresaola, prosciutto frankfurter porchetta ham hock short ribs short loin andouille alcatra. Andouille shank meatball pig venison shankle ground round sausage kielbasa. Chicken pig meatloaf fatback leberkas venison tri-tip burgdoggen tail chuck sausage kevin shank biltong brisket.", "Sirloin shank t-bone capicola strip steak salami, hamburger kielbasa burgdoggen jerky swine andouille rump picanha. Sirloin porchetta ribeye fatback, meatball leberkas swine pancetta beef shoulder pastrami capicola salami chicken. Bacon cow corned beef pastrami venison biltong frankfurter short ribs chicken beef. Burgdoggen shank pig, ground round brisket tail beef ribs turkey spare ribs tenderloin shankle ham rump. Doner alcatra pork chop leberkas spare ribs hamburger t-bone. Boudin filet mignon bacon andouille, shankle pork t-bone landjaeger. Rump pork loin bresaola prosciutto pancetta venison, cow flank sirloin sausage.", "Porchetta pork belly swine filet mignon jowl turducken salami boudin pastrami jerky spare ribs short ribs sausage andouille. Turducken flank ribeye boudin corned beef burgdoggen. Prosciutto pancetta sirloin rump shankle ball tip filet mignon corned beef frankfurter biltong drumstick chicken swine bacon shank. Buffalo kevin andouille porchetta short ribs cow, ham hock pork belly drumstick pastrami capicola picanha venison.", "Picanha andouille salami, porchetta beef ribs t-bone drumstick. Frankfurter tail landjaeger, shank kevin pig drumstick beef bresaola cow. Corned beef pork belly tri-tip, ham drumstick hamburger swine spare ribs short loin cupim flank tongue beef filet mignon cow. Ham hock chicken turducken doner brisket. Strip steak cow beef, kielbasa leberkas swine tongue bacon burgdoggen beef ribs pork chop tenderloin.", "Kielbasa porchetta shoulder boudin, pork strip steak brisket prosciutto t-bone tail. Doner pork loin pork ribeye, drumstick brisket biltong boudin burgdoggen t-bone frankfurter. Flank burgdoggen doner, boudin porchetta andouille landjaeger ham hock capicola pork chop bacon. Landjaeger turducken ribeye leberkas pork loin corned beef. Corned beef turducken landjaeger pig bresaola t-bone bacon andouille meatball beef ribs doner. T-bone fatback cupim chuck beef ribs shank tail strip steak bacon." };

            using (var context = new OasisContext(
                       serviceProvider.GetRequiredService <DbContextOptions <OasisContext> >()))
            {
                string[] approvalStatus = new string[] { "Approved", "Disapproved", "RequiresApproval" };
                string[] bidStatus      = new string[] { "In Progress", "Stoped Due To Weather", "Completed", "Not Started", "Waiting approval", "Design stage", "Approved by client", "Approved by NBD", "Needs revision", };
                string[] productTypes   = new string[] { "Plant Inventory", "Pottery Inventory", "Materials Inventory" };
                string[] _firstName     = new string[] { "Adam", "Alex", "Aaron", "Ben", "Carl", "Dan", "David", "Edward", "Fred", "Frank", "George", "Hal", "Hank", "Ike", "John", "Jack", "Joe", "Larry", "Monte", "Matthew", "Mark", "Nathan", "Otto", "Paul", "Peter", "Roger", "Roger", "Steve", "Thomas", "Tim", "Ty", "Victor", "Walter" };
                string[] _lastName      = new string[] { "Anderson", "Ashwoon", "Aikin", "Bateman", "Bongard", "Bowers", "Boyd", "Cannon", "Cast", "Deitz", "Dewalt", "Ebner", "Frick", "Hancock", "Haworth", "Hesch", "Hoffman", "Kassing", "Knutson", "Lawless", "Lawicki", "Mccord", "McCormack", "Miller", "Myers", "Nugent", "Ortiz", "Orwig", "Ory", "Paiser", "Pak", "Pettigrew", "Quinn", "Quizoz", "Ramachandran", "Resnick", "Sagar", "Schickowski", "Schiebel", "Sellon", "Severson", "Shaffer", "Solberg", "Soloman", "Sonderling", "Soukup", "Soulis", "Stahl", "Sweeney", "Tandy", "Trebil", "Trusela", "Trussel", "Turco", "Uddin", "Uflan", "Ulrich", "Upson", "Vader", "Vail", "Valente", "Van Zandt", "Vanderpoel", "Ventotla", "Vogal", "Wagle", "Wagner", "Wakefield", "Weinstein", "Weiss", "Woo", "Yang", "Yates", "Yocum", "Zeaser", "Zeller", "Ziegler", "Bauer", "Baxster", "Casal", "Cataldi", "Caswell", "Celedon", "Chambers", "Chapman", "Christensen", "Darnell", "Davidson", "Davis", "DeLorenzo", "Dinkins", "Doran", "Dugelman", "Dugan", "Duffman", "Eastman", "Ferro", "Ferry", "Fletcher", "Fietzer", "Hylan", "Hydinger", "Illingsworth", "Ingram", "Irwin", "Jagtap", "Jenson", "Johnson", "Johnsen", "Jones", "Jurgenson", "Kalleg", "Kaskel", "Keller", "Leisinger", "LePage", "Lewis", "Linde", "Lulloff", "Maki", "Martin", "McGinnis", "Mills", "Moody", "Moore", "Napier", "Nelson", "Norquist", "Nuttle", "Olson", "Ostrander", "Reamer", "Reardon", "Reyes", "Rice", "Ripka", "Roberts", "Rogers", "Root", "Sandstrom", "Sawyer", "Schlicht", "Schmitt", "Schwager", "Schutz", "Schuster", "Tapia", "Thompson", "Tiernan", "Tisler" };
                string[] countryList    = new string[] { "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas (the)", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia (Plurinational State of)", "Bonaire, Sint Eustatius and Saba", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory (the)", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Cayman Islands (the)", "Central African Republic (the)", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands (the)", "Colombia", "Comoros (the)", "Congo (the Democratic Republic of the)", "Congo (the)", "Cook Islands (the)", "Costa Rica", "Croatia", "Cuba", "Curaçao", "Cyprus", "Czechia", "Côte d'Ivoire", "Denmark", "Djibouti", "Dominica", "Dominican Republic (the)", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", "Ethiopia", "Falkland Islands (the) [Malvinas]", "Faroe Islands (the)", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories (the)", "Gabon", "Gambia (the)", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Holy See (the)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea (the Democratic People's Republic of)", "Korea (the Republic of)", "Kuwait", "Kyrgyzstan", "Lao People's Democratic Republic (the)", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands (the)", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia (Federated States of)", "Moldova (the Republic of)", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands (the)", "New Caledonia", "New Zealand", "Nicaragua", "Niger (the)", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands (the)", "Norway", "Oman", "Pakistan", "Palau", "Palestine, State of", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines (the)", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Republic of North Macedonia", "Romania", "Russian Federation (the)", "Rwanda", "Réunion", "Saint Barthélemy", "Saint Helena, Ascension and Tristan da Cunha", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin (French part)", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten (Dutch part)", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Sudan", "Spain", "Sri Lanka", "Sudan (the)", "Suriname", "Svalbard and Jan Mayen", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan", "Tajikistan", "Tanzania, United Republic of", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands (the)", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates (the)", "United Kingdom of Great Britain and Northern Ireland (the)", "United States Minor Outlying Islands (the)", "United States of America (the)", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela (Bolivarian Republic of)", "Viet Nam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe", "Åland Islands" };
                string[] streetNumber   = new string[] { "25489", "87459", "35478", "15975", "95125", "78965" };
                string[] CompanyName    = new string[] { "Media", "Inc", "Builders", "Shop", "Demolishers", "Styles" };
                string[] position       = new string[] { "CEO", "Manager", "Employee", "Supervisor", "CTO" };

                string[] streetName = new string[] { "A street", "B street", "C street", "D street", "E street", "F street" };
                ;
                string[] cityName = new string[] { "Riyadh", "Damman", "Jedda", "Tabouk", "Makka", "Maddena", "Haiel" };

                string[] stateName = new string[] { "Qassem State", "North State", "East State", "South State", "West State" };

                string[] zipCode = new string[] { "28889", "96459", "35748", "15005", "99625", "71465" };

                //bool Checkarrray(List<string> list, string s)
                //{
                //    if (list.Contains(s))
                //        return true;
                //    return false;
                //}


                if (!context.Roles.Any())
                {
                    context.Roles.AddRange(

                        new Role
                    {
                        Name             = "Designer",
                        LabourCostPerHr  = Convert.ToDecimal(40.0),
                        LabourPricePerHr = Convert.ToDecimal(65.0)
                    },
                        new Role
                    {
                        Name             = "Botanist",
                        LabourCostPerHr  = Convert.ToDecimal(50.0),
                        LabourPricePerHr = Convert.ToDecimal(75.0)
                    },
                        new Role
                    {
                        Name             = "Sales Associate",
                        LabourCostPerHr  = Convert.ToDecimal(50.0),
                        LabourPricePerHr = Convert.ToDecimal(75.0)
                    }
                        );
                    context.SaveChanges();
                }


                int[] roleID = context.Roles.Select(p => p.ID).ToArray();


                if (!context.Employees.Any())
                {
                    for (int i = 0; i < 10; i++)
                    {
                        var a = new Employee()
                        {
                            FirstName      = _firstName[random.Next(_firstName.Count())],
                            MiddleName     = _firstName[random.Next(_firstName.Count())],
                            LastName       = _lastName[random.Next(_lastName.Count())],
                            AddressLineOne = streetNumber[random.Next(streetNumber.Count())] + streetName[random.Next(streetName.Count())],
                            City           = cityName[random.Next(cityName.Count())],
                            Province       = stateName[random.Next(stateName.Count())],
                            Country        = countryList[random.Next(countryList.Count())],
                            Phone          = 1234567890,
                            Email          = _firstName[random.Next(_firstName.Count())] + _lastName[random.Next(_lastName.Count())] + "@outlook.com",
                            RoleID         = roleID[random.Next(roleID.Count())],
                            IsUser         = true,
                        };

                        try
                        {
                            context.Add(a);
                            context.SaveChanges();
                        }
                        catch
                        {
                        }
                    }
                }

                //if (!context.Customers.Any())
                //{
                //    for (int i = 0; i < 50; i++)
                //    {

                //        var a = new Customer()
                //        {
                //            FirstName = _firstName[random.Next(_firstName.Count())],
                //            MiddleName = _firstName[random.Next(_firstName.Count())],
                //            LastName = _lastName[random.Next(_lastName.Count())],
                //            AddressLineOne = streetNumber[random.Next(streetNumber.Count())] + " " + streetName[random.Next(streetName.Count())],
                //            City = cityName[random.Next(cityName.Count())],
                //            Province = stateName[random.Next(stateName.Count())],
                //            Country = countryList[random.Next(countryList.Count())],
                //            Phone = 1234567890,
                //            Email = _firstName[random.Next(_firstName.Count())] + _lastName[random.Next(_lastName.Count())] + "@outlook.com",
                //            OrgName = _firstName[random.Next(_firstName.Count())] + " " + CompanyName[random.Next(CompanyName.Count())],
                //            Position = position[random.Next(position.Count())]
                //        };

                //        try
                //        {
                //            context.Add(a);
                //            context.SaveChanges();
                //        }
                //        catch
                //        {
                //            //do nothing
                //        }
                //    }

                //}



                //int[] CustomerIDs = context.Customers.Select(p => p.ID).ToArray();
                ////if (!context.Projects.Any())
                ////{
                ////    List<string> projectName = new List<string>();

                ////    foreach (int i in CustomerIDs)
                ////    {

                ////        var project = _firstName[random.Next(_firstName.Count())] + "Project";

                ////        while (Checkarrray(projectName, project))
                ////        {
                ////            project = _lastName[random.Next(_lastName.Count())] + "Project";

                ////        }

                ////        projectName.Add(project);

                ////        try {
                ////        context.Projects.Add(
                ////           new Project
                ////           {
                ////               Name = project,
                ////               SiteAddressLineOne = "586 First Ave",
                ////               City = "Welland",
                ////               Province = "Ontario",
                ////               Country = "Canada",
                ////               CustomerID = random.Next(CustomerIDs.Count())
                ////           });

                ////            context.SaveChangesAsync();
                ////        }
                ////        catch
                ////        {

                ////        }

                ////    }
                ////}

                ////if (!context.Projects.Any())
                ////{
                ////    List<string> projectName = new List<string>();
                ////    foreach (int i in CustomerIDs)
                ////    {
                ////        for (int j = 0; j < 5; j++)
                ////        {

                ////            var project = _firstName[random.Next(_firstName.Count())] + "Project";

                ////            while (Checkarrray(projectName, project))
                ////            {
                ////                project = _lastName[random.Next(_lastName.Count())] + "Project";

                ////            }

                ////            Project a = new Project()
                ////            {
                ////                Name = project,
                ////                SiteAddressLineOne = streetNumber[random.Next(streetNumber.Count())] + " " + streetName[random.Next(streetName.Count())],
                ////                City = cityName[random.Next(cityName.Count())],
                ////                Province = stateName[random.Next(stateName.Count())],
                ////                Country = countryList[random.Next(countryList.Count())],
                ////                CustomerID = i


                ////            };

                ////            try
                ////            {
                ////                context.Add(a);
                ////                context.SaveChanges();

                ////            }
                ////            catch
                ////            {
                ////                dod nothing repeat
                ////            }
                ////        }



                ////    }
                ////    context.SaveChanges();
                ////}



                //if (!context.Projects.Any())
                //{
                //    context.Projects.AddRange(
                //    new Project
                //    {
                //        Name = "Alpha",
                //        SiteAddressLineOne = "586 First Ave",
                //        City = "Welland",
                //        Province = "Ontario",
                //        Country = "Canada",
                //        CustomerID = random.Next(CustomerIDs.Count())
                //    },
                //    new Project
                //    {
                //        Name = "Beta",
                //        SiteAddressLineOne = "586",
                //        SiteAddressLineTwo = "First Ave",
                //        City = "Welland",
                //        Province = "Ontario",
                //        Country = "Canada",
                //        CustomerID = random.Next(CustomerIDs.Count())
                //    },
                //     new Project
                //     {
                //         Name = "Mall",
                //         SiteAddressLineOne = "586 First Ave",
                //         City = "Welland",
                //         Province = "Ontario",
                //         Country = "Canada",
                //         CustomerID = random.Next(CustomerIDs.Count())
                //     },
                //     new Project
                //     {
                //         Name = "Seaway Mall",
                //         SiteAddressLineOne = "586 First Ave",
                //         City = "Welland",
                //         Province = "Ontario",
                //         Country = "Canada",
                //         CustomerID = random.Next(CustomerIDs.Count())
                //     },
                //      new Project
                //      {
                //          Name = "Start up",
                //          SiteAddressLineOne = "586 First Ave",
                //          City = "Welland",
                //          Province = "Ontario",
                //          Country = "Canada",
                //          CustomerID = random.Next(CustomerIDs.Count())
                //      }, new Project
                //      {
                //          Name = "Walmart",
                //          SiteAddressLineOne = "786 First Ave",
                //          City = "Niagara",
                //          Province = "Ontario",
                //          Country = "Canada",
                //          CustomerID = random.Next(CustomerIDs.Count())
                //      },
                //        new Project
                //        {
                //            Name = "BestBuy",
                //            SiteAddressLineOne = "5096 First Ave",
                //            City = "Hamilton",
                //            Province = "Ontario",
                //            Country = "Canada",
                //            CustomerID = random.Next(CustomerIDs.Count())
                //        },
                //         new Project
                //         {
                //             Name = "Staples",
                //             SiteAddressLineOne = "596 First Ave",
                //             City = "St Chatehrines",
                //             Province = "Ontario",
                //             Country = "Canada",
                //             CustomerID = random.Next(CustomerIDs.Count())
                //         },
                //          new Project
                //          {
                //              Name = "Burger King",
                //              SiteAddressLineOne = "176 First Ave",
                //              City = "Toronto",
                //              Province = "Ontario",
                //              Country = "Canada",
                //              CustomerID = random.Next(CustomerIDs.Count())
                //          },
                //           new Project
                //           {
                //               Name = "Tim Hortons",
                //               SiteAddressLineOne = "586 First Ave",
                //               City = "Welland",
                //               Province = "Ontario",
                //               Country = "Canada",
                //               CustomerID = random.Next(CustomerIDs.Count())
                //           },
                //            new Project
                //            {
                //                Name = "A&W Canada",
                //                SiteAddressLineOne = "586 First Ave",
                //                City = "Welland",
                //                Province = "Ontario",
                //                Country = "Canada",
                //                CustomerID = random.Next(CustomerIDs.Count())
                //            }
                //      ); ;
                //    context.SaveChanges();
                //}


                if (!context.Customers.Any())
                {
                    context.Customers.AddRange(
                        new Customer
                    {
                        OrgName        = "Wonderboy Media",
                        FirstName      = "Amal",
                        MiddleName     = "E",
                        LastName       = "Shaiju",
                        Position       = "CEO",
                        AddressLineOne = "586 First Ave",
                        City           = "Welland",
                        Province       = "Ontario",
                        Country        = "Canada",
                        Phone          = 9055551212,
                        Email          = "*****@*****.**",
                    },
                        new Customer
                    {
                        OrgName         = "Weiner Media",
                        FirstName       = "Jesline",
                        LastName        = "Stanly",
                        Position        = "CTO",
                        AddressLineOne  = "596",
                        AddressLineTwo  = "First Ave",
                        ApartmentNumber = "Flat 96",
                        City            = "Welland",
                        Province        = "Ontario",
                        Country         = "Canada",
                        Phone           = 9055551213,
                        Email           = "*****@*****.**",
                    },
                        new Customer
                    {
                        OrgName        = "VAl Media",
                        FirstName      = "Val",
                        LastName       = "Garaskky",
                        Position       = "Manager",
                        AddressLineOne = "598 First Ave",
                        City           = "Welland",
                        Province       = "Ontario",
                        Country        = "Canada",
                        Phone          = 9055551215,
                        Email          = "*****@*****.**",
                    },
                        new Customer
                    {
                        OrgName        = "Yasmeen Designers",
                        FirstName      = "Yasmeen",
                        LastName       = "Faager",
                        Position       = "CFO",
                        AddressLineOne = "590 First Ave",
                        City           = "Welland",
                        Province       = "Ontario",
                        Country        = "Canada",
                        Phone          = 9055554213,
                        Email          = "*****@*****.**",
                    },
                        new Customer
                    {
                        OrgName        = "Rufaro Media",
                        FirstName      = "Rufaro",
                        Position       = "CKO",
                        LastName       = "Gonsalaz",
                        AddressLineOne = "580 First Ave",
                        City           = "Welland",
                        Province       = "Ontario",
                        Country        = "Canada",
                        Phone          = 9255554213,
                        Email          = "*****@*****.**",
                    });
                    context.SaveChanges();
                }


                if (!context.Projects.Any())
                {
                    context.Projects.AddRange(
                        new Project
                    {
                        Name = "Alpha",
                        SiteAddressLineOne = "586 First Ave",
                        City       = "Welland",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Amal").ID
                    },
                        new Project
                    {
                        Name = "Beta",
                        SiteAddressLineOne = "586",
                        SiteAddressLineTwo = "First Ave",
                        City       = "Welland",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Jesline").ID
                    },
                        new Project
                    {
                        Name = "Mall",
                        SiteAddressLineOne = "586 First Ave",
                        City       = "Welland",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Yasmeen").ID
                    },
                        new Project
                    {
                        Name = "Seaway Mall",
                        SiteAddressLineOne = "586 First Ave",
                        City       = "Welland",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Val").ID
                    },
                        new Project
                    {
                        Name = "Start up",
                        SiteAddressLineOne = "586 First Ave",
                        City       = "Welland",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Rufaro").ID
                    }, new Project
                    {
                        Name = "Walmart",
                        SiteAddressLineOne = "786 First Ave",
                        City       = "Niagara",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Amal").ID
                    },
                        new Project
                    {
                        Name = "BestBuy",
                        SiteAddressLineOne = "5096 First Ave",
                        City       = "Hamilton",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Jesline").ID
                    },
                        new Project
                    {
                        Name = "Staples",
                        SiteAddressLineOne = "596 First Ave",
                        City       = "St Chatehrines",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Val").ID
                    },
                        new Project
                    {
                        Name = "Burger King",
                        SiteAddressLineOne = "176 First Ave",
                        City       = "Toronto",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Yasmeen").ID
                    },
                        new Project
                    {
                        Name = "Tim Hortons",
                        SiteAddressLineOne = "586 First Ave",
                        City       = "Welland",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Rufaro").ID
                    },
                        new Project
                    {
                        Name = "A&W Canada",
                        SiteAddressLineOne = "586 First Ave",
                        City       = "Welland",
                        Province   = "Ontario",
                        Country    = "Canada",
                        CustomerID = context.Customers.FirstOrDefault(d => d.FirstName == "Amal").ID
                    }
                        );
                    context.SaveChanges();
                }



                if (!context.ApprovalStatuses.Any())
                {
                    foreach (string i in approvalStatus)
                    {
                        ApprovalStatus a = new ApprovalStatus()
                        {
                            Name = i
                        };
                        context.Add(a);
                    }
                    context.SaveChanges();
                }


                if (!context.ProductTypes.Any())
                {
                    foreach (string i in productTypes)
                    {
                        ProductType a = new ProductType()
                        {
                            Name = i
                        };
                        context.Add(a);
                    }
                    context.SaveChanges();
                }

                if (!context.Products.Any())
                {
                    context.Products.AddRange(
                        new Product
                    {
                        Code          = "Lacco",
                        Description   = "Lacco Australasica",
                        size          = "15 Gal",
                        Price         = 450.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Plant Inventory").ID
                    },
                        new Product
                    {
                        Code          = "Cham",
                        Description   = "Chamaedorea",
                        size          = "15 Gal",
                        Price         = 499.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Plant Inventory").ID
                    },
                        new Product
                    {
                        Code          = "Cera",
                        Description   = "Ceratozamia molongo",
                        size          = "14 in",
                        Price         = 400.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Plant Inventory").ID
                    },
                        new Product
                    {
                        Code          = "Areca",
                        Description   = "arecastum coco",
                        size          = "15 gal",
                        Price         = 458.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Plant Inventory").ID
                    },
                        new Product
                    {
                        Code          = "Cary",
                        Description   = "caryota mitius",
                        size          = "15 gal",
                        Price         = 154.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Plant Inventory").ID
                    },
                        new Product
                    {
                        Code          = "Margi",
                        Description   = "marginata",
                        size          = "2 gal",
                        Price         = 75.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Plant Inventory").ID
                    },
                        new Product
                    {
                        Code          = "TCP50",
                        Description   = "t/c Pot",
                        size          = "50 Gal",
                        Price         = 110.95,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Pottery Inventory").ID
                    },
                        new Product
                    {
                        Code          = "GP50",
                        Description   = "Granite pot",
                        size          = "50 Gal",
                        Price         = 195.95,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Pottery Inventory").ID
                    },
                        new Product
                    {
                        Code          = "TCF03",
                        Description   = "t/c figurine-swan",
                        size          = "",
                        Price         = 45.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Pottery Inventory").ID
                    },
                        new Product
                    {
                        Code          = "MBBB30",
                        Description   = "Marble bird bath",
                        size          = "30 in",
                        Price         = 250.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Pottery Inventory").ID
                    },
                        new Product
                    {
                        Code          = "GFN48",
                        Description   = "Granite Fountain",
                        size          = "48 in",
                        Price         = 750.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Pottery Inventory").ID
                    },
                        new Product
                    {
                        Code          = "CBRK5",
                        Description   = "Decorative Cedar Bark",
                        size          = "bag(5 cu Ft)",
                        Price         = 15.95,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Materials Inventory").ID
                    },
                        new Product
                    {
                        Code          = "CRGRN",
                        Description   = "Crushed granite",
                        size          = "Yard",
                        Price         = 14.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Materials Inventory").ID
                    },
                        new Product
                    {
                        Code          = "PGRV",
                        Description   = "Pea gravel",
                        size          = "Yard",
                        Price         = 20.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Materials Inventory").ID
                    },
                        new Product
                    {
                        Code          = "GRVI",
                        Description   = "1 Gravel",
                        size          = "Yard",
                        Price         = 12.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Materials Inventory").ID
                    },
                        new Product
                    {
                        Code          = "TSOIL",
                        Description   = "Top soil",
                        size          = "Yard",
                        Price         = 20.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Materials Inventory").ID
                    },
                        new Product
                    {
                        Code          = "PBLKG",
                        Description   = "Patio block-gray",
                        size          = "each",
                        Price         = 0.84,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Materials Inventory").ID
                    },
                        new Product
                    {
                        Code          = "PBLKR",
                        Description   = "Patio block-red",
                        size          = "each",
                        Price         = 0.84,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Materials Inventory").ID
                    },


                        new Product
                    {
                        Code          = "Arenga",
                        Description   = "Arenga Pinnata",
                        size          = "15 Gal",
                        Price         = 516.00,
                        ProductTypeID = context.ProductTypes.SingleOrDefault(p => p.Name == "Plant Inventory").ID
                    });
                    context.SaveChanges();
                }

                if (!context.BidStatuses.Any())
                {
                    foreach (string i in bidStatus)
                    {
                        BidStatus a = new BidStatus()
                        {
                            Name = i
                        };
                        context.Add(a);
                    }
                    context.SaveChanges();
                }

                int[] projectID           = context.Projects.Select(s => s.ID).ToArray();
                int[] designerID          = context.Employees.Where(p => p.Role.Name == "Designer").Select(p => p.ID).ToArray();
                int[] salesAssociateID    = context.Employees.Where(p => p.Role.Name == "Sales Associate").Select(p => p.ID).ToArray();
                int[] approvalStatusID    = context.ApprovalStatuses.Select(p => p.ID).ToArray();
                int[] bidStatusID         = context.BidStatuses.Select(p => p.ID).ToArray();
                int   ProjectCount        = projectID.Count();
                int   designerCount       = designerID.Count();
                int   bidStatusCount      = bidStatusID.Count();
                int   salesAssociateCount = salesAssociateID.Count();

                if (!context.Bids.Any())
                {
                    foreach (int i in projectID)
                    {
                        for (int j = 0; j < 2; j++)
                        {
                            int range = 5 * 365; //5 years

                            Bid a = new Bid()
                            {
                                DateCreated       = DateTime.Today.AddDays(random.Next(range)),
                                EstAmount         = 0,
                                EstBidStartDate   = DateTime.Today.AddDays(random.Next(range)),
                                EstBidEndDate     = DateTime.Today.AddDays(random.Next(range)),
                                Comments          = baconNotes[random.Next(4)],
                                DesignerID        = designerID[random.Next(designerCount)],
                                SalesAsscociateID = salesAssociateID[random.Next(salesAssociateCount)],
                                ProjectID         = projectID[random.Next(ProjectCount)],
                                BidStatusID       = bidStatusID[random.Next(bidStatusCount)],
                            };


                            a.Approval.ClientStatusID   = approvalStatusID[random.Next(approvalStatusID.Count())];
                            a.Approval.DesignerStatusID = approvalStatusID[random.Next(approvalStatusID.Count())];
                            try
                            {
                                if (a.Approval.ClientStatusID == context.ApprovalStatuses.SingleOrDefault(p => p.Name == "Approved").ID&& a.Approval.DesignerStatusID == context.ApprovalStatuses.SingleOrDefault(p => p.Name == "Approved").ID)
                                {
                                    a.IsFinal = true;
                                }

                                context.Add(a);
                                context.SaveChanges();
                            }
                            catch
                            {
                                // dod nothing repeat
                            }
                        }
                    }
                    context.SaveChanges();
                }



                int[] bidID     = context.Bids.Select(s => s.ID).ToArray();
                int[] productID = context.Products.Select(p => p.ID).ToArray();

                //Bid Products
                if (!context.BidProducts.Any())
                {
                    // loop over bid

                    foreach (int i in bidID)
                    {
                        int breaker = random.Next(productID.Count());
                        // loop over products
                        foreach (var j in productID)
                        {
                            if (j == breaker)
                            {
                                break;
                            }
                            BidProduct bidProduct = new BidProduct()
                            {
                                BidID     = i,
                                Quantity  = random.Next(1, 100),
                                ProductID = j
                            };

                            try
                            {
                                context.Add(bidProduct);
                                context.SaveChanges();
                            }
                            catch
                            {
                                // do nothing
                            }
                        }
                    }
                }

                if (!context.BidLabours.Any())
                {
                    // loop over bid

                    foreach (int i in bidID)
                    {
                        int breaker = random.Next(productID.Count());

                        // loop over role
                        foreach (var j in roleID)
                        {
                            if (j == breaker)
                            {
                                break;
                            }

                            BidLabour bidLabour = new BidLabour()
                            {
                                BidID  = i,
                                Hours  = random.Next(1, 8),
                                RoleID = j
                            };

                            try
                            {
                                context.Add(bidLabour);
                                context.SaveChanges();
                            }
                            catch
                            {
                                // do nothing
                            }
                        }
                    }
                }


                Thread.Sleep(2000);
                //loop over bids
                if (context.Bids.Where(p => p.EstAmount == 0).Any())
                {
                    var allBids = context.Bids.ToList();

                    //Loop over bids
                    foreach (var i in allBids)
                    {
                        var    allBidProducts = context.BidProducts.Where(p => p.BidID == i.ID);
                        var    allBidLabour   = context.BidLabours.Where(p => p.BidID == i.ID);
                        double total          = 0;

                        // loop over bid products
                        foreach (var j in allBidProducts)
                        {
                            // Add bid price * qnty to total
                            total += j.Product.Price * j.Quantity;
                        }

                        foreach (var j in allBidLabour)
                        {
                            total += (double)j.Role.LabourPricePerHr * j.Hours;
                        }

                        context.Bids.SingleOrDefault(p => p.ID == i.ID).EstAmount = total;

                        try
                        {
                            context.SaveChangesAsync();
                        }
                        catch
                        {
                            // do nothing
                        }
                    }
                }
            }
        }
Example #8
0
        private double UpdateBidProducts(List <ProductDeserialize> ProductsToAdd, Bid bidToUpdate)
        {
            List <string> a = new List <string>();
            List <string> b = new List <string>();

            for (int i = 0; i < ProductsToAdd.Count; i++)
            {
                a.Add(ProductsToAdd[i].ProductID.ToString());
                b.Add(ProductsToAdd[i].Quantity.ToString());
            }

            var selectedOptions  = a.ToArray();
            var selectedQuantity = b.ToArray();



            double total = 0;

            var allProducts     = _context.Products.ToList();             // All product ID's
            var allProductPrice = _context.Products.Select(p => p.Price); // All product ID's

            if (selectedOptions.Length < 1 || selectedQuantity.Length < 1)
            {
                bidToUpdate.BidProducts = new List <BidProduct>();
                return(total);
            }


            foreach (var product in allProducts)
            {
                //if input array contains this product
                if (selectedOptions.Contains(product.ID.ToString()))
                {
                    var selctedOptionIndex = Array.IndexOf(selectedOptions, product.ID.ToString());              // index of product in selectedOptions
                    var inputQnty          = Convert.ToDecimal(selectedQuantity[selctedOptionIndex]);            //  input Qnty

                    var bidproductrow = bidToUpdate.BidProducts.SingleOrDefault(p => p.ProductID == product.ID); // bid product row

                    //if product is alreay assigned to the bid
                    if (bidproductrow != null)
                    {
                        total += product.Price * (int)inputQnty;
                        // check if the qnty is not same as inputed qnty
                        if (bidproductrow.Quantity != Convert.ToDecimal(selectedQuantity[selctedOptionIndex]))
                        {
                            //change the quantity to input qnty
                            bidproductrow.Quantity = (int)inputQnty;
                        }
                    }
                    else // assign the produc to bid
                    {
                        total += product.Price * (int)inputQnty;

                        var specToAdd = new BidProduct
                        {
                            BidID     = bidToUpdate.ID,
                            ProductID = product.ID,
                            Quantity  = (int)inputQnty
                        };

                        _context.BidProducts.Add(specToAdd);
                    }
                }
                //else not delete the row
                else
                {
                    // try to delete if the product actually is assigned to the bid
                    try
                    {
                        var specToRemove = bidToUpdate.BidProducts.SingleOrDefault(p => p.ProductID == product.ID);
                        _context.Remove(specToRemove);
                    }
                    catch
                    {
                        // Do nothing and loop
                    }
                }
            }
            _context.SaveChangesAsync();

            return(total);
        }