예제 #1
0
        public ActionResult EditPost(vmForumTopicCreate model)
        {
            //get topic being edited
            Topic _topic = db_Forum.GetTopic_ByID(model.TopicId);

            if (_topic != null)
            {
                // Update the Topic
                db_Forum.InsertUpdateTopic(model, 0);

                Guid?newPostID = db_Forum.InsertUpdatePost(model.Id, model.Content, null, null, null, null, null, null, null, null, null, true);

                // 7. Tag handling
                db_Forum.DeleteTopicTags(model.TopicId, "Topic Tag");
                foreach (string feature in model.SelectedTags ?? new List <string>())
                {
                    db_Forum.InsertUpdateTopicTags(model.TopicId, "Topic Tag", feature);
                }

                // 11. Update Azure search
                AzureSearch.PopulateSearchIndexForumTopic(model.TopicId);
            }

            return(RedirectToAction("ShowTopic", "Forum", new { slug = _topic.Slug }));
        }
예제 #2
0
        public ActionResult EditPost(vmForumTopicCreate model)
        {
            //get topic being edited
            Topic _topic = db_Forum.GetTopic_ByID(model.TopicId);

            if (_topic != null)
            {
                int UserIDX = db_Accounts.GetUserIDX();

                // Update the Topic
                db_Forum.InsertUpdateTopic(model, UserIDX);

                Guid?newPostID = db_Forum.InsertUpdatePost(model.Id, model.Content, null, null, null, null, null, null, null, null, null, true);

                //3b. Set last update datetime
                db_Forum.UpdateTopic_SetLastPostDate(model.TopicId, null);

                // 5. Poll handling
                if (_topic.Poll_Id != null)
                {
                    if (model.PollAnswers.Count(x => x != null) > 1)
                    {
                        // Update Poll
                        Guid?PollID = db_Forum.InsertUpdatePoll(_topic.Poll_Id, model.IsPollClosed, System.DateTime.Now, model.PollCloseAfterDays, UserIDX);

                        // Update poll answers
                        foreach (PollAnswer answer in model.PollAnswers)
                        {
                            if (answer.Answer != null)
                            {
                                db_Forum.InsertUpdatePollAnswer(answer.Id, answer.Answer, PollID);
                            }
                        }
                    }
                }

                // 7. Tag handling
                db_Forum.DeleteTopicTags(model.TopicId, "Topic Tag");
                foreach (string feature in model.SelectedTags ?? new List <string>())
                {
                    db_Forum.InsertUpdateTopicTags(model.TopicId, "Topic Tag", feature);
                }

                // 11. Update Azure search
                AzureSearch.PopulateSearchIndexForumPost(newPostID);
            }

            return(RedirectToAction("ShowTopic", "Forum", new { slug = _topic.Slug }));
        }
예제 #3
0
        public ActionResult EditPost(Guid?id)
        {
            Post _post = db_Forum.GetPost_ByID(id.ConvertOrDefault <Guid>());

            if (_post != null)
            {
                Topic _topic = db_Forum.GetTopic_ByID(_post.Topic_Id);

                var viewModel = new vmForumTopicCreate
                {
                    //stuff from post
                    Name                = _topic.Name,
                    Content             = _post.PostContent,
                    IsSticky            = _topic.IsSticky,
                    IsLocked            = _topic.IsLocked,
                    Category            = _topic.Category_Id,
                    SelectedTags        = db_Forum.GetTopicTags_ByAttributeSelected(_topic.Id, "Topic Tag"),
                    Id                  = _post.Id,
                    TopicId             = _topic.Id,
                    Categories          = ddlForumHelpers.get_ddl_categories_tree(),
                    OptionalPermissions = GetOptionalPermissions(),
                    IsTopicStarter      = _post.IsTopicStarter ?? false,
                    PollAnswers         = new List <PollAnswer>(),
                    PollCloseAfterDays  = 0,
                    AllTags             = db_Forum.GetTopicTags_ByAttributeAll(_topic.Id, "Tags").Select(x => new SelectListItem {
                        Value = x, Text = x
                    })
                };

                //add polling information
                if (_topic.Poll_Id != null)
                {
                    Poll _poll = db_Forum.GetPoll_ByID(_topic.Poll_Id.ConvertOrDefault <Guid>());
                    if (_poll != null)
                    {
                        viewModel.PollAnswers        = db_Forum.GetPollAnswers_ByPollID(_topic.Poll_Id.ConvertOrDefault <Guid>());
                        viewModel.PollCloseAfterDays = _poll.ClosePollAfterDays ?? 0;
                        viewModel.IsPollClosed       = _poll.IsClosed;
                    }
                }

                return(View(viewModel));
            }
            else
            {
                TempData["Error"] = "Post not found";
                return(RedirectToAction("Index", "Forum"));
            }
        }
예제 #4
0
        public ActionResult Create(Guid?id)
        {
            var viewModel = new vmForumTopicCreate
            {
                SubscribeToTopic    = true,
                Categories          = ddlForumHelpers.get_ddl_categories_tree(),
                Category            = id.ConvertOrDefault <Guid>(),
                OptionalPermissions = GetOptionalPermissions(),
                IsTopicStarter      = true,
                SelectedTags        = new List <string>(),
                AllTags             = db_Forum.GetTopicTags_ByAttributeAll(Guid.NewGuid(), "Tags").Select(x => new SelectListItem {
                    Value = x, Text = x
                })
            };

            return(View(viewModel));
        }
