public ActionResult PostNewThread(string subject, string message) { var fVal = TempData.Where(t => t.Key == "ForumId").FirstOrDefault().Value; if (fVal == null) { return(RedirectToAction("Index")); } int forumId = (int)fVal; ForumPartition model = Storage.ForumPartitions.Where(p => p.Id == forumId).First(); if (model == null || model.DeactivationDate != null) { return(RedirectToAction("Index")); } //Debug.Assert(false); if (!string.IsNullOrWhiteSpace(subject) && !string.IsNullOrWhiteSpace(message)) { User owner = Storage.Users.Where(u => u.Id == WebSecurity.CurrentUserId).FirstOrDefault(); if (owner == null) { return(RedirectToAction("Index")); } if (owner.DeactivationDate != null) { WebSecurity.Logout(); return(RedirectToAction("Index")); } Message newMessage = new Message { CreationDate = DateTime.Now, MessageOwner = owner, Text = message, ModeratorAction = ModedatorActionType.None }; Storage.Messages.Add(newMessage); Topic newTopic = new Topic() { TopicOwner = owner, FirstMessage = newMessage, TopicName = subject, CreationDate = DateTime.Now, Views = 0, TopicType = TopicTypes.Common }; Storage.Messages.Add(newMessage); //Storage.Topics.Add(newTopic); model.Topics.Add(newTopic); Storage.SaveChanges(); } return(RedirectToAction("ThreadsPage", new { ForumId = model.Id })); //return RedirectToAction() }
public ActionResult CreateNewThread(string ForumId = "") { if (string.IsNullOrEmpty(ForumId)) { return(RedirectToAction("Index")); } ForumPartition partition = null; int partitionId; if (!int.TryParse(ForumId, out partitionId) || (partition = Storage.ForumPartitions.Where(p => p.Id == partitionId).FirstOrDefault()) == null) { return(RedirectToAction("Index")); } return(View("CreateNewThreadPage", partition)); }