public string ReadFromFolderContents(ChilledDbContext context, int id) { _feedMeta = context.RSSHeaders.FirstOrDefault(rss => rss.RSSNumber == id); if (_feedMeta == null) { return(""); } var feedBuilder = new MemoryStream(); using (var xml = XmlWriter.Create(feedBuilder, new XmlWriterSettings() { Encoding = Encoding.UTF8 })) { xml.WriteStartDocument(); WriteRSSHeader(xml); WriteChannelHeader(xml); WriteLogo(xml); WriteItunesStuff(xml); WriteAtomFeedInfo(xml); WritePodcastHeader(xml); var podcasts = context.Podcasts.Include(p => p.GemData).Where(pod => pod.FeedId == id).OrderByDescending(p => p.PubDate); foreach (var podcast in podcasts) { WritePodcast(xml, podcast); } xml.WriteEndDocument(); } feedBuilder.Position = 0; using (var reader = new StreamReader(feedBuilder)) { return(reader.ReadToEnd()); } }
public void EditBlogPost(BlogGem blog, ChilledDbContext context) { var oldData = context.BlogPosts.FirstOrDefault(b => b.Id == int.Parse(blog.Id)); if (oldData != null) { var rss = context.RSSHeaders.FirstOrDefault(r => r.RSSNumber == blog.FeedId); oldData.Hashtags = GetHashTags(blog.Hashtags); oldData.MarkdownContent = blog.MarkdownContent; oldData.Published = blog.Published; oldData.RSSHeaderId = rss.Id; oldData.SubTitle = blog.Subtitle; oldData.Title = blog.Title; context.SaveChanges(); } }
public void AddNewBlogPost(BlogGem blog, ChilledDbContext context, ChilledUser user) { var rss = context.RSSHeaders.FirstOrDefault(r => r.RSSNumber == blog.FeedId); context.BlogPosts.Add(new BlogPost() { Hashtags = GetHashTags(blog.Hashtags), MarkdownContent = blog.MarkdownContent, Published = blog.Published, RSSHeaderId = rss.Id, SubTitle = blog.Subtitle, Title = blog.Title, Author = user }); context.SaveChanges(); }
public Configuration AddBlogsToGemList(ChilledDbContext context, int id = int.MinValue, string userId = "") { var blogs = context.BlogPosts .Where(p => (id == int.MinValue) ? true : p.RSSHeader.RSSNumber == id) .Include(b => b.Author) .Include(b => b.Pictures) .OrderByDescending(p => p.Published); foreach (var blog in blogs) { if (string.IsNullOrEmpty(userId) || userId == blog.Author.Id) { Gems.Add(new BlogGem(blog)); } } return(this); }
public async Task <bool> CreateNewEpisode(PodcastMetadata podCast, ChilledDbContext context, string currentUserId) { podCast.Title = podCast.Title.Trim(); var filename = Regex.Replace(podCast.PodcastFile.FileName, " ", "_"); using (var txn = context.Database.BeginTransaction()) { var podcastEntity = new Gem() { Title = podCast.Title, SummaryText = new string(podCast.Description.Take(250).ToArray()), GemType = GemType.Podcast, CreatedById = currentUserId, PodcastData = new Podcast() { Description = podCast.Description, ShortDescription = podCast.ShortDescription, LengthInBytes = podCast.PodcastFile.Length, ItunesDuration = podCast.ItunesDuration, PubDate = podCast.PubDate, FeedId = podCast.FeedId } }; context.Gems.Add(podcastEntity); context.SaveChanges(); podcastEntity.PodcastData.Location = $"http://{urlPath}/uploads/podcasts/{podcastEntity.Id}/{filename}"; podcastEntity.FilePath = Path.Combine(podcastDbDirectory, podcastEntity.Id.ToString()); Directory.CreateDirectory(podcastEntity.FilePath); using (var stream = new FileStream(Path.Combine(podcastEntity.FilePath, filename), FileMode.CreateNew)) { await podCast.PodcastFile.CopyToAsync(stream); stream.Flush(); } podcastEntity.FilePath = Path.Combine(podcastEntity.FilePath, filename); context.SaveChanges(); txn.Commit(); } return(true); }
public Configuration AddPicturesToGemList(ChilledDbContext context) { var pictures = context.Pictures.Include(p => p.GemData).OrderByDescending(p => p.CreatedDate); foreach (var pic in pictures) { Gems.Add(new PictureGem { Id = pic.Id.ToString(), Title = pic.GemData.Title, Type = GetRandomGemType(), PictureLink = pic.Location, ArtistSource = pic.ArtistLink, ArtistName = pic.ArtistName }); } return(this); }
public Configuration AddPodcastToGemList(ChilledDbContext context, int id = int.MinValue) { var podcasts = context.Podcasts.Include(p => p.GemData).Where(p => (id == int.MinValue) ? true : p.FeedId == id).OrderByDescending(p => p.PubDate).ToList(); foreach (var pod in podcasts) { Gems.Add(new PodcastGem { Id = pod.Id.ToString(), AudioLink = pod.Location, Title = pod.GemData.Title, Text = pod.Description, Type = GetRandomGemType(), FeedId = pod.FeedId }); } return(this); }
public async Task SavePictureToDatabase(PictureGemManagerViewModel gem, ChilledUser user, Paths paths, ChilledDbContext context) { var gemDB = new Gem() { Title = gem.PictureMetadata.Title, CreatedBy = user, GemType = GemType.Picture, SummaryText = gem.PictureMetadata.SummaryText, PictureData = new Picture() { HoverText = gem.PictureMetadata.HoverText, ArtistName = gem.PictureMetadata.ArtistName, ArtistLink = gem.PictureMetadata.ArtistLink, CreatedDate = DateTime.Now, FileSize = gem.PictureMetadata.PictureFile.Length } }; context.Gems.Add(gemDB); context.SaveChanges(); var filePath = paths.PicturesDirectory; var fileFolder = Path.Combine(filePath, gemDB.Id.ToString()); var fileName = gem.PictureMetadata.PictureFile.FileName; var filetype = gem.PictureMetadata.PictureFile.ContentType; var fullyQualified = Path.Combine(fileFolder, fileName); Directory.CreateDirectory(fileFolder); using (var stream = new FileStream(fullyQualified, FileMode.CreateNew)) { await gem.PictureMetadata.PictureFile.CopyToAsync(stream); stream.Flush(); } gemDB.PictureData.Location = $"//{paths.URLPath}/uploads/pictures/{gemDB.Id}/{fileName}"; gemDB.FilePath = fullyQualified; context.SaveChanges(); }
public GemMasterController(UserManager <ChilledUser> userManager, ChilledDbContext context, IOptions <Paths> pathsOpt) { _userManager = userManager; _context = context; _pathsOpt = pathsOpt; }
public HomeController(IOptions <Paths> pathsOpt, ChilledDbContext context) { _pathsOpt = pathsOpt; _context = context; }