Esempio n. 1
0
 void UpdateShows(Producer producer, List <ShowParsedDto> items)
 {
     try
     {
         var itemsToSave = items.Select(x => new Show
         {
             Title         = x.Title,
             Description   = x.Description,
             Mp3           = x.Mp3,
             PublishedDate = x.PublishedDate ?? DateTime.Now
         }).ToList();
         itemsToSave.ForEach(s =>
         {
             s.ProducerId = producer.Id;
             if (!_db.Shows.Any(x => x.Title == s.Title))
             {
                 _db.Shows.Add(s);
             }
         });
         _db.SaveChanges();
         Console.WriteLine("---------------------------");
         Console.WriteLine(producer.Name + "- saved to db!");
         Console.WriteLine("---------------------------");
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error while updating feed: {producer.Name}: \n\r" + e.Message);
         Console.WriteLine(e);
     }
 }
        public Task <Producer> Handle(ProducerPostRequest request, CancellationToken cancellationToken)
        {
            _db.Producers.Add(request.Producer);
            _db.SaveChanges();
            _feedUpdater.UpdateShows(request.Producer);

            return(Task.FromResult(request.Producer));
        }