public ActionResult SaveComment(string commentaire, string note, int afficheID) { AvisAffiche nouvelAvis = new AvisAffiche(); nouvelAvis.DateAvis = DateTime.Now; nouvelAvis.Message = commentaire; nouvelAvis.Auteur = User.Identity.Name; double dnote = 0; if (!double.TryParse(note, NumberStyles.Any, CultureInfo.InvariantCulture, out dnote)) { throw new Exception("Impossible de parser la note" + note); } nouvelAvis.note = dnote; using (var context = new CNGLUTTEDBEntities()) { Affiche aff = context.Affiches.Where(a => a.AfficheID == afficheID).SingleOrDefault(); if (aff == null) { return(RedirectToAction("Index", "AfficheUser")); } //var p = context.AvisAffiches.ToList(); //var maxId = p.Max(x => x.AvisAfficheID); //nouvelAvis.AvisAfficheID = maxId + 1; nouvelAvis.AfficheID = aff.AfficheID; context.AvisAffiches.Add(nouvelAvis); context.SaveChanges(); } return(RedirectToAction("DetailsAfficheAvecAvis", "AfficheUser", new { id = afficheID })); }
public ActionResult DeleteConfirmed(int id) { AvisAffiche avisAffiche = db.AvisAffiches.Find(id); db.AvisAffiches.Remove(avisAffiche); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: AvisAdmin/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AvisAffiche avisAffiche = db.AvisAffiches.Find(id); if (avisAffiche == null) { return(HttpNotFound()); } return(View(avisAffiche)); }