public async Task <IActionResult> AddVideo(int id, string videoLink) { try { var content = new BlogContent(); content.Content = videoLink; content.ContentType = ContentType.Video; content.BlogId = id; content.ContentOrder = await _db.BlogContents .AsNoTracking() .Where(c => c.BlogId.Equals(id)).CountAsync(); await _db.BlogContents.AddAsync(content); await _db.SaveChangesAsync(); HttpContext.Session.SetInt32("Message", (int)Messages.AddedVideoSuccessfully); return(RedirectToAction(actionName: "EditBlog", controllerName: "Blog", routeValues: new { id = id, jumpTarget = "#blog-description-content-list", area = "Admin_EN" })); } catch (Exception) { throw; } }
public void SaveCategories(BlogContent blog) { if (blog.Category.ToList().Count == 0) { List <Category> categories = new List <Category> { new Category { Name = "Terror" }, new Category { Name = "Romance" }, new Category { Name = "Accion" }, new Category { Name = "Comedia" }, new Category { Name = "Misterio" }, }; blog.Category.AddRange(categories); blog.SaveChanges(); } }
public ViewResult AritcleList2(string sortOrder, string searchString) { BlogContent blogContent = new BlogContent(); ViewBag.FirstNameSortParm = String.IsNullOrEmpty(sortOrder) ? "first_desc" : ""; ViewBag.LastNameSortParm = sortOrder == "last" ? "last_desc" : "last"; var workers = from w in blogContent.Artciles select w; if (!string.IsNullOrEmpty(searchString)) { workers = workers.Where(w => w.Title.Contains(searchString) || w.Title.Contains(searchString)); } switch (sortOrder) { case "first_desc": workers = workers.OrderByDescending(w => w.Id); break; case "last_desc": workers = workers.OrderByDescending(w => w.Title); break; case "last": workers = workers.OrderBy(w => w.UseId); break; default: workers = workers.OrderBy(w => w.IsRemove); break; } return(View(workers.ToList())); }
/// <summary> /// 页面加载 /// </summary> /// <param name="e"></param> protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); object[] parameters = e.Parameter as object[]; if (parameters != null) { if (parameters.Length == 1 && (parameters[0] as CNBlog) != null) { _blog = parameters[0] as CNBlog; BlogTitle.Text = _blog.Title; AuthorName.Content = _blog.AuthorName; PublishTime.Text = _blog.PublishTime; Views.Text = _blog.Views; Diggs.Text = "[" + _blog.Diggs + "]"; Comments.Text = _blog.Comments; BitmapImage bi = new BitmapImage { UriSource = new Uri(_blog.AuthorAvator) }; Avatar.Source = bi; AuthorName.Tag = _blog.BlogApp; string blog_body = await BlogService.GetBlogContentAsync(_blog.ID); if (blog_body != null) { if (App.Theme == ApplicationTheme.Dark) //暗主题 { blog_body += "<style>body{background-color:black;color:white;}</style>"; } BlogContent.NavigateToString(blog_body); } Loading.IsActive = false; } } }
public async Task <IActionResult> Edit(int id, [Bind("BlogId,Title,Content,ImageUrl,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] BlogContent blogContent) { if (id != blogContent.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(blogContent); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogContentExists(blogContent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["BlogId"] = new SelectList(_context.Blogs, "Id", "Id", blogContent.BlogId); return(View(blogContent)); }
public ActionResult Delete(Post post) { using (var blog = new BlogContent()) { Post pos = blog.Post.Find(post.Id); blog.Post.Remove(pos); blog.SaveChanges(); return(RedirectToAction("Index")); } }
// GET: Blog public ActionResult Index() { using (var blog = new BlogContent()) { PostVM post = new PostVM(); post.Posts = blog.Post.ToList(); post.Categories = blog.Category.ToList(); return(View(post)); } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); object[] parameters = e.Parameter as object[]; if (parameters != null) { if (parameters.Length == 1 && (parameters[0] as CnBlog) != null) { _blog = parameters[0] as CnBlog; BlogTitle.Text = _blog.Title; AuthorName.Content = _blog.AuthorName; PublishTime.Text = _blog.PublishTime; Views.Text = _blog.Views; Diggs.Text = "[" + _blog.Diggs + "]"; Comments.Text = _blog.Comments; BitmapImage bi = new BitmapImage { UriSource = new Uri(_blog.AuthorAvator) }; Avatar.Source = bi; AuthorName.Tag = _blog.BlogApp; string blogBody = await BlogService.GetBlogContentAsync(_blog.Id); if (blogBody != null) { HideScrollbar(ref blogBody); BlogContent.NavigateToString(blogBody); } // 获取评论数据 _commentHtml = CommentTool.BaseChatHtml; HideScrollbar(ref _commentHtml); BlogComment.NavigateToString(_commentHtml); List <CnBlogComment> listComments = await BlogService.GetBlogCommentsAsync(_blog.Id, 1, 199); if (listComments != null) { string comments = ""; foreach (CnBlogComment comment in listComments) { comments += CommentTool.Receive(comment.AuthorAvatar, comment.AuthorName == _blog.AuthorName ? "[博主]" + _blog.AuthorName : comment.AuthorName, comment.Content, comment.PublishTime, comment.Id); } _commentHtml = _commentHtml.Replace("<a id='ok'></a>", "") + comments + "<a id='ok'></a>"; Debug.Write(_commentHtml); HideScrollbar(ref _commentHtml); BlogComment.NavigateToString(_commentHtml); } Loading.IsActive = false; } } }
public ActionResult Detail(DetailVM detail) { using (var blog = new BlogContent()) { detail.comment.Date = DateTime.Now; detail.comment.IdPost = detail.post.Id; blog.Comment.Add(detail.comment); blog.SaveChanges(); } return(Detail(detail.post.Id)); }
/// <summary> /// 点击标题栏上的刷新 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void RefreshButton_Click(object sender, RoutedEventArgs e) { Loading.IsActive = true; string blog_body = await BlogService.GetBlogContentAsync(_blog.ID); if (blog_body != null) { BlogContent.NavigateToString(blog_body); Loading.IsActive = false; } }
public async Task <IActionResult> Create([Bind("BlogId,Title,Content,ImageUrl,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] BlogContent blogContent) { if (ModelState.IsValid) { _context.Add(blogContent); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BlogId"] = new SelectList(_context.Blogs, "Id", "Id", blogContent.BlogId); return(View(blogContent)); }
private async Task CreateBlogContentForTests(string title, string content, int blogId, IDeletableEntityRepository <BlogContent> cRepo) { var blogContent = new BlogContent { BlogId = blogId, Title = title, Content = content, }; await cRepo.AddAsync(blogContent); await cRepo.SaveChangesAsync(); }
public BlogContent CreateNewPostAsync(CreatePostViewModel model) { var post = new BlogContent { ApplicationUser = model.ApplicationUser, Title = model.Title, Content = model.Content, CreatedAt = DateTime.Now, UserId = model.ApplicationUser.Id, TagId = 1, }; _context.Add(post); _context.SaveChanges(); return(post); }
public async Task CreateBlogContent(string title, string content) { var getBlogId = await this.blogRepository.All() .Where(x => x.Title == title).Select(x => x.Id) .FirstOrDefaultAsync(); var blogContent = new BlogContent { BlogId = getBlogId, Title = title, Content = content, }; await this.blogContentRepository.AddAsync(blogContent); await this.blogContentRepository.SaveChangesAsync(); }
public ActionResult Delete(int?id) { if (!id.HasValue) { return(HttpNotFound()); } using (var blog = new BlogContent()) { Post post = blog.Post.Find(id); if (post == null) { return(new HttpNotFoundResult()); } return(View(post)); } }
public ActionResult ManagePost(int?Id) { using (var blog = new BlogContent()) { PostVM post = new PostVM(); post.SaveCategories(blog); post.Categories = blog.Category.ToList(); if (Id.HasValue) { post.post = blog.Post.Find(Id); return(View(post)); } else { return(View(post)); } } }
public ActionResult Detail(int?id) { if (!id.HasValue) { return(HttpNotFound()); } using (var blog = new BlogContent()) { DetailVM detail = new DetailVM(); detail.post = blog.Post.Find(id); detail.Categories = blog.Category.ToList(); detail.comments = blog.Comment.Where(com => com.IdPost == id.Value).ToList(); if (detail.post == null) { return(new HttpNotFoundResult()); } return(View(detail)); } }
public ActionResult ManagePost(Post post) { if (ModelState.IsValid) { } using (var blog = new BlogContent()) { if (post.Id == 0) { post.Date = DateTime.Now; blog.Post.Add(post); } else { Post _post = blog.Post.Find(post.Id); _post.Title = post.Title; _post.IdCategory = post.IdCategory; _post.Content = post.Content; } blog.SaveChanges(); return(RedirectToAction("Index")); } }
public IActionResult Index(Node node, BlogContent content) { return(View()); }
public async Task <IActionResult> AddImage(int id, IFormFile image) { //Create images/blog_content/large/blog_id/ Folder string largePath = System.IO.Path.Combine(_host.WebRootPath, "images/blog_content", "large", "blog_" + id); if (!Directory.Exists(largePath)) { Directory.CreateDirectory(largePath); } //Create images/blog_content/medium/blog_id/ Folder string mediumPath = System.IO.Path.Combine(_host.WebRootPath, "images/blog_content", "medium", "blog_" + id); if (!Directory.Exists(mediumPath)) { Directory.CreateDirectory(mediumPath); } //Create images/blog_content/small/blog_id/ Folder string smallPath = System.IO.Path.Combine(_host.WebRootPath, "images/blog_content", "small", "blog_" + id); if (!Directory.Exists(smallPath)) { Directory.CreateDirectory(smallPath); } try { //Upload new images: var imageName = "_" + System.DateTime.Now.ToString("YYYYMMDDhhmmss") + Path.GetFileName(image.FileName); //Save new large image: var newLargePath = System.IO.Path.Combine(_host.WebRootPath, "images/blog_content/large/blog_" + id); var finalNewLargePath = Path.Combine(newLargePath, imageName); //Resize and save medium image: var newMediumPath = System.IO.Path.Combine(_host.WebRootPath, "images/blog_content/medium/blog_" + id); var finalNewMediumPath = System.IO.Path.Combine(newMediumPath, imageName); //Resize and save small image: var newSmallPath = System.IO.Path.Combine(_host.WebRootPath, "images/blog_content/small/blog_" + id); var finalNewSmallPath = System.IO.Path.Combine(newSmallPath, imageName); using (var webPFileStream = new FileStream(finalNewLargePath, FileMode.Create)) { using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false)) { imageFactory.Load(image.OpenReadStream()) .Resize(new Size(900, 0)) .Save(webPFileStream); } } using (var webPFileStream = new FileStream(finalNewMediumPath, FileMode.Create)) { using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false)) { imageFactory.Load(image.OpenReadStream()) .Resize(new Size(600, 0)) .Save(webPFileStream); } } using (var webPFileStream = new FileStream(finalNewSmallPath, FileMode.Create)) { using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false)) { imageFactory.Load(image.OpenReadStream()) .Resize(new Size(400, 0)) .Save(webPFileStream); } } var blogContent = new BlogContent(); blogContent.BlogId = id; blogContent.ContentType = ContentType.Image; blogContent.Content = imageName; blogContent.ContentOrder = await _db.BlogContents.AsNoTracking() .Where(c => c.BlogId.Equals(id)).CountAsync(); await _db.BlogContents.AddAsync(blogContent); await _db.SaveChangesAsync(); HttpContext.Session.SetInt32("Message", (int)Messages.AddedImageSuccessfully); return(RedirectToAction(actionName: "EditBlog", controllerName: "Blog", routeValues: new { id = id, jumpTarget = "#blog-description-content-list", area = "Admin_EN" })); } catch (Exception e) { return(Json(false)); } }
private async void Refresh(uint id) { blog = await blogApi.GetBlog(id); BlogContent.NavigateToString(blog.Content); }
public HomeController(ILogger <HomeController> logger, BlogContent content) { _logger = logger; _content = content; }
private readonly BlogContent _db;//只读 public BaseService(BlogContent db) { this._db = db; }