/// <summary> /// 分页查询栏目 /// </summary> /// <param name="cateFilter">对象</param> /// <param name="limit">一页共几条</param> /// <param name="page">目前第几页</param> /// <returns>pagination</returns> public static dynamic Find(CMS_Category cateFilter, int limit, int page) { try { using (CMSDatabase_Model cms = new CMSDatabase_Model()) { Pagination pagination = new Pagination(); var list = from data in cms.CMS_Category select data; if (cateFilter.cid > 0) { list = list.Where(data => data.cid == cateFilter.cid).Select(data => data); } pagination.total = list.Count(); list = list.OrderByDescending(data => data.cid); list = list.Skip(limit * (page - 1)).Take(limit); pagination.rows = list.ToList(); return(pagination); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 添加栏目 /// </summary> /// <param name="c"></param> /// <returns></returns> public int AddCol(CMS_Category c) { var ls = d1.CMS_Category.Max(a => a.navorder); c.navorder = ls + 1; d1.CMS_Category.Add(c); return(d1.SaveChanges()); }
/// <summary> /// 修改栏目信息 /// </summary> /// <param name="u"></param> /// <returns></returns> public int UpdInfoByCid(CMS_Category u) { var ls = d1.CMS_Category.Find(u.cid); ls.ctitle = u.ctitle; ls.cname = u.cname; ls.nav = u.nav; ls.search = u.search; return(d1.SaveChanges()); }
/// <summary> /// 修改 /// </summary> /// <param name="cateFilter">对象</param> /// <returns>int</returns> public static dynamic Edit(CMS_Category cateFilter) { try { return(CMS_Category_DAL.Edit(cateFilter)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 分页查询栏目 /// </summary> /// <param name="cateFilter">对象</param> /// <param name="limit">一页共几条</param> /// <param name="page">目前第几页</param> /// <returns>pagination</returns> public static dynamic Find(CMS_Category cateFilter, int limit, int page) { try { Pagination pagination = CMS_Category_DAL.Find(cateFilter, limit, page); return(pagination); } catch (Exception ex) { throw ex; } }
public ActionResult Edit(CMS_Category cate) { try { var count = CMS_Category_BLL.Edit(cate); return(Json(count, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
//查询 public ActionResult Find(int rows, int page) { try { CMS_Category cateFilter = new CMS_Category(); Pagination pagination = CMS_Category_BLL.Find(cateFilter, rows, page); return(Json(pagination, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
public ActionResult FindByID(int cid) { try { CMS_Category cateFilter = new CMS_Category(); cateFilter.cid = cid; Pagination pagination = CMS_Category_BLL.Find(cateFilter, 10, 1); List <CMS_Category> list = pagination.rows as List <CMS_Category>; return(Json(list[0], JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
/// <summary> /// 修改 /// </summary> /// <param name="cateFilter">对象</param> /// <returns>int</returns> public static dynamic Edit(CMS_Category cateFilter) { try { using (CMSDatabase_Model cms = new CMSDatabase_Model()) { cms.Entry(cateFilter).State = System.Data.Entity.EntityState.Modified; var count = cms.SaveChanges(); return(count); } } catch (Exception ex) { throw ex; } }
/** * Link categories and tags to a post. * * This is combined into one function, because the Wordpress XML uses the same "category" tag * for both categories and tags for a post, and just uses the "domain" attribute to distinguish * between them. * * @param entity context * @param CMS_Document postDoc * @param CONTENT_BlogPost post */ protected static void LinkCategoriesAndTags(kenticofreeEntities context, CMS_Document postDoc, CONTENT_BlogPost post) { var xml = (from c in wpxml.Descendants("item") where Int32.Parse(c.Element(wpns + "post_id").Value) == post.BlogPostID select c ).Single(); var categories = (from c in xml.Descendants("category") select new { Domain = c.Attribute("domain").Value, Nicename = c.Attribute("nicename").Value } ); foreach (var cat in categories) { if (cat.Domain == "post_tag") { CMS_TagGroup tg = GetTagGroup(context); CMS_Tag tag = (from t in context.CMS_Tag where t.TagName == cat.Nicename && t.TagGroupID == tg.TagGroupID select t ).SingleOrDefault(); postDoc.CMS_Tag.Add(tag); if (String.IsNullOrEmpty(postDoc.DocumentTags)) { postDoc.DocumentTags = tag.TagName; } else { postDoc.DocumentTags = postDoc.DocumentTags + ", " + tag.TagName; } tag.TagCount++; } else if (cat.Domain == "category") { CMS_Category category = (from c in context.CMS_Category where c.CategoryName == cat.Nicename select c ).SingleOrDefault(); postDoc.CMS_Category.Add(category); category.CategoryCount++; } } context.SaveChanges(); }
protected void btnSave_Click(object sender, EventArgs e) { //上传图标 string strIconFileName = string.Empty;//图标路径 try { if (!string.IsNullOrEmpty(this.file0.PostedFile.FileName)) { if (!System.IO.Directory.Exists(Server.MapPath("~") + @"/Images")) { System.IO.Directory.CreateDirectory(Server.MapPath("~") + @"/Images"); } if (!System.IO.Directory.Exists(String.Format(@"{0}/Images/{1}", Server.MapPath("~"), GlobalSession.strSiteCode))) { System.IO.Directory.CreateDirectory(String.Format(@"{0}/Images/{1}", Server.MapPath("~"), GlobalSession.strSiteCode)); } string orignalName = this.file0.PostedFile.FileName; //获取客户机上传文件的文件名 string extendName = orignalName.Substring(orignalName.LastIndexOf(".")); //获取扩展名 if (extendName != ".gif" && extendName != ".jpg" && extendName != ".jpeg" && extendName != ".png") { MessageBox.Show(this, "文件格式有误!"); return; }//检查文件格式 string newName = String.Format("{0}_{1}{2}", DateTime.Now.Millisecond, file0.PostedFile.ContentLength, extendName);//对文件进行重命名 strIconFileName = String.Format(@"{0}Images/{1}/{2}", Server.MapPath("~"), GlobalSession.strSiteCode, newName); file0.PostedFile.SaveAs(strIconFileName); } } catch (Exception ex) { MessageBox.Show(this, "上传发生错误!原因是:" + ex.ToString()); } CategoryDAL dal = new CategoryDAL(); CMS_Category modelUpdate = new CMS_Category() { //类别ID ID = strID, //站点代码 SiteCode = GlobalSession.strSiteCode, //类别名称 Name = this.txtName.Text, //图标路径 Pic = string.IsNullOrEmpty(strIconFileName) ? strIconFileName : strIconFileName.Substring(Server.MapPath("~").Length), //简要说明 Summary = this.txtSummary.Text, //类别内容 Content = this.hd_content.Value, //链接 Link = this.txtLink.Text, //排序 Order = int.Parse(this.txtOrder.Text) }; if (dal.UpdateCategoryData(modelUpdate)) { MessageBox.Show(this, "修改成功!"); } else { MessageBox.Show(this, "修改失败!"); } }
/** * Add categories into the database. * * @param entity context */ protected static void ProcessCategories(kenticofreeEntities context) { Console.WriteLine("Adding categories to database."); var categories = (from c in wpxml.Descendants(wpns + "category") select new CMS_Category { CategoryCount = 0, CategoryDisplayName = c.Element(wpns + "cat_name").Value, CategoryName = c.Element(wpns + "category_nicename").Value, CategoryDescription = c.Element(wpns + "cat_name").Value, CategoryEnabled = true, CategoryGUID = Guid.NewGuid(), CategoryLastModified = DateTime.Now, CategorySiteID = Int32.Parse(config.Get("siteId")), CategoryNamePath = "/" + c.Element(wpns + "category_nicename").Value, CategoryLevel = 0, CategoryParentID = null }); CMS_Category lastCat = null; // TODO: Add category nesting (not doing it right now, because our export doesn't nest categories) foreach (CMS_Category cat in categories) { // Make sure we don't add a category that already exists var exists = (from c in context.CMS_Category where c.CategoryName == cat.CategoryName select c ); if (!exists.Any()) { if (lastCat == null) { lastCat = (from o in context.CMS_Category where o.CategorySiteID == cat.CategorySiteID && o.CategoryLevel == cat.CategoryLevel orderby o.CategoryOrder descending select o ).FirstOrDefault(); if (lastCat == null) { lastCat = new CMS_Category() { CategoryOrder = 0 }; } } cat.CategoryOrder = lastCat.CategoryOrder + 1; /* We can't make the IDPath until we get an ID, and I can't find how Kentico does this, * so we have to do it the long way. */ context.CMS_Category.AddObject(cat); context.SaveChanges(); // Add the category // Bulid the path and update our category cat.CategoryIDPath = "/" + cat.CategoryID.ToString().PadLeft(8, '0'); context.SaveChanges(); // Let's save the last inserted category, so we don't have to access the database so much lastCat = cat; } } }