private void CreateAndAddDbPodfilterUrl(string podcastUrl) { var savedPodcast = new SavedPodcast { LastUpdated = DateTime.Now, LastUsed = DateTime.Now, Modifications = GetPodcastModifications().Select(x => x.Modification).ToList(), Url = podcastUrl }; try{ var persistedPodcast = _savedPodcastProvider.Persist(savedPodcast); var baseUrl = GetBaseUrl(); if (persistedPodcast.Id > (long)System.Int32.MaxValue) { throw new ArgumentException("The podcast id is too large."); } TempData["savedPodcastId"] = (int)persistedPodcast.Id; TempData["savedPodcastUrl"] = $"{baseUrl}/api/filter/{persistedPodcast.Id}"; } catch (Exception ex) { TempData["errorMessage"] = $"There was a problem ({ex}). Please try again. If the problem persists contat the administrator."; } }
public async Task <IActionResult> AddFavorite(string id) { string user = FindUser(); var results = await _dal.SearchEpisodeIdAsync(id); var ep = results.episodes.ToList().First(); SavedPodcast favorite = new SavedPodcast(); favorite.UserId = user; favorite.EpisodeId = ep.id; favorite.PodcastName = ep.show.name; favorite.EpisodeName = ep.name; favorite.Publisher = ep.show.publisher; favorite.Description = ep.description; favorite.AudioPreviewUrl = ep.audio_preview_url; favorite.ExternalUrls = ep.external_urls.spotify; List <Image1> img = new List <Image1>(ep.images); var firstPic = img.First(); favorite.ImageUrl = firstPic.url; favorite.Duration = ep.duration_ms; favorite.ReleaseDate = DateTime.Parse(ep.release_date); ViewBag.EpName = ep.name; if (ModelState.IsValid) { if (_context.SavedPodcast.Any(id => id.EpisodeId.Equals(ep.id) & id.UserId.Equals(user))) { return(View("DuplicateFavorite")); } else { await _context.SavedPodcast.AddAsync(favorite); await _context.SaveChangesAsync(); } } return(RedirectToAction("UserFavorites")); }
/// <summary> /// Constructor for use within the application. Does not add the <see cref="SavedPodcast.Modifications"/> to the <see cref="Modifications"/>. /// </summary> /// <param name="podcast"></param> public SavedPodcastDto(SavedPodcast podcast) { SavedPodcast = podcast; }