// GET: ViewModelOrderPizzaq public ActionResult IndexVM(string sortOrder, string searchString) { ViewBag.Message = "Welcome to the Orders!"; ViewModelOrderPizzas ODSP = new ViewModelOrderPizzas { ODS = Repo.GetOrders(), ODP = Repo.GetPizzas() }; ViewBag.PriceSortParm = sortOrder == "Price" ? "Price_desc" : "Price"; ViewBag.DateSortParm = sortOrder == "Date" ? "Date_desc" : "Date"; ODSP.ODS = from s in _context.Orders select s; if (!String.IsNullOrEmpty(searchString)) { ODSP.ODS = ODSP.ODS.Where(s => s.CustomerName.ToUpper().Contains(searchString.ToUpper()) || s.CustomerPhoneNumber.Contains(searchString)); } switch (sortOrder) { case "Price": ODSP.ODS = ODSP.ODS.OrderBy(s => s.PizzaFprice); break; case "Price_desc": ODSP.ODS = ODSP.ODS.OrderByDescending(s => s.PizzaFprice); break; case "Date": ODSP.ODS = ODSP.ODS.OrderBy(s => s.OrderDate); break; case "Date_desc": ODSP.ODS = ODSP.ODS.OrderByDescending(s => s.OrderDate); break; default: ODSP.ODS = ODSP.ODS.OrderBy(s => s.PizzaFprice); break; } return(View(ODSP)); }
public void LoadFromDB() { #region Not in use /*ingredients.Add(new Ingredients * { * * topping = "Pepperonie", * qty = 25 * * }); * * ingredients.Add(new Ingredients * { * * topping = "Sausagge", * qty = 25 * * }); * * ingredients.Add(new Ingredients * { * * topping = "Bacon", * qty = 25 * * }); * * Console.WriteLine("Inventory Populated!"); * Console.WriteLine("");*/ #endregion #region Database var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("Appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); Console.WriteLine(configuration.GetConnectionString("PizzaPalace")); #endregion var optionsBuilder = new DbContextOptionsBuilder <PizzaPalaceContext>(); optionsBuilder.UseSqlServer(configuration.GetConnectionString("PizzaPalace")); var repo = new PizzaStoreRepository(new PizzaPalaceContext(optionsBuilder.Options)); var pizza = repo.GetPizzas(); //*Pizza var userin = repo.GetUserInfo(); //UserInformation var locations = repo.GetLocations(); //Locations var orderHas = repo.GetOrderHasPizzas(); //Order_Has_Pizza var orderDb = repo.GetOrders(); //Orders foreach (var item in locations) { location.Add(new Address { IdAddress = item.IdLocation, Line1 = item.LocationName } ); } foreach (var item in userin) { foreach (var item2 in locations) { if (item.LocationIdLocation == item2.IdLocation) { //add user info here to a list make a new list is what i need to do dont forget. users.Add(new User { Id = item.IdUser, Name = new Name { First = item.FirstName, Last = item.LastName }, Address = new Address { IdAddress = int.Parse(item2.IdLocation.ToString()), Line1 = item2.LocationName.ToString() } }); } } } foreach (var item in pizza) { piz.Add(new Pizza.Library.Pizza.Pizza { IdPizza = item.IdPizza, NamePizza = item.PizzaName.ToString(), CountPizza = int.Parse(item.PiizaCount.ToString()), CostPizza = decimal.Parse(item.PizzaPrice.ToString()) }); } foreach (var item in orderHas) { orderHasPizzas.Add(new OrderHasPizza { IdOrderHasPizza = item.IdOrderHasPizza, OrderIdOrder = item.OrderIdOrder, OrderLocationIdLocation = item.OrderLocationIdLocation, OrderUserIdUser = item.OrderUserIdUser, OrderUserLocationIdLocation = item.OrderUserLocationIdLocation, PizzaIdPizza = item.PizzaIdPizza, AmountOfPizzaInOrder = item.AmountOfPizzaInOrder }); } foreach (var item in orderDb) { stOrder.Add(new Store.Data.Orders { IdOrder = item.IdOrder, LocationIdLocation = item.LocationIdLocation, UserIdUser = item.UserIdUser, UserLocationIdLocation = item.UserLocationIdLocation, DateOfOrders = item.DateOfOrders, }); } try { //Method used to convert all database informtaion to process it into a List int count = 0; foreach (var itemOrd in orderDb) { if (itemOrd.IdOrder == orderHasPizzas[count].OrderIdOrder) { order.Add(new Pizza.Library.Orders { Id = int.Parse(orderHasPizzas[count].OrderIdOrder.ToString()), Location = int.Parse(orderHasPizzas[count].OrderLocationIdLocation.ToString()), User = new User { Id = int.Parse(users[count].Id.ToString()), Name = new Name { First = users[count].Name.First.ToString(), Last = users[count].Name.Last.ToString() }, Address = new Address { IdAddress = int.Parse(location[count].IdAddress.ToString()), Line1 = location[count].Line1.ToString() } }, Pizza = new Pizza.Library.Pizza.Pizza { IdPizza = int.Parse(piz[count].IdPizza.ToString()), NamePizza = piz[count].NamePizza.ToString(), CountPizza = int.Parse(piz[count].CountPizza.ToString()), CostPizza = decimal.Parse(piz[count].CostPizza.ToString()) }, AmountOfPizza = int.Parse(orderHasPizzas[count].AmountOfPizzaInOrder.ToString()), Date = DateTime.Parse(stOrder[count].DateOfOrders.ToString()) }); count++; } } } catch (FormatException ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } catch (Exception ex) { Logger logger = LogManager.GetCurrentClassLogger(); logger.ErrorException("Format Error", ex); Console.WriteLine($"Unexpected error: {ex.Message}"); } }
public ActionResult MakeOrder(IFormCollection viewCollection, MVCustomer cust) { Random rdm = new Random(); int ONum = rdm.Next(1, 1000000); int UseridTD = int.Parse(TempData.Peek("custid").ToString()); string LocationTD = TempData.Peek("locationName").ToString(); string NameTD = TempData.Peek("firstname").ToString(); string LastnameTD = TempData.Peek("lastname").ToString(); string PhoneTD = TempData.Peek("phone").ToString(); if (Count == 12) { ViewData["msg"] = "ERROR YOU CANNOT ORDER MORE THAN 12 PIZZAS!!!!! "; return(RedirectToAction(nameof(MakeOrder))); } string selectedSize = viewCollection["SelectedSize"]; string selectedTopping = viewCollection["SelectedTopping"]; string selectedCrust = viewCollection["SelectedCrust"]; if (selectedSize == "Small") { price = 5.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 5.00; TempData["order_total"] = total; } else if (selectedSize == "Medium") { price = 10.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 10.00; TempData["order_total"] = total; } else if (selectedSize == "Large") { price = 15.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 15.00; TempData["order_total"] = total; } else if (selectedCrust == "1") { price = .50; total = int.Parse(TempData.Peek("order_total").ToString()); total += .50; TempData["order_total"] = total; } else { price = 20.00; total = int.Parse(TempData.Peek("order_total").ToString()); total += 20.00; TempData["order_total"] = total; } if (TempData.Peek("Count").ToString() == "1") { Count = 1; } else { Count = int.Parse(TempData.Peek("Count").ToString()); } if (Count < 2)//only if the order is new is going to be created { //add order Repo.AddOrders(ONum, NameTD, LastnameTD, LocationTD, price, total, DateTime.Now, "T'Challa Slice", PhoneTD); Repo.SaveChanges(); } bool PG = bool.Parse(selectedCrust); Repo.AddPizza(selectedSize, selectedTopping, PG, ONum); Repo.SaveChanges(); // increment counter to know next time, that this is not a new order. Count++; TempData["Count"] = Count; var orderId = Repo.GetOrders().FirstOrDefault(x => x.CustomerPhoneNumber == PhoneTD && x.CustomerName == NameTD); TempData["orderId"] = orderId.Id; return(RedirectToAction(nameof(MakeOrder))); }