Exemplo n.º 1
0
        public IActionResult ProductDetails(int id)
        {
            int i    = 3;
            var prod = res.GetProductById(id);

            //get all products under same category
            var result = res.GetProductsByCategory(prod.Category).ToList();

            Random         rnd            = new Random();
            List <Product> Randomproducts = new List <Product>();

            while (i > 0)
            {
                int index = rnd.Next(result.Count);
                Randomproducts.Add(result.ElementAt(index));
                i--;
            }
            var productSummary = new ProductViewMode
            {
                Product = prod,
                ProductswithSameCategory = Randomproducts
            };


            return(View(productSummary));
        }
        public IHttpActionResult PostProduct(ProductViewMode Viewproduct)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}
            category SelectedCat = db.categories.FirstOrDefault(cat => cat.CategoryId == Viewproduct.CatId);
            Product  product     = new Product()
            {
                ProductId   = Viewproduct.ProductId,
                productName = Viewproduct.productName,
                Description = Viewproduct.Description,
                ImgUrl      = "./assets/Images/Dummy.jpg",
                Price       = Viewproduct.Price,
                CategoryObj = SelectedCat
            };

            db.products.Add(product);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = product.ProductId }, product));
        }
Exemplo n.º 3
0
        public ProductForm(ProductViewMode productViewMode, int cat3_id)
        {
            InitializeComponent();

            switch (productViewMode)
            {
                case ProductViewMode.LIST:
                    {
                        ProductItemCtl foodItemControl = new ProductItemCtl();
                        panelUCHolder.Controls.Add(foodItemControl);
                        foodItemControl.Dock = DockStyle.Fill;
                        ScreenTitle = "Product List";

                    }
                    break;

                case ProductViewMode.INSERT:
                    {
                        AddProductItemCtl foodItemControl = new AddProductItemCtl();
                        panelUCHolder.Controls.Add(foodItemControl);
                        foodItemControl.Dock = DockStyle.Fill;
                        ScreenTitle = "Add New Product";

                    }
                    break;

                case ProductViewMode.UPDATE:
                    {
                        AddProductItemCtl foodItemControl = new AddProductItemCtl(cat3_id);
                        panelUCHolder.Controls.Add(foodItemControl);
                        foodItemControl.Dock = DockStyle.Fill;
                        ScreenTitle = "Update Product";

                    }
                    break;
            }
        }