Exemplo n.º 1
0
 public async Task AddTopics(string roomId, IList <int> ids)
 {
     if (ids.Count() != 0)
     {
         try
         {
             //get topics from service
             _logger.LogInformation("Fetching all Topics by ids: {}", ids);
             var allTopics = _commonResource.GetTopics();
             var topics    = new List <TopicModel>();
             foreach (var id in ids)
             {
                 var topic = allTopics.FirstOrDefault(t => t.Id == id);
                 if (topic != null)
                 {
                     topics.Add(topic);
                 }
             }
             _messageService.AddTopicsToRoom(roomId, topics.Select(t => t.Id).ToList());
             await Clients.Group(roomId).SendAsync("Topics", topics.Select(t => t.Name));
         }
         catch (Exception)
         {
             _logger.LogWarning("Unable to Fetch Topics");
         }
     }
     else
     {
         _logger.LogInformation("No Topics Selected");
     }
 }