Esempio n. 1
0
 public ActionResult Create(ProductModel pm)
 {
     try
     {
         Product p = new Product
         {
             DateProd    = pm.DateProd,
             Category    = pm.Category,
             Description = pm.Description,
             Name        = pm.Name,
             ImageName   = pm.ImageName,
             Price       = pm.Price,
             Quantity    = pm.Quantity,
             CategoryId  = pm.CategoryId
         };
         // TODO: Add insert logic here
         sp.Add(p);
         sp.Commit();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            ServiceProduct sp = new ServiceProduct();
            Product        p  = new Product()
            {
                DateProd    = new DateTime(2020, 11, 25),
                Description = "Tomate",
                Name        = "Tomate",
                Price       = 7000,
                Quantity    = 1000
            };

            sp.AddProduct(p);
            sp.Commit();
            Console.WriteLine("Base créée avec succès");
            Console.ReadKey();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            MyfinanctCtx     ctx = new MyfinanctCtx();
            IServiceProduct  sp  = new ServiceProduct();
            IServiceCategory sc  = new ServiceCategory();

            Category c = new Category {
                Name = "vetements"
            };

            ctx.Categories.Add(c);
            Product p1 = new Product()
            {
                Name        = "Prod1",
                Description = "description",
                Price       = 2200,
                Quantity    = 5,
                DateProd    = DateTime.Now,
                Category    = c
            };

            Product p2 = new Product()
            {
                Name        = "Produit 2",
                Description = "description du produit 2",
                Price       = 100,
                Quantity    = 10,
                DateProd    = DateTime.Now,
                Category    = c
            };


            sp.Add(p1);
            sp.Add(p2);
            sc.Add(c);
            // sc.Commit();
            sp.Commit();
            // ctx.Products.Add(p1);
            // ctx.SaveChanges();//ne perend pas cpt au niveau de la base de données
            Console.WriteLine("base crée");
            Console.ReadKey();
        }