Esempio n. 1
0
        public static ViewForumModel ConvertToViewForumModel(this Forum forum, bool includeTopics, bool publicOnly)
        {
            ViewForumModel returnValue = new ViewForumModel()
            {
                ForumId = forum.ForumId,
                ForumTitle = forum.ForumTitle,
                IsPublic = forum.IsPublic
            };

            if (includeTopics)
            {
                returnValue.ForumTopics = new List<ForumTopicModel>();

                if (publicOnly)
                {
                    foreach (ForumTopic topic in forum.ForumTopics.Where(FT => FT.IsPublic).OrderBy(FT => FT.TopicTitle))
                        returnValue.ForumTopics.Add(topic.ConvertToForumTopicModel());
                }
                else
                {
                    foreach (ForumTopic topic in forum.ForumTopics.OrderBy(FT => FT.TopicTitle))
                        returnValue.ForumTopics.Add(topic.ConvertToForumTopicModel());
                }
            }

            return returnValue;
        }
Esempio n. 2
0
        public ActionResult ViewForum(Guid forumId)
        {
            ViewForumModel viewForumModel = new ViewForumModel(){};

            using (CGWebEntities entities = new CGWebEntities())
            {
                Forum currentForum = entities.Forums.Where(F => F.ForumId.Equals(forumId)).Single();

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

                if (Request.IsAuthenticated)
                {
                    viewForumModel = currentForum.ConvertToViewForumModel(true, false);
                }
                else
                {
                    viewForumModel = currentForum.ConvertToViewForumModel(true, true);
                }
            }

            return View(viewForumModel);
        }