コード例 #1
0
 public static ChatMessageFileResult ConvertToResult(
     ChatMessageFile chatMessageFile
     )
 {
     return(new ChatMessageFileResult
     {
         ChatMessageId = chatMessageFile.ChatMessageId,
         FileBinary = chatMessageFile.FileBinary,
         Id = chatMessageFile.Id
     });
 }
コード例 #2
0
        /// <summary>
        /// Функция создания сообщения
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <ChatMessageResult> CreateFile(ChatMessageFileDto file)
        {
            var user = await _userRepository.GetWithId(file.profileId);

            var userTo = await _userRepository.GetProfileForUserName(file.account);

            var message = new ChatMessage
            {
                ChatRoomId = file.chatRoomId,
                DateTime   = DateTime.Now,
                Message    = "",
                UserId     = user.Id
            };
            var fileBase64String = Convert.FromBase64String(file.fileBinary);
            var chatMessageFile  = new ChatMessageFile
            {
                ChatMessageId = message.Id,
                FileBinary    = fileBase64String,
                fileName      = file.fileName
            };
            await _chatMessageRepository.CreateAsync(message);

            await _chatMessageFileRepository.Create(chatMessageFile);

            await _domainContext.SaveChangesAsync();

            return(new ChatMessageResult
            {
                DateTime = message.DateTime,
                fileId = chatMessageFile.Id,
                fileName = chatMessageFile.fileName,
                IsFile = true,
                Message = "",
                profileId = file.profileId,
                profileTo = userTo.ProfileId,
            });
        }
コード例 #3
0
        public async Task <Guid> Create(ChatMessageFile chatMessage)
        {
            await _domainContext.ChatMessageFiles.AddAsync(chatMessage);

            return(chatMessage.Id);
        }