[HttpPost("GetReaderArticles")] //[HttpPost("GetReaderArticles/{topicOption}")] <- was giving issues
        public async Task <ActionResult> GetReaderArticles(ViewTopicModel model)
        {
            //System.Console.WriteLine("ViewTopicModel Name: " + model.Name);
            var topicOption = model.Name;

            var article = new List <ArticleViewModel>()
            {
            };
            var response = await _http.GetAsync(apiUrl + "Article/GetArticleByTopic/" + topicOption);

            if (response.IsSuccessStatusCode)
            {
                var jsonResponse = await response.Content.ReadAsStringAsync();

                var ArticleVMs = JsonConvert.DeserializeObject <List <ArticleViewModel> >(jsonResponse);

                var TopicVMs = JsonConvert.DeserializeObject <List <ViewTopicModel> >(TempData["TopicVMs"].ToString());

                TempData["TopicVMs"] = JsonConvert.SerializeObject(TopicVMs);

                var ArticleTopicBundleVM = new ArticleTopicBundleViewModel(ArticleVMs, TopicVMs);
                ArticleTopicBundleVM.ChosenTopicToFilterBy = topicOption;
                return(await Task.FromResult(View("TopicSpecificArticles", ArticleTopicBundleVM)));
            }
            return(View("error"));
        }
Exemplo n.º 2
0
        public ActionResult ViewTopic(ForumTopicRequestModel requestModel)
        {
            ViewTopicModel viewTopicModel = new ViewTopicModel()
            {
                Threads = new List <ForumThreadModel>()
            };

            using (CGWebEntities entities = new CGWebEntities())
            {
                ForumTopic currentTopic = entities.ForumTopics.Where(T => T.TopicId.Equals(requestModel.TopicId)).Single();
                viewTopicModel.CurrentTopic = currentTopic.ConvertToForumTopicModel();
                viewTopicModel.ParentForum  = currentTopic.Forum.ConvertToViewForumModel(false, false);

                if (!currentTopic.IsPublic && !Request.IsAuthenticated)
                {
                    return(RedirectToAction("Login", "Account"));
                }

                var currentTopicGroup = entities.ForumThreads.Where(FT => FT.ForumTopic.Equals(requestModel.TopicId));

                int currentTopicViewLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumTopicPagingLimit"]);
                viewTopicModel.CurrentPage = requestModel.CurrentPage;
                viewTopicModel.MaxPages    = (int)Math.Ceiling((double)currentTopicGroup.Count() / (double)currentTopicViewLimit);

                foreach (ForumThread thread in currentTopicGroup.OrderByDescending(FT => FT.CreatedOn).OrderByDescending(FT => FT.IsSticky).Skip(currentTopicViewLimit * requestModel.CurrentPage).Take(currentTopicViewLimit))
                {
                    viewTopicModel.Threads.Add(thread.ConvertToForumThreadModel(false));
                }
            }

            return(View(viewTopicModel));
        }
Exemplo n.º 3
0
        public ActionResult ViewTopic(Guid topicId, string threadTitle, string threadContent, bool isSticky)
        {
            ViewTopicModel viewTopicModel = new ViewTopicModel()
            {
                Threads = new List <ForumThreadModel>()
            };

            using (CGWebEntities entities = new CGWebEntities())
            {
                UserProfile currentUserProfile = entities.UserProfiles.Where(P => P.UserName.Equals(User.Identity.Name)).Single();

                ForumThread newThread = new ForumThread()
                {
                    CreatedBy     = currentUserProfile.UserId,
                    CreatedOn     = DateTime.UtcNow,
                    ForumTopic    = topicId,
                    IsSticky      = isSticky,
                    ModifiedOn    = null,
                    ThreadContent = threadContent,
                    ThreadId      = Guid.NewGuid(),
                    ThreadTitle   = HtmlSanitizerUtility.SanitizeInputStringNoHTML(threadTitle)
                };

                entities.ForumThreads.Add(newThread);
                entities.SaveChanges();
                ModelState.Clear();

                ForumTopic currentTopic = entities.ForumTopics.Where(T => T.TopicId.Equals(topicId)).Single();
                viewTopicModel.CurrentTopic = currentTopic.ConvertToForumTopicModel();
                viewTopicModel.ParentForum  = currentTopic.Forum.ConvertToViewForumModel(false, false);

                if (!currentTopic.IsPublic && !Request.IsAuthenticated)
                {
                    return(RedirectToAction("Login", "Account"));
                }

                var currentTopicGroup = entities.ForumThreads.Where(FT => FT.ForumTopic.Equals(topicId));

                int currentTopicViewLimit = Convert.ToInt32(ConfigurationManager.AppSettings["ForumTopicPagingLimit"]);
                viewTopicModel.MaxPages    = (int)Math.Ceiling((double)currentTopicGroup.Count() / (double)currentTopicViewLimit);
                viewTopicModel.CurrentPage = viewTopicModel.MaxPages - 1;

                foreach (ForumThread thread in currentTopicGroup.OrderByDescending(FT => FT.CreatedOn).OrderByDescending(FT => FT.IsSticky).Skip(currentTopicViewLimit * viewTopicModel.CurrentPage).Take(currentTopicViewLimit))
                {
                    viewTopicModel.Threads.Add(thread.ConvertToForumThreadModel(false));
                }
            }

            return(View(viewTopicModel));
        }