public IActionResult ViewBlog(int id) { BlogItem blogItem = _blogProvider.GetBlog(id); if (blogItem == null) { return(RedirectToAction(nameof(Index))); } BlogPostViewModel model = GetBlogPostViewModel(blogItem); model.Breadcrumbs.Add(new BreadcrumbItem(Languages.LanguageStrings.Blog, $"/{Name}/{nameof(Index)}", false)); model.Breadcrumbs.Add(new BreadcrumbItem(blogItem.Title, model.Url, false)); return(View(model)); }
public async Task <IActionResult> Rss(string type) { string host = Request.Scheme + "://" + Request.Host; var blog = await _blogProvider.GetBlog(); var posts = await _feedProvider.GetEntries(type, host); var items = new List <SyndicationItem>(); var feed = new SyndicationFeed( blog.Title, blog.Description, new Uri(host), host, posts.FirstOrDefault().Published ); if (posts != null && posts.Count() > 0) { foreach (var post in posts) { var item = new SyndicationItem( post.Title, post.Description.MdToHtml(), new Uri(post.Id), post.Id, post.Published ); item.PublishDate = post.Published; items.Add(item); } } feed.Items = items; var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, NewLineHandling = NewLineHandling.Entitize, NewLineOnAttributes = true, Indent = true }; using (var stream = new MemoryStream()) { using (var xmlWriter = XmlWriter.Create(stream, settings)) { var rssFormatter = new Rss20FeedFormatter(feed, false); rssFormatter.WriteTo(xmlWriter); xmlWriter.Flush(); } return(File(stream.ToArray(), "application/xml; charset=utf-8")); } }
public async Task <ActionResult> Upload(IFormFile file, UploadType uploadType, int postId = 0) { var author = await _authorProvider.FindByEmail(User.Identity.Name); var post = postId == 0 ? new Post() : await _postProvider.GetPostById(postId); var path = $"{author.Id}/{DateTime.Now.Year}/{DateTime.Now.Month}"; var fileName = $"data/{path}/{file.FileName}"; if (uploadType == UploadType.PostImage) { fileName = Url.Content("~/") + fileName; } if (await _storageProvider.UploadFormFile(file, path)) { var blog = await _blogProvider.GetBlog(); switch (uploadType) { case UploadType.Avatar: author.Avatar = fileName; return((await _authorProvider.Update(author)) ? new JsonResult(fileName) : BadRequest()); case UploadType.AppLogo: blog.Logo = fileName; return((await _blogProvider.Update(blog)) ? new JsonResult(fileName) : BadRequest()); case UploadType.AppCover: blog.Cover = fileName; return((await _blogProvider.Update(blog)) ? new JsonResult(fileName) : BadRequest()); case UploadType.PostCover: post.Cover = fileName; return(new JsonResult(fileName)); case UploadType.PostImage: return(new JsonResult(fileName)); } return(Ok()); } else { return(BadRequest()); } }
public async Task <ActionResult> Upload([FromForm] IFormFile file, UploadType uploadType, int postId = 0) { var author = await _authorProvider.FindByEmail(User.Identity.Name); var post = postId == 0 ? new Post() : await _postProvider.GetPostById(postId); var path = Guid.NewGuid().ToString(); var fileName = path; if (await _storageProvider.UploadFormFile(file, path)) { var blog = await _blogProvider.GetBlog(); switch (uploadType) { case UploadType.Avatar: author.Avatar = fileName; return((await _authorProvider.Update(author)) ? new JsonResult(fileName) : BadRequest()); case UploadType.AppLogo: blog.Logo = fileName; return((await _blogProvider.Update(blog)) ? new JsonResult(fileName) : BadRequest()); case UploadType.AppCover: blog.Cover = fileName; return((await _blogProvider.Update(blog)) ? new JsonResult(fileName) : BadRequest()); case UploadType.PostCover: post.Cover = fileName; return(new JsonResult(fileName)); case UploadType.PostImage: return(new JsonResult(fileName)); } return(Ok()); } else { return(BadRequest("Fail when uploading file")); } }
public async Task <Blog> GetBlog() { return(await _blogProvider.GetBlog()); }