public ActionResult Confirmer(LivreInventaire livres) { if (ModelState.IsValid) { livres.Id = db.LivreInventaire.Where(i => i.NomEtudiant == livres.NomEtudiant && i.CodeIdentification == livres.CodeIdentification).FirstOrDefault().Id; this.AjouterLivreAVendre(livres); this.RetirerLivreInventaire(livres); return RedirectToAction("RemiseLivre", "Livres"); } else { ModelState.AddModelError("", "Quelque chose ne va pas avec le model"); return View(livres); } }
private void RetirerLivreInventaire(LivreInventaire livres) { if(livres != null) { var testlivre = db.LivreInventaire.Where(i => i.Id == livres.Id).FirstOrDefault(); if (testlivre != null) { db.Entry(testlivre).State = EntityState.Deleted; db.SaveChanges(); } } }
private void AjouterLivreAVendre(LivreInventaire livres) { livres.Etat = livres.ValeurEtat.ElementAt(livres.typeId).name; var livrepret = db.LivreAVendreSet.Where(i => i.CodeIdentification == livres.CodeIdentification && i.Etat == livres.Etat && i.Etat == livres.Etat).FirstOrDefault(); if (livrepret == null) { livrepret = new LivreAVendre(); livrepret.CodeIdentification = livres.CodeIdentification; livrepret.Cooperative = livres.Cooperative; livrepret.Etat = livres.Etat; livrepret.Id = db.LivreAVendreSet.Count() + 1; livrepret.Quantite = 1; //Add a la db db.LivreAVendreSet.Add(livrepret); db.SaveChanges(); } else { livrepret.Quantite++; db.Entry(livrepret).State = EntityState.Modified; db.SaveChanges(); } }
public ActionResult EditEtat([Bind(Include = "CodeIdentification,Etat,ContinuerAjout,typeID,ValeurEtat")] LivreInventaire livres) { if (ModelState.IsValid) { ApplicationDbContext user = new ApplicationDbContext(); LivreInventaire LivreInv = new LivreInventaire(); livres.Etat = livres.ValeurEtat.ElementAt(livres.typeId).name; livres.Cooperative = user.Users.Where(i => i.UserName == User.Identity.Name).FirstOrDefault().coopid; livres.Titre = db.Livres.Where(i=>i.CodeIdentification == livres.CodeIdentification).FirstOrDefault().Nom; livres.NomEtudiant = User.Identity.Name.ToString(); livres.Telephone = user.Users.Where(i => i.UserName == livres.NomEtudiant).First().Telephone; System.Diagnostics.Debug.WriteLine("Telephone : " + livres.Telephone); livres.Id = db.LivreInventaire.Max(i => i.Id) + 1; livres.Quantite = 1; db.LivreInventaire.Add(livres); db.SaveChanges(); } if (livres.ContinuerAjout == true) return RedirectToAction("Search", "Livres"); else return RedirectToAction("Index","Home"); }
public ActionResult Edit([Bind(Include="Nom,Auteur,NbrPages,Prix,IdCoop,CodeIdentification")] Livres livres) { if (ModelState.IsValid) { LivreInventaire LivreInv = new LivreInventaire(); LivreInv = db.LivreInventaire.FirstOrDefault(i => i.CodeIdentification == livres.CodeIdentification); if(LivreInv == null) { LivreInv = new LivreInventaire(); LivreInv.CodeIdentification = livres.CodeIdentification; LivreInv.Cooperative = livres.IdCoop; LivreInv.Quantite = 1; LivreInv.Id = db.LivreInventaire.Count() + 1; } db.Entry(livres).State = EntityState.Modified; // db.LivreInventaire.Add(livres.livreinventaire); db.SaveChanges(); return RedirectToAction("EditEtat","Livres", new { id = LivreInv.CodeIdentification }); } return View(livres); }
private void AjouterLivreAVendre(LivreInventaire livres) { livres.Etat = livres.ValeurEtat.ElementAt(livres.typeId).name; var livrepret = db.LivreAVendreSet.Where(i => i.CodeIdentification == livres.CodeIdentification && i.Etat == livres.Etat && i.Etat == livres.Etat).FirstOrDefault(); Livres InfoLivre = db.Livres.Where(i => i.CodeIdentification == livres.CodeIdentification).First(); if (livrepret == null || livrepret.Cooperative != livres.Cooperative) { livrepret = new LivreAVendre(); livrepret.CodeIdentification = livres.CodeIdentification; livrepret.Cooperative = livres.Cooperative; livrepret.Etat = livres.Etat; livrepret.Titre = InfoLivre.Nom; livrepret.Id = db.LivreAVendreSet.Count() + 1; livrepret.Auteur = InfoLivre.Auteur; if(livres.Etat == "Comme Neuf") { livrepret.Prix = ((InfoLivre.Prix)*(decimal)0.75); } else if (livres.Etat == "Moyennement Abîmé") { livrepret.Prix = ((InfoLivre.Prix) * (decimal)0.50); } else { livrepret.Prix = ((InfoLivre.Prix) * (decimal)0.25); } livrepret.Proprietaire += (livres.NomEtudiant + ";"); livrepret.Quantite = 1; //Add a la db db.LivreAVendreSet.Add(livrepret); db.SaveChanges(); } else if(livrepret.Cooperative == livres.Cooperative) { livrepret.Quantite++; livrepret.Proprietaire += (livres.NomEtudiant + ";"); db.Entry(livrepret).State = EntityState.Modified; db.SaveChanges(); } }