Beispiel #1
0
 public Messages(UserBaseContract user, int?selectedMessageId, string receiverName, UserInboxType inbox)
 {
     User              = user;
     ReceiverName      = receiverName ?? string.Empty;
     SelectedMessageId = selectedMessageId;
     Inbox             = inbox;
 }
Beispiel #2
0
        public UserMessage(User user, UserInboxType inbox, User from, User to, string subject, string body, bool highPriority)
            : this()
        {
            ParamIs.NotNull(() => user);

            User         = user;
            Inbox        = inbox;
            Sender       = from;
            Receiver     = to;
            Subject      = subject;
            Message      = body;
            HighPriority = highPriority;
        }
Beispiel #3
0
        public PartialFindResult <UserMessageContract> GetList(int id, PagingProperties paging, UserInboxType inboxType,
                                                               bool unread, int?anotherUserId, IUserIconFactory iconFactory)
        {
            PermissionContext.VerifyResourceAccess(new[] { id });

            return(HandleQuery(ctx =>
            {
                var query = ctx.Query()
                            .Where(u => u.User.Id == id)
                            .WhereInboxIs(inboxType, unread)
                            .WhereIsUnread(unread);

                if (anotherUserId.HasValue)
                {
                    if (inboxType == UserInboxType.Received)
                    {
                        query = query.Where(m => m.Sender.Id == anotherUserId);
                    }
                    else if (inboxType == UserInboxType.Sent)
                    {
                        query = query.Where(m => m.Receiver.Id == anotherUserId);
                    }
                }


                var messages = query
                               .OrderByDescending(m => m.Created)
                               .Paged(paging, true)
                               .ToArray()
                               .Select(m => new UserMessageContract(m, iconFactory))
                               .ToArray();

                var count = paging.GetTotalCount ? query.Count() : 0;

                return new PartialFindResult <UserMessageContract>(messages, count);
            }));
        }
        public static IQueryable <UserMessage> WhereInboxIs(this IQueryable <UserMessage> query, UserInboxType inboxType, bool onlyReceived)
        {
            if (onlyReceived)
            {
                if (inboxType == UserInboxType.Nothing)
                {
                    return(query.Where(m => m.Inbox == UserInboxType.Notifications || m.Inbox == UserInboxType.Received));
                }
                else if (inboxType == UserInboxType.Sent)
                {
                    return(query.Where(m => false));
                }
            }

            return(inboxType == UserInboxType.Nothing ? query : query.Where(m => m.Inbox == inboxType));
        }
Beispiel #5
0
 private PartialFindResult <UserMessageContract> CallGetList(UserInboxType inboxType, bool unread = false)
 {
     return(queries.GetList(receiver.Id, new PagingProperties(0, 10, true), inboxType, unread, null, new FakeUserIconFactory()));
 }