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()); } } } }
// POST: api/GgcmsCategories public IHttpActionResult Add(GgcmsCategories info) { var result = Dbctx.GgcmsCategories.Add(info); UpFileClass.FileSave(info, info.files); CacheHelper.RemoveAllCache(CacheTypeNames.Categorys); Dbctx.SaveChanges(); ClearCache(); return(Ok(result)); }
public ActionResult Category(string id, int page = 1) { GgcmsCategories category; if (Tools.IsInt(id)) { int intid = Tools.parseInt(id); category = dataHelper.Categories(intid); } else { category = dataHelper.Categories(id); } if (category == null) { return(HttpNotFound()); } if (!string.IsNullOrWhiteSpace(category.Content)) { category.Content = ContentKeys(category.Content); } ViewBag.Description = category.Description; ViewBag.Keywords = category.Keywords; Pagination pagination = new Pagination(); pagination.page = page; pagination.baseLink = dataHelper.Prefix + "/Category/" + id + "/{page}"; pagination.pageSize = Tools.parseInt(sysConfigs["cfg_page_size"], 10); if (category.PageSize > 0) { pagination.pageSize = category.PageSize; } //跳转到错误页 if (category == null) { } int[] ids = GgcmsCategories.GetCategoryIds(category); ViewBag.pagination = pagination; ViewBag.Title = category.CategoryName; ViewBag.category = category; var result = dataHelper.Articles(ids, pagination); ViewBag.articles = result.Records; pagination.setMaxSize(Convert.ToInt32(result.Count)); ViewBag.topId = dataHelper.GetCategoryTopId(category); ViewBag.PageType = 1; var pt = getTemplate(PageType.category, category); ViewBag.pageTmpl = pt; return(View(pt.templateUrl)); }
public IHttpActionResult Delete(int id) { GgcmsCategories oldinfo = Dbctx.GgcmsCategories.Find(id); if (oldinfo == null) { return(BadRequest("信息不存在")); } //List<int> idlist = GetDeleteIds(oldinfo.ticket_key); //var query = Dbctx.ticket_information.Where(x => idlist.Contains(x.id)); Dbctx.GgcmsCategories.Remove(oldinfo); Dbctx.SaveChanges(); ClearCache(); return(Ok(oldinfo)); }
// PUT: api/GgcmsCategories/5 public IHttpActionResult Edit(GgcmsCategories info) { if (Dbctx.GgcmsCategories.Where(x => x.Id == info.Id).Count() == 0) { return(BadRequest("信息不存在")); } info.RouteKey = HttpUtility.UrlEncode(info.RouteKey); UpFileClass.FileSave(info, info.files); //Dbctx.GgcmsCategories.Attach(info); //Dbctx.Entry(info).Property("goods_name").IsModified = true; var ent = Dbctx.Entry(info); ent.State = EntityState.Modified; Dbctx.SaveChanges(); ClearCache(); return(Ok(info)); }
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); }