Example #1
0
        public HttpResponseMessage SendMessage([FromBody] AspNetUserMessage message)
        {
            try
            {
                if (message.SentDate == DateTime.MinValue)
                {
                    message.SentDate = DateTime.Now;
                }

                // If the receiver user blocked the sender; abort the process
                if (db.AspNetBlockedUsers.Any(o => o.From == message.To && o.To == message.From))
                {
                    throw new Exception($"User {message.From} blocked {message.To}! The message can not be sent.");
                }

                // ReadDate should be enforced as null since the receiver hasnt read the msg yet
                message.ReadDate = null;
                // User is not blocked try to send the message
                db.AspNetUserMessages.Add(message);
                db.SaveChanges();

                return(CreateMessage(200, "OK"));
            }
            catch (Exception e)
            {
                // Log the error to the database
                LogException(e);
                return(CreateMessage(500, " Internal Server Error"));
            }
        }
Example #2
0
 public void MarkAsModified(AspNetUserMessage item)
 {
 }