예제 #5
0
        public ActionResult Create(vmForumTopicCreate topicViewModel)
        {
            int UserIDX = db_Accounts.GetUserIDX();

            // If viewModel is returned back to the view, repopulate view model fist
            topicViewModel.OptionalPermissions = GetOptionalPermissions();
            topicViewModel.Categories          = ddlForumHelpers.get_ddl_categories_tree();
            topicViewModel.IsTopicStarter      = true;
            topicViewModel.PollAnswers         = topicViewModel.PollAnswers ?? new List <PollAnswer>();
            topicViewModel.SelectedTags        = topicViewModel.SelectedTags ?? new List <string>();
            topicViewModel.AllTags             = db_Forum.GetTopicTags_ByAttributeAll(Guid.NewGuid(), "Tags").Select(x => new SelectListItem {
                Value = x, Text = x
            });
            /*---- End Re-populate ViewModel ----*/

            if (ModelState.IsValid)
            {
                // ************************ VALIDATION **********************************************
                // See if the user has actually added some content to the topic
                if (string.IsNullOrEmpty(topicViewModel.Content))
                {
                    if (topicViewModel.PollAnswers.Count > 0)
                    {
                        topicViewModel.Content = topicViewModel.Name;
                    }
                    else
                    {
                        TempData["Error"] = "You must supply content for the post.";
                        return(RedirectToAction("Create"));
                    }
                }

                // Check posting flood control
                if (!db_Forum.PassedTopicFloodTest(topicViewModel.Name, UserIDX))
                {
                    TempData["Error"] = "Can only post once per minute";
                    return(RedirectToAction("Create"));
                }

                // Log user out if they are LockedOut but still authenticated
                T_OE_USERS u = db_Accounts.GetT_OE_USERSByIDX(UserIDX);
                if (u != null && u.LOCKOUT_ENABLED)
                {
                    FormsAuthentication.SignOut();
                    return(RedirectToAction("Index", "Home"));
                }

                // Check Permissions for topic opions
                if (!topicViewModel.OptionalPermissions.CanLockTopic)
                {
                    topicViewModel.IsLocked = false;
                }
                // ************************ END VALIDATION **********************************************

                // 1. Create the Topic
                Topic _Topic = db_Forum.InsertUpdateTopic(topicViewModel, UserIDX);
                if (_Topic != null)
                {
                    // 2. Create Post and add to Topic
                    Guid?_postID = db_Forum.InsertUpdatePost(null, topicViewModel.Content, null, null, true, null, null, null, null, _Topic.Id, UserIDX, false);

                    if (_postID != null)
                    {
                        // 3. Reupdate the topic with post ID
                        db_Forum.InsertUpdateTopic_withPost(_Topic.Id, _postID.ConvertOrDefault <Guid>());

                        //3b. Set last update datetime
                        db_Forum.UpdateTopic_SetLastPostDate(_Topic.Id, null);


                        // 4. Update the users points score for posting
                        db_Forum.InsertUpdateMembershipUserPoints(null, 1, System.DateTime.UtcNow, 0, _postID, null, UserIDX);


                        // 5. Poll handling
                        if (topicViewModel.PollAnswers.Count(x => x != null) > 1)
                        {
                            // Create a new Poll
                            Guid?PollID = db_Forum.InsertUpdatePoll(null, false, System.DateTime.Now, topicViewModel.PollCloseAfterDays, UserIDX);

                            // Now sort the answers
                            foreach (PollAnswer answer in topicViewModel.PollAnswers)
                            {
                                if (answer.Answer != null)
                                {
                                    db_Forum.InsertUpdatePollAnswer(null, answer.Answer, PollID);
                                }
                            }

                            // Add the poll to the topic
                            db_Forum.SetTopicPollID(_Topic.Id, PollID.ConvertOrDefault <Guid>());
                        }


                        // 6. File handling
                        if (topicViewModel.Files != null && topicViewModel.Files.Any())
                        {
                            UPloadPostFiles(topicViewModel.Files, UserIDX, _postID.ConvertOrDefault <Guid>());
                        }


                        // 7. Tag handling
                        db_Forum.DeleteTopicTags(_Topic.Id, "Topic Tag");
                        foreach (string feature in topicViewModel.SelectedTags ?? new List <string>())
                        {
                            db_Forum.InsertUpdateTopicTags(_Topic.Id, "Topic Tag", feature);
                        }


                        // 8. Subscribe the user to the topic if they have checked the checkbox
                        if (topicViewModel.SubscribeToTopic)
                        {
                            db_Forum.InsertUpdateTopicNotification(null, _Topic.Id, UserIDX);
                        }

                        // 9. Success so now send the emails
                        //NotifyNewTopics(category, topic, unitOfWork);


                        // 10. Badge Checking
                        db_Forum.EarnBadgePostTopicEvent(UserIDX);

                        // 11. Update Azure search
                        AzureSearch.PopulateSearchIndexForumPost(_postID);

                        // Redirect to the newly created topic
                        return(RedirectToAction("ShowTopic", "Forum", new { slug = _Topic.Slug }));
                    }
                }
            }

            if (TempData["Error"] == null)
            {
                TempData["Error"] = "Unable to save data";
            }
            return(View(topicViewModel));
        }