Beispiel #1
0
        public IActionResult Edit(EditThreadViewModel model)
        {
            forumThread.ThreadID      = model.ThreadID;
            forumThread.ThreadMessage = model.ThreadMessage;

            forumThread.EditForumThread();

            return(RedirectToAction("Index"));
        }
        public ActionResult InsertEditThreadView(int threadId, int boardId, string userId, string subject)
        {
            EditThreadViewModel etvm = new EditThreadViewModel()
            {
                ThreadId = threadId, BoardId = boardId, UserId = userId, Subject = subject
            };

            return(PartialView("_EditThread", etvm));
        }
Beispiel #3
0
        public IActionResult Edit(int threadID)
        {
            forumThread = forumThreadCollection.GetForumThread(threadID);
            EditThreadViewModel model = new EditThreadViewModel()
            {
                ThreadID      = forumThread.ThreadID,
                ThreadMessage = forumThread.ThreadMessage
            };

            return(View(model));
        }
Beispiel #4
0
        public async Task <ActionResult> EditThread(int groupId, int threadId, EditThreadViewModel model)
        {
            // Gets the thread
            Thread thread = await ThreadManager.FindByIdAsync(threadId);

            // Changes the values
            thread.Tags = model.Tags.Split(',').ToList().Select(s => s.Trim()).Where(s => !String.IsNullOrEmpty(s)).ToArray();
            thread.Name = model.Name;

            // Updates the thread
            await ThreadManager.UpdateAsync(thread);

            return(RedirectToAction("Thread"));
        }
Beispiel #5
0
        public async Task <ActionResult> EditThread(int groupId, int threadId)
        {
            ViewBag.GroupId  = groupId;
            ViewBag.ThreadId = threadId;

            // Getting the thread
            Thread thread = await ThreadManager.FindByIdAsync(threadId);

            EditThreadViewModel model = new EditThreadViewModel
            {
                Name = thread.Name,
                Tags = String.Join(", ", thread.Tags)
            };

            return(View(model));
        }
Beispiel #6
0
        public ActionResult EditThread(int id, int? MoveTo, string Lock, string Delete)
        {
            using (ForumRespository db = new ForumRespository())
            {
                Forum_Thread EditedThread = db.GetThreadByID(id);
                if (EditedThread == null)
                    return NotFoundView("Post");

                var model = new EditThreadViewModel();
                var Category = EditedThread.Forum_Category;

                model.AddNavigation(EditedThread);
                model.AddNavigation("Edit Thread");

                var Editor = GetCurrentUser(db);

                model.AllowDelete = db.CheckCategoryPermissions(Category, Editor, P => (P.AllowDeleteOwnThread && EditedThread.Forum_Posts[0].PosterID == Editor.UserID && EditedThread.PosterID != (int)BuildInUser.Guest) || P.AllowDeleteAllThread);
                model.AllowMove = db.CheckCategoryPermissions(Category, Editor, P => P.AllowMoveThread);
                model.AllowLock = db.CheckCategoryPermissions(Category, Editor, P => P.AllowLockThread);

                if (!model.AllowDelete && !model.AllowLock && !model.AllowMove)
                    return AuthenticationHelper.AccessDeniedView(model);

                model.id = id;
                model.ThreadName = EditedThread.Title;
                model.CategoryID = Category.CategoryID;
                model.CategoryName = Category.Name;

                model.IsLocked = EditedThread.Locked;

                foreach (var MoveToCategory in db.GetAllCategories())
                {
                    if (MoveToCategory == Category) continue; // Cannot move the where the thread is already
                    if (!MoveToCategory.AllowPosts) continue; // Cannot move to a category that does not allow posts
                    if (!db.CheckCategoryPermissions(MoveToCategory, Editor, P => P.AllowNewThread)) continue; // Cannot move to a category where you are not allowed to create new threads.
                    model.ValidMoveDestinations.Add(new AdminNamedID() { ID = MoveToCategory.CategoryID, Name = MoveToCategory.Name});
                }

                if (IsHttpPost)
                {
                    if (!AntiForgeryTokenValid)
                    {
                        ModelState.AddModelError("AntiForgery", "The antiforgery token was invalid.");
                    }
                    else
                    {
                        if (model.AllowDelete && !String.IsNullOrEmpty(Delete))
                        {
                            db.DeleteThread(EditedThread);
                            db.Save();
                            return RedirectToAction("ViewCategory", new { id = model.CategoryID });
                        }
                        if (model.AllowMove)
                        {
                            var Destination = db.GetCategoryByID((int)MoveTo);
                            if (Destination != null && model.ValidMoveDestinations.Exists(D => D.ID == Destination.CategoryID))
                            {
                                EditedThread.Forum_Category = Destination;
                            }
                        }
                        if (model.AllowLock)
                            EditedThread.Locked = !String.IsNullOrEmpty(Lock);
                        db.Save();
                        return RedirectToAction("ViewThread", new { id = model.id });
                    }
                }
                return View(model);
            }
        }