Example #1
0
        public PostFormModel(IEnumerable<PostType> availableTypes,int threadId)
        {
            PostForm = new PostForm {ThreadId = threadId};

            var types = availableTypes.Select(c => new SelectListItem { Text = c.Describe(Resources.Thread.ResourceManager), Value = c.ToString() }).ToList();

            if (availableTypes.Count() > 1)
                types.Insert(0, new SelectListItem { Selected = true, Text = Resources.Thread.PostSelectType, Value = string.Empty });
            else
                PostForm.Type = (PostType)Enum.Parse(typeof(PostType), types[0].Value);

            AvailableTypes = types;
        }
Example #2
0
        public virtual ActionResult ThreadDetails(int threadId, PostForm postForm = null)
        {
            var thread = Repository.Thread.Get(threadId);

            if (!IsAuthorExpertOrModerator(thread))
            {
                FormsAuthentication.RedirectToLoginPage();
                return null;
            }

            if(thread.State == ThreadState.Hidden)
            {
                Flash.Error(Resources.Thread.ThreadHidden);
                return RedirectToAction(MVC.StaticPages.Home());
            }

            if (!thread.IsPaid && !IsAuthor(thread) && !AuthenticationHelper.IsModerator)
            {
                FormsAuthentication.RedirectToLoginPage();
                return null;
            }

            if(AuthenticationHelper.CurrentUser.IsExpert)
            {
                if (AuthenticationHelper.CurrentUser != thread.Author && AuthenticationHelper.CurrentUser.Expert.VerificationStatus != ExpertVerificationStatus.Verified)
                {
                    if(thread.Expert != AuthenticationHelper.CurrentUser.Expert)
                    {
                        Flash.Error(Resources.Account.VerificationNeeded);
                        return RedirectToAction(MVC.StaticPages.Home());   
                    }
                }
            }

            string view;
            IEnumerable<PostType> postTypes;
            var model = new ThreadDetailsModel(thread);

            if (AuthenticationHelper.IsExpert && thread.Author != AuthenticationHelper.CurrentUser)
            {
                postTypes = new List<PostType> { PostType.Answer, PostType.DetailsRequest };
                view = MVC.Thread.Views.ThreadDetailsForExperts;
            }
            else if (thread.Author == AuthenticationHelper.CurrentUser)
            {
                postTypes = new Collection<PostType> { PostType.Details };
                view = MVC.Thread.Views.ThreadDetailsForAuthor;
            }
            else // moderator
            {
                postTypes = new List<PostType> { PostType.ModeratorAnswer, PostType.ExpertPM };
                view = MVC.Thread.Views.ThreadDetailsForModerator;
                model.IsModerationMode = true;
                model.ThreadEvents = Repository.Event.GetThreadEvents(threadId);
            }

            model.PostFormModel = new PostFormModel(postTypes, model.Thread.Id);
            if (postForm != null && postForm.ThreadId != 0 && postForm.Type != 0)
                model.PostFormModel.PostForm = postForm;

            return View(view, model);
        }