コード例 #1
0
ファイル: ChatService.cs プロジェクト: DanilSlbv/ReactChat
 public async Task <ResponseModel <string> > AddAsync(ChatModel chatModel)
 {
     if (await _chatRepository.CreateAsync(MapToChat.MapToChatEntity(chatModel)))
     {
         return(new GetResponse <string>("").GetSuccessResponse());
     }
     return(new GetResponse <string>("").GetErrorResponse("Error when try to create."));
 }
コード例 #2
0
        public async Task <string> GetChatNameAsync(string userName)
        {
            ChatWithNestedObjects chatWithNestedObjects = await _chatRepository.GetByNameAsync(userName);

            if (chatWithNestedObjects is null)
            {
                Chat chat = new Chat {
                    Name = userName
                };
                await _chatRepository.CreateAsync(chat);

                return(chat.Name);
            }
            return(chatWithNestedObjects.Chat.Name);
        }
コード例 #3
0
        public async Task ExecuteAsync(Message message, TelegramBotClient client)
        {
            var chatId = message.Chat.Id;

            var name = !string.IsNullOrEmpty(message.Chat.Title)
                ? message.Chat.Title
                : $"{message.Chat.FirstName} {message.Chat.LastName}";

            var chat = new ChatDto
            {
                Id   = chatId,
                Name = name
            };

            await _repository.CreateAsync(chat);

            await client.SendTextMessageAsync(chatId, $"Chat registered with a name {name}");
        }