/// <summary> /// Adds order to the database /// </summary> /// <param name="dogOrder">dog order to be added to the database</param> /// <returns>order added to the database</returns> public DogOrder AddOrder(DogOrder dogOrder) { try{ Entity.DogOrder dogOrd = new Entity.DogOrder(); dogOrd.BuyerId = dogOrder.DogBuyer.PhoneNumber; dogOrd.StoreId = dogOrder.StoreLocation.id; dogOrd.DateOrder = dogOrder.OrderDate; dogOrd.Total = dogOrder.Total; _context.DogOrders.Add(dogOrd); _context.SaveChanges(); Entity.OrderItem orderItem; dogOrd = ( from DogOrder in _context.DogOrders where DogOrder.BuyerId == dogOrder.DogBuyer.PhoneNumber && DogOrder.StoreId == dogOrder.StoreLocation.id && DogOrder.DateOrder == dogOrder.OrderDate && DogOrder.Total == dogOrder.Total select DogOrder ).Single(); foreach (Model.Item item in dogOrder.GetItems()) { Entity.Inventory inv = ( from Inventory in _context.Inventories where Inventory.StoreId == dogOrder.StoreLocation.id && Inventory.DogId == item.Dog.id select Inventory ).Single(); inv.Quantity -= item.Quantity; _context.SaveChanges(); orderItem = new Entity.OrderItem(); orderItem.DogId = item.Dog.id; orderItem.OrderId = dogOrd.Id; orderItem.Quantity = item.Quantity; _context.OrderItems.Add(orderItem); _context.SaveChanges(); } return(dogOrder); } catch (Exception e) { Console.WriteLine("Something went wrong :("); Log.Error(e.Message); return(null); } }
public DogOrder AddOrder(DogOrder dogOrder) { return(_repoDS.AddOrder(dogOrder)); }
/// <summary> /// Takes in address and storelocation of order history you're looking for and a special option /// parameter where user has inputted the query they wish to perform /// </summary> /// <param name="address">address of the store you're looking for orders of</param> /// <param name="location">name of the store you're looking for orders of</param> /// <param name="option">int where user has specified the query they wish to perform</param> /// <returns>List of orders purchased at store</returns> public List <DogOrder> FindStoreOrders(string address, string location, int option) { Model.StoreLocation store = FindStore(address, location); List <Entity.DogOrder> dogOrders = new List <Entity.DogOrder>(); switch (option) { case 1: dogOrders = ( from DogOrder in _context.DogOrders where DogOrder.StoreId == store.id orderby DogOrder.DateOrder ascending select DogOrder ).ToList(); break; case 2: dogOrders = ( from DogOrder in _context.DogOrders where DogOrder.StoreId == store.id orderby DogOrder.DateOrder descending select DogOrder ).ToList(); break; case 3: dogOrders = ( from DogOrder in _context.DogOrders where DogOrder.StoreId == store.id orderby DogOrder.Total ascending select DogOrder ).ToList(); break; case 4: dogOrders = ( from DogOrder in _context.DogOrders where DogOrder.StoreId == store.id orderby DogOrder.Total descending select DogOrder ).ToList(); break; default: return(null); } Model.DogBuyer dogBuyer; List <Entity.OrderItem> orderItems; List <Model.DogOrder> returnOrders = new List <Model.DogOrder>(); Model.DogOrder returnOrder; Entity.Dog dog; foreach (Entity.DogOrder dogOrder in dogOrders) { dogBuyer = FindBuyer(dogOrder.BuyerId); orderItems = ( from OrderItem in _context.OrderItems where OrderItem.OrderId == dogOrder.Id select OrderItem ).ToList(); returnOrder = new DogOrder( dogBuyer, dogOrder.Total, store ); returnOrder.OrderDate = dogOrder.DateOrder; foreach (Entity.OrderItem orderItem in orderItems) { dog = ( from Dog in _context.Dogs where Dog.ItemId == orderItem.DogId select Dog ).Single(); returnOrder.AddItemToOrder(new Model.OrderItem( new Model.Dog( dog.Breed, dog.Gender.ToCharArray()[0], dog.Price ), orderItem.Quantity.Value )); } returnOrders.Add(returnOrder); } return(returnOrders); }
/// <summary> /// Over-arching order method that gives customer the tools to perform an order /// </summary> private void OrderDog() { string input; bool repeat = true; do { Console.WriteLine("What store would you like to buy from?"); Console.WriteLine("[0] View list of stores"); Console.WriteLine("[1] I know what store I want to order from"); input = Console.ReadLine(); switch (input) { case "0": foreach (StoreLocation s in ViewStoreList()) { Console.WriteLine(s.ToString()); } repeat = false; break; case "1": repeat = false; break; default: Console.WriteLine("Invalid input"); break; } }while(repeat); repeat = true; do { Console.WriteLine("Enter the store you'd like to buy from"); Console.WriteLine("[0] View list of stores"); Console.WriteLine("[1] I know what store I want to order from"); input = Console.ReadLine(); switch (input) { case "0": foreach (StoreLocation s in ViewStoreList()) { Console.WriteLine(s.ToString()); } repeat = false; break; case "1": repeat = false; break; default: Console.WriteLine("Invalid input"); break; } }while(repeat); ViewStoreInv(); repeat = true; _runningCount = 0; //string storeLocation = validation.ValidateString("Enter the store's name:"); //string storeAddress = validation.ValidateAddress("Enter the store's address in format CityName, ST"); _dogOrder = new DogOrder(_dogBuyer, 0, _storeLoBL.GetStore(_address, _location)); do { char gender = validation.ValidateGender("Enter the gender of dog you'd like to purchase"); string breed = validation.ValidateString("Enter the breed of the Dog you'd like to purchase"); int quant = validation.ValidateInt("Enter how many you would like to purchase"); Item lineItem = _storeLoBL.FindItem(new StoreLocation(_address, _location), new Dog(breed, gender, 1000.0), quant); if (lineItem != null) { _dogOrder.AddItemToOrder(lineItem); _dogOrder.Total += ((double)quant * lineItem.Dog.Price); } else { Console.WriteLine("Not a valid item"); } Console.WriteLine("Enter c to complete order or any other character to continue"); if (Console.ReadLine().Equals("c")) { repeat = false; } //get all the items you want to order }while(repeat); if (_orBL.AddOrder(_dogOrder) == null) { Console.WriteLine("If you're seeing this, something went terribly wrong"); } //send the list of items to the database and remove them from the store's inventory }