예제 #1
0
        public ActionResult Details([Bind(Include = "ID,Text,DateTime")] Comment comment, int? id)
        {
            TutorialComment tutorialcomment = new TutorialComment();

            tutorialcomment.Comment = comment;

            if (ModelState.IsValid)
            {
                string userid = User.Identity.GetUserId();
                var currentuser = db.Users.SingleOrDefault(u => u.Id == userid);

                var currentutorial = db.Tutorials.SingleOrDefault(v => v.ID == id);

                tutorialcomment.Comment.User = currentuser;
                tutorialcomment.Comment.Tutorial = currentutorial;
                tutorialcomment.Comment.DateTime = DateTime.Now;

                db.Comments.Add(tutorialcomment.Comment);
                db.SaveChanges();
                return RedirectToAction("Details");
            }

            return View(tutorialcomment);
        }
예제 #2
0
        // GET: /Tutorial/Details/5
        public ActionResult Details(int? id)
        {
            var comment = from s in db.Comments.Include(t => t.Tutorial).Include(f => f.User.Files)
                           select s;

            TutorialComment tutorialcomment = new TutorialComment();

            tutorialcomment.Comments = comment;

            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            Tutorial tutorial = db.Tutorials.Find(id);

            tutorialcomment.Tutorial = tutorial;

            if (tutorialcomment.Tutorial == null)
            {
                return HttpNotFound();
            }

            return View(tutorialcomment);
        }