public ActionResult DeleteForum(int ForumID) { var attachments = _attachmentRepository.Where(item => item.Post.Thread.ForumID == ForumID); _fileServices.DeleteAttachments(attachments); _forumRepository.Delete(ForumID); SetSuccess("Forum Deleted"); return(RedirectToAction("Forums")); }
public ActionResult ThreadValidate(ThreadViewModel model) { EditorType editorType; if (model.PostEditor.PostID == 0) editorType = EditorType.Create; else editorType = EditorType.Edit; if (editorType == EditorType.Create) { if (!_permissionServices.CanCreateThread(model.ForumID, _currentUser.UserID)) { SetNotice("You don't have permission to create a thread in this forum"); return RedirectToAction("ViewForum", "Board", new { ForumID = model.ForumID }); } } else { if (!_postServices.CanEditPost(model.PostEditor.PostID, _currentUser.UserID)) { SetError("You can't edit this post"); return RedirectToAction("ViewThread", "Board", new { ThreadID = model.ThreadEditor.ThreadID }); } } if (!_permissionServices.CanCreateThreadType(model.ForumID, _currentUser.UserID, (ThreadType)model.ThreadEditor.ThreadType)) { model.ThreadEditor.ThreadType = (int)ThreadType.Regular; ModelState.AddModelError("ThreadEditor.ThreadType", "You don't have permission to create a thread of this type"); } if (!model.Preview.HasValue && _currentUser.LastPostDate.HasValue) { int MinTimeLimit = int.Parse(SiteConfig.TimeBetweenPosts.Value); double ValToCompare = (DateTime.UtcNow - _currentUser.LastPostDate.Value).TotalSeconds; if (ValToCompare < MinTimeLimit) ModelState.AddModelError("TimeBetweenPosts", "You may only create new posts every " + MinTimeLimit + " seconds (" + Math.Round((MinTimeLimit - ValToCompare)) + " seconds remaining)"); } ValidateThreadImage(model.ThreadEditor.Image); HttpPostedFileBase[] files = null; if (_permissionServices.CanCreateAttachment(model.ForumID, _currentUser.UserID)) { if (model.PostEditor.Files != null) { ValidatePostedFiles(model.PostEditor.Files); files = model.PostEditor.Files.Where(item => item != null && item.ContentLength > 0 && !string.IsNullOrWhiteSpace(item.FileName)).ToArray(); } } else model.PostEditor.Delete = null; if (!_permissionServices.CanCreatePoll(model.ForumID, _currentUser.UserID)) { model.PollEditor.Text = string.Empty; model.PollEditor.Options = string.Empty; } if (IsModelValidAndPersistErrors() && !model.Preview.HasValue) { if (editorType == EditorType.Create) { Thread thread = _threadServices.CreateThread( model.ForumID, _currentUser.UserID, model.ThreadEditor.Title, (ThreadType)model.ThreadEditor.ThreadType, model.ThreadEditor.Image, model.PostEditor.Message, model.PollEditor.Text, model.PollEditor.OptionsSplit, files); if (_threadServices.IsSubscribed(thread.ThreadID, _currentUser.UserID) && model.PostEditor.SubscribeToThread) _threadServices.Subscribe(thread.ThreadID, _currentUser.UserID); SetSuccess("Thread created"); return RedirectToAction("ViewThread", "Board", new { ThreadID = thread.ThreadID }); } else { Thread thread = _threadServices.GetThread(model.ThreadEditor.ThreadID); var poll = model.PollEditor; bool createPoll = true; if (thread.Poll != null) { if (thread.Poll.TotalVotes > 0) { if (poll != null && poll.Delete) { _pollServices.DeletePoll(model.ThreadEditor.ThreadID); } else createPoll = false; } else { _pollServices.DeletePoll(model.ThreadEditor.ThreadID); } } if (createPoll && poll != null && !string.IsNullOrWhiteSpace(poll.Text)) _pollServices.CreatePoll(poll.Text, poll.OptionsSplit, model.ThreadEditor.ThreadID); if (model.PostEditor.Delete != null) _fileServices.DeleteAttachments(model.PostEditor.Delete); _threadServices.UpdateThread(model.ThreadEditor.ThreadID, model.ThreadEditor.Title, (ThreadType)model.ThreadEditor.ThreadType, model.ThreadEditor.Image); _postServices.UpdatePost(model.PostEditor.PostID, model.PostEditor.Message, files); SetSuccess("Thread edited"); return RedirectToAction("ViewThread", "Board", new { ThreadID = model.ThreadEditor.ThreadID }); } } if (model.Preview.HasValue) { TempData["Preview_Text"] = model.PostEditor.Message; TempData["Preview_Title"] = model.ThreadEditor.Title; } if (editorType == EditorType.Create) return RedirectToAction("CreateThread", new { ForumID = model.ForumID }); else return RedirectToAction("EditThread", new { ThreadID = model.ThreadEditor.ThreadID }); }