public ISoldProductModel FindById(int id) { SoldProduct item = _db.SoldProducts.Find(id); ISoldProductModel model = MapTheSoldProductObject(item); return(model); }
public void PaySelectedSoldProducts_ShouldWork() { List <ISoldProductModel> inputList = Factory.InstanceISoldProductModelList(); ISoldProductModel product1 = Factory.InstanceSoldProductModel(); ISoldProductModel product2 = Factory.InstanceSoldProductModel(); product1.ID = 23; product1.Name = "product1"; product1.Price = 1.5M; product1.Detail = ""; product2.ID = 12; product2.Name = "product2"; product2.Price = 3.5M; product2.Detail = "algo"; inputList.Add(product1); inputList.Add(product2); int[] elements = { 0 }; Mock <ISoldProductDataAccess> soldproductData = new Mock <ISoldProductDataAccess>(); Mock <ISoldProductAccomplishedDataAccess> soldproductDataAccomplished = new Mock <ISoldProductAccomplishedDataAccess>(); MainMenuHelper.PaySelectedSoldProducts(inputList, elements, soldproductData.Object, soldproductDataAccomplished.Object); Assert.NotEmpty(inputList); Assert.Single(inputList); inputList[0].Should().BeEquivalentTo(product2); }
public void ProductToSoldProduct_ShouldBeMapped() { IProductModel product = Factory.InstanceProductModel(); product.Name = "some product"; product.Price = 888.45M; product.CategoryID = 654; product.Category.ID = 654; product.Category.Name = "some category"; int idTable = 36; Mock <IDataAccessSubCategory <ITableModel> > data = new Mock <IDataAccessSubCategory <ITableModel> >(); data.Setup(x => x.FindById(idTable)). Returns(new TableModel() { ID = 36, AreaID = 7, NumberOfTable = 9765, Occupied = true, Area = new AreaModel { ID = 7, Name = "some area" } }); ISoldProductModel soldProduct = MappingObjects.ProductToSoldProduct(product, idTable, data.Object); Assert.Equal(product.Name, soldProduct.Name); Assert.Equal(product.Price, soldProduct.Price); Assert.Equal("", soldProduct.Detail); soldProduct.Category.Should().BeEquivalentTo(product.Category); soldProduct.Table.Should().BeEquivalentTo(data.Object.FindById(idTable)); }
private ITableModel MapTheTableObject(Table item) { ITableModel model = Factory.InstanceTableModel(); model.ID = item.ID; model.NumberOfTable = item.NumberOfTable; model.Occupied = item.Occupied; model.Area.ID = item.AreaID; model.AreaID = item.AreaID; model.Area.Name = item.Area.Name; foreach (SoldProduct product in item.SoldProducts) { ISoldProductModel soldProduct = Factory.InstanceSoldProductModel(); soldProduct.ID = product.ID; soldProduct.Name = product.Name; soldProduct.Price = product.Price; soldProduct.TableID = product.TableID; soldProduct.CategoryID = product.CategoryID; soldProduct.Category.ID = product.CategoryID; soldProduct.Category.Name = product.Category.Name; soldProduct.Detail = product.Detail; soldProduct.Table = model; model.SoldProducts.Add(soldProduct); } return(model); }
// It display a form in order to edit a selected product from the table public ActionResult Edit(int?idItem) { if (idItem != null) { try { ISoldProductModel product = soldProductData.FindById((int)idItem); if (product == null) { log.Error("Could't find a product in the Database - return null"); return(View("ErrorEditProduct")); } return(View(product)); } catch (Exception ex) { log.Error("Could't load product from Database", ex); return(View("ErrorRetriveData")); } } else { log.Error("The sold product ID was null while trying to access"); return(View("ErrorEditProduct")); } }
public void PaySelectedSoldProducts_ShouldGiveException() { List <ISoldProductModel> inputList = Factory.InstanceISoldProductModelList(); ISoldProductModel product1 = Factory.InstanceSoldProductModel(); ISoldProductModel product2 = Factory.InstanceSoldProductModel(); product1.ID = 23; product1.Name = "product1"; product1.Price = 1.5M; product1.Detail = ""; product2.ID = 12; product2.Name = "product2"; product2.Price = 3.5M; product2.Detail = "algo"; inputList.Add(product1); inputList.Add(product2); int[] elements = { 0, 3 }; Mock <ISoldProductDataAccess> soldproductData = new Mock <ISoldProductDataAccess>(); Mock <ISoldProductAccomplishedDataAccess> soldproductDataAccomplished = new Mock <ISoldProductAccomplishedDataAccess>(); Action act = () => MainMenuHelper.PaySelectedSoldProducts(inputList, elements, soldproductData.Object, soldproductDataAccomplished.Object); Assert.Throws <ArgumentOutOfRangeException>(act); }
// PUT: api/SoldProducts/5 public void Put([FromBody] SoldProductModel product) { if (ModelState.IsValid) { ISoldProductModel model = product; soldProductData.Update(model); } }
public void Update(ISoldProductModel model) { var item = _db.SoldProducts.Find(model.ID); item.Price = model.Price; item.Detail = model.Detail; _db.SaveChanges(); }
public void Create(ISoldProductModel model) { SoldProduct item = new SoldProduct(); item.Name = model.Name; item.CategoryID = model.CategoryID; item.TableID = model.TableID; item.Price = model.Price; item.Detail = model.Detail; _db.SoldProducts.Add(item); _db.SaveChanges(); }
public void Update(ISoldProductModel model) { using (var response = APIClientConfig.ApiClient.PutAsJsonAsync($"soldproducts/{model.ID}", model)) { response.Wait(); if (response.Result.IsSuccessStatusCode) { } else { throw new Exception(response.Result.ReasonPhrase); } } }
public void Create(ISoldProductModel model) { using (var post = APIClientConfig.ApiClient.PostAsJsonAsync("soldproducts", model)) { post.Wait(); if (post.Result.IsSuccessStatusCode) { } else { throw new Exception(post.Result.ReasonPhrase); } } }
/// <summary> /// It maps an object of type ProductModel to SoldProductModel /// </summary> public static ISoldProductModel ProductToSoldProduct(IProductModel product, int idTable, IDataAccessSubCategory <ITableModel> tableData) { ISoldProductModel soldProduct = Factory.InstanceSoldProductModel(); soldProduct.Name = product.Name; soldProduct.Price = product.Price; soldProduct.CategoryID = product.CategoryID; soldProduct.TableID = idTable; soldProduct.Detail = ""; soldProduct.Category.ID = product.CategoryID; soldProduct.Category.Name = product.Category.Name; soldProduct.Table = tableData.FindById(idTable); return(soldProduct); }
private ISoldProductModel MapTheSoldProductObject(SoldProduct item) { ISoldProductModel model = Factory.InstanceSoldProductModel(); model.ID = item.ID; model.Name = item.Name; model.CategoryID = item.CategoryID; model.Category.ID = item.CategoryID; model.Category.Name = _db.Categories.Where(x => x.ID == item.CategoryID).FirstOrDefault().Name; model.TableID = item.TableID; model.Table.ID = item.TableID; model.Price = item.Price; model.Detail = item.Detail; return(model); }
public void SoldProductToSoldProductAccomplished_ShouldBeMapped() { ISoldProductModel soldProduct = Factory.InstanceSoldProductModel(); soldProduct.Name = "some product"; soldProduct.Price = 999.93M; soldProduct.Category.Name = "some category"; soldProduct.Category.ID = 897; soldProduct.CategoryID = 897; ISoldProductAccomplishedModel soldProductAccomplished = MappingObjects.SoldProductToSoldProductAccomplished(soldProduct); Assert.Equal(soldProduct.Name, soldProductAccomplished.Name); Assert.Equal(soldProduct.Price, soldProductAccomplished.Price); soldProductAccomplished.Category.Should().BeEquivalentTo(soldProduct.Category); }
public ActionResult TableAddProduct(int?idTable, int?idCategory, int?idProduct) { if (idProduct != null) { try { // Finding the selected product and the table where is going to be added ITableModel table = tableData.FindById((int)idTable); IProductModel product = productData.FindById((int)idProduct); if (product == null) { log.Error("Could't find a product in the Database - return null"); return(View("ErrorAddProduct")); } // Creates a SoldProductModel from a ProductModel that can be added to a list in each TableModel ISoldProductModel soldProduct = MappingObjects.ProductToSoldProduct(product, (int)idTable, tableData); soldProductData.Create(soldProduct); // Sets the current table as opened (Occupied by products) table.Occupied = true; tableData.Update(table); table.SoldProducts = soldProductData.GetByTable(table.ID); // Joins list of products and selected table to a single model mainPageModel.Products = productData.GetBySubGroup((int)idCategory).OrderBy(x => x.Name).ToList();; mainPageModel.Tables.Add(table); } catch (Exception ex) { log.Error("Could't load products, sold products or tables from Database", ex); return(View("ErrorRetriveData")); } return(View(mainPageModel)); } else { log.Error("The product ID was null while trying to access"); return(View("ErrorAddProduct")); } }
public ISoldProductModel FindById(int id) { using (var response = APIClientConfig.ApiClient.GetAsync($"soldproducts/{id}")) { response.Wait(); if (response.Result.IsSuccessStatusCode) { var readTask = response.Result.Content.ReadAsAsync <SoldProductModel>(); readTask.Wait(); ISoldProductModel model = readTask.Result; return(model); } else { throw new Exception(response.Result.ReasonPhrase); } } }
/// <summary> /// It completes the payment of selected items in a list based in indexes from variable "Paid" /// </summary> public static void PaySelectedSoldProducts(List <ISoldProductModel> fullList, int[] Paid, ISoldProductDataAccess soldProductData, ISoldProductAccomplishedDataAccess soldProductAccomplishedData) { List <ISoldProductModel> sold = Factory.InstanceISoldProductModelList(); foreach (int item in Paid) { ISoldProductModel product = Factory.InstanceSoldProductModel(); product = fullList[item]; ISoldProductAccomplishedModel auxProduct = MappingObjects.SoldProductToSoldProductAccomplished(product); soldProductAccomplishedData.Create(auxProduct); sold.Add(product); } foreach (ISoldProductModel element in sold) { fullList.Remove(element); } soldProductData.DeleteList(sold); }
public ActionResult EditConfirmed([Bind(Include = "ID, Price, Detail")] SoldProductModel product) { if (ModelState.IsValid) { ISoldProductModel model = product; try { soldProductData.Update(model); return(RedirectToAction("TableCategories", new { id = soldProductData.FindById(model.ID).TableID })); } catch (Exception ex) { log.Error("Could't load sold product from Database", ex); return(View("ErrorRetriveData")); } } else { log.Error("The model state of the sold product is invalid"); return(View("ErrorEditProduct")); } }
public ActionResult DeleteConfirmed(int idItem) { try { ISoldProductModel product = soldProductData.FindById(idItem); ITableModel table = tableData.GetAll().Where(x => x.ID == product.TableID).FirstOrDefault(); //if the table is without any product set it to empty if (table.SoldProducts.Count() == 1) { table.Occupied = false; tableData.Update(table); } soldProductData.Delete(idItem); return(RedirectToAction("TableCategories", new { id = product.TableID })); } catch (Exception ex) { log.Error("Could't load sold products or tables from Database", ex); return(View("ErrorRetriveData")); } }
/// <summary> /// It maps an object of type SoldProductModel to SoldProductAccomplishedModel /// </summary> public static ISoldProductAccomplishedModel SoldProductToSoldProductAccomplished(ISoldProductModel product) { ISoldProductAccomplishedModel soldProductAccomplished = Factory.InstanceSoldProductAccomplishedModel(); soldProductAccomplished.Name = product.Name; soldProductAccomplished.CategoryID = product.CategoryID; soldProductAccomplished.Price = product.Price; soldProductAccomplished.Category.ID = product.CategoryID; soldProductAccomplished.Category.Name = product.Category.Name; return(soldProductAccomplished); }