public static ChatMessageFileResult ConvertToResult( ChatMessageFile chatMessageFile ) { return(new ChatMessageFileResult { ChatMessageId = chatMessageFile.ChatMessageId, FileBinary = chatMessageFile.FileBinary, Id = chatMessageFile.Id }); }
/// <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, }); }
public async Task <Guid> Create(ChatMessageFile chatMessage) { await _domainContext.ChatMessageFiles.AddAsync(chatMessage); return(chatMessage.Id); }