public void Test_UpdateToppingInventory() { var options = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb1") .Options; AStore store = new AStore(); Topping t = new Topping(store, 0, 100, "Test Topping", new ItemType()); store.ToppingsList.Add(t); int expected = 99; using (var context = new StoreContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add <AStore>(store); context.SaveChanges(); } using (var context = new StoreContext(options)) { StoreRepository storeRepo = new StoreRepository(context); storeRepo.UpdateToppingInventory(store.StoreID, t.PizzaType.Name, expected); var test = context.Toppings.SingleOrDefault(n => n.PizzaType.Name == t.PizzaType.Name); Assert.Equal(expected, test.Inventory); } }
public void Test_AddPizzaToStore() { var options = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb2") .Options; AStore store = new AStore(); BasicPizza newPizza = new BasicPizza(); newPizza.Type = "Test Pizza"; using (var context = new StoreContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add <AStore>(store); context.SaveChanges(); } using (var context = new StoreContext(options)) { StoreRepository storeRepo = new StoreRepository(context); storeRepo.AddPizzaToStore(store.StoreID, newPizza); var pres = context.BasicPizza.SingleOrDefault(p => p.Type == newPizza.Type); Assert.Equal(pres.Type, newPizza.Type); } }
public void Test_GetStores() { var options = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb0") .Options; AStore store1 = new AStore(); store1.Name = "Store1"; using (var context = new StoreContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add <AStore>(store1); context.SaveChanges(); } using (var context = new StoreContext(options)) { StoreRepository storeRepo = new StoreRepository(context); AStore store2 = new AStore(); store2.Name = "Store1"; List <AStore> stores = storeRepo.GetStores(); Assert.Equal(store2.Name, stores[0].Name); } }
public void Test_AddNewComp() { var options = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb14") .Options; using (var context = new StoreContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreRepository storeRepo = new StoreRepository(context); StoreLogic sl = new StoreLogic(storeRepo); AStore store = new AStore(); store.Name = "Store1"; ItemType item = new ItemType("toppings"); APizzaComponent testComp = new APizzaComponent("test", item); context.Add <AStore>(store); context.Add <ItemType>(item); context.Add <APizzaComponent>(testComp); context.SaveChanges(); RawNewComp rawTest = new RawNewComp(); rawTest.ID = store.StoreID; rawTest.ItemID = item.TypeID; rawTest.ItemName = item.Name; rawTest.CompName = "testcomp"; rawTest.Price = 0; Assert.True(sl.AddNewComp(rawTest)); } }
public bool AddNewTopping(RawNewComp obj, APizzaComponent pComp, AStore curStore) { Topping newTopping = mapper.CompToTopping(pComp, obj, curStore); storeRepo.AddNewTopping(newTopping); return(true); }
public bool AddNewCrust(RawNewComp obj, APizzaComponent pComp, AStore curStore) { Crust newCrust = mapper.CompToCrust(pComp, obj, curStore); storeRepo.AddNewCrust(newCrust); return(true); }
public IEnumerable <AStore> ViewOrders(AStore store) { // lambda - lINQ (linq to objects) // EF Loading = Eager Loading var orders = _context.Stores //load all stores .Include(s => s.Orders) // load all orders for all stores .ThenInclude(o => o.Pizzas) // load all pizzas for all orders .Where(s => s.Name == store.Name); // LINQ = lang integrated query // var pizzas = _context.Pizzas // .Include(p => p.Crust) // .Include(s => s.Size) // .Include(p => p.Toppings) // .Where(p => p.EntityId = order.Pizza) // looking for specific order // EF Explicit Loading var st = _context.Stores.FirstOrDefault(s => s.Name == store.Name); _context.Entry <AStore>(store).Collection <Order>(s => s.Orders).Load(); // load all orders+ properties for 1 store // sql - LINQ (ling to sql) // EF Lazy Loading var orders2 = from r in _context.Stores //join ro in _context.Orders on r.EntityId == ro.StoreEntityId where r.Name == store.Name select r; return(orders.ToList()); }
/// <summary> /// Updates database with any changes made to a store outside of repository /// </summary> public void UpdateStore(AStore curStore) { // context.Stores.Attach(curStore); // context.Entry(curStore).Collection(p => p.PresetPizzas).IsModified = true; // context.Stores.Update(curStore); // context.SaveChanges(); }
public bool AddNewSize(RawNewComp obj, APizzaComponent pComp, AStore curStore) { Size newSize = mapper.CompToSize(pComp, obj, curStore); storeRepo.AddNewSize(newSize); return(true); }
public void Test_GetStoreOrders() { var options = new DbContextOptionsBuilder <OrderContext>() .UseInMemoryDatabase(databaseName: "TestDb6") .Options; AStore store = new AStore(); Order testOrder = new Order(); testOrder.Store = store.StoreID; testOrder.JSONPizzaOrder = "teststring"; using (var context = new OrderContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.Add <Order>(testOrder); context.SaveChanges(); } using (var context = new OrderContext(options)) { OrderRepository orderRepo = new OrderRepository(context); List <Order> getOrders = orderRepo.GetStoreOrders(store.StoreID); Assert.Equal(testOrder.JSONPizzaOrder, getOrders[0].JSONPizzaOrder); } }
/// <summary> /// after you select a store then a menu is displayed /// </summary> /// <returns></returns> private static AStore SelectStore() { AStore theStore = new AStore(); int number; string input = Console.ReadLine(); bool isTrue = int.TryParse(input, out number); // be careful (think execpetion/error handling) if (isTrue) { if (number > 4) // this is comparing the size of the stores index, checks if number is out of bounds { System.Console.WriteLine("input " + number + " was not listed but defaulted to the last store"); number = 4; theStore = _storeSingleton.Stores[number - 1]; } if (number <= 0)// this is comparing the size of the stores index, checks if number is a zero or a negative value { System.Console.WriteLine("input " + number + " was not listed but defaulted to the first store"); number = 1; theStore = _storeSingleton.Stores[number - 1]; } theStore = _storeSingleton.Stores[number - 1]; } else { System.Console.WriteLine("Incorrect input, please enter a number corresponding to a store. Received " + input + " " + number); DisplayStoreMenu(); SelectStore(); } //DisplayPizzaMenu(); return(theStore); }
public bool AddNewPizza(RawNewPizza obj) { AStore curStore = storeRepo.FindStore(obj.ID); if (curStore is null) { return(false); } Crust newCrust = storeRepo.GetCrustByID(obj.Crust.ID); if (newCrust is null) { return(false); } List <Topping> toppings = new List <Topping>(); foreach (RawComp rc in obj.AllToppings) { Topping t = storeRepo.GetToppingByID(rc.ID); if (t is null) { return(false); } toppings.Add(t); } BasicPizza newPizza = mapper.RawToBasicPizzaMapper(obj, newCrust, toppings); if (!storeRepo.AddPizzaToStore(obj.ID, newPizza)) { return(false); } return(true); }
public void Test_GetStore() { var options = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb13") .Options; using (var context = new StoreContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreRepository storeRepo = new StoreRepository(context); StoreLogic sl = new StoreLogic(storeRepo); AStore store1 = new AStore(); store1.Name = "Store1"; context.Add <AStore>(store1); context.SaveChanges(); AStore stores = sl.GetStore(store1.StoreID); Assert.Equal(store1.Name, stores.Name); } }
public void Test_GetStoreToppings() { var options = new DbContextOptionsBuilder <StoreContext>() .UseInMemoryDatabase(databaseName: "TestDb15") .Options; using (var context = new StoreContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); StoreRepository storeRepo = new StoreRepository(context); StoreLogic sl = new StoreLogic(storeRepo); AStore store1 = new AStore(); store1.Name = "Store1"; ItemType type = new ItemType("testtype"); APizzaComponent comp = new APizzaComponent("testcomp", type); Topping testtopping = new Topping(store1, 0, 0, comp); context.Add <AStore>(store1); context.Add <Topping>(testtopping); context.SaveChanges(); List <Topping> toppings = sl.GetStoreToppings(store1.StoreID); Assert.Equal(testtopping.PizzaType.Name, toppings[0].PizzaType.Name); } }
public int AddStore(AStore store) { var mappedStore = mapper.Map(store); context.Add(mappedStore); context.SaveChanges(); return(mappedStore.StoreId); }
public Store Map(AStore store) { return(new Store { //StoreId = store.StoreId, StoreLocation = store.StoreLocation }); }
private void FinishOrder(ClientConsole client, Customer c, AStore store, Order o) { store.AddOrder(o); c.AddToOrderHistory(o); StoreSingleton.Instance.UpdateStores(); CustomerSingleton.Instance.UpdateCustomers(); }
public void TestBuildingStore() { AStore expected = new AStore(1, "test", "test", new string[] { "11a", "11p" }); AStore actual = Factory.CreateStore(1, "test", "test", new string[] { "11a", "11p" }); Assert.True(expected.Equals(actual)); }
/// <summary> /// /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body"> (optional)</param> /// <returns>ApiResponse of Object(void)</returns> public ApiResponse <Object> ApiStorePostWithHttpInfo(AStore body = null) { var localVarPath = "/api/Store"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json-patch+json", "application/json", "text/json", "application/_*+json" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (body != null && body.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(body); // http body (model) parameter } else { localVarPostBody = body; // byte array } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)this.Configuration.ApiClient.CallApi(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("ApiStorePost", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)), null)); }
public void PrintCrusts(AStore store) { maxMenuOptions = store.CrustList.Count; PrintLine(); for (int i = 0; i < store.CrustList.Count; i++) { Console.WriteLine("{0} : {1} - {2}", i + 1, store.CrustList[i].Name, store.CrustList[i].Price); } }
public IEnumerable <AStore> ViewOrders(AStore store) { var orders = _context.Stores .Include(s => s.Orders) .ThenInclude(o => o.Pizza) .Where(s => s.Name == store.Name); return(orders.ToList()); }
public void AddOrder(AStore store, Order order) { if (store.Orders == null) { store.Orders = new List <Order>(); } order.TimeOfPurchase = order.TimeStamp; store.Orders.Add(order); _context.SaveChanges(); }
public void PrintToppings(AStore store) { maxMenuOptions = store.ToppingsList.Count + 1; PrintLine(); for (int i = 0; i < store.ToppingsList.Count; i++) { Console.WriteLine("{0} : {1} - {2}", i + 1, store.ToppingsList[i].Name, store.ToppingsList[i].Price); } Console.WriteLine("{0} : Finish", store.ToppingsList.Count + 1); }
/// <summary> /// Gets the max number of toppings allowed per pizza for a store /// </summary> /// <param name="id">Store's Guid id</param> /// <returns>Max # of toppings per pizza</returns> public int GetMaxToppings(Guid id) { AStore store = context.Stores.SingleOrDefault(n => Guid.Equals(n.StoreID, id)); if (store is AStore) { return(store.MaxToppings); } return(-1); }
/// <summary> /// Gets the max price per order a store will allow /// </summary> /// <param name="id">Store's ID</param> /// <returns>Max price per order</returns> public decimal GetMaxPrice(Guid id) { AStore store = context.Stores.SingleOrDefault(n => Guid.Equals(n.StoreID, id)); if (store is AStore) { return(store.MaxPrice); } return(-1); }
/// <summary> /// Gets the name of a store based off the id /// </summary> /// <param name="id">Store's ID</param> /// <returns>Name of the store</returns> public string GetName(Guid id) { AStore store = context.Stores.SingleOrDefault(n => Guid.Equals(n.StoreID, id)); if (store is AStore) { return(store.Name); } return(""); }
public void PrintPizzaOptionsNoSize(AStore curStore) { PrintLine(); for (int i = 0; i < curStore.PresetPizza.Count; i++) { Console.WriteLine("{0}: {1}", i + 1, curStore.PresetPizza[i].PrintNoSize(true)); } Console.WriteLine("{0}: Custom Pizza", curStore.PresetPizza.Count + 1); }
public void UpdateStore(AStore newItem) { var oldItem = context.Stores.Find(newItem.StoreId); if (oldItem != null) { oldItem.StoreId = newItem.StoreId; oldItem.StoreLocation = newItem.StoreLocation; context.SaveChanges(); } }
private void PrintStoreSalesDay(AStore store, int days) { Console.WriteLine("Last {0} days: ", days); Dictionary <string, int> count = store.GetPizzaCount(days); foreach (KeyValuePair <string, int> kvp in count) { Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value); } Console.WriteLine("Last {0} days sales: " + store.GetTotalSales(days), days); }
private void PrintStoreTotalSales(AStore store) { Console.WriteLine("Alltime: "); Dictionary <string, int> count = store.GetTotalPizzaCount(); foreach (KeyValuePair <string, int> kvp in count) { Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value); } Console.WriteLine("Total all time sales: " + store.GetTotalSales()); }