public ActionResult Create(Liste_produit liste_produit)
        {
            if (ModelState.IsValid)
            {
                db.Liste_produit.Add(liste_produit);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Id_article = new SelectList(db.Article, "Id_article", "Libelle_article", liste_produit.Id_article);
            ViewBag.Id_operation = new SelectList(db.Mouvement_stock, "ID_mouvement", "Date_mouvement", liste_produit.Id_operation);
            return View(liste_produit);
        }
        public ActionResult _Create(short id, short Article)
        {
            ProduitL produitl = new ProduitL();

             if (TryUpdateModel(produitl, null, null, new[] { "Article" }))
             {
                 Liste_produit liste_produit = new Liste_produit{

              Id_operation = id,
               Id_article = Article,
               Prix = produitl.Prix,
               Quantite = produitl.Quantite

             };
                 db.Liste_produit.Add(liste_produit);
                 db.SaveChanges();

             }

             var art = from ar in db.Article
                       select new Arti
                       {
                           Id_article = ar.Id_article,
                           Libelle_article = ar.Libelle_article,
                       };

             ViewData["Article"] = art.ToList();
             return View();
        }
        public ActionResult Insert(short Article)
        {
            short id = short.Parse(HttpContext.Application["pr"].ToString());

            ProduitL produitl = new ProduitL();

            if (TryUpdateModel(produitl, null, null, new[] { "Article" }))
            {
                Liste_produit liste_produit = new Liste_produit
                {

                    Id_operation = id,
                    Id_article = Article,
                    Prix = produitl.Prix,
                    Quantite = produitl.Quantite

                };
                db.Liste_produit.Add(liste_produit);
                db.SaveChanges();

            }

            var art = from ar in db.Article
                      select new Arti
                      {
                          Id_article = ar.Id_article,
                          Libelle_article = ar.Libelle_article,
                      };

            ViewData["Article"] = art.ToList();
            return View();
        }
Beispiel #4
0
        public ActionResult Insert(short idm, string article)
        {
            try
            {
            int px = article.IndexOf("-") + 2;
            int p = article.Length - px;
            string v = article.Substring(px, p);

            //Create a new instance of the Customer class.
            Liste_produit customer = new Liste_produit
            {
            Id_article = short.Parse(v),
            Id_operation = idm
            };

            Article Art = new Article();
            Mouvement_stock Mv = new Mouvement_stock();

            Art = db.Article.Find(customer.Id_article);
            Mv = db.Mouvement_stock.Find(idm);

            //Perform model binding (fill the customer properties and validate it).
            if (TryUpdateModel(customer))
            {
            if (Mv.Type_mouvement == "Sortie de stock")
            {
                if (Art.Qte_article < customer.Quantite)
                {
                    ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                }
                else
                {
                    //The model is valid - insert the customer and redisplay the grid.
                    customer.Prix_Total = customer.Quantite * customer.Prix;
                    db.Liste_produit.Add(customer);
                    db.SaveChanges();
                    //modiification de la qte d'article
                    Art.Qte_article = Art.Qte_article - customer.Quantite;
                    db.Entry(Art).State = EntityState.Modified;
                    db.SaveChanges();
                    //GridRouteValues() is an extension method which returns the
                    //route values defining the grid state - current page, sort expression, filter etc.
                    return RedirectToAction("Index", new { idm = customer.Id_operation });
                }

            }
            else
            {
                //The model is valid - insert the customer and redisplay the grid.
                customer.Prix_Total = customer.Quantite * customer.Prix;
                db.Liste_produit.Add(customer);
                db.SaveChanges();
                //modiification de la qte d'article
                Art.Qte_article = Art.Qte_article + customer.Quantite;
                db.Entry(Art).State = EntityState.Modified;
                db.SaveChanges();
                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                return RedirectToAction("Index", new { idm = customer.Id_operation });
            }
            }

            if (customer.Quantite > 0)
            {
            if (Mv.Type_mouvement == "Sortie de stock")
            {
                if (Art.Qte_article < customer.Quantite)
                {
                    ModelState.AddModelError("", "La quantité est supérieure à la quantité en stock");
                }
                else
                {
                    //The model is valid - insert the customer and redisplay the grid.
                    customer.Prix_Total = customer.Quantite * customer.Prix;
                    db.Liste_produit.Add(customer);
                    db.SaveChanges();
                    //modiification de la qte d'article
                    Art.Qte_article = Art.Qte_article - customer.Quantite;
                    db.Entry(Art).State = EntityState.Modified;
                    db.SaveChanges();
                    //GridRouteValues() is an extension method which returns the
                    //route values defining the grid state - current page, sort expression, filter etc.
                    return RedirectToAction("Index", new { idm = customer.Id_operation });
                }

            }
            else
            {
                //The model is valid - insert the customer and redisplay the grid.
                customer.Prix_Total = customer.Quantite * customer.Prix;
                db.Liste_produit.Add(customer);
                db.SaveChanges();
                //modiification de la qte d'article
                Art.Qte_article = Art.Qte_article + customer.Quantite;
                db.Entry(Art).State = EntityState.Modified;
                db.SaveChanges();
                //GridRouteValues() is an extension method which returns the
                //route values defining the grid state - current page, sort expression, filter etc.
                return RedirectToAction("Index", new { idm = customer.Id_operation });
            }
            }
            }
            catch {
            ModelState.AddModelError("", "l'article est incorrect");
            }
              //The model is invalid - render the current view to show any validation errors.
              var articles = db.Article;
              ViewData["articles"] = articles.ToList();

              List<String> listToBind = new List<String>();

              Preference preference = new Preference();
              preference = db.Preference.Find(1);

              if (preference.CRecherche.Trim() == "Code article".Trim())
              {
              foreach (var item in articles.ToList())
              {
              listToBind.Add(item.Code_article + " - " + item.Id_article);
              }
              }
              else
              {
              foreach (var item in articles.ToList())
              {
              listToBind.Add(item.Libelle_article + " - " + item.Id_article);
              }
              }
              ViewData["art"] = listToBind;

              ViewData["op"] = db.Mouvement_stock.Find(idm);

              var liste_produit = from l in db.Liste_produit.Include(l => l.Article).Include(l => l.Mouvement_stock)
                          where l.Id_operation == idm select l ;
              return View("Index", liste_produit.ToList());
        }