Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width" />
- <title>@ViewBag.Title</title>
- @Styles.Render("~/Content/css")
- @Styles.Render("~/content/themes/base/css")
- @Scripts.Render("~/bundles/jquery")
- @Scripts.Render("~/bundles/jqueryui")
- @Scripts.Render("~/bundles/jqueryval")
- @Scripts.Render("~/bundles/modernizr")
- <script>
- $(function () {
- $("#edit-dialog").dialog(
- {
- autoOpen:false,
- height: 140,
- modal: true
- });
- $("#model-opener").click(function () {
- $("#edit-dialog").dialog("open");
- });
- });
- </script>
- </head>
- <body>
- @RenderBody()
- @RenderSection("scripts", required: false)
- </body>
- </html>
- @using RegisterPageBasic.Models
- @model IEnumerable<Messege>
- @{
- ViewBag.Title = "Current";
- }
- <h2>@ViewBag.TopicName</h2>
- @foreach (Messege messeges in Model)
- {
- <fieldset>
- <p>Пользователь <b>@messeges.Author</b> Написал:</p>
- <p>@messeges.Messegee</p>
- <p>@messeges.CreationDate</p>
- @if (messeges.Author == HttpContext.Current.User.Identity.Name)
- {
- <p>@Html.ActionLink("Edit", "EditMessege", new { ID = messeges.MessegeID })</p>
- }
- </fieldset>
- @using (Html.BeginForm())
- {
- @Html.TextArea("MessegeToTopic", "This is value", new { ID = @ViewBag.MessegeID })
- <input type="submit" value="OK" />
- }
- @if (ViewBag.CheckBox)
- {
- Html.Partial("EditMessage");
- }
- public class TopicController : Controller
- {
- [HttpGet]
- public ActionResult CreateTopic()
- {
- return View();
- }
- [HttpPost]
- [Authorize]
- public ActionResult CreateTopic(Topic topic,string messegeToTopic)
- {
- using (TopicContext _db = new TopicContext(ConfigurationManager.ConnectionStrings[1].ConnectionString))
- {
- topic.Author = HttpContext.User.Identity.Name;
- topic.CreationDate = DateTime.Now;
- _db.Topics.Add(topic);
- _db.SaveChanges();
- }
- return View();
- }
- [HttpGet]
- public ActionResult AllTopics()
- {
- TopicRepository topicRepos = new TopicRepository();
- IEnumerable<Topic> topic = topicRepos.GetAllTopics();
- return View(topic);
- }
- [HttpGet]
- [Authorize]
- public ActionResult Current(int ID,string TopicName)
- {
- MessegeRepository messegeRepos = new MessegeRepository();
- IEnumerable<Messege> messeege = messegeRepos.GetAllMessegesForTopicById(ID);
- ViewBag.MessegeID = ID;
- ViewBag.TopicName = TopicName;
- ViewBag.CheckBox = false;
- return View(messeege);
- }
- [HttpPost]
- [Authorize]
- public ActionResult Current(string messegeToTopic, int ID)
- {
- using (MessegeContext _db = new MessegeContext(ConfigurationManager.ConnectionStrings[1].ConnectionString))
- {
- Messege currentMessage = new Messege();
- currentMessage.TopicID = ID;
- currentMessage.Messegee = messegeToTopic;
- currentMessage.Author = HttpContext.User.Identity.Name;
- currentMessage.CreationDate = DateTime.Now;
- _db.Messeges.Add(currentMessage);
- _db.SaveChanges();
- }
- ViewBag.CheckBox = false;
- MessegeRepository messegeRepos = new MessegeRepository();
- IEnumerable<Messege> messeege = messegeRepos.GetAllMessegesForTopicById(ID);
- return View(messeege);
- }
- [HttpGet]
- public PartialViewResult EditMessege(int ID)
- {
- using (MessegeContext _db = new MessegeContext(ConfigurationManager.ConnectionStrings[1].ConnectionString))
- {
- Messege editMessege = _db.Messeges.FirstOrDefault(m => m.MessegeID == ID);
- ViewBag.CheckBox = true;
- ViewBag.TopicID = ID;
- return PartialView(editMessege);
- }
- }
- [HttpPost]
- public ActionResult EditMessege(string messegeToTopic,int ID)
- {
- using (MessegeContext _db = new MessegeContext(ConfigurationManager.ConnectionStrings[1].ConnectionString))
- {
- Messege messege = _db.Messeges.FirstOrDefault(m => m.MessegeID == ID);
- messege.Messegee = messegeToTopic;
- _db.SaveChanges();
- MessegeRepository messegeRepos = new MessegeRepository();
- int TopicID = messegeRepos.GetTopicIDByMessgeID(ID);
- return RedirectToAction("Current", new { ID = TopicID, TopicName = ViewBag.TopicName});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement