public async Task <OrderResponse> AddProductToOrderAsync(Guid orderId, ProductToBuy product, Guid productId) { var order = await _appDbContext.Orders.FirstOrDefaultAsync(o => o.Id == orderId); order.Products = _appDbContext.ProductToBuy.Where(p => p.OrderId == orderId).ToList(); if (order.Products.Any(p => p.Name == product.Name)) { order.Products.FirstOrDefault(p => p.Name == product.Name).Quantity += 1; } else { order.Products.Add(product); } order.TotalPrice += product.Price * product.Quantity; _appDbContext.Products.FirstOrDefaultAsync(p => p.Id == productId).Result.Quantity -= 1; await _appDbContext.SaveChangesAsync(); return(new OrderResponse() { Success = true, Message = "You updated the order with following data.", Errors = null, Order = new OrderForResponse() { Products = order.Products, TotalPrice = order.TotalPrice, Street = order.Street, HouseNumber = order.HouseNumber, PostCode = order.PostCode, City = order.City } }); }
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox suppliers = (ComboBox)sender; ProductToBuy product = suppliers.BindingGroup.Items[0] as ProductToBuy; product.idProveedor = (suppliers.SelectedItem as ProveedorDto).idProveedor; }
public ActionResult AddPreOrder(ProductToBuy preOrder) { preOrder.userID = Convert.ToInt32(System.Web.HttpContext.Current.User.Identity.Name); preOrder.approved = false; preOrder.description = ""; repository.SaveProductToBuy(preOrder); return(RedirectToAction("CreatePreOrder")); }
private void updateProductToBuy(object sender) { ProductToBuy productSelected = Order.SelectedValue as ProductToBuy; productSelected.quantity = float.Parse((((TextBox)(sender)).Text)); productSelected.total = productSelected.quantity * productSelected.price; productsToBuyList.ResetBindings(); textPago.Text = string.Empty; textPago.Focus(); }
public void FixedPriceTest() { var product = new ProductToBuy { Product = Products.ProductA, count = 1 }; var product1 = new ProductToBuy { Product = Products.ProductB, count = 1 }; var product2 = new ProductToBuy { Product = Products.ProductC, count = 1 }; var obj = new SKU(new List <ProductToBuy> { product, product1, product2 }); var finalPrice = obj.PromotionalPrice; Assert.AreEqual(100, finalPrice); product = new ProductToBuy { Product = Products.ProductA, count = 5 }; product1 = new ProductToBuy { Product = Products.ProductB, count = 5 }; product2 = new ProductToBuy { Product = Products.ProductC, count = 1 }; obj = new SKU(new List <ProductToBuy> { product, product1, product2 }); finalPrice = obj.PromotionalPrice; Assert.AreEqual(370, finalPrice); product = new ProductToBuy { Product = Products.ProductA, count = 3 }; product1 = new ProductToBuy { Product = Products.ProductB, count = 5 }; product2 = new ProductToBuy { Product = Products.ProductC, count = 1 }; var product3 = new ProductToBuy { Product = Products.ProductD, count = 1 }; obj = new SKU(new List <ProductToBuy> { product, product1, product2, product3 }); finalPrice = obj.PromotionalPrice; Assert.AreEqual(280, finalPrice); }
public ActionResult Edit([Bind(Include = "productToBuyID,userID,title,productCategoryID,amount,price,description,approved")] ProductToBuy productToBuy) { productToBuy.userID = Convert.ToInt32(System.Web.HttpContext.Current.User.Identity.Name); if (ModelState.IsValid) { db.Entry(productToBuy).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.productCategoryID = new SelectList(r.ProductCategories, "productCategoryID", "name", productToBuy.productCategoryID); ViewBag.userID = new SelectList(r.Users, "userID", "userID", productToBuy.userID); return(View(productToBuy)); }
// GET: Personal/ProductToBuys/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductToBuy productToBuy = r.ProductsToBuy.FirstOrDefault(p => p.productToBuyID == id); if (productToBuy == null) { return(HttpNotFound()); } return(View(productToBuy)); }
private void ComboBox_TargetUpdated(object sender, System.Windows.Data.DataTransferEventArgs e) { ComboBox suppliers = (ComboBox)sender; ProductToBuy product = suppliers.BindingGroup.Items[0] as ProductToBuy; if (product.idProveedor == 0) { suppliers.SelectedIndex = 0; } else { suppliers.SelectedValue = product.idProveedor; } }
public ActionResult EditProductToBuy(ProductToBuy productToBuy) { if (ModelState.IsValid) { repository.SaveProductToBuy(productToBuy); TempData["message"] = string.Format("Передзамовлення {0} було збережено!", productToBuy.title); return(RedirectToAction("ProductsToBuyList")); } else { return(View(productToBuy)); } }
public ProductToBuy GetProductWithSuppliers(string pluProducto) { string webApiUrl = WebApiMethods.GetProductoWithSuppliers + pluProducto; ProductToBuy productToBuy = new ProductToBuy(); HttpStatusCode resultProduct = App.HttpTools.HttpGetSingle <ProductToBuy>(webApiUrl, ref productToBuy, $"Error en la obteción de información del producto {pluProducto}"); if (resultProduct == HttpStatusCode.OK) { return(productToBuy); } else { return(null); } }
// GET: Personal/ProductToBuys/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ProductToBuy productToBuy = r.ProductsToBuy.FirstOrDefault(p => p.productToBuyID == id); if (productToBuy == null) { return(HttpNotFound()); } ViewBag.productCategoryID = new SelectList(r.ProductCategories, "productCategoryID", "name", productToBuy.productCategoryID); ViewBag.userID = new SelectList(r.Users, "userID", "userID", productToBuy.userID); return(View(productToBuy)); }
private void textPago_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { float quantity = 1; if (textPago.Text.Contains('*')) { string[] cantidad = textPago.Text.Split('*'); float.TryParse(cantidad[0], out quantity); textPago.Text = cantidad[1]; } ProductToBuy productResult = _orderPurchasePresenter.GetProductWithSuppliers(textPago.Text); if (productResult != null) { addProductToBuy(productResult, quantity); } } }
private void addProductToBuy(ProductToBuy productResult, float quantity) { ProductToBuy productExist = productsToBuyList.Where(x => x.idProducto.Equals(productResult.idProducto)).FirstOrDefault(); if (productExist != null) { productExist.quantity += quantity; productExist.total = productExist.price * productExist.quantity; productsToBuyList.ResetBindings(); } else { productResult.quantity = quantity; productResult.total = productResult.price * quantity; productsToBuyList.Add(productResult); } textPago.Text = string.Empty; textPago.Focus(); }
public void SaveProductToBuy(ProductToBuy productToBuy) { if (productToBuy.productToBuyID == 0) { _db.ProductsToBuy.Add(productToBuy); } else { var dbEntry = _db.ProductsToBuy.Find(productToBuy.productToBuyID); if (dbEntry != null) { dbEntry.title = productToBuy.title; dbEntry.userID = productToBuy.userID; dbEntry.description = productToBuy.description; dbEntry.productCategoryID = productToBuy.productCategoryID; dbEntry.amount = productToBuy.amount; dbEntry.price = productToBuy.price; dbEntry.approved = productToBuy.approved; } } _db.SaveChanges(); }
public void TestMethod3() { int expected = 280; List <ProductToBuy> listProduct = new List <ProductToBuy>(); PriceCalculation priceCalculation = new PriceCalculation(); ProductToBuy productToBuy = new ProductToBuy(); JSONParser parser = new JSONParser(); dynamic promotionEngineModel = parser.ParseJSON(); priceCalculation.UnitPrice = promotionEngineModel.UnitPrice; priceCalculation.ActivePromotions = promotionEngineModel.ActivePromotions; productToBuy.ProuductName = "A"; productToBuy.ProductQuantity = 3; listProduct.Add(productToBuy); productToBuy = new ProductToBuy(); productToBuy.ProuductName = "B"; productToBuy.ProductQuantity = 5; listProduct.Add(productToBuy); productToBuy = new ProductToBuy(); productToBuy.ProuductName = "C"; productToBuy.ProductQuantity = 1; listProduct.Add(productToBuy); productToBuy = new ProductToBuy(); productToBuy.ProuductName = "D"; productToBuy.ProductQuantity = 1; listProduct.Add(productToBuy); int actual = priceCalculation.GetTotalPrice(listProduct); Assert.AreEqual(expected, actual, "Test Method 3 failed"); }