Example #1
0
        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));
        }
Example #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            AstroKoment astroKoment = db.AstroKoments.Find(id);

            db.AstroKoments.Remove(astroKoment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
 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));
 }
Example #4
0
        // 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));
        }
Example #5
0
        // 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));
        }