예제 #1
0
        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
                }
            });
        }
예제 #2
0
        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;
        }
예제 #3
0
 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"));
 }
예제 #4
0
        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();
        }
예제 #5
0
        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);
        }
예제 #6
0
 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));
 }
예제 #7
0
        // 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));
        }
예제 #8
0
        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;
            }
        }
예제 #9
0
        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));
            }
        }
예제 #10
0
        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);
            }
        }
예제 #11
0
        // 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));
        }
예제 #12
0
 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);
         }
     }
 }
예제 #13
0
        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();
        }
예제 #14
0
 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();
 }
예제 #15
0
        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");
        }