예제 #1
0
        /// <summary>
        /// Accepts the invite link. Returns true if the user was added, false if not.
        /// </summary>
        /// <param name="inviteLink">GUID to accept.</param>
        /// <param name="userUID">User accepting the invite.</param>
        /// <returns></returns>
        public async Task <bool> AcceptInviteLinkAsync(Guid inviteLink, string userUID)
        {
            var link = await DbContext.PodcastInvites.Include(x => x.Podcast)
                       .ThenInclude(x => x.Users).FirstOrDefaultAsync(x => x.InviteUID == inviteLink);

            if (link != null && (link.Expiry == null || link.Expiry > DateTime.Now))
            {
                if (link.Podcast.Users.Any(x => x.UserUID == userUID))
                {
                    return(false);
                }

                var podcastUser = new Db.PodcastUser
                {
                    UserUID   = userUID,
                    PodcastID = link.PodcastID,
                    IsAdmin   = false
                };

                await DbContext.PodcastUsers.AddAsync(podcastUser);

                await DbContext.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
예제 #2
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
                    }
                }
            });
        }