public async Task <IActionResult> Edit(int id, [Bind("Id,PrixUnitaire,Quantite")] DetailsCommande detailsCommande, int idCommande)
        {
            if (id != detailsCommande.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(detailsCommande);
                    _context.SaveChangesAsync().Wait();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DetailsCommandeExists(detailsCommande.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Details", "Commandes", new { id = idCommande }));
            }
            return(View(detailsCommande));
        }
        // GET: Panier/Delete/5
        public ActionResult Delete(int id)
        {
            Commande        c = (Commande)Session["panier"];
            DetailsCommande d = c.DetailsCommandes.Where(dc => dc.IdDetailsCommandes == id).First();

            return(View(d));
        }
Exemple #3
0
        public IHttpActionResult PutDetailsCommande(long id, DetailsCommande detailsCommande)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != detailsCommande.DetailsID)
            {
                return(BadRequest());
            }

            db.Entry(detailsCommande).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DetailsCommandeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public ActionResult Edit([Bind(Include = "IdDetailsCommandes,IdCommande,IdProduit,Prix,Quantite")] DetailsCommande detailsCommande)
 {
     if (ModelState.IsValid)
     {
         rep.Modifier(detailsCommande);
         return(RedirectToAction("Index"));
     }
     ViewBag.IdCommande = new SelectList(repC.Lister().Select(c => new { c.IdCommande, c.StateDeCommande }), "IdCommande", "StateDeCommande", detailsCommande.IdCommande);
     ViewBag.IdProduit  = new SelectList(repP.Lister().Select(p => new { p.IdProduit, p.NomProduit }), "IdProduit", "NomProduit", detailsCommande.IdProduit);
     return(View(detailsCommande));
 }
        public async Task <IActionResult> Create([Bind("Id,PrixUnitaire,Quantite")] DetailsCommande detailsCommande)
        {
            if (ModelState.IsValid)
            {
                _context.Add(detailsCommande);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(detailsCommande));
        }
Exemple #6
0
        public IHttpActionResult GetDetailsCommande(long id)
        {
            DetailsCommande detailsCommande = db.DetailsCommandes.Find(id);

            if (detailsCommande == null)
            {
                return(NotFound());
            }

            return(Ok(detailsCommande));
        }
        public ContentResult Incrementer(int IdProduit)
        {
            Panier = (Commande)Session["panier"];
            DetailsCommande detail = Panier.DetailsCommandes.Where(d => d.IdProduit == IdProduit).First();

            detail.Quantite++;
            Session["panier"] = Panier;
            return(new ContentResult()
            {
                Content = detail.Quantite.ToString()
            });
        }
Exemple #8
0
        public IHttpActionResult PostDetailsCommande(DetailsCommande detailsCommande)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.DetailsCommandes.Add(detailsCommande);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = detailsCommande.DetailsID }, detailsCommande));
        }
        // GET: DetailsCommandes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DetailsCommande detailsCommande = rep.Trouver((int)id);

            if (detailsCommande == null)
            {
                return(HttpNotFound());
            }
            return(View(detailsCommande));
        }
        public ActionResult AddToCart(int id, int qte)
        {
            if (ModelState.IsValid)
            {
                if (User.Identity.IsAuthenticated)
                {
                    //check if client is associated to user
                    string IdClient = HttpContext.Session.GetString("IdClient");

                    if (IdClient != null)
                    {
                        if (HttpContext.Session.GetString("panier") == null) //check if shopping cart exists
                        {
                            Commande panier = new Commande();
                            panier.Idclient         = int.Parse(IdClient);
                            panier.Date             = DateTime.Now;
                            panier.IdstatutCommande = 1; //statut1 = commande preparee
                            panier.DetailsCommande  = new List <DetailsCommande>();
                            string str_panier = JsonConvert.SerializeObject(panier);
                            HttpContext.Session.SetString("panier", str_panier);
                        }
                        Commande panier_courant = JsonConvert.DeserializeObject <Commande>(HttpContext.Session.GetString("panier"));

                        //create a new detailCommande and associate to commande
                        //test si detail commande existe
                        DetailsCommande detail = panier_courant.DetailsCommande.Where(d => d.Idproduit == id).FirstOrDefault();
                        if (detail == null)
                        {
                            detail = new DetailsCommande()
                            {
                                Idproduit = id, Quantite = qte, Prix = repoProduit.GetItem(id).Prix
                            };
                            panier_courant.DetailsCommande.Add(detail);
                        }
                        else
                        {
                            detail.Quantite += qte;
                        }

                        string str_panier_courant = JsonConvert.SerializeObject(panier_courant);
                        HttpContext.Session.SetString("panier", str_panier_courant);
                    }
                }
                else
                {
                    return(RedirectToAction("Login", "Account"));
                }
            }
            return(RedirectToAction("Index", "Panier"));
        }
Exemple #11
0
        public IHttpActionResult DeleteDetailsCommande(long id)
        {
            DetailsCommande detailsCommande = db.DetailsCommandes.Find(id);

            if (detailsCommande == null)
            {
                return(NotFound());
            }

            db.DetailsCommandes.Remove(detailsCommande);
            db.SaveChanges();

            return(Ok(detailsCommande));
        }
        // GET: DetailsCommandes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DetailsCommande detailsCommande = rep.Trouver((int)id);

            if (detailsCommande == null)
            {
                return(HttpNotFound());
            }
            ViewBag.IdCommande = new SelectList(repC.Lister().Select(c => new { c.IdCommande, c.StateDeCommande }), "IdCommande", "StateDeCommande", detailsCommande.IdCommande);
            ViewBag.IdProduit  = new SelectList(repP.Lister().Select(p => new { p.IdProduit, p.NomProduit }), "IdProduit", "NomProduit", detailsCommande.IdProduit);
            return(View(detailsCommande));
        }
 public ActionResult Delete(int id, FormCollection collection)
 {
     try
     {
         // TODO: Add delete logic here
         Commande        c = (Commande)Session["panier"];
         DetailsCommande d = c.DetailsCommandes.Where(dc => dc.IdDetailsCommandes == id).First();
         if (d != null)
         {
             c.DetailsCommandes.Remove(d);
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Exemple #14
0
 public ActionResult RemoveFromShoppingCart(int idproduit)
 {
     if (ModelState.IsValid)
     {
         if (User.Identity.IsAuthenticated)
         {
             if (HttpContext.Session.GetString("panier") != null)
             {
                 Commande        panier_courant = JsonConvert.DeserializeObject <Commande>(HttpContext.Session.GetString("panier"));
                 DetailsCommande detail         = panier_courant.DetailsCommande.Where(d => d.Idproduit == idproduit).FirstOrDefault();
                 if (detail != null)
                 {
                     panier_courant.DetailsCommande.Remove(detail);
                 }
                 string str_panier_courant = JsonConvert.SerializeObject(panier_courant);
                 HttpContext.Session.SetString("panier", str_panier_courant);
             }
         }
     }
     return(RedirectToAction("Index", "Panier"));
 }