示例#1
0
        public ActionResult Archive(Guid? id, int? year, int? month, int? day, bool? posts, bool? petitions, bool? user, bool? group)
        {
            if (!id.HasValue)
            {
                if (!Request.IsAuthenticated)
                    throw new AuthenticationException();

                id = UserContext.Current.Id;
            }

            var dude = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(x => x.Id == id.Value);
            if (dude == null)
                new BusinessLogicException("Чувак не найден");

            posts = !posts.HasValue || posts.Value;
            petitions = !petitions.HasValue || petitions.Value;

            var contentType = new ContentTypeFilter { Posts = posts.Value, Petitions = petitions.Value };

            user = !user.HasValue || user.Value;
            group = !group.HasValue || group.Value;

            var personality = new Personality { User = user.Value, Group = group.Value };

            return View(new UserArchiveViewModel(dude, year, month, day, contentType, personality));
        }
        public UserArchiveViewModel(User user, int? year, int? month, int? day, ContentTypeFilter contentType, Personality personality)
        {
            Feed = new _ContentFeedViewModel();
            Calendar = new _CalendarViewModel();

            if (user != null)
            {
                FullName = user.FullName;
                UserId = user.Id;
                ContentType = contentType;
                Personality = personality;

                if (contentType.IsSomethingChecked() && personality.IsSomethingChecked())
                {
                    IEnumerable<Content> content = user.Contents.Where(x => x.State == (byte)ContentState.Approved);
                    IEnumerable<Content> feed = null;

                    if (contentType.Posts)
                    {
                        IEnumerable<Post> posts = null;

                        if (personality.User && personality.Group)
                            posts = content.OfType<Post>();
                        else if (personality.User)
                            posts = content.OfType<Post>().Where(x => !x.GroupId.HasValue);
                        else if (personality.Group)
                            posts = content.OfType<Post>().Where(x => x.GroupId.HasValue);

                        if (feed == null)
                            feed = posts;
                        else
                            feed = feed.Union(posts);
                    }
                    if (contentType.Petitions)
                    {
                        IEnumerable<Petition> petitions = null;

                        if (personality.User && personality.Group)
                            petitions = content.OfType<Petition>();
                        else if (personality.User)
                            petitions = content.OfType<Petition>().Where(x => x.Group == null);
                        else if (personality.Group)
                            petitions = content.OfType<Petition>().Where(x => x.Group != null);

                        if (feed == null)
                            feed = petitions;
                        else
                            feed = feed.Union(petitions);
                    }

                    if (year.HasValue)
                        feed = feed.Where(x => x.PublishDate.Value.Year == year.Value);
                    if (month.HasValue)
                        feed = feed.Where(x => x.PublishDate.Value.Month == month.Value);
                    if (day.HasValue)
                        feed = feed.Where(x => x.PublishDate.Value.Day == day.Value);

                    Feed = new _ContentFeedViewModel(feed.OrderByDescending(x => x.PublishDate));
                    Calendar = new _CalendarViewModel(user, year, month, day);
                }
            }
        }
示例#3
0
        public ActionResult Archive(string id, int? year, int? month, int? day, bool? posts, bool? polls, bool? petitions, bool? elections)
        {
            var group = GroupService.GetGroupByLabelOrId(id);

            var redirect = HideInvisibleGroup(group);
            if (redirect != null)
                return redirect;

            posts = !posts.HasValue || posts.Value;
            polls = !polls.HasValue || polls.Value;
            petitions = !petitions.HasValue || petitions.Value;
            elections = !elections.HasValue || elections.Value;

            var contentType = new ContentTypeFilter
            {
                Posts = posts.Value,
                Polls = polls.Value,
                Petitions = petitions.Value,
                Elections = elections.Value
            };

            return View(new GroupArchiveViewModel(group, year, month, day, contentType));
        }
        public GroupArchiveViewModel(Group group, int? year, int? month, int? day, ContentTypeFilter contentType)
        {
            Feed = new _ContentFeedViewModel();
            Calendar = new _CalendarViewModel();

            if (group != null)
            {
                GroupId = group.Id;
                GroupName = group.Name;
                GroupUrl = group.Url;
                ContentType = contentType;

                if (contentType.IsSomethingChecked())
                {
                    IEnumerable<Content> content1 = group.Content.OfType<Post>().Where(x => x.State == (byte)ContentState.Approved);
                    IEnumerable<Content> content2 = group.Content.OfType<Voting>().Where(x => x.State == (byte)ContentState.Approved);
                    IEnumerable<Content> content = content1.Union(content2);
                    IEnumerable<Content> feed = null;

                    if (contentType.Posts)
                    {
                        IEnumerable<Post> posts = content.OfType<Post>();

                        if (feed == null)
                            feed = posts;
                        else
                            feed = feed.Union(posts);
                    }
                    if (contentType.Polls)
                    {
                        IEnumerable<Poll> polls = content.OfType<Poll>();

                        if (feed == null)
                            feed = polls;
                        else
                            feed = feed.Union(polls);
                    }
                    if (contentType.Petitions)
                    {
                        IEnumerable<Petition> petitions = content.OfType<Petition>();

                        if (feed == null)
                            feed = petitions;
                        else
                            feed = feed.Union(petitions);
                    }
                    if (contentType.Elections)
                    {
                        IEnumerable<Election> elections = content.OfType<Election>();

                        if (feed == null)
                            feed = elections;
                        else
                            feed = feed.Union(elections);
                    }

                    if (year.HasValue)
                        feed = feed.Where(x => x.PublishDate.Value.Year == year.Value);
                    if (month.HasValue)
                        feed = feed.Where(x => x.PublishDate.Value.Month == month.Value);
                    if (day.HasValue)
                        feed = feed.Where(x => x.PublishDate.Value.Day == day.Value);

                    Feed = new _ContentFeedViewModel(feed.OrderByDescending(x => x.PublishDate));
                    Calendar = new _CalendarViewModel(group, year, month, day);
                }
            }
        }