Exemple #1
0
        private async Task <Message> Send(Message message, bool isNoramlMessage = true)
        {
            await Db.Entry(CurrentUser).Collection(u => u.UsersChats).Query().Include(uc => uc.Chat).LoadAsync();

            var chat = CurrentUser.UsersChats.SingleOrDefault(uc => uc.ChatId == message.ChatId)?.Chat;

            if (chat == null)
            {
                return(null);
            }
            message.Chat = chat;
            // if chatRoom don't save to databse
            if (chat.ChatType == ChatType.ChatRoom && isNoramlMessage)
            {
                return(message);
            }
            await Messages.AddAsync(message);

            if (message.Attachments != null)
            {
                await Attachments.AddRangeAsync(message.Attachments);
            }
            await Db.SaveChangesAsync();

            return(message);
        }