Exemplo n.º 1
0
        public async Task <Message> SetReadByIdAsync(int id, User user, bool read)
        {
            var message = await context.Messages.FindAsync(id);

            message.MessagesReceivers.ForEach(m =>
            {
                if (m.User.Email == user.Email)
                {
                    m.IsRead = read;
                }
            });
            message.MessagesCCs.ForEach(m =>
            {
                if (m.User.Email == user.Email)
                {
                    m.IsRead = read;
                }
            });
            message.MessagesBCCs.ForEach(m =>
            {
                if (m.User.Email == user.Email)
                {
                    m.IsRead = read;
                }
            });
            await context.SaveChangesAsync();

            return(createMessage(message));
        }
Exemplo n.º 2
0
        public IQueryable <Message> GetByReceiver(User receiver)
        {
            var userEntity      = context.Users.First(u => u.Email.Equals(receiver.Email));
            var messageEntities = context.Messages.Where(m => m.Receivers.Contains(userEntity)).OrderByDescending(m => m.ReceivedTime);

            return(createMessages(messageEntities));
        }
Exemplo n.º 3
0
        private static Message createMessage(Database.POCO.Message entity, User sender)
        {
            var msg = new Message(entity, sender);

            msg.Attachments = entity.Attachments.Select(a => new Attachment(a, msg)).ToList();

            entity.MessagesReceivers.ForEach(mr => msg.AddReceiver(new User(mr.User), mr.IsRead));
            entity.MessagesCCs.ForEach(mcc => msg.AddCcUser(new User(mcc.User), mcc.IsRead));
            entity.MessagesBCCs.ForEach(mbcc => msg.AddBccUser(new User(mbcc.User), mbcc.IsRead));

            return(msg);
        }
Exemplo n.º 4
0
        public IQueryable <Message> GetBySender(User sender)
        {
            var messageEntities = context.Messages.Where(m => m.Sender.Email.Equals(sender.Email));

            return(messageEntities.Select(me => createMessage(me, sender)));
        }