public ActionResult CreateBiological(Biological bio, HttpPostedFileBase file, bool? isNew)
        {
            //ModelState.IsValid => Vérifier à partir de la configuration ainsi des annotations si les données sont valides
            if (!ModelState.IsValid || file.ContentLength == 0 || isNew == null)
            {
                return View(bio);
            }

            bio.ImageName = file.FileName;

            Session["Product"] = bio;
            TempData["isNew"] = isNew;
            TempData["Image"] = file;

            return RedirectToAction("ValidateBiological");
        }
 public ActionResult ValidateBiological(bool? insertion)
 {
     Biological p = Session["Product"] as Biological;
     if (insertion == true)
     {
         HttpPostedFileBase file = TempData["Image"] as HttpPostedFileBase;
         if (file.ContentLength > 0)
         {
             service.CreateProduct(p);
             var path = Path.Combine(Server.MapPath("~/Content/Upload"), p.ImageName);
             file.SaveAs(path);
         }
         return RedirectToAction("Index");
     }
     else
     {
         return View(p);
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            /*Provider P1 = new Provider { Password = "******", ConfirmPassword = "******" };
             * System.Console.WriteLine(P1.IsApproved);
             * //Provider.SetIsApproved(P1);
             * //Provider.SetIsApproved(P1.Password, P1.ConfirmPassword, P1.IsApproved);
             * //System.Console.WriteLine(P1.IsApproved);
             *
             * string password = "******";
             * string confirmPassword = "******";
             * bool isApproved = false;
             * Provider.SetIsApproved(password, confirmPassword, ref isApproved);
             * System.Console.WriteLine(isApproved);
             * System.Console.ReadLine();*/

            Category CAT1 = new Category {
                Name = "Category1"
            };
            Category CAT2 = new Category {
                Name = "Category2"
            };
            Category CAT3 = new Category {
                Name = "Category3"
            };

            Product PROD1 = new Product()
            {
                Name = "Product1", MYCategory = CAT1, DateProd = new DateTime(2020, 12, 12)
            };
            Product PROD2 = new Product()
            {
                Name = "Product2", MYCategory = CAT1, DateProd = new DateTime(2019, 9, 12)
            };
            Product PROD3 = new Biological()
            {
                Name = "Product3", MYCategory = CAT3, DateProd = new DateTime(2020, 10, 1)
            };
            Product PROD4 = new Product()
            {
                Name = "Product4", DateProd = new DateTime(2019, 6, 30)
            };
            Product PROD5 = new Chemical()
            {
                Name = "Prodcut5", MYCategory = CAT2, DateProd = new DateTime(2020, 11, 5)
            };
            Product PROD6 = new Product()
            {
                Name = "Prodcut6", MYCategory = CAT3, DateProd = new DateTime(2020, 15, 22)
            };

            Provider PROV1 = new Provider {
                UserName = "******", Password = "******", ConfirmPassword = "******", Email = "Provider1@mail"
            };

            PROV1.Products.Add(PROD1);
            PROV1.Products.Add(PROD2);
            PROV1.Products.Add(PROD3);
            Provider PROV2 = new Provider {
                UserName = "******", Password = "******", ConfirmPassword = "******", Email = "Provider2@mail"
            };

            PROV2.Products.Add(PROD1);
            PROV2.Products.Add(PROD5);
            Provider PROV3 = new Provider {
                UserName = "******", Password = "******", ConfirmPassword = "******", Email = "Provider3@mail"
            };

            PROV3.Products.Add(PROD1);
            PROV3.Products.Add(PROD4);
            Provider PROV4 = new Provider {
                UserName = "******", Password = "******", ConfirmPassword = "******", Email = "Provider4@mail"
            };

            PROV4.Products.Add(PROD6);
            PROV4.Products.Add(PROD4);
            Provider PROV5 = new Provider {
                UserName = "******", Password = "******", ConfirmPassword = "******", Email = "Provider5@mail"
            };

            PROV5.Products.Add(PROD6);
            PROV5.Products.Add(PROD4);


            PROV1.GetProducts("Name", "Provider2");
            System.Console.WriteLine();
            PROV1.GetProducts("DateProd", "2020/12/12");
            System.Console.ReadLine();

            /*Product Prod = new Product()
             * {
             *  Name = "Product1",
             *  DateProd = DateTime.Now
             * };
             *
             * MyDBContext context = new MyDBContext();
             *
             * context.addProduct(Prod);*/
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            //avec un constructeur
            Product prod = new Product(12, 999, 5014, DateTime.Now, "myProd", "new prod");

            System.Console.WriteLine("my product name is : " + prod.Name);
            System.Console.WriteLine(prod.ToString());
            //avec initialiseur d'objet
            Product prod2 = new Product
            {
                Name     = "mySecondProd",
                Quantity = 100
            };

            System.Console.WriteLine("my second prod name is " + prod2.Name);
            Chemical chem = new Chemical
            {
                Price    = 100,
                Name     = "Chemical product",
                DateProd = new DateTime(2020, 10, 01),
                City     = "Ghazela"
            };

            Biological biological = new Biological
            {
                Herbs    = "herbs",
                DateProd = new DateTime(2020, 10, 01),
                Name     = "bio pruduct"
            };

            //ToString()
            System.Console.WriteLine(" chemical prod " + chem.ToString());

            /*//sans la chouche service
             * //Création de la base de données
             * MyContext myContext = new MyContext();
             * myContext.Products.Add(prod);//ajout du product au DbSet<Products>
             * myContext.Products.Add(chem);
             * myContext.Products.Add(biological);
             *
             * myContext.SaveChanges();//synchronisation avec la base
             * System.Console.WriteLine(" product added successfully");*/
            //avec la couche service
            Provider prov = new Provider
            {
                UserName        = "******",
                Email           = "*****@*****.**",
                Password        = "******",
                ConfirmPassword = "******",
                IsApproved      = false
            };
            ProviderRepository provRepo = new ProviderRepository();

            provRepo.AddProvider(prov);
            foreach (Provider p in provRepo.GetProviders())
            {
                System.Console.WriteLine("My Provider =" + p.UserName);
            }

            //passage par  reference
            System.Console.WriteLine(prov.Password + "  " + prov.ConfirmPassword);
            System.Console.WriteLine(provRepo.SetIsApproved(prov));
            //passage par valeur
            System.Console.WriteLine(provRepo.SetIsApproved("123", "123", false));

            System.Console.WriteLine("Fin");
            System.Console.ReadKey();

            //Polymorphisem
            // System.Console.WriteLine(prod.GetType);
        }