Beispiel #1
0
        public async Task <IActionResult> CreatePodcast(int episode, string title, string description)
        {
            if (ModelState.IsValid)
            {
                if (User.IsInRole("Podcast"))
                {
                    // Grab the next episode number
                    Models.Podcast lastPod = _dbContext.Podcasts.Where(p => p.Episode == episode).FirstOrDefault();
                    if (lastPod == null)
                    {
                        // Create the podcast object
                        Models.Podcast podcast = new Models.Podcast();
                        podcast.Episode       = episode;
                        podcast.Title         = title;
                        podcast.Description   = description;
                        podcast.DatePosted    = DateTime.Now;
                        podcast.DatePublished = DateTime.Now;
                        podcast.DateEdited    = DateTime.Now;
                        podcast.Files         = await SaveFilesAsync(Request.Form.Files, episode);

                        _dbContext.Podcasts.Add(podcast);
                        _dbContext.SaveChanges();
                        return(Json(new { result = true }));
                    }
                    return(Json(new { error = "That episode already exists" }));
                }
                return(Json(new { error = "You don't have permission to create a podcast" }));
            }
            return(Json(new { error = "No podcast created" }));
        }
Beispiel #2
0
        public async Task <IActionResult> EditPodcast(int podcastId, int episode, string title, string description, string fileIds)
        {
            if (ModelState.IsValid)
            {
                if (User.IsInRole("Podcast"))
                {
                    Models.Podcast podcast = _dbContext.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault();
                    if (podcast != null)
                    {
                        if (_dbContext.Podcasts.Where(p => p.Episode != episode).FirstOrDefault() == null || podcast.Episode == episode)
                        {
                            podcast.Episode     = episode;
                            podcast.Title       = title;
                            podcast.Description = description;
                            podcast.DateEdited  = DateTime.Now;
                            // Remove any files not in fileIds
                            List <string> fileIdList = new List <string>();
                            if (!string.IsNullOrEmpty(fileIds))
                            {
                                fileIdList = fileIds.Split(',').ToList();
                            }
                            for (int i = 0; i < podcast.Files.Count; i++)
                            {
                                PodcastFile curFile = podcast.Files.ElementAt(i);
                                if (!fileIdList.Exists(id => id == curFile.PodcastFileId.ToString()))
                                {
                                    if (System.IO.File.Exists(curFile.Path))
                                    {
                                        System.IO.File.Delete(curFile.Path);
                                    }
                                    _dbContext.PodcastFiles.Remove(curFile);
                                    podcast.Files.Remove(curFile);
                                }
                            }
                            await SaveFilesAsync(Request.Form.Files, episode);

                            // Add any new files
                            List <PodcastFile> newFiles = await SaveFilesAsync(Request.Form.Files, episode);

                            foreach (PodcastFile file in newFiles)
                            {
                                podcast.Files.Add(file);
                            }

                            // Save podcast
                            _dbContext.Entry(podcast).State = EntityState.Modified;
                            _dbContext.SaveChanges();
                            return(Json(new { result = true }));
                        }
                        return(Json(new { error = "That episode already exists" }));
                    }
                    return(Json(new { error = "No podcast found" }));
                }
                return(Json(new { error = "You don't have permission to edit this podcast" }));
            }
            return(Json(new { error = "Invalid Inputs" }));
        }
Beispiel #3
0
        /// <summary>
        /// Gets the RSS feed
        /// </summary>
        /// <returns></returns>
        private rss GetFeed(bool isAudio)
        {
            rss root = new rss()
            {
                version = _rssVersion
            };

            Models.Podcast lastPodcast = this.Podcasts.OrderByDescending(i => i.PublicationDate).FirstOrDefault();

            root.channel = new rssChannel()
            {
                ttl            = _ttl,
                title          = this.Header.Title,
                link           = this.Header.Url,
                language       = this.Header.Language,
                description    = this.Header.Description,
                copyright      = $"Copyright {DateTime.Today:yyyy} - {this.Header.CopyrightName}",
                managingEditor = $"{this.Header.CopyrightEmail} ({this.Header.CopyrightName})",
                webMaster      = $"{this.Header.CopyrightEmail} ({this.Header.CopyrightName})",
                pubDate        = lastPodcast.PublicationDate.ToPodcastDateTimeString(),
                lastBuildDate  = lastPodcast.PublicationDate.ToPodcastDateTimeString(),
                link1          = new link()
                {
                    href = (isAudio ? this.Header.FeedAudioUrl : this.Header.FeedVideoUrl),
                    rel  = "self",
                    type = "application/rss+xml"
                },
                image = new rssChannelImage()
                {
                    url         = this.Header.ImageUrl,
                    title       = this.Header.Title,
                    link        = this.Header.Url,
                    width       = 144,
                    height      = 400,
                    description = this.Header.Description
                },
                category  = this.GetCategories(),
                subtitle  = this.Header.Description,
                @explicit = "no",
                author    = this.Header.Authors,
                summary   = this.Header.Description,
                owner     = new owner()
                {
                    name  = this.Header.Authors,
                    email = this.Header.CopyrightEmail
                },
                image1 = new image()
                {
                    href = this.Header.ImageUrl
                },
                category1 = this.GetCategoriesKeyValue().ToArray(),
                item      = this.GetListOfPodcasts(isAudio)
            };

            return(root);
        }
Beispiel #4
0
 public PodcastViewModel(Models.Podcast podcast)
 {
     PodcastId     = podcast.PodcastId;
     Episode       = podcast.Episode;
     Title         = podcast.Title;
     Description   = podcast.Description;
     Files         = podcast.Files.ToList();
     Tags          = podcast.Tags.ToList();
     DatePosted    = podcast.DatePosted;
     Published     = podcast.Published;
     DatePublished = podcast.DatePublished;
     DateEdited    = podcast.DateEdited;
 }
Beispiel #5
0
 public IActionResult DeletePodcast(int podcastId)
 {
     if (ModelState.IsValid)
     {
         if (User.IsInRole("Podcast"))
         {
             Models.Podcast podcast = _dbContext.Podcasts.Where(p => p.PodcastId == podcastId).FirstOrDefault();
             if (podcast != null)
             {
                 foreach (PodcastFile file in podcast.Files)
                 {
                     System.IO.File.Delete(file.Path);
                 }
                 _dbContext.Podcasts.Remove(podcast);
                 _dbContext.SaveChanges();
                 return(Json(new { result = true }));
             }
             return(Json(new { error = "No podcast found" }));
         }
         return(Json(new { error = "You don't have permission to delete this podcast" }));
     }
     return(Json(new { error = "Invalid Inputs" }));
 }
Beispiel #6
0
 public IActionResult PublishPodcast(int podcastId, bool publish)
 {
     if (ModelState.IsValid)
     {
         if (User.IsInRole("Podcast"))
         {
             Models.Podcast podcast = _dbContext.Podcasts.Find(podcastId);
             if (podcast != null)
             {
                 podcast.Published = publish;
                 if (publish)
                 {
                     podcast.DatePublished = DateTime.Now;
                 }
                 _dbContext.Entry(podcast).State = EntityState.Modified;
                 _dbContext.SaveChanges();
                 return(Json(new { result = true }));
             }
             return(Json(new { error = "No podcast found" }));
         }
         return(Json(new { error = "You don't have permission to publish this podcast" }));
     }
     return(Json(new { error = "Invalid Inputs" }));
 }
Beispiel #7
0
 public async Task OpenPlayer(Models.Podcast item)
 {
     await CoreMethods.PushPageModel <PlayerPageModel>(item, true, true);
 }