public void Index(Product p)
        {
            BusinessManager bm = BusinessManager.Instance;

            p.CategoryId = 1;
            bm.AddProduct(p);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            try
            {
                BusinessManager bm = BusinessManager.Instance;

                List <Category> categories = bm.GetAllCategories();
                System.Console.WriteLine("---- liste des categories -----");
                foreach (Category c in categories)
                {
                    System.Console.WriteLine("catégorie id {0} : {1}", c.Id, c.Wording);
                }

                Product product = new Product();
                product.Id       = 1;
                product.Name     = "Test";
                product.Category = categories.FirstOrDefault();

                bm.AddProduct(product);

                List <Product> products = bm.GetAllProducts();
                System.Console.WriteLine("---- LISTE DES PRODUITS -----");
                foreach (Product p in products)
                {
                    System.Console.WriteLine("Catégorie ID {0} : {1}", p.CategoryId, p.Name);
                }
            } catch (Exception e)
            {
                Console.WriteLine(String.Format("Erreur : {0}", e.Message));
            }

            Console.ReadKey();
        }
Пример #3
0
        public void BaseSetUp()
        {
            HandleCategory();

            OnTestProduct = new Product
            {
                Id          = 999,
                CategoryId  = 1,
                Stock       = 10,
                Label       = "On test",
                Description = "On test product",
                Code        = "109090",
                Price       = 100,
                Active      = true
            };

            BusinessManager = BusinessManager.Instance;
            BusinessManager.AddProduct(OnTestProduct);
        }
Пример #4
0
        public ActionResult Create(ProductEditViewModel model)
        {
            try
            {
                model.Categories = bm.GetAllCategories();

                if (model == null || !ModelState.IsValid)
                {
                    return(View(model));
                }

                model.Product.Category = bm.GetCategoryById(model.Product.CategoryId);
                bm.AddProduct(model.Product);

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View(model));
            }
        }