Beispiel #1
0
        private async Task AttachMessageToChat(Message messageForAttach, Contracts.Entity.Chat chatWhereWeSendMessage)
        {
            await _unitOfWork.ChatMessageRepository?.AddAsync(
                new ChatMessage
            {
                ChatId    = chatWhereWeSendMessage.Id,
                MessageId = messageForAttach.Id,
                DateSend  = DateTime.UtcNow
            });

            await _unitOfWork.CommitAsync();
        }
Beispiel #2
0
        private async Task <Contracts.Entity.Chat> CreateDefaultChat(bool chatPublic, string SenderId, User user)
        {
            Contracts.Entity.Chat chatForSend = null;
            using (var transaction = await _unitOfWork.BeginTransactionAsync())
            {
                chatForSend = await _unitOfWork.ChatRepository.AddAsync(new Contracts.Entity.Chat {
                    DefaultChat = true, Public = chatPublic
                });

                await _unitOfWork.CommitAsync();

                var userChatSneder = await _unitOfWork.UserChatRepository.AddAsync(new UserChat { ChatId = chatForSend.Id, UserId = SenderId });

                var userChatReciever = await _unitOfWork.UserChatRepository.AddAsync(new UserChat { ChatId = chatForSend.Id, UserId = user.Id });

                chatForSend.UserChats.Add(userChatSneder);
                chatForSend.UserChats.Add(userChatReciever);
                await _unitOfWork.CommitAsync();

                await transaction.CommitAsync();
            }

            return(chatForSend);
        }
Beispiel #3
0
        private async Task AttachMessageToChat(SendMessageToChatDto sendMessageToChat, string SenderId, Contracts.Entity.Chat chatWhereWeSendMessage)
        {
            var message = await _unitOfWork.MessageRepository?.AddAsync(
                new Message
            {
                SenderId         = SenderId,
                MessageData      = sendMessageToChat.Message,
                DeletedForAll    = false,
                DeletedForSender = false,
            });

            await _unitOfWork.CommitAsync();

            await _unitOfWork.ChatMessageRepository?.AddAsync(
                new ChatMessage
            {
                ChatId    = chatWhereWeSendMessage.Id,
                MessageId = message.Id,
                DateSend  = DateTime.UtcNow
            });

            await _unitOfWork.CommitAsync();
        }
Beispiel #4
0
 private static bool?ChatContainUser(string userId, Contracts.Entity.Chat chatForSend)
 {
     return(chatForSend.UserChats?.Any(uch => uch.UserId == userId));
 }