Beispiel #1
0
        /// <summary>
        /// Adds or updates the specified episode object to the database, if an unassigned episode already exists with the same UID.
        /// </summary>
        /// <param name="userUid">UID of the user.</param>
        /// <param name="episode">Episode to add to the database.</param>
        /// <returns></returns>
        public async Task <bool> UpdateEpisodeAsync(string userUid, DomainModels.Episode episode)
        {
            var dbPodcast = await DbContext.Podcasts.Include(x => x.Episodes).FirstOrDefaultAsync(c => c.UID == episode.PodcastUID && c.Members.Any(x => x.UserUID == userUid));

            if (dbPodcast == null)
            {
                return(false);
            }

            var dbEpisode = dbPodcast.Episodes.FirstOrDefault(c => c.UID == episode.UID);

            if (dbEpisode == null)
            {
                dbEpisode = await CreateNewEpisode(userUid, episode);
            }

            if (dbEpisode == null)
            {
                return(false);
            }

            dbEpisode.Title       = episode.Title;
            dbEpisode.Description = episode.Description;

            await DbContext.SaveChangesAsync();

            return(true);
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateEpisode([FromBody] DTOs.Episode episode)
        {
            string userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            var dmEpisode = new DomainModels.Episode
            {
                UID         = episode.UID,
                Title       = episode.Title,
                Description = episode.Description,
                PodcastUID  = episode.PodcastUID,
                RssUrl      = episode.RssUrl,
                MediaUrl    = episode.MediaUrl,
                PublishDate = episode.PublishDate
            };

            var isUpdated = await Repository.UpdateEpisodeAsync(userId, dmEpisode);

            if (isUpdated)
            {
                return(Ok());
            }
            else
            {
                return(Unauthorized());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new episode from the stored unassigned episode.
        /// </summary>
        /// <param name="userUid">UserUID of the current user.</param>
        /// <param name="episode">Episode to create.</param>
        /// <returns></returns>
        private async Task <Db.Episode> CreateNewEpisode(string userUid, DomainModels.Episode episode)
        {
            var dbPodcast = await DbContext.Podcasts.FirstOrDefaultAsync(c => c.UID == episode.PodcastUID && c.Members.Any(x => x.UserUID == userUid));

            var dbUnassignedEpisode = await DbContext.UnassignedEpisodes.Include(c => c.Clips).FirstOrDefaultAsync(c => c.UID == episode.UID);

            if (dbUnassignedEpisode == null)
            {
                return(null);
            }

            var clipStreams = new List <Stream>();

            foreach (var clip in dbUnassignedEpisode.Clips)
            {
                clipStreams.Add(await StreamBuilder.GetStreamFromUrlAsync(clip.MediaUrl));
            }

            var compiledStream = Audio.AudioConcatUtils.SequenceAudioStreams(clipStreams);
            var url            = await MediaStorage.UploadStreamAsync("rss", dbPodcast.UID, Guid.NewGuid(), compiledStream);

            var dbEpisode = new Db.Episode
            {
                UID         = Guid.NewGuid(),
                Title       = episode.Title,
                Description = episode.Description,
                RssUrl      = string.Concat(Config["RssPath"], dbPodcast.UID, "/", episode.UID),
                MediaUrl    = url,
                PublishDate = DateTime.Now,
                PodcastID   = dbPodcast.ID
            };

            DbContext.Episodes.Add(dbEpisode);
            dbUnassignedEpisode.IsCompleted = true;
            await DbContext.SaveChangesAsync();

            return(dbEpisode);
        }