public ModelLibrary.Price GetItemPrice(ModelLibrary.Item item, int menuId, int itemCatId) { ItemCtrl itemCtrl = new ItemCtrl(); var itemo = itemCtrl.ConvertItemToDb(item, menuId, itemCatId); return(itemCtrl.GetItemPrice(1000000)); }
private async void buttonCreate_Click(object sender, RoutedEventArgs e) { var selectedItem = (ModelLibrary.Item)dataGridItemList.SelectedItem; double price; bool success = double.TryParse(textBoxNamePrice.Text, out price); if (success) { var priceObj = new ModelLibrary.Price { VarPrice = price, StartDate = DateTime.Now, EndDate = DateTime.Now.AddYears(100) }; var item = new ModelLibrary.Item { Description = textBoxDescription.Text, Name = textBoxName.Text, Price = priceObj }; //var itemCat = (ModelLibrary.ItemCat)comboBoxCategory.SelectedItem; if (comboBoxCategory.SelectedItem != null) { var validation = ValidateItem(item); var priceValidation = ValidatePrice(priceObj); if (validation == true && priceValidation) { var selectedCategory = (ModelLibrary.ItemCat)comboBoxCategory.SelectedItem; await Services._ItemProxy.CreateItemAsync(item, amenuId, selectedCategory.Id); var returnedItem = await Services._ItemProxy.GetItemByNameAsync(item.Name); await Services._PriceProxy.CreatePriceAsync(priceObj, returnedItem.Id); dataGridItemList.Items.Clear(); var modelMenu = await Services._ItemProxy.GetAllItemsByMenuAsync(amenuId); foreach (Item itemo in modelMenu) { dataGridItemList.Items.Add(itemo); } ; } else { MessageBox.Show("Validation did not pass"); } } else { MessageBox.Show("Select category"); } } else { MessageBox.Show("Price needs to be a double(NN.N(N))"); } }
public void Edit_Item_With_Price() { ItemCtrl itemCtrl = new ItemCtrl(); ItemDb itemDb = new ItemDb(); //Setup ItemService itemService = new ItemService(); PriceService priceService = new PriceService(); //Act JustFeastDbDataContext db = new JustFeastDbDataContext(); var testItem = itemService.GetItem(1000000); var testPrice = priceService.GetLatestPrice(1000000); ModelLibrary.Item newItemUpdated = new ModelLibrary.Item { Id = 1000000, Name = "testNameUpdated", Description = "testDescrUpdated", Price = testPrice }; priceService.UpdatePrice(testPrice, 1000000); itemService.UpdateItem(newItemUpdated, 1000000, 1000000); priceService.UpdatePrice(testPrice, 1000000); //Assert Assert.IsFalse(testItem.Name == "testNameUpdated"); }
public void Delete_Item_Service() { ItemCtrl itemCtrl = new ItemCtrl(); ItemService itemService = new ItemService(); //Setup ModelLibrary.Item rtrnItem = itemService.GetItem(1000000); var isNull = false; //Act itemService.DeleteItem(1000000); //Assert try { itemService.GetItem(1000000); } catch (Exception e) { isNull = true; } Assert.IsTrue(isNull); }
private bool ValidateItem(ModelLibrary.Item item) { var context = new ValidationContext(item, null, null); var result = new List <System.ComponentModel.DataAnnotations.ValidationResult>(); return(Validator.TryValidateObject(item, context, result, true)); }
public ModelLibrary.Item CreateItem(ModelLibrary.Item item, int menuId, int itemCatId) { var itemDb = new ItemDb(); var dbItem = new DatabaseAccessLibrary.Item { name = item.Name, menuId = menuId, description = item.Description, itemCatId = itemCatId, }; var modelItem = new ModelLibrary.Item { Name = item.Name, Description = item.Description, }; var context = new ValidationContext(item, null, null); var result = new List <ValidationResult>(); var isModelStateValid = Validator.TryValidateObject(item, context, result, true); if (!isModelStateValid) { throw new ValidationException(); } itemDb.AddItem(dbItem); return(modelItem); }
public void UpdateItem(ModelLibrary.Item item, int menuId, int itemCatId) { var itemDb = new ItemDb(); var dbItem = ConvertItemToDb(item, menuId, itemCatId); itemDb.UpdateItem(dbItem); }
public void Create_Table_Valid_Inputs(string name, string description, bool shouldValidate) { //Setup var sut = new ModelLibrary.Item { Name = name, Description = description, }; var context = new ValidationContext(sut, null, null); var result = new List <ValidationResult>(); //Act var isModelStateValid = Validator.TryValidateObject(sut, context, result, true); //Assert Assert.IsTrue(isModelStateValid == shouldValidate); }
public DatabaseAccessLibrary.Item ConvertItemToDb(ModelLibrary.Item modelItem, int menuId, int itemCatId) { JustFeastDbDataContext db = new JustFeastDbDataContext(); //var CheckItem = db.Items.Single(a => a.id == modelItem.Id); var dbItem = new DatabaseAccessLibrary.Item(); var menu = db.Menus.SingleOrDefault(p => p.id == menuId); var itemCat = db.ItemCats.SingleOrDefault(p => p.id == itemCatId); if (menu != null && itemCat != null && modelItem != null) { dbItem = new DatabaseAccessLibrary.Item { id = modelItem.Id, description = modelItem.Description, itemCatId = itemCatId, menuId = menuId, name = modelItem.Name, }; } return(dbItem); }
public ModelLibrary.Item ConvertItemToModel(DatabaseAccessLibrary.Item dbItem) { var db = new JustFeastDbDataContext(); var priceCtrl = new PriceCtrl(); var price = db.Prices.Where(p => p.itemId == dbItem.id).OrderByDescending(p => p.startDate).FirstOrDefault(); if (dbItem != null && price != null) { var modelItem = new ModelLibrary.Item { Id = dbItem.id, Name = dbItem.name, Description = dbItem.description, Price = priceCtrl.ConvertPriceToModel(price) }; return(modelItem); } else { return(null); } }
public ModelLibrary.Item ConvertItemToModelWithoutPrice(DatabaseAccessLibrary.Item dbItem) { if (dbItem != null) { var modelItem = new ModelLibrary.Item { Id = dbItem.id, Name = dbItem.name, Description = dbItem.description, }; return(modelItem); } else { var modelItem = new ModelLibrary.Item { Id = dbItem.id, Name = dbItem.name, Description = dbItem.description, }; return(modelItem); } }
public void Create_Item_With_Price_Service_Test() { ItemCtrl itemCtrl = new ItemCtrl(); ItemDb itemDb = new ItemDb(); //Setup #region creates ModelItem, ModelPrice ModelLibrary.Price newPrice = new ModelLibrary.Price { VarPrice = 12, StartDate = DateTime.Now, EndDate = DateTime.Now.AddYears(100) }; ModelLibrary.Item newItem = new ModelLibrary.Item { Name = "testName", Description = "testDescr", Price = newPrice }; ItemService itemService = new ItemService(); PriceService priceService = new PriceService(); #endregion //Act JustFeastDbDataContext db = new JustFeastDbDataContext(); itemService.CreateItem(newItem, 1000000, 1000000); var checkItem = db.Items.SingleOrDefault(p => p.name == newItem.Name && p.description == newItem.Description); priceService.CreatePrice(newPrice, checkItem.id); //Get Item(1,1,"PerfectlyGoodName"); //Assert Assert.IsNotNull(db.Items.SingleOrDefault(p => p.id == checkItem.id)); Assert.IsNotNull(db.Prices.Where(p => p.itemId == checkItem.id).OrderByDescending(p => p.startDate).First()); }
public void Create_Item_Service() { ItemCtrl itemCtrl = new ItemCtrl(); //Setup var menu = new ModelLibrary.Menu { Active = false, Id = 1000000, Name = "newName", RestaurantId = 1000000, }; var itemCat = new ModelLibrary.ItemCat { Id = 1000000, Name = "Soup" }; var price = new ModelLibrary.Price { StartDate = DateTime.Now.Date, EndDate = new DateTime(9999, 12, 31), VarPrice = 12.5 }; var item = new ModelLibrary.Item { Id = 1000000, Name = "Controllerforabi", Description = "Totallynotadescription", Price = price, }; //Act var itemdb = itemCtrl.CreateItem(item, menu.Id, itemCat.Id); //Assert Assert.AreEqual(item.Name, itemdb.Name); }
public void UpdateItem(ModelLibrary.Item updatedItem, int menuId, int itemCatId) { itemCtrl.UpdateItem(updatedItem, menuId, itemCatId); }
public void CreateItem(ModelLibrary.Item item, int menuId, int itemCatId) { itemCtrl.CreateItem(item, menuId, itemCatId); }
private async void buttonSave_Click(object sender, RoutedEventArgs e) { double price; ModelLibrary.Item selectedItem = (ModelLibrary.Item)dataGridItemList.SelectedItem; bool success = double.TryParse(textBoxNamePrice.Text, out price); if (success) { ModelLibrary.Price priceo = new ModelLibrary.Price { VarPrice = double.Parse(textBoxNamePrice.Text) }; ModelLibrary.Item updatedItem = new ModelLibrary.Item { Id = selectedItem.Id, Description = textBoxDescription.Text, Name = textBoxName.Text, Price = priceo }; await Services._PriceProxy.UpdatePriceAsync(priceo, selectedItem.Id); var catItem = (ModelLibrary.ItemCat)comboBoxCategory.SelectedItem; var selectedCatId = catItem == null ? 0 : catItem.Id; if (catItem != null) { var itemValidation = ValidateItem(updatedItem); var priceValidation = ValidatePrice(priceo); if (itemValidation == true && priceValidation == true) { await Services._ItemProxy.UpdateItemAsync(updatedItem, amenuId, selectedCatId); // IFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF dataGridItemList.Items.Clear(); var modelMenu = await Services._ItemProxy.GetAllItemsByMenuAsync(amenuId); foreach (Item itemo in modelMenu) { dataGridItemList.Items.Add(itemo); } ; } else { MessageBox.Show("Validation did not pass!"); } } else { MessageBox.Show("Select category"); } } else { MessageBox.Show("Price needs to be a double(NN.N(N))"); } }