Exemplo n.º 1
0
        public static float ItemPrice(ShoppingCartItem shoppingCartItem)
        {
            ProductMapper productMapper = new ProductMapper();
            Product product = productMapper.GetProduct(shoppingCartItem.IdProduct);

            return product.Price * shoppingCartItem.Quantity;
        }
        public void AddOrder()
        {
            var productMapper = new ProductMapper();
            var order = new Samsung_Order();
            order.userId = 4;
            order.totalPrice = Convert.ToInt32(shoppingCart.TotalPrice);

            using (var db = new EntitySamsung())
            {
                db.Samsung_Order.Add(order);
                db.SaveChanges();

                foreach (var item in shoppingCart.ShoppingCartItemsList)
                {
                    var orderItem = new Samsung_OrderItem();
                    orderItem.orderId = order.id;
                    orderItem.productId = item.IdProduct;
                    orderItem.quantity = item.Quantity;
                    db.Samsung_OrderItem.Add(orderItem);

                    productMapper.EditStockProduct(item.IdProduct, item.Quantity);

                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
 public static ProductVM GetProduct(int id)
 {
     ProductMapper productMapper = new ProductMapper();
        Product returnedProduct =  productMapper.GetProduct(id);
        ProductVM newProductVm = new ProductVM(returnedProduct.Id,returnedProduct.Name, returnedProduct.Category,  returnedProduct.Color,
        returnedProduct.Details, returnedProduct.Price, returnedProduct.Stock);
     return newProductVm;
 }
Exemplo n.º 4
0
        public static List<ProductVM> GetAllProducts()
        {
            ProductMapper productMapper = new ProductMapper();
            List<Product> returnedProductsList = productMapper.GetAllProducts();
            List<ProductVM> returnedProductsVm =new List<ProductVM>();
            foreach (var productItem in returnedProductsList)
            {
                ProductVM newProductVm = new ProductVM(productItem.Id, productItem.Name, productItem.Category, productItem.Color,
               productItem.Details, productItem.Price, productItem.Stock);
                returnedProductsVm.Add(newProductVm);
            }

            return returnedProductsVm;
        }
Exemplo n.º 5
0
 public static Boolean AddItem(ShoppingCartItemVM shoppingCartItemVm)
 {
     ProductMapper productMapper = new ProductMapper();
     Product product = productMapper.GetProduct(shoppingCartItemVm.IdProduct);
     if (product.Stock >= shoppingCartItemVm.Quantity)
     {
         ShoppingCartMapper shoppingCartMapper = new ShoppingCartMapper();
         ShoppingCartItem shoppingCartItem = new ShoppingCartItem(shoppingCartItemVm.IdProduct,
             shoppingCartItemVm.Quantity);
         shoppingCartMapper.AddShoppingCartItem(shoppingCartItem);
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 6
0
 public static void EditProduct(ProductVM productVM)
 {
     ProductMapper productMapper = new ProductMapper();
     Product inputProduct = new Product(productVM.Id, productVM.Name, productVM.Category, productVM.Color, productVM.Details, productVM.Price, productVM.Stock);
     productMapper.EditProduct(inputProduct);
 }