public Blog Save(string id, string owner, string title, string keywords, string data, params string[] categories) { Blog blog = Get(id); using (IConnectinContext cc = DBContext.DB1) { cc.BeginTransaction(); if (blog == null) { blog = new Blog(); blog.Owner = owner; } blog.Title = title; blog.Keywords = keywords; blog.Content = data; HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(data); blog.Summary = doc.DocumentNode.InnerText; blog.Summary = blog.Summary.Substring(0, blog.Summary.Length > 300 ? 300 : blog.Summary.Length); blog.Save(); (BlogLinkCategory.blog == id).Delete <BlogLinkCategory>(); foreach (string item in categories) { BlogLinkCategory blc = new BlogLinkCategory(); blc.Blog = blog.ID; blc.Category = item; blc.Save(); } cc.Commit(); } return(blog); }
public static void Transaction(IConnectinContext cc, Action <IConnectinContext> handler) { using (cc) { cc.BeginTransaction(); handler(cc); cc.Commit(); } }
public static void Transaction(DB db, Action <IConnectinContext> handler) { using (IConnectinContext cc = DBContext.GetConnection(db)) { cc.BeginTransaction(); handler(cc); cc.Commit(); } }
public static void Transaction(string connName, Action <IConnectinContext> handler) { using (IConnectinContext cc = DBContext.GetConnection(connName)) { cc.BeginTransaction(); handler(cc); cc.Commit(); } }
public void CategoryDelete(params string[] categories) { using (IConnectinContext cc = DBContext.DB1) { cc.BeginTransaction(); (BlogLinkCategory.category == categories).Delete <BlogLinkCategory>(); (BlogCategory.iD == categories).Delete <BlogCategory>(); cc.Commit(); } }
public void Delete(params string[] blogs) { using (IConnectinContext cc = DBContext.DB1) { cc.BeginTransaction(); (BlogLinkCategory.blog == blogs).Delete <BlogLinkCategory>(); (Blog.iD == blogs).Delete <Blog>(); cc.Commit(); } }
public static int Add(params Mappings.DataObject[] obj) { int result = 0; using (IConnectinContext cc = DBContext.DB1) { cc.BeginTransaction(); result = Add(cc, obj); cc.Commit(); } return(result); }