Exemplo n.º 1
0
        public async Task <ConversationMessageDTO> ChangingMessageStatusToDelivered(int conversationMessageId)
        {
            ConversationMessageDTO conversationMessagesForReturn = new ConversationMessageDTO();

            if (conversationMessageId > 0)
            {
                var convMessage = await _db.ConversationMessages.Where(x => x.ConversationMessageId == conversationMessageId).FirstOrDefaultAsync();

                if (convMessage != null)
                {
                    convMessage.Status           = ConversationMessage.messageStatus.Delivered;
                    _db.Entry(convMessage).State = EntityState.Modified;
                    await _db.SaveChangesAsync();

                    conversationMessagesForReturn.ConversationId = convMessage.ConversationId;
                    conversationMessagesForReturn.SenderId       = convMessage.SenderId;
                    conversationMessagesForReturn.AdId           = convMessage.AdId;
                    conversationMessagesForReturn.Message        = convMessage.Message;
                    conversationMessagesForReturn.ReceiverId     = convMessage.ReceiverId;
                    conversationMessagesForReturn.Status         = convMessage.Status;
                    conversationMessagesForReturn.CreatedAt      = convMessage.CreatedAt;
                }
            }

            return(conversationMessagesForReturn);
        }
Exemplo n.º 2
0
        public async Task <ConversationMessageDTO> SaveMessageToConversation(int conversationId, int adId, string message, string userId, string contactId)
        {
            Conversation           conversation                 = new Conversation();
            ConversationMessage    conversationMessage          = new ConversationMessage();
            ConversationMessageDTO conversationMessageForReturn = new ConversationMessageDTO();

            if (String.IsNullOrEmpty(message))
            {
                return(conversationMessageForReturn);
            }

            if (conversationId == 0)
            {
                conversation = await CreateNewConversation(adId, userId, contactId);
            }
            else
            {
                conversation = await _db.Conversations.Where(x => x.ConversationId == conversationId).FirstOrDefaultAsync();
            }

            conversationMessage =
                new ConversationMessage
            {
                ConversationId = conversation.ConversationId,
                AdId           = adId,
                SenderId       = userId,
                ReceiverId     = contactId,
                Message        = message,
                CreatedAt      = DateTime.Now
            };

            await _db.ConversationMessages.AddAsync(conversationMessage);

            await _db.SaveChangesAsync();

            conversationMessageForReturn =
                new ConversationMessageDTO
            {
                ConversationId         = conversationMessage.ConversationId,
                ConversationMessagesId = conversationMessage.ConversationMessageId,
                AdId       = conversationMessage.AdId,
                SenderId   = userId,
                ReceiverId = contactId,
                Message    = message,
                CreatedAt  = DateTime.Now
            };

            return(conversationMessageForReturn);
        }