Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using BasketballAcademyBlog.Models;
- using Blog.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace BasketballAcademyBlog.Controllers
- {
- public class CommentController : Controller
- {
- // GET: Comment
- public ActionResult Index()
- {
- return View();
- }
- //GET Publication/ReadPost
- [Authorize]
- public ActionResult Create()
- {
- return View();
- }
- //POST Publication/ReadPost
- [HttpPost]
- [Authorize]
- public ActionResult CreateComment(Comment comment)
- {
- if (ModelState.IsValid)
- {
- using (var database = new BlogDbContext())
- {
- var authorId = database
- .Users
- .Where(u => u.UserName == this.User.Identity.Name)
- .First()
- .Id;
- comment.AuthorId = authorId;
- database.Comments.Add(comment);
- database.SaveChanges();
- return RedirectToAction("Index");
- }
- }
- return View(comment);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement