public void Test_Razor_Lits() { var runner = new Runner(); var data = new BlogView() { Id = 1, Posts = new List <BlogPost>() { new BlogPost() { Id = 5 }, new BlogPost() { Id = 12 }, } }; var model = Runnable.Command(data, separator: ","); model.M(p => p.Lit(m => m.Id)); model.Sql(";"); model.M(p => p.Open(m => m.Posts).Lit(m => m.Id)); model.Sql(";"); model.M(p => p.Vals(m => m.Posts).Skip(1).FirstOrDefault().Lit(m => m.Id)); var result = runner.Sql(model); result.ShouldBe("1;5;12"); }
public void Test_Razor_Model_Props() { var runner = new Runner(); var data = new BlogView() { Id = 1, Posts = new List <BlogPost>() { new BlogPost() { Id = 1 }, new BlogPost() { Id = 2, CreatedOn = DateTime.Now }, } }; var model = Runnable.Command(data, separator: ","); model.M(p => p.Prop(m => m.Id)); model.Sql(";"); model.M(p => p.Open(m => m.Posts).Prop(m => m.Id)); model.Sql(";"); model.M(p => p.Open(m => m.Posts).Prop(m => m.CreatedOn)); model.Sql(";"); model.M(p => p.Vals(m => m.Posts).Skip(1).FirstOrDefault().Prop(m => m.Id)); var result = runner.Sql(model); result.ShouldBe(@"""Model.Id"";""Model.Posts.Item[0].Id"";""Model.Posts.Item[0].CreatedOn"";""Model.Posts.Item[1].Id"""); }
public async Task <IActionResult> Edit(int id, [Bind("BlogViewId")] BlogView blogView) { if (id != blogView.BlogViewId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(blogView); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogViewExists(blogView.BlogViewId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(blogView)); }
public void Test_Razor_Pars() { var runner = new Runner(); var data = new BlogView() { Id = 1, Posts = new List <BlogPost>() { new BlogPost() { Id = 1 }, new BlogPost() { Id = 2, CreatedOn = DateTime.Now }, } }; var model = Runnable.Command(data, separator: ","); model.M(p => p.Par(m => m.Id)); model.Sql(";"); model.M(p => p.Open(m => m.Posts).Par(m => m.Id)); model.Sql(";"); model.M(p => p.Open(m => m.Posts).Par(m => m.CreatedOn)); model.Sql(";"); model.M(p => p.Vals(m => m.Posts).Skip(1).FirstOrDefault().Par(m => m.Id)); model.Sql(";"); model.M(p => p.Par(m => m.Id)); var result = runner.Sql(model); result.ShouldBe("@P0;@P1;@P2;@P3;@P0"); }
private void button1_Click_1(object sender, EventArgs e) { BlogView blogView = new BlogView(); BlogService blogService = new BlogService(); IList blogList = new ArrayList();// blogService.getAllBlogs(); BlogController blogController = new BlogController(blogView, blogList); blogController.LoadView(); blogView.ShowDialog(); }
public static BlogModel MergeViewWithModelBlog(BlogModel model, BlogView view) { model.CommentsNotify = view.CommentsNotify; model.PostPerPage = view.PostPerPage; model.AllowComments = view.AllowComments; model.DateFormat = view.DateFormat; model.TimeFormat = view.TimeFormat; return(model); }
public async Task <IActionResult> Create([Bind("BlogViewId")] BlogView blogView) { if (ModelState.IsValid) { _context.Add(blogView); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(blogView)); }
public async Task <IActionResult> Blog(BlogView result) { if (!ModelState.IsValid) { return(View(result)); } var blogSettings = await _settingsService.GetBlogSettingsById(result.Id); await _settingsService.SetBlogSettings(SettingsHelpers.MergeViewWithModelBlog(blogSettings, result)); return(RedirectToAction("Blog", "Settings")); }
public static BlogView ConvertToViewBlog(BlogModel result) { var blogView = new BlogView { Id = result.Id, CommentsNotify = result.CommentsNotify, PostPerPage = result.PostPerPage, AllowComments = result.AllowComments, DateFormat = result.DateFormat, TimeFormat = result.TimeFormat }; return(blogView); }
public ActionResult Blog(string tituloUrl = "") { BlogView b = new BlogView(tituloUrl); if (b.blog != null) { ViewBag.description = b.blog.subtitulo; return(View(b)); } else { return(RedirectToAction("Index")); } }
public IActionResult Index(int id) { BlogView model = new BlogView(Context.HttpContext); model.Blog.Id = id; if (User.Identity.IsAuthenticated) { string accountSource = CookieUtil.GetCookie(AccountSource.LoginSource, User); if (accountSource == AccountSource.Git) { //直接返回cookie中的结果,并建立session model.User = _signService.GetGitUser(); model.IsLogin = true; } } else { model.IsLogin = false; } return(View(model)); }
/// <summary> /// 递归编译 /// </summary> /// <param name="blogViewLiat"></param> /// <returns></returns> private int CompileList(List <FileEntity> blogViewLiat) { int count = 0; foreach (FileEntity item in blogViewLiat) { if (item.GetName() == "README.MD") { continue; } if (item.GetFileType() == FileType.Directory) { if (item.GetList() != null && item.GetList().Count > 0) { count += CompileList(item.GetList()); } continue; } // md文件创建日期 DateTime createTime = File.GetCreationTime(item.GetFullPath()); // 获取md文件内容 string mdStr = FileHelper.ReadFile(item.GetFullPath()); // 获取blog头部的配置 string mdhead = mdStr.Substring(mdStr.IndexOf("---StartBlogHead") + 16, mdStr.IndexOf("---EndBlogHead") - 16); Entitys.BlogHead blogHead = Newtonsoft.Json.JsonConvert.DeserializeObject <Entitys.BlogHead>(mdhead); // 获取blog内容 string mdBody = mdStr.Substring(mdStr.IndexOf("---EndBlogHead") + 14); // 根据md文件创建日期获取html文件创建路径 string relativePath = Path.Combine(new string[] { createTime.Year.ToString(), createTime.Month.ToString(), createTime.Day.ToString(), item.GetName() }); string dirStr = Path.Combine(Program.GetBlogDir(), relativePath); // html 文件的所在深度 int deep = relativePath.Count(c => c == '\\') + 1; // 获取html文件的相对路径 string relativeUrl = "" + relativePath.Replace("\\", "/"); string relativeHead = ""; for (int i = 0; i < deep; i++) { relativeHead += "../"; } relativeUrl = relativeHead + relativeUrl; StringBuilder blogFootStr = new StringBuilder(); blogFootStr.AppendLine(""); blogFootStr.AppendLine("<p>"); blogFootStr.AppendLine(string.Format("<a title =\"pre\" class=\"prev-article\" href=\"{0}\" > 上一篇</a>", "#")); blogFootStr.AppendLine(string.Format("<a title=\"next\" class=\"next-article\" href=\"#{0}\">下一篇</a>", "#")); blogFootStr.AppendLine("</p>"); // 将md文件转换成html MarkdownSharp.Markdown md = new MarkdownSharp.Markdown(); string articleStr = string.Format("<article><h1 class=\"article-title\">{0}</h1>\n\r\n\r{1}\n\r\n\r{2}</article>", blogHead.title, md.Transform(mdBody), blogFootStr.ToString()); //string articleStr = string.Format("<article><h1 class=\"article-title\">{0}</h1>\n\r\n\r{1}\n\r\n\r{2}</article>", blogHead.title, MarkDownHelper.ConvertToHtml(mdBody), blogFootStr.ToString()); // 创建html文件存放路径 if (!Directory.Exists(dirStr)) { Directory.CreateDirectory(dirStr); } // html文件路径 string pathStr = Path.Combine(dirStr, "index.html"); //样式文件的引用 todo:处理本地文件和非本地文件非关系 string styleRef = "\n\r<link rel=\"stylesheet\" type=\"text/css\" href=\"" + relativeHead + "Styles/style.css\" />"; styleRef = string.Join("\r\n", Program.GetConfig().Site.headref.Where(str => !str.Contains("href=\"http://") & !str.Contains("href=\"https://") & !str.Contains("src=\"http://") & !str.Contains("src=\"https://"))).Replace("href=\"", "href=\"" + relativeHead); styleRef += string.Join("\r\n", Program.GetConfig().Site.headref.Where(str => str.Contains("href=\"http://") || str.Contains("href=\"https://") || str.Contains("src=\"http://") || str.Contains("src=\"https://"))); if (FileHelper.WriteFile(string.Format(htmlModel, headStr + styleRef, articleStr), pathStr)) { count++; BlogView blogView = new BlogView(); blogView.tags = new List <string>(); blogView.title = blogHead.title; //todo: edit blogView.edittime = DateTime.Now; blogView.createtime = createTime; blogView.describe = blogHead.description; // 计算HashCode var hash = System.Security.Cryptography.HashAlgorithm.Create(); var fs = File.Open(item.GetFullPath(), FileMode.Open); byte[] bts = hash.ComputeHash(fs); fs.Close(); blogView.hashcode = string.Join("-", bts); blogView.id = item.GetId(); blogView.num = item.GetId(); blogView.tags = blogHead.tags; blogView.type = blogHead.type; blogView.url = relativeUrl; blogView.imgurls = blogHead.photos; this.blogListView.bloglist.Add(blogView); indexHtml.AppendLine(""); indexHtml.AppendLine("<p>"); indexHtml.AppendLine(string.Format(" <a title=\"{0}\" target=\"_self\" href=\"{1}\\\">", blogView.title, relativeUrl.Replace("../", ""))); indexHtml.AppendLine(string.Format(" <h3>{0}</h3>", blogView.title)); indexHtml.AppendLine(string.Format(" <h4>{0}</h4>", blogView.describe)); foreach (string imgurl in blogView.imgurls) { indexHtml.AppendLine(string.Format(" <img alt=\"{0}\" src=\"{1}\" />", blogView.title, imgurl)); } indexHtml.AppendLine(" </a>"); indexHtml.AppendLine("</p>"); if (!typeList.Contains(blogView.type)) { typeList.Add(blogView.type); } tagList.Concat(blogView.tags); //if (!tagList.Concat(blogView.tags)) // tagList.Add(blogView.tag); } } return(count); }
public BlogPresenter(BlogView view) { this.view = view; }
public BlogViewTestBase() { var blogViewRepository = new InMemoryViewRepository<BlogViewItem>(); BlogView = new BlogView(blogViewRepository); }