예제 #1
0
        public IEnumerable <SentMessagesModel> GetAllMessagesSentByAUser([FromBody] AllMessageRequest Request)
        {
            try
            {
                if (Request.Date == null)
                {
                    Request.Date = new DateTime();
                }

                // Get all the messages sent by the user to the given date
                var messages  = db.AspNetUserMessages.Where(o => o.From == Request.From && o.SentDate >= Request.Date).ToList();
                var groupByTo = messages.GroupBy(m => m.To);
                List <SentMessagesModel> sentMessages = new List <SentMessagesModel>();

                foreach (var currentGroup in groupByTo)
                {
                    // Sort by sent date before appending to the response
                    sentMessages.Add(new SentMessagesModel()
                    {
                        SentTo = currentGroup.Key, Messages = currentGroup.OrderByDescending(t => t.SentDate).ToList()
                    });
                }

                return(sentMessages);
            }
            catch (Exception e)
            {
                // Log the error to the database
                LogException(e);
                return(null);
            }
        }
예제 #2
0
        public IEnumerable <AspNetUserMessage> GetAllMessages([FromBody] AllMessageRequest Request)
        {
            try
            {
                if (Request.Date == null)
                {
                    Request.Date = new DateTime();
                }

                // Get all the messages sent or received by the user
                var messages = db.AspNetUserMessages.Where(o => (o.From == Request.From || o.To == Request.From) && o.SentDate >= Request.Date).ToList();

                return(messages);
            }
            catch (Exception e)
            {
                // Log the error to the database
                LogException(e);
                return(null);
            }
        }