public async override Task HandleMessageAsync(Vocalia.ServiceBus.Types.Podcast.Podcast message) { using (var scope = ServiceScope.CreateScope()) using (var DbContext = scope.ServiceProvider.GetService <PodcastContext>()) { //Update database of editor. if (!DbContext.Podcasts.Any(x => x.UID == message.UID)) { var podcast = new Db.Podcast { Title = message.Title, ImageUrl = message.ImageUrl, RSS = message.RssUrl, IsExplicit = message.IsExplicit, CategoryID = message.CategoryID, LanguageID = message.LanguageID, Active = true, UID = message.UID }; DbContext.Podcasts.Add(podcast); await DbContext.SaveChangesAsync(); } } }
/// <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(); }
/// <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 } } }); }
public async override Task HandleMessageAsync(Vocalia.ServiceBus.Types.Editor.Podcast message) { using (var scope = ServiceScope.CreateScope()) using (var DbContext = scope.ServiceProvider.GetService <EditorContext>()) { //Pass onto next service bus. var publishServiceBus = scope.ServiceProvider.GetService <IObjectBus <Vocalia.ServiceBus.Types.Publishing.Podcast> >(); await publishServiceBus.SendAsync(new Vocalia.ServiceBus.Types.Publishing.Podcast { UID = message.UID, ImageUrl = message.ImageUrl, Name = message.Name, Members = message.Members }); //Update database of editor. if (!DbContext.Podcasts.Any(x => x.UID == message.UID)) { var podcast = new Db.Podcast { Name = message.Name, ImageUrl = message.ImageUrl, UID = message.UID }; DbContext.Podcasts.Add(podcast); var members = message.Members.Select(x => new Member { PodcastID = podcast.ID, IsAdmin = x.IsAdmin, UserUID = x.UserUID }); DbContext.Members.AddRange(members); await DbContext.SaveChangesAsync(); } } }