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

            if (dbPodcast == null)
            {
                await CreateNewPodcast(userUid, podcast);

                return(true);
            }

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

            dbPodcast.Title       = podcast.Title;
            dbPodcast.Description = podcast.Description;
            dbPodcast.CategoryID  = podcast.CategoryID;
            dbPodcast.LanguageID  = podcast.LanguageID;
            dbPodcast.IsExplicit  = podcast.IsExplicit;
            dbPodcast.IsActive    = podcast.IsActive;

            await DbContext.SaveChangesAsync();

            return(true);
        }
Example #2
0
        public async Task <IActionResult> UpdatePodcast([FromBody] DTOs.Podcast podcast)
        {
            string userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            var dmPodcast = new DomainModels.Podcast
            {
                UID         = podcast.UID,
                CategoryID  = podcast.CategoryID,
                LanguageID  = podcast.LanguageID,
                Title       = podcast.Title,
                Description = podcast.Description,
                ImageUrl    = podcast.ImageUrl,
                IsExplicit  = podcast.IsExplicit,
                IsActive    = podcast.IsActive
            };

            var isUpdated = await Repository.UpdatePodcastAsync(userId, dmPodcast);

            if (isUpdated)
            {
                return(Ok());
            }
            else
            {
                return(Unauthorized());
            }
        }
Example #3
0
        /// <summary>
        /// Inserts a new podcast into the database.
        /// </summary>
        /// <param name="userUid">UID of the user.</param>
        /// <param name="podcast">Podcast to insert.</param>
        /// <returns></returns>
        private async Task CreateNewPodcast(string userUid, DomainModels.Podcast podcast)
        {
            var unassignedPodcast = await DbContext.UnassignedPodcasts.Include(c => c.Members).FirstOrDefaultAsync(c => c.UID == podcast.UID && c.Members.Any(x => x.UserUID == userUid));

            if (unassignedPodcast == null)
            {
                return;
            }

            var dbPodcast = new Db.Podcast
            {
                UID         = podcast.UID,
                Title       = podcast.Title,
                Description = podcast.Description,
                CategoryID  = podcast.CategoryID,
                LanguageID  = podcast.LanguageID,
                ImageUrl    = podcast.ImageUrl,
                IsActive    = podcast.IsActive,
                IsExplicit  = podcast.IsExplicit,
                RssUrl      = Config["RssPath"] + podcast.UID
            };

            DbContext.Podcasts.Add(dbPodcast);

            var dbMembers = unassignedPodcast.Members.Select(c => new Db.Member
            {
                UserUID   = c.UserUID,
                PodcastID = dbPodcast.ID
            });

            DbContext.Members.AddRange(dbMembers);
            unassignedPodcast.IsCompleted = true;

            await ListenBus.SendAsync(new Vocalia.ServiceBus.Types.Podcast.Podcast
            {
                UID        = dbPodcast.UID,
                Title      = dbPodcast.Title,
                ImageUrl   = dbPodcast.ImageUrl,
                IsExplicit = dbPodcast.IsExplicit,
                RssUrl     = string.Concat(Config["RssPath"], dbPodcast.UID),
                CategoryID = dbPodcast.CategoryID,
                LanguageID = dbPodcast.LanguageID
            });

            await DbContext.SaveChangesAsync();
        }