public ActionResult Article(int id, int page = 1) { GgcmsArticles article = dataHelper.Article(id, page); //跳转到错误页 if (article == null) { } Pagination pagination = new Pagination(); pagination.page = page; pagination.baseLink = dataHelper.Prefix + "/Article/" + id + "/{page}"; pagination.pageSize = 1; pagination.setMaxSize(article.pagesCount); ViewBag.pagination = pagination; article.Content = ContentKeys(article.Content); GgcmsCategories category = dataHelper.Categories(article.Category_Id); ViewBag.Description = article.Description; ViewBag.Keywords = article.Keywords; ViewBag.Title = article.Title; ViewBag.article = article; ViewBag.category = category; ViewBag.topId = dataHelper.GetCategoryTopId(category); var pt = getTemplate(PageType.article, article); ViewBag.pageTmpl = pt; ViewBag.PageType = 2; return(View(pt.templateUrl)); }
// DELETE: api/GgcmsCategories/5 public IHttpActionResult Delete(int id) { GgcmsArticles info = Dbctx.GgcmsArticles.Find(id); if (info == null) { return(BadRequest("信息不存在")); } //删除关联模型数据 var category = dbHelper.Categories(Math.Abs(info.Category_Id)); if (category != null) { if (category.ExtModelId > 0) { ExtendModule.Delete(info.Id, category.ExtModelId); } updateArticleNumber(info.Category_Id, -1); } Dbctx.GgcmsArticles.Remove(info); //删除关联附件 Dbctx.GgcmsAttachments.RemoveRange(Dbctx.GgcmsAttachments.Where(x => x.Articles_Id == info.Id)); //删除关联分页 Dbctx.GgcmsArticlePages.RemoveRange(Dbctx.GgcmsArticlePages.Where(x => x.Article_Id == info.Id)); Dbctx.SaveChanges(); ClearCache(); CacheHelper.RemoveAllCache(CacheTypeNames.Categorys); return(Ok(info)); }
// 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 PageTemplate getTemplate(PageType ptype = PageType.home, dynamic info = null) { string cfgStyle = sysConfigs["cfg_default_style"]; string templateDir = ConfigurationManager.AppSettings["TemplateDir"].ToString(); templateDir = "~/Views/" + templateDir + "/" + cfgStyle; string staticDir = ConfigurationManager.AppSettings["StaticDir"].ToString(); string styleDir = ConfigurationManager.AppSettings["StyleDir"].ToString(); string stylePath = "/" + staticDir + "/" + styleDir + "/" + cfgStyle; bool isMobile = getIsMobile(); GgcmsCategories category; string tmplName; switch (ptype) { case PageType.home: string home = sysConfigs["cfg_template_home"]; string turl = templateDir + "/" + home; if (isMobile && !string.IsNullOrEmpty(sysConfigs["cfg_template_m_home"].Trim())) { turl = templateDir + "/" + sysConfigs["cfg_template_m_home"]; } return(new PageTemplate { templatePath = templateDir, templateUrl = turl, stylePath = stylePath }); case PageType.category: tmplName = sysConfigs["cfg_template_list"]; category = info as GgcmsCategories; string style = category.StyleName ?? cfgStyle ?? ""; if (!string.IsNullOrWhiteSpace(style)) { templateDir = "~/Views/" + ConfigurationManager.AppSettings["TemplateDir"].ToString() + "/" + style; stylePath = "/" + staticDir + "/" + styleDir + "/" + style; if (isMobile && !string.IsNullOrWhiteSpace(category.MobileTmplName.Trim())) { tmplName = category.MobileTmplName; } else if (!string.IsNullOrWhiteSpace(category.TmplName)) { tmplName = category.TmplName; } } return(new PageTemplate { templatePath = templateDir, templateUrl = templateDir + "/" + tmplName, stylePath = stylePath }); case PageType.article: tmplName = sysConfigs["cfg_template_view"]; GgcmsArticles article = info as GgcmsArticles; category = dataHelper.Categories(article.Category_Id); if (!string.IsNullOrEmpty(article.StyleName.Trim())) { templateDir = "~/Views/" + ConfigurationManager.AppSettings["TemplateDir"].ToString() + "/" + article.StyleName; stylePath = "/" + staticDir + "/" + styleDir + "/" + article.StyleName; if (isMobile && !string.IsNullOrEmpty(article.MobileTmplName.Trim())) { tmplName = article.MobileTmplName; } else if (!string.IsNullOrEmpty(article.TmplName.Trim())) { tmplName = article.TmplName; } } else if (!string.IsNullOrEmpty(category.StyleName.Trim())) { templateDir = "~/Views/" + ConfigurationManager.AppSettings["TemplateDir"].ToString() + "/" + category.StyleName; stylePath = "/" + staticDir + "/" + styleDir + "/" + category.StyleName; if (isMobile && !string.IsNullOrEmpty(category.ArticleMobileTmplName.Trim())) { tmplName = category.ArticleMobileTmplName; } else if (!string.IsNullOrEmpty(category.ArticleTmplName.Trim())) { tmplName = category.ArticleTmplName; } } return(new PageTemplate { templatePath = templateDir, templateUrl = templateDir + "/" + tmplName, stylePath = stylePath }); } return(new PageTemplate()); }
// PUT: api/GgcmsCategories/5 public IHttpActionResult Edit(GgcmsArticles info) { if (Dbctx.GgcmsArticles.Where(x => x.Id == info.Id).Count() == 0) { return(BadRequest("信息不存在")); } //Dbctx.GgcmsArticles.Attach(info); //Dbctx.Entry(info).Property("goods_name").IsModified = true; var ent = Dbctx.Entry(info); ent.State = EntityState.Modified; info.pagesCount = info.pages.Where(x => x.state != EntityState.Deleted).Count() + 1; UpFileClass.FileSave(info, info.files.FindAll(x => x.fileType != 3)); var old = Dbctx.GgcmsArticles.Find(info.Id); if (old.Category_Id != info.Category_Id) { updateArticleNumber(info.Category_Id, 1); updateArticleNumber(old.Category_Id, -1); CacheHelper.RemoveAllCache(CacheTypeNames.Categorys); } var list = Dbctx.GgcmsAttachments.Where(x => x.Articles_Id == info.Id).ToList(); //附件 foreach (GgcmsAttachments attach in list) { var item = info.attachments.Find(x => x.Id == attach.Id); if (item == null) { Dbctx.GgcmsAttachments.Remove(attach); } else { attach.AttaUrl = item.AttaUrl; attach.AttaTitle = item.AttaTitle; attach.Describe = item.Describe; attach.CreateTime = DateTime.Now; attach.RealName = item.RealName; } } foreach (GgcmsAttachments attach in info.attachments) { if (attach.Id == 0) { attach.Articles_Id = info.Id; attach.CreateTime = DateTime.Now; Dbctx.GgcmsAttachments.Add(attach); } } if (info.ModuleInfo != null) { info.ExtModelId = info.ModuleInfo.Id; if (old.ExtModelId > 0 && info.ExtModelId != old.ExtModelId) { ExtendModule.Delete(info.Id, old.ExtModelId); } 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); } else if (old.ExtModelId > 0) { ExtendModule.Delete(info.Id, old.ExtModelId); } //分页保存 if (info.pages.Count > 0) { foreach (var page in info.pages) { UpFileClass.FileSave(page, page.files); if (page.state == EntityState.Added) { page.Article_Id = info.Id; Dbctx.GgcmsArticlePages.Add(page); } else if (page.state == EntityState.Modified) { var pageEnt = Dbctx.Entry(page); pageEnt.State = EntityState.Modified; } else if (page.state == EntityState.Deleted) { var p = Dbctx.GgcmsArticlePages.Find(page.Id); if (p != null) { Dbctx.GgcmsArticlePages.Remove(p); } } //只更新分页信息 else if (page.state == EntityState.Unchanged) { Dbctx.GgcmsArticlePages.Attach(page); Dbctx.Entry(info).Property("OrderId").IsModified = true; } } } Dbctx.SaveChanges(); ClearCache(); return(Ok(info)); }