Beispiel #1
0
        public ActionResult CreatePost(vmForumTopicView model)
        {
            int UserIDX = db_Accounts.GetUserIDX();

            // ************************ VALIDATION **********************************************
            // Check posting flood control
            if (!db_Forum.PassedPostFloodTest(UserIDX))
            {
                TempData["Error"] = "Please wait at least 30 seconds between posts";
                return(RedirectToAction("ShowTopic", new { slug = model.Topic.Slug }));
            }

            // 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"));
            }

            //required fields
            if (model.NewPostContent == null)
            {
                TempData["Error"] = "You must supply post content.";
                return(RedirectToAction("ShowTopic", new { slug = model.Topic.Slug }));
            }
            // ************************ END VALIDATION **********************************************


            Guid?_postID = db_Forum.InsertUpdatePost(null, model.NewPostContent, null, null, false, false, false, null, null, model.Topic.Id, UserIDX, false);

            if (_postID != null)
            {
                //set topic last post date
                db_Forum.UpdateTopic_SetLastPostDate(model.Topic.Id, null);

                // Success send any notifications
                NotifyTopics(model.Topic.Id, UserIDX, "Post");

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

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


            // Return view
            return(RedirectToAction("ShowTopic", "Forum", new { slug = model.Topic.Slug }));
        }
Beispiel #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 }));
        }
Beispiel #3
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));
        }