Advertisement
davichonov365

Untitled

Dec 17th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. using BasketballAcademyBlog.Models;
  2. using Blog.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8.  
  9. namespace BasketballAcademyBlog.Controllers
  10. {
  11. public class CommentController : Controller
  12. {
  13. // GET: Comment
  14. public ActionResult Index()
  15. {
  16. return View();
  17. }
  18.  
  19. //GET Publication/ReadPost
  20. [Authorize]
  21. public ActionResult Create()
  22. {
  23. return View();
  24. }
  25.  
  26. //POST Publication/ReadPost
  27.  
  28. [HttpPost]
  29. [Authorize]
  30. public ActionResult CreateComment(Comment comment)
  31. {
  32. if (ModelState.IsValid)
  33. {
  34. using (var database = new BlogDbContext())
  35. {
  36. var authorId = database
  37. .Users
  38. .Where(u => u.UserName == this.User.Identity.Name)
  39. .First()
  40. .Id;
  41. comment.AuthorId = authorId;
  42.  
  43. database.Comments.Add(comment);
  44. database.SaveChanges();
  45. return RedirectToAction("Index");
  46. }
  47. }
  48. return View(comment);
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement