Exemplo n.º 1
0
 public NeighbourViewModel With(UserProfile user)
 {
     ID = user.UserId;
     Name = user.DisplayName;
     Address = user.Address ?? "unknown";
     Groups = user.Groups.Count;
     Campaigns = user.Campaigns.Count;
     return this;
 }
Exemplo n.º 2
0
 public IndexViewModel With(IEnumerable<Models.Group> campaigns, UserProfile user)
 {
     Groups = new List<GroupViewModel>();
     foreach (Models.Group grp in campaigns)
     {
         var grpModel = new GroupViewModel().With(grp);
         if (!grp.Members.Contains(user)) grpModel.NotSubscribed();
         Groups.Add(grpModel);
     }
     return this;
 }
        public UserMessagesViewModel With(UserProfile user, UserProfile selectedParticipant)
        {
            Participants = new Dictionary<int, string>();
            foreach (var msg in user.SentMessages)
            {
                if (!Participants.ContainsKey(msg.AddresseeId))
                {
                    Participants.Add(msg.Addressee.UserId,msg.Addressee.DisplayName);
                }
            }
            foreach (var msg in user.ReceivedMessages)
            {
                if (!Participants.ContainsKey(msg.SenderId))
                {
                    Participants.Add(msg.Sender.UserId, msg.Sender.DisplayName);
                }
            }
            var tempList = new List<KeyValuePair<int, string>>(Participants);
            foreach(var kvp in tempList)
            {
                var unread = user.ReceivedMessages.Count(m => m.SenderId == kvp.Key && !m.IsRead);
                if (unread > 0)
                {
                    Participants[kvp.Key] = string.Format("{0} ({1})", kvp.Value, unread.ToString());
                }
            }
            Messages = new List<UserMessageViewModel>();
            if (selectedParticipant != null)
            {

                Messages =
                    user.SentMessages.Where(m => m.AddresseeId == selectedParticipant.UserId)
                        .Select(m => new UserMessageViewModel(m, true))
                        .Union(
                            user.ReceivedMessages.Where(m => m.SenderId == selectedParticipant.UserId)
                                .Select(m => new UserMessageViewModel(m, false))).OrderBy(m => m.Sent).ToList();

                SelectedParticipantId = selectedParticipant.UserId;
            }

            return this;
        }
Exemplo n.º 4
0
        public IndexViewModel With(UserProfile user)
        {
            Campaigns = new Dictionary<int, string>();
            Groups = new Dictionary<int, string>();
            Evts = new Dictionary<int, string>();

            Neightbours = new Dictionary<int, string>();

            foreach (UserProfile n in user.Community.Members)
            {
                if (n.UserId != user.UserId)
                {
                    if (n.DisplayName.Length > 20)
                    {
                        Neightbours.Add(n.UserId, string.Format("{0} ...", n.DisplayName.Substring(0, 20)));
                    }
                    else
                    {
                        Neightbours.Add(n.UserId, n.DisplayName);
                    }
                }
            }
            foreach (Models.Campaign campaign in user.Campaigns)
            {
                if (campaign.Name.Length > 20)
                {
                    Campaigns.Add(campaign.CampaignId, string.Format("{0} ...", campaign.Name.Substring(0, 20)));
                }
                else
                {
                    Campaigns.Add(campaign.CampaignId, campaign.Name);
                }
            }

            UnreadMessages = user.ReceivedMessages.Count(m => m.IsRead == false);

            foreach (Models.Group group in user.Groups)
            {
                if (group.Name.Length > 20)
                {
                    Groups.Add(group.GroupId, string.Format("{0} ...", group.Name.Substring(0, 20)));
                }
                else
                {
                    Groups.Add(group.GroupId, group.Name);
                }
            }

            foreach (Models.Event evt in user.Community.Events)
            {
                if (evt.Name.Length > 20)
                {
                    string summary = string.Format("{0}: {1} ...", evt.DateTime.ToShortDateString(),
                                                   evt.Name.Substring(0, 20));
                    Evts.Add(evt.EventId, summary);
                }
                else
                {
                    string summary = string.Format("{0}: {1}", evt.DateTime.ToShortDateString(), evt.Name);
                    Evts.Add(evt.EventId, summary);
                }
            }

            Comments =
                new MessagesViewModel().With(user.Community.Messages.OrderByDescending(m => m.MessageId))
                                       .Using("Community", user.CommunityID)
                                       .ShowPostForm();

            return this;
        }
Exemplo n.º 5
0
        public void MarkUsersMessagesAsReadByParticipant(UserProfile user, UserProfile participant)
        {
            if (participant != null)
            {

                foreach (UserMessage msg in user.ReceivedMessages.Where(m => !m.IsRead && m.SenderId == participant.UserId))
                {
                    msg.IsRead = true;
                }

                _unitOfWork.Save();
            }
        }