Beispiel #1
0
        public ActionResult Section(int?sectionID, int?pageIndex)
        {
            var section = MessageSectionService.GetByPK(sectionID);

            if (section == null)
            {
                return(null);
            }
            if ((section.IsGraduateClubOrChildren) &&
                !User.GetOrDefault(x => x.InRole(Role.GraduateClubAccess)))
            {
                return(BaseView(new PagePart("Доступ только для выпускников")));
            }
            if (section.Children.Any())
            {
                var model2 = new SectionListVM {
                    MessageSections = section.Children
                                      .AsQueryable().IsActive().ToList(),
                    User = User
                };
                foreach (var messageSection in model2.MessageSections)
                {
                    messageSection.MessageCount = MessageSectionService
                                                  .SectionMessageCounts().GetValueOrDefault(messageSection
                                                                                            .MessageSectionID);
                    messageSection.LastMessageDate = MessageSectionService
                                                     .SectionLastMessageDates().GetValueOrDefault(messageSection
                                                                                                  .MessageSectionID);
                }
                return(View(ViewNames.SectionList, model2));
            }
            pageIndex = pageIndex ?? 1;
            var messages = UserMessageService.GetAll()
                           .Where(um => um.MessageSectionID == sectionID && um.IsActive)
                           .OrderByDescending(um =>
                                              um.Children.Max(um2 => (DateTime?)um2.CreateDate)
                                              ?? um.CreateDate)
                           .ToPagedList(pageIndex.Value - 1);
            var messageIds    = messages.Select(x => x.UserMessageID).ToList();
            var messageCounts = UserMessageService
                                .GetAll(x => messageIds.Contains(x.UserMessageID))
                                .Select(x => new { x.UserMessageID, x.Children.Count }).ToList()
                                .ToDictionary(x => x.UserMessageID, x => x.Count);
            var model =
                new SectionMessageListVM {
                Messages      = messages,
                MessageCounts = messageCounts,
                Section       = section,
            };

            return(View(ViewNames.MessageList, model));
        }
Beispiel #2
0
 public List <string> GetBreadCrumbs(SectionMessageListVM model)
 {
     return(GetBreadCrumbs(model.Section, false));
 }