public ActionResult DeleteConfirmed(int id)
        {
            ModelKoment modelKoment = db.ModelKoments.Find(id);

            db.ModelKoments.Remove(modelKoment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "ID,ModelID,Text,SendDate,ProfileID")] ModelKoment modelKoment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(modelKoment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ModelID   = new SelectList(db.Models, "ID", "Name", modelKoment.ModelID);
     ViewBag.ProfileID = new SelectList(db.Profiles, "Id", "UserName", modelKoment.ProfileID);
     return(View(modelKoment));
 }
        // GET: ModelKoment/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ModelKoment modelKoment = db.ModelKoments.Find(id);

            if (modelKoment == null)
            {
                return(HttpNotFound());
            }
            return(View(modelKoment));
        }
        // GET: ModelKoment/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ModelKoment modelKoment = db.ModelKoments.Find(id);

            if (modelKoment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ModelID   = new SelectList(db.Models, "ID", "Name", modelKoment.ModelID);
            ViewBag.ProfileID = new SelectList(db.Profiles, "Id", "UserName", modelKoment.ProfileID);
            return(View(modelKoment));
        }
        public ActionResult Create([Bind(Include = "ID,ModelID,Text,SendDate,ProfileID")] ModelKoment modelKoment)
        {
            //if (ModelState.IsValid)
            //{
            //    db.ModelKoments.Add(modelKoment);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}

            //ViewBag.ModelID = new SelectList(db.Models, "ID", "Name", modelKoment.ModelID);
            //ViewBag.ProfileID = new SelectList(db.Profiles, "Id", "UserName", modelKoment.ProfileID);
            //return View(modelKoment);

            try
            {
                if (ModelState.IsValid)
                {
                    modelKoment.SendDate = DateTime.Now;
                    modelKoment.Profile  = db.Profiles
                                           .Where(p => p.UserName == User.Identity.Name).FirstOrDefault();
                    modelKoment.Model = db.Models
                                        .Where(a => a.ID == modelKoment.ModelID).FirstOrDefault();

                    db.ModelKoments.Add(modelKoment);
                    db.SaveChanges();
                    var routeValue = new RouteValueDictionary
                                         (new { action = "Details", controller = "Model", id = modelKoment.ModelID });
                    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 = "Model", id = modelKoment.ModelID });

            return(RedirectToRoute(routeValue2));
        }