Beispiel #1
0
        /// <summary>
        /// Updates the podcast with the specified info, if the user is an admin.
        /// </summary>
        /// <param name="userUID">User performing the request.</param>
        /// <param name="podcast">Podcast info to update.</param>
        /// <returns></returns>
        public async Task UpdatePodcastAsync(string userUID, PodcastUpload podcast)
        {
            var imageDataByteArray = Convert.FromBase64String(podcast.ImageData);

            var dbPodcast = await DbContext.Podcasts.FirstOrDefaultAsync(x => x.UID == podcast.UID &&
                                                                         x.Users.Any(c => c.UserUID == userUID && c.IsAdmin));

            if (dbPodcast != null)
            {
                dbPodcast.Name        = podcast.Name;
                dbPodcast.Description = podcast.Description;
                dbPodcast.ImageUrl    = await ImageStorage.UploadImageAsync(imageDataByteArray, podcast.FileType);

                await DbContext.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> EditPodcast([FromBody] PodcastUpload podcast)
        {
            string userId = User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            var domainModel = new Vocalia.Ingest.DomainModels.PodcastUpload
            {
                Name        = podcast.Name,
                UID         = podcast.UID,
                Description = podcast.Description,
                ImageData   = podcast.ImageData,
                FileType    = podcast.FileType
            };

            await Repository.UpdatePodcastAsync(userId, domainModel);

            return(Ok());
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new podcast for the specified user using the provided information.
        /// </summary>
        /// <param name="userUID">ID to create the podcast for.</param>
        /// <param name="podcast">Podcast info to add.</param>
        /// <param name="fileType">File type of the image being uploaded.</param>
        /// <returns></returns>
        public async Task CreatePodcastAsync(string userUID, PodcastUpload podcast)
        {
            var imageDataByteArray = Convert.FromBase64String(podcast.ImageData);

            var dbPodcast = new Db.Podcast
            {
                Name        = podcast.Name,
                Description = podcast.Description,
                ImageUrl    = await ImageStorage.UploadImageAsync(imageDataByteArray, podcast.FileType)
            };

            await DbContext.Podcasts.AddAsync(dbPodcast);

            var dbPodcastUsers = new Db.PodcastUser
            {
                PodcastID = dbPodcast.ID,
                UserUID   = userUID,
                IsAdmin   = true
            };

            await DbContext.PodcastUsers.AddAsync(dbPodcastUsers);

            await DbContext.SaveChangesAsync();

            await PodcastBus.SendAsync(new ServiceBus.Types.Editor.Podcast
            {
                Name     = dbPodcast.Name,
                UID      = dbPodcast.UID,
                ImageUrl = dbPodcast.ImageUrl,
                Members  = new List <Member>()
                {
                    new Member()
                    {
                        IsAdmin = true, UserUID = userUID
                    }
                }
            });
        }