Example #1
0
        public ViewResult Index(int? sect = null, int? topic = null, int page = 1)
        {
            using(var uow = CreateUnitOfWork())
            {
                ForumViewModel model = new ForumViewModel(this);

                if (this.SecurityUser.IsPermission(typeof(ForumTopic), TypePermission.Delete))
                {
                    model.UserRole = UserRole.Moderator;
                }
                else if (this.SecurityUser.IsPermission(typeof(ForumTopic), TypePermission.Create))
                {
                    model.UserRole = UserRole.User;
                }
                else
                {
                    model.UserRole = UserRole.Guest;
                }


                if (sect == null)
                {
                    model.Type = ForumVMType.Root;
                    model.Title = "Разделы";
                    model.Items = _sectionService.GetAll(uow).ToViewModel();
                }
                else if (topic == null)
                {
                    model.Type = ForumVMType.Section;
                    model.Title = _sectionService.Get(uow, sect.Value).Title;
                    model.Items = _topicService.GetAll(uow).Where(x => x.SectionID == sect.Value).ToViewModel();
                    model.SectionID = sect;
                }
                else
                {
                    model.Type = ForumVMType.Topic;
                    model.Title = _topicService.GetForViewing(uow, topic.Value).Title;
                    model.Items = _postService.GetAll(uow).Where(x => x.TopicID == topic.Value).ToViewModel();
                    model.SectionID = sect;
                    model.TopicID = topic;
                }

                if (model.Type != ForumVMType.Root)
                {
                    model.CurrentPage = page;
                    model.PageCount = (int)Math.Ceiling((double)model.Items.Count() / ITEMS_PER_PAGE);
                    model.Items = model.Items.Skip((model.CurrentPage - 1) * ITEMS_PER_PAGE).Take(ITEMS_PER_PAGE);
                }

                return View("Index", model);
            }
        }
Example #2
0
        public ActionResult Search(string searchStr, int? sect = null)
        {
            using (var uow = CreateUnitOfWork())
            {
                ForumViewModel model = new ForumViewModel(this) {Type = ForumVMType.Search, SectionID = sect};

                var sections = _sectionService.GetAll(uow);
                if (sect != null)
                {
                    sections = sections.Where(x => x.ID == sect.Value);
                }

                model.Items = sections.FullTextSearch(searchStr, this.CacheWrapper).ToList();

                return View("Index", model);
            }
        }