private void GenerateArticles(GgcmsCategories cinfo) { string aurl = prefix + "/Article/"; string svrpath = context.Server.MapPath("~"); string dir = Path.GetFullPath(svrpath + "/article"); using (GgcmsDB db = new GgcmsDB()) { var list = db.GgcmsArticles.Where(x => x.Category_Id == cinfo.Id).ToList(); foreach (var info in list) { string fn = Path.GetFullPath(dir + "/" + info.Id.ToString()); fn = fn + "\\index.html"; GeneratePage(fn, aurl + info.Id); decimal count = info.pagesCount; for (int p = 1; p < count; p++) { int page = p + 1; fn = Path.GetFullPath(dir + "/" + info.Id.ToString() + "/" + page.ToString()); fn = fn + "\\index.html"; GeneratePage(fn, aurl + info.Id + "/" + page.ToString()); } } } }
private void GenerateCategories(List <GgcmsCategories> list) { string curl = prefix + "/Category/"; string svrpath = context.Server.MapPath("~"); string dir = Path.GetFullPath(svrpath + "/category"); var cfgs = dhlp.SysConfigs(); int pageSize = Convert.ToInt32(cfgs["cfg_page_size"]); using (GgcmsDB db = new GgcmsDB()) { foreach (var c in list) { string fn = Path.GetFullPath(dir + "/" + (string.IsNullOrWhiteSpace(c.RouteKey) ? c.Id.ToString() : c.RouteKey.Trim())); fn = fn + "\\index.html"; GeneratePage(fn, curl + c.Id); decimal count = db.GgcmsArticles.Where(x => x.Category_Id == c.Id).Count(); int psize = c.PageSize == 0 ? pageSize : c.PageSize; int pagecount = Convert.ToInt32(Math.Ceiling(count / psize)); for (int p = 1; p < pagecount; p++) { int page = p + 1; fn = Path.GetFullPath(dir + "/" + (string.IsNullOrWhiteSpace(c.RouteKey) ? c.Id.ToString() : c.RouteKey.Trim()) + "/" + page.ToString()); fn = fn + "\\index.html"; GeneratePage(fn, curl + c.Id + "/" + page.ToString()); } GenerateArticles(c); } } }
// POST: api/GgcmsCategories public IHttpActionResult Add(GgcmsArticles info) { //提交除附加模型外的文件-标题图,内容中的图 UpFileClass.FileSave(info, info.files.FindAll(x => x.fileType != 3)); info.CreateTime = DateTime.Now; updateArticleNumber(info.Category_Id, 1); CacheHelper.RemoveAllCache(CacheTypeNames.Categorys); if (info.ModuleInfo != null && info.ModuleInfo.Id > 0) { info.ExtModelId = info.ModuleInfo.Id; } info.pagesCount = info.pages.Count + 1; var result = Dbctx.GgcmsArticles.Add(info); Dbctx.SaveChanges(); //附件 using (GgcmsDB db = new GgcmsDB()) { foreach (GgcmsAttachments attach in info.attachments) { attach.Articles_Id = info.Id; attach.CreateTime = DateTime.Now; db.GgcmsAttachments.Add(attach); } db.SaveChanges(); } //数据模型 if (info.ModuleInfo != null && info.ModuleInfo.Id > 0) { foreach (var file in info.files.FindAll(x => x.fileType == 3)) { foreach (var item in info.ModuleInfo.Columns) { if (item.ColName == file.propertyName) { item.Value = UpFileClass.FileSave(file.filePath.ToString(), item.Value.ToString(), (int)file.fileType); } } } ExtendModule.SaveData(info.Id, info.ModuleInfo); } //分页保存 if (info.pages.Count > 0) { foreach (var page in info.pages) { UpFileClass.FileSave(page, page.files); page.Article_Id = info.Id; Dbctx.GgcmsArticlePages.Add(page); } Dbctx.SaveChanges(); } ClearCache(); return(Ok(result)); }
private void UpdateTask(GgcmsTasks tinfo) { using (GgcmsDB db = new GgcmsDB()) { var ent = db.Entry(tinfo); ent.State = EntityState.Modified; db.SaveChanges(); CacheHelper.RemoveAllCache(CacheTypeNames.Tasks); } }
protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); Context = HttpContext.Current; Session = Context.Session; Server = Context.Server; httpRequest = Context.Request; httpResponse = Context.Response; base.Initialize(controllerContext); Context = HttpContext.Current; Session = Context.Session; Server = Context.Server; httpRequest = Context.Request; httpResponse = Context.Response; Dbctx = new GgcmsDB(); dbHelper = new DataHelper(); }
public void Run() { using (GgcmsDB db = new GgcmsDB()) { if (taskInfo.All) { GenerateHome(); GenerateCategories(db.GgcmsCategories.ToList()); } else { if (taskInfo.Categories.Count() > 0) { GenerateCategories(db.GgcmsCategories.Where(x => taskInfo.Categories.Contains(x.Id)).ToList()); } } } }
public static List <GgcmsTasks> GetTasks() { string cacheName = CacheTypeNames.Tasks.ToString(); List <GgcmsTasks> tasks = new List <GgcmsTasks>(); object obj = GetCache(cacheName); if (obj == null) { GgcmsDB db = new GgcmsDB(); tasks = db.GgcmsTasks.Where(x => x.Switch == 1).ToList(); SetCache(cacheName, tasks, new TimeSpan(0, 20, 0)); } else { tasks = obj as List <GgcmsTasks>; } return(tasks); }
public static List <GgcmsKeywords> GetKeywords() { string cacheName = CacheTypeNames.Keys.ToString(); List <GgcmsKeywords> keys = new List <GgcmsKeywords>(); object obj = GetCache(cacheName); if (obj == null) { GgcmsDB db = new GgcmsDB(); keys = db.GgcmsKeywords.Where(x => x.Status == 1).ToList(); SetCache(cacheName, keys, new TimeSpan(0, 20, 0)); } else { keys = obj as List <GgcmsKeywords>; } return(keys); }
private void updateArticleNumber(int id, int num) { try { using (GgcmsDB db = new GgcmsDB()) { GgcmsCategories cinfo = db.GgcmsCategories.Find(id); if (cinfo == null) { return; } if (cinfo.ParentId > 0) { updateArticleNumber(cinfo.ParentId, num); } cinfo.ArticleTotal = cinfo.ArticleTotal + num; db.SaveChanges(); } } catch { } }
public static List <GgcmsCategories> GetCategorys(string prefix = "") { string cacheName = CacheTypeNames.Categorys.ToString(); List <GgcmsCategories> categorys = new List <GgcmsCategories>(); object obj = GetCache(cacheName); if (obj == null) { GgcmsDB db = new GgcmsDB(); var tmps = (from r in db.GgcmsCategories where r.CategoryType == 0 orderby r.OrderId ascending select r).ToList(); categorys = GgcmsCategories.GetCategoryList(0, tmps as List <GgcmsCategories>, prefix); SetCache(cacheName, categorys); } else { categorys = obj as List <GgcmsCategories>; } return(categorys); }
public static Dictionary <string, string> GetSysConfigs() { string cacheName = CacheTypeNames.SysConfigs.ToString(); Dictionary <string, string> cfgs = new Dictionary <string, string>(); object obj = GetCache(cacheName); if (obj == null) { GgcmsDB db = new GgcmsDB(); var tmps = from r in db.GgcmsDictionaries where r.GroupKey == "system_configs" select new { r.Id, r.DictKey, r.DictValue }; foreach (var item in tmps) { cfgs.Add(item.DictKey, item.DictValue); } SetCache(cacheName, cfgs); } else { cfgs = obj as Dictionary <string, string>; } return(cfgs); }