public ActionResult Index()
        {
            var adminMessages = _messageRepository.GetAdminMessages();

            var users = _userRepository.GetAllUsersWithoutProtectedData().ToDictionary(u => u.Id, u => u);

            var model = new AdminMessagesViewModel
            {
                Replied         = new List <AdminConversationViewModel>(),
                WaitingForReply = new List <AdminConversationViewModel>()
            };

            foreach (var conversation in adminMessages.GroupBy(m => new MessageGroupingKey(m.SenderId, m.RecipientId)))
            {
                var userId = conversation.First().SenderId ?? conversation.First().RecipientId;
                if (!userId.HasValue)
                {
                    continue; // this should not happen, but to satisfy code analysis...
                }
                var user = users[userId.Value];

                var conversationModel = new AdminConversationViewModel
                {
                    UserId                 = user.Id,
                    UserDisplayName        = user.DisplayName,
                    UserFacebookProfileUrl = user.FacebookProfileUrl,
                    UserEmail              = user.Email,
                    Messages               = conversation.Select(m => GetMessageViewModel(m, null)).OrderBy(m => m.Timestamp).ToArray()
                };
                if (conversation.OrderByDescending(m => m.Timestamp).First().RecipientId.HasValue)
                {
                    model.Replied.Add(conversationModel); // newest has recipient Id -> it went to user
                }
                else
                {
                    model.WaitingForReply.Add(conversationModel); // newest does not have recipient Id -> it went to Admin
                }
            }


            return(View(model));
        }
Example #2
0
        // GET: AdminMessageContent
        public ActionResult Index(PagerParameters pagerParameters, AdminMessagesViewModel adminViewModel)
        {
            var messages          = _messageService.GetAllMessages().Where(s => s.IsApprowed == false).ToList();
            var entriesProjection = messages.Select(e =>
            {
                return(Shape.MessageEntry(
                           SendDate: e.SendDate,
                           Id: e.Id,
                           Subject: e.Subject,
                           Sender: e.Sender,
                           Text: e.Text,
                           UserId: e.UserId
                           ));
            });

            var     pager      = new Pager(_siteService.GetSiteSettings(), pagerParameters.Page, pagerParameters.PageSize);
            var     entries    = entriesProjection.Skip(pager.GetStartIndex()).Take(pager.PageSize);
            dynamic pagerShape = Shape.Pager(pager).TotalItemCount(entriesProjection.Count());

            return(View("Index", new AdminMessagesViewModel {
                Messages = entries.ToArray(), Pager = pagerShape
            }));
        }