public ActionResult Create([Bind(Include = "ID,AstroID,Text")] AstroKoment astroKoment) { try { if (ModelState.IsValid) { astroKoment.SendDate = DateTime.Now; astroKoment.Profile = db.Profiles .Where(p => p.UserName == User.Identity.Name).FirstOrDefault(); astroKoment.Astro = db.Astroes .Where(a => a.ID == astroKoment.AstroID).FirstOrDefault(); db.AstroKoments.Add(astroKoment); db.SaveChanges(); var routeValue = new RouteValueDictionary (new { action = "Details", controller = "Astro", id = astroKoment.AstroID }); return(RedirectToRoute(routeValue)); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } var routeValue2 = new RouteValueDictionary (new { action = "Details", controller = "Astro", id = astroKoment.AstroID }); return(RedirectToRoute(routeValue2)); }
public ActionResult DeleteConfirmed(int id) { AstroKoment astroKoment = db.AstroKoments.Find(id); db.AstroKoments.Remove(astroKoment); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,AstroID,Text,SendDate")] AstroKoment astroKoment) { if (ModelState.IsValid) { db.Entry(astroKoment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.modelId = new SelectList(db.Astroes, "ID", "Name", astroKoment.AstroID); return(View(astroKoment)); }
// GET: AstroKoment/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AstroKoment astroKoment = db.AstroKoments.Find(id); if (astroKoment == null) { return(HttpNotFound()); } return(View(astroKoment)); }
// GET: AstroKoment/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AstroKoment astroKoment = db.AstroKoments.Find(id); if (astroKoment == null) { return(HttpNotFound()); } ViewBag.modelId = new SelectList(db.Astroes, "ID", "Name", astroKoment.AstroID); return(View(astroKoment)); }