public ActionResult SendMessage([FromBody] Models.Message message, [FromBody] string userToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            User user = _context.Users.FirstOrDefault(u => u.UserToken == userToken);

            if (user == null)
            {
                return(NotFound("Invalid token"));
            }

            string accessToken = user.Accounts.FirstOrDefault(a => a.PlatformName == message.NetworkName).AccessToken;

            if (accessToken == null)
            {
                return(BadRequest("Access token for network not found"));
            }

            Connector connector = _context.Connectors.FirstOrDefault(c => c.NetworkName == message.NetworkName);

            Data.Models.Message dataMessage = new Data.Models.Message()
            {
                NetworkName = message.NetworkName,
                ReceiverId  = message.ReceiverId,
                Text        = message.Text
            };

            _connectorSender.SendMessage(connector, dataMessage, accessToken);

            return(Ok());
        }
Esempio n. 2
0
        public static Domain.Models.Message Map(this Data.Models.Message message, bool protect = true)
        {
            var m = new Domain.Models.Message();

            m.ID            = message.ID;
            m.ParentID      = message.ParentID;
            m.CorrelationID = message.CorrelationID;

            m.Content          = message.Content;
            m.FormattedContent = message.FormattedContent;
            //existing messages do not have formatted content saved - check here
            if (String.IsNullOrEmpty(m.FormattedContent))
            {
                Debug.WriteLine("Formatting PM Content!");
                m.FormattedContent = Formatting.FormatMessage(m.Content);
            }

            m.CommentID    = message.CommentID;
            m.CreatedBy    = message.CreatedBy;
            m.CreationDate = message.CreationDate;
            m.IsAnonymized = message.IsAnonymized;

            m.ReadDate = message.ReadDate;

            if (message.IsAnonymized && protect)
            {
                m.Sender = message.ID.ToString();
            }
            else
            {
                m.Sender = message.Sender;
            }

            m.Recipient     = message.Recipient;
            m.RecipientType = (IdentityType)message.RecipientType;
            m.SenderType    = (IdentityType)message.SenderType;

            m.Title        = message.Title;
            m.SubmissionID = message.SubmissionID;
            m.Subverse     = message.Subverse;
            m.Type         = (MessageType)message.Type;

            return(m);
        }
        public async Task <bool> Add(string senderId, string SenderUsername, string title, string content)
        {
            var message = new Data.Models.Message
            {
                Id             = Guid.NewGuid().ToString(),
                SenderId       = senderId,
                SenderUsername = SenderUsername,
                Created        = DateTime.UtcNow,
                Title          = title,
                Content        = content,
                IsProcessed    = false,
                IsDeleted      = false
            };

            context.Add(message);
            var result = await context.SaveChangesAsync();

            return(result != 0);
        }