public void AddOrderItemToOrder(Product product, int count, ClientOrder order) { if(product==null) throw new ArgumentException("A product with the specified ID not found", "productId"); if (count <= 0) throw new ArgumentException("Count should be greatest then zero", "count"); ClientOrderItem existingOrderItem = order.Products.FirstOrDefault(p => p.Id == product.Id); if (existingOrderItem != null) { existingOrderItem.Count += count; Command command = CommandList.FirstOrDefault(c => c.Entity == existingOrderItem && c.FieldName == "Count" && c.CommandType == CommandType.Update); if (command != null) { command.Value = existingOrderItem.Count; } else { CommandList.AddUpdateOrderItemCommand(existingOrderItem, "Count", existingOrderItem.Count); } order.Products.ResetItem(order.Products.IndexOf(existingOrderItem)); } else { ClientOrderItem orderItem = new ClientOrderItem(product.Id); orderItem.Count = count; orderItem.Price = product.Price.Price; orderItem.Name = product.Name; order.Products.Add(orderItem); CommandList.AddCreateOrderItemCommand(orderItem); CommandList.AddUpdateOrderItemCommand(orderItem, "Count", orderItem.Count); } }
public void AddItem(Product product, int quantity) { var line = lines.FirstOrDefault(l => l.Product.ProductID == product.ProductID); if (line == null) lines.Add(new CartLine { Product = product, Quantity = quantity }); else line.Quantity += quantity; }
public void AddOrderItemToOrderTest() { ClientOrder testOrder = new ClientOrder(1) { PlacingDate = DateTime.Now, Status = Status.New, Products = new System.ComponentModel.BindingList<ClientOrderItem>() }; Product testProduct = new Product() { Id = 1, Name = "Test product 1", Price = new ProductPrice() { Price = 100 } }; int value = 10; presenter.CommandList.Clear(); mockCustomerEditOrderView.Order = testOrder; presenter.AddOrderItemToOrder(testProduct, value, testOrder); Assert.AreEqual(presenter.CommandList[0].Entity, mockCustomerEditOrderView.Order.Products[0]); Assert.AreEqual(presenter.CommandList[0].CommandType, CommandType.Create); Assert.AreEqual(presenter.CommandList[1].Entity, mockCustomerEditOrderView.Order.Products[0]); Assert.AreEqual(presenter.CommandList[1].CommandType, CommandType.Update); Assert.AreEqual(presenter.CommandList[1].FieldName, "Count"); Assert.AreEqual(presenter.CommandList[1].Value, value); }
public void AddItem(Product product, int quantity) { // FirstOrDefault() is a LINQ extension method on IEnumerable var line = lines .FirstOrDefault(l => l.Product.ID == product.ID); if (line == null) lines.Add(new CartLine { Product = product, Quantity = quantity }); else line.Quantity += quantity; }
public void Edit_Action_Saves_Product_To_Repository_And_Redirects_To_Index() { AdminController controller = new AdminController(mockRepository.Object); Product product = new Product(); var result = (RedirectToRouteResult)controller.Edit(product, null); mockRepository.Verify(x => x.SaveProduct(product)); Assert.AreEqual("Index", result.RouteValues["action"]); }
public void SaveProduct(Product product) { EnsureValid(product, "Name", "Description", "Category", "Price"); if (product.ProductID == 0) productsTable.InsertOnSubmit(product); else { productsTable.Attach(product); productsTable.Context.Refresh(RefreshMode.KeepCurrentValues, product); } productsTable.Context.SubmitChanges(); }
public void SaveProduct(Product product) { if (product.ID == 0) { productsTable.InsertOnSubmit(product); } else { productsTable.Attach(product); productsTable.Context.Refresh(RefreshMode.KeepCurrentValues, product); } productsTable.Context.SubmitChanges(); }
public void Can_Remove_Item() { Cart cart = new Cart(); Product p1 = new Product() { ProductID = 1, Price = 5 }; Product p2 = new Product() { ProductID = 2, Price = 15 }; cart.AddItem(p1, 15); cart.AddItem(p2, 7); cart.RemoveLine(p1); Assert.AreEqual(1, cart.Lines.Count); Assert.AreEqual(2, cart.Lines[0].Product.ProductID); Assert.AreEqual(7, cart.Lines[0].Quantity); }
public ActionResult Edit(Product product, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { product.ImageMimeType = image.ContentType; product.ImageData = new byte[image.ContentLength]; image.InputStream.Read(product.ImageData, 0, image.ContentLength); } productsRepository.SaveProduct(product); TempData["message"] = product.Name + " has been saved."; return RedirectToAction("Index"); } else // Validation error, so redisplay same view return View(product); }
public void Can_Add_Items_To_Cart() { Product p1 = new Product { ProductID = 1 }; Product p2 = new Product { ProductID = 2 }; Cart cart = new Cart(); cart.AddItem(p1, 1); cart.AddItem(p1, 2); cart.AddItem(p2, 10); Assert.AreEqual(2, cart.Lines.Count, "Wrong number of lines in cart"); var p1Line = cart.Lines.Where(l => l.Product.ProductID == 1).First(); var p2Line = cart.Lines.Where(l => l.Product.ProductID == 2).First(); Assert.AreEqual(3, p1Line.Quantity); Assert.AreEqual(10, p2Line.Quantity); }
public void SaveProduct(Product product) { EnsureValid(product, "Name", "Description", "Category", "Price"); // If it's a new product, just attach it to the DataContext if (product.ProductID == 0) productsTable.InsertOnSubmit(product); else { // If we're updating an existing product, tell the DataContext // to be responsible for saving this instance productsTable.Attach(product); // Also tell the DataContext to detect any changes since the last save productsTable.Context.Refresh(RefreshMode.KeepCurrentValues, product); } productsTable.Context.SubmitChanges(); }
public List<Product> GetAllProducts() { List<Product> ProductList = new List<Product>(); SqlCeConnection conn = new SqlCeConnection(SQLQueryString.ConnStr); conn.Open(); try { Console.WriteLine("Connection is successfully made!"); string commandText = SQLQueryString.SelectProduct; SqlCeCommand cmd = new SqlCeCommand(commandText, conn); SqlCeDataReader dr = cmd.ExecuteReader(); Product prod; while (dr.Read()) { // List<ProductPrice> PriceList = new List<ProductPrice>(); //Console.WriteLine("{0}\t{1}\t{2}", dr[0], dr[1], dr[2]); prod = new Product(); prod.Id = (int)dr[0]; prod.Name = dr[1].ToString(); prod.Units = (int)dr[2]; prod.Price = CurrentPrice((int)dr[0]); // PriceList.AddRange(GetProductPrice((int)dr[0])); // prod.Prices = PriceList; ProductList.Add(prod); } return ProductList; } finally { conn.Close(); } }
public ActionResult Edit(Product product, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image != null) { product.ImageMimeType = image.ContentType; string filenameimage = ((image.FileName).Split('\\')).Last(); string path = Server.MapPath("~/Image/" + filenameimage); product.ImagePath = path; image.SaveAs(path); } productsRepository.SaveProduct(product); TempData["message"] = "Xe "+ product.Name + " đã được lưu lại!"; return RedirectToAction("Index"); } else return View(product); }
public void GetAllProductsTest() { Product p1 = new Product() { Id = 1, Name = "Test product 1", Units = 3, Price = new ProductPrice() { Price = 100 } }; Product p2 = new Product() { Id = 1, Name = "Test product 2", Units = 3, Price = new ProductPrice() { Price = 200 } }; Product p3 = new Product() { Id = 1, Name = "Test product 3", Units = 3, Price = new ProductPrice() { Price = 300 } }; IList<Product> products = new List<Product>(){p1,p2,p3}; mockContract.GetProducts().Returns(products); var newProducts = presenter.GetAllProducts(); Assert.AreEqual(newProducts, products); }
private void detach_Products(Product entity) { this.SendPropertyChanging(); entity.Manufacture = null; }
partial void DeleteProduct(Product instance);
partial void UpdateProduct(Product instance);
partial void InsertProduct(Product instance);
private void detach_Products(Product entity) { this.SendPropertyChanging(); entity.Model = null; }
private void attach_Products(Product entity) { this.SendPropertyChanging(); entity.Model = this; }
private void detach_Products(Product entity) { this.SendPropertyChanging(); entity.ThongSoHopSo = null; }
private void attach_Products(Product entity) { this.SendPropertyChanging(); entity.ThongSoKichThuoc = this; }
public void Summary_Action_Renders_View_With_Total() { CartController controller = new CartController(null, null); Cart cart = new Cart(); Product p1 = new Product() { ProductID = 1, Price = 12 }; Product p2 = new Product() { ProductID = 2, Price = 50 }; cart.AddItem(p1, 12); cart.AddItem(p2, 5); ViewResult result = controller.Summary(cart); Assert.AreEqual(cart, ((Cart)result.ViewData.Model)); Assert.AreEqual(cart.Lines.Count, ((Cart)result.ViewData.Model).Lines.Count); Assert.AreEqual(cart.ComputeTotalValue(), ((Cart)result.ViewData.Model).ComputeTotalValue()); }
public void RemoveLine(Product product) { lines.RemoveAll(l => l.Product.ProductID == product.ProductID); }
public void SaveProduct(Product product) { throw new NotImplementedException(); }
public void RemoveLine(Product product) { _lines.RemoveAll(p => p.Product.ProductId == product.ProductId); }
public Product GetProduct(int prodID, DateTime placingdate, SqlCeConnection conn) { IList<Product> ProductList = new List<Product>(); try { string commandText = SQLQueryString.SelectProductList; SqlCeCommand cmd = new SqlCeCommand(commandText, conn); cmd.Parameters.AddWithValue("@id", prodID); SqlCeDataReader dr = cmd.ExecuteReader(); Product prod; while (dr.Read()) { prod = new Product(); prod.Id = (int)dr[0]; prod.Name = dr[1].ToString(); prod.Units = (int)dr[2]; prod.Price = CurrentPrice((int)dr[0], placingdate, conn); ProductList.Add(prod); return prod; } return null; } catch (SqlCeException ex) { log.Error(ex.Message); return null; } }
public void DeleteProduct(Product product) { productsTable.DeleteOnSubmit(product); productsTable.Context.SubmitChanges(); }