Advertisement
Guest User

Untitled

a guest
Jan 5th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width" />
  6. <title>@ViewBag.Title</title>
  7.  
  8. @Styles.Render("~/Content/css")
  9. @Styles.Render("~/content/themes/base/css")
  10. @Scripts.Render("~/bundles/jquery")
  11. @Scripts.Render("~/bundles/jqueryui")
  12. @Scripts.Render("~/bundles/jqueryval")
  13. @Scripts.Render("~/bundles/modernizr")
  14.  
  15. <script>
  16. $(function () {
  17. $("#edit-dialog").dialog(
  18. {
  19. autoOpen:false,
  20. height: 140,
  21. modal: true
  22. });
  23.  
  24. $("#model-opener").click(function () {
  25. $("#edit-dialog").dialog("open");
  26. });
  27. });
  28.  
  29. </script>
  30. </head>
  31. <body>
  32. @RenderBody()
  33. @RenderSection("scripts", required: false)
  34. </body>
  35. </html>
  36.  
  37. @using RegisterPageBasic.Models
  38. @model IEnumerable<Messege>
  39. @{
  40. ViewBag.Title = "Current";
  41. }
  42.  
  43. <h2>@ViewBag.TopicName</h2>
  44.  
  45. @foreach (Messege messeges in Model)
  46. {
  47. <fieldset>
  48. <p>Пользователь <b>@messeges.Author</b> Написал:</p>
  49. <p>@messeges.Messegee</p>
  50. <p>@messeges.CreationDate</p>
  51. @if (messeges.Author == HttpContext.Current.User.Identity.Name)
  52. {
  53. <p>@Html.ActionLink("Edit", "EditMessege", new { ID = messeges.MessegeID })</p>
  54. }
  55. </fieldset>
  56.  
  57. @using (Html.BeginForm())
  58. {
  59. @Html.TextArea("MessegeToTopic", "This is value", new { ID = @ViewBag.MessegeID })
  60. <input type="submit" value="OK" />
  61. }
  62.  
  63. @if (ViewBag.CheckBox)
  64. {
  65. Html.Partial("EditMessage");
  66. }
  67.  
  68. public class TopicController : Controller
  69. {
  70. [HttpGet]
  71. public ActionResult CreateTopic()
  72. {
  73. return View();
  74. }
  75.  
  76. [HttpPost]
  77. [Authorize]
  78. public ActionResult CreateTopic(Topic topic,string messegeToTopic)
  79. {
  80.  
  81. using (TopicContext _db = new TopicContext(ConfigurationManager.ConnectionStrings[1].ConnectionString))
  82. {
  83. topic.Author = HttpContext.User.Identity.Name;
  84. topic.CreationDate = DateTime.Now;
  85. _db.Topics.Add(topic);
  86. _db.SaveChanges();
  87. }
  88.  
  89. return View();
  90. }
  91. [HttpGet]
  92. public ActionResult AllTopics()
  93. {
  94. TopicRepository topicRepos = new TopicRepository();
  95. IEnumerable<Topic> topic = topicRepos.GetAllTopics();
  96.  
  97. return View(topic);
  98. }
  99.  
  100. [HttpGet]
  101. [Authorize]
  102. public ActionResult Current(int ID,string TopicName)
  103. {
  104. MessegeRepository messegeRepos = new MessegeRepository();
  105. IEnumerable<Messege> messeege = messegeRepos.GetAllMessegesForTopicById(ID);
  106. ViewBag.MessegeID = ID;
  107. ViewBag.TopicName = TopicName;
  108. ViewBag.CheckBox = false;
  109.  
  110. return View(messeege);
  111. }
  112. [HttpPost]
  113. [Authorize]
  114. public ActionResult Current(string messegeToTopic, int ID)
  115. {
  116. using (MessegeContext _db = new MessegeContext(ConfigurationManager.ConnectionStrings[1].ConnectionString))
  117. {
  118. Messege currentMessage = new Messege();
  119. currentMessage.TopicID = ID;
  120. currentMessage.Messegee = messegeToTopic;
  121. currentMessage.Author = HttpContext.User.Identity.Name;
  122. currentMessage.CreationDate = DateTime.Now;
  123. _db.Messeges.Add(currentMessage);
  124. _db.SaveChanges();
  125. }
  126. ViewBag.CheckBox = false;
  127. MessegeRepository messegeRepos = new MessegeRepository();
  128. IEnumerable<Messege> messeege = messegeRepos.GetAllMessegesForTopicById(ID);
  129.  
  130. return View(messeege);
  131. }
  132. [HttpGet]
  133. public PartialViewResult EditMessege(int ID)
  134. {
  135. using (MessegeContext _db = new MessegeContext(ConfigurationManager.ConnectionStrings[1].ConnectionString))
  136. {
  137. Messege editMessege = _db.Messeges.FirstOrDefault(m => m.MessegeID == ID);
  138. ViewBag.CheckBox = true;
  139. ViewBag.TopicID = ID;
  140. return PartialView(editMessege);
  141. }
  142. }
  143. [HttpPost]
  144. public ActionResult EditMessege(string messegeToTopic,int ID)
  145. {
  146. using (MessegeContext _db = new MessegeContext(ConfigurationManager.ConnectionStrings[1].ConnectionString))
  147. {
  148. Messege messege = _db.Messeges.FirstOrDefault(m => m.MessegeID == ID);
  149. messege.Messegee = messegeToTopic;
  150. _db.SaveChanges();
  151.  
  152. MessegeRepository messegeRepos = new MessegeRepository();
  153. int TopicID = messegeRepos.GetTopicIDByMessgeID(ID);
  154. return RedirectToAction("Current", new { ID = TopicID, TopicName = ViewBag.TopicName});
  155. }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement