/// <summary> /// 获得所有博客的分类 /// </summary> /// <param name="newCache">是否重新获取</param> /// <returns></returns> public static List<BlogTypes> GetAllType(bool newCache = false) { if (null == HttpRuntime.Cache["BlogType"] || newCache) { BLL.BlogTypesBLL tag = new BlogTypesBLL(); HttpRuntime.Cache["BlogType"] = tag.GetList(t => true).ToList().OrderBy(t => t.TypeName).ToList(); } return (List<BlogTypes>)HttpRuntime.Cache["BlogType"]; }
//#region 01 取得所有博客标签 ///// <summary> ///// 取得所有博客标签 ///// </summary> ///// <param name="newCache">是否重新获取</param> ///// <returns></returns> //public static List<BlogTags> GetAllTag(bool newCache = false) //{ // if (null == HttpRuntime.Cache["BlogTag"] || newCache) // { // BLL.BlogTagsBLL tag = new BlogTagsBLL(); // HttpRuntime.Cache["BlogTag"] = tag.GetList(t => true).ToList(); // } // return (List<BlogTags>)HttpRuntime.Cache["BlogTag"]; //} //#endregion #region 02 获得所有博客的分类 /// <summary> /// 获得所有博客的分类 /// </summary> /// <param name="newCache">是否重新获取</param> /// <returns></returns> public static List <BlogTypes> GetAllType(bool newCache = false) { if (null == HttpRuntime.Cache["BlogType"] || newCache) { BLL.BlogTypesBLL tag = new BlogTypesBLL(); HttpRuntime.Cache["BlogType"] = tag.GetList(t => true).ToList().OrderBy(t => t.TypeName).ToList(); } return((List <BlogTypes>)HttpRuntime.Cache["BlogType"]); }
/// <summary> /// 获得所有种类 /// </summary> /// <param name="newCache">是否更新缓存并返回最新信息</param> /// <returns></returns> public static List <Blog.Domain.BlogTypes> GetAllType(bool newCache = false) { if (null == HttpRuntime.Cache["BlogTypes"] || newCache) { BlogTypesBLL typeBll = new BlogTypesBLL(); HttpRuntime.Cache["BlogTypes"] = typeBll.GetList(t => true).ToList(); } return(HttpRuntime.Cache["BlogTypes"] as List <Blog.Domain.BlogTypes>); }
// // GET: /UnitTest/ public ActionResult Test() { BlogTypesBLL typeBLL = new BlogTypesBLL(); typeBLL.Mod(new BlogTypes { TypeName = "", BlogTypeId = 1007 }, "TypeName"); try { var result = typeBLL.save(); return(View(result.ToString())); }catch (Exception ex) { return(View(ex.ToString())); } }
/// <summary> /// 编辑文章类型 /// </summary> /// <param name="typename"></param> /// <param name="typeid"></param> /// <returns></returns> public ActionResult EditType(string typename, int typeid) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLLSession.UserInfoSessioin) { jsdata.Messg = "您还未登录~"; } else if (string.IsNullOrEmpty(typename)) { jsdata.Messg = "类型不能为空~"; } else if (null == typeid) { jsdata.Messg = "未取到文章ID~"; } if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return(Json(jsdata)); } #endregion BLL.BlogTypesBLL bll = new BlogTypesBLL(); var blogtype = new ModelDB.BlogTypes() { Id = typeid, TypeName = typename }; bll.Up(blogtype, "TypeName"); if (bll.save() > 0) //保存 { BLL.Common.CacheData.GetAllType(true); //更新缓存 jsdata.State = EnumState.成功; // jsdata.Messg = "修改成功~"; } else { jsdata.State = EnumState.失败; jsdata.Messg = "操作失败~"; } return(Json(jsdata)); }
/// <summary> /// 新增文章类型 /// </summary> /// <param name="newtypename"></param> /// <param name="userid"></param> /// <returns></returns> public ActionResult NewAddType(string newtypename) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLLSession.UserInfoSessioin) { jsdata.Messg = "您还未登录~"; } else if (string.IsNullOrEmpty(newtypename)) { jsdata.Messg = "类型不能为空~"; } if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return(Json(jsdata)); } #endregion int userid = BLLSession.UserInfoSessioin.Id; BLL.BlogTypesBLL bll = new BlogTypesBLL(); bll.Add( new ModelDB.BlogTypes() { TypeName = newtypename, UsersId = userid, IsDel = false } ); if (bll.save() > 0) //保存 { BLL.Common.CacheData.GetAllType(true); //更新缓存 jsdata.State = EnumState.成功; jsdata.Messg = "新增成功~"; } else { jsdata.State = EnumState.失败; jsdata.Messg = "新增失败~"; } return(Json(jsdata)); }
/// <summary> /// 由给定的博文类型名查找该类型对象ID,没有找到时就新建一个 /// </summary> /// <param name="typename">博文类型名</param> /// <param name="userName">该博文所属用户的用户名</param> /// <returns></returns> private int GetTypeId(string typename, string userName) { BlogTypesBLL blogType = new BlogTypesBLL(); var r = blogType.GetList(t => t.TypeName == typename); if (r.Count() >= 1) { int id = -1; r.ToList().ForEach(w => { if (w.UserId == GetUserId(userName)) { id = w.BlogTypeId; } }); if (id != -1) { return(id); } else { blogType.Add(new BlogTypes() { TypeName = typename, UserId = GetUserId(userName), // BlogUsers=BLL.Common.GetDataHelper.GetUser(userName) }); blogType.save(false); return(GetTypeId(typename, userName)); } } else { blogType.Add(new BlogTypes() { TypeName = typename, UserId = GetUserId(userName), // BlogUsers = BLL.Common.GetDataHelper.GetUser(userName) }); blogType.save(false); return(GetTypeId(typename, userName)); } }
public ActionResult Register(BlogUsers user) { JSData json = new JSData(); BlogTypesBLL typeBLL = new BlogTypesBLL(); BlogUsersBLL userBLL = new BlogUsersBLL(); BlogUsers checkName = userBLL.GetList(t => t.UserName == user.UserName).FirstOrDefault(); BlogUsers checkEmail = userBLL.GetList(t => t.Email == user.Email).FirstOrDefault(); if (checkName != null) { json.State = EnumState.失败; json.Message = "用户名已存在!"; } else if (checkEmail != null) { json.State = EnumState.失败; json.Message = "该邮箱已被注册!"; } else { user.UserNickname = user.UserName; userBLL.Add(user); typeBLL.Add(new BlogTypes { TypeName = "未分类", UserId = user.UserId, BlogUsers = user }); try { userBLL.save(); typeBLL.save(); }catch (Exception ex) { throw ex; } BLL.DataCache.GetUsersInfo(true);//更新缓存 BLLSession.UserInfoSessioin = user; json.State = EnumState.正常重定向; json.JSurl = "/"; json.Message = "恭喜你," + user.UserName + "注册成功!"; } return(Json(json)); }
private int GetTypeId(string typename, string userName) { BlogTypesBLL blogtype = new BlogTypesBLL(); var blogtagmode = blogtype.GetList(t => t.TypeName == typename); if (blogtagmode.Count() >= 1) { return(blogtagmode.FirstOrDefault().Id); } else { blogtype.Add(new ModelDB.BlogTypes() { TypeName = typename, CreateTime = DateTime.Now, IsDel = false, UsersId = GetUserId(userName) }); blogtype.save(); return(GetTypeId(typename, userName)); } }
/// <summary> /// 若在数据库找到该用户名,则返回该用户id,否则创建该用户名用户 /// </summary> /// <param name="userName"></param> /// <returns></returns> private int GetUserId(string userName) { BlogTypesBLL type = new BlogTypesBLL(); BlogUsersBLL user = new BlogUsersBLL(); var blogtagmode = user.GetList(t => t.UserName == userName); if (blogtagmode.Count() >= 1) { return(blogtagmode.FirstOrDefault().UserId); } else if (userName == "admin") { user.Add(new BlogUsers() { UserName = userName, IsDel = false, UserPass = "******", UserNickname = "小mu虫", Email = "*****@*****.**" }); user.save(); if (type.GetList(t => t.TypeName == "未分类").Count() < 1) { type.Add(new BlogTypes() { TypeName = "未分类", UserId = user.GetList(t => t.UserName == userName).FirstOrDefault().UserId }); type.save(); } return(GetUserId(userName)); } else { Exception ex = new Exception("在博客家园中没有该用户,请先新建该用户!"); throw ex; } }
/// <summary> /// 删除文章类型 /// </summary> /// <param name="id">要删除的类型id</param> /// <returns></returns> public String DeleteTypeById(int id) { bool result = false; BlogsBLL blogBLL = new BlogsBLL(); BlogTypesBLL typeBLL = new BlogTypesBLL(); var theTypeBlogs = blogBLL.GetList(t => t.BlogTypeId == id, isAsNoTracking: false).ToList(); var defaultTypeID = typeBLL.GetList(t => t.TypeName == "未分类").FirstOrDefault().BlogTypeId; foreach (Blogs blog in theTypeBlogs) //将属于要删除类型的博客分到 未分类 中 { blog.BlogTypeId = defaultTypeID; } try { blogBLL.save(); result = typeBLL.Del(t => t.BlogTypeId == id); BLL.DataCache.GetAllType(true); } catch (Exception ex) { return(ex.ToString()); } return(result.ToString()); }
public string Release() { JSData jsdata = new JSData(); var content = Request.Form["content"]; //正文内容 var title = Request.Form["title"]; //标题 var oldtag = Request.Form["oldtag"]; //旧的标签(从checkbox中选取的) var newtag = Request.Form["newtag"]; //新的标签(在tag_text中输入的) var type = Request.Form["chk_type"]; //文章类型 var isshowhome = Request.Form["isshowhome"]; //是否显示在主页 var blogid = Request.Form["blogid"]; // int numblogid = -1; int.TryParse(blogid, out numblogid); #region 数据验证 if (null == BLL.Common.BLLSession.UserInfoSessioin) { jsdata.Message = "您还未登录~"; } /*else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock) * jsdata.Message = "您的账户未激活,暂只能评论。~";*/ else if (string.IsNullOrEmpty(content)) { jsdata.Message = "内容不能为空~"; } else if (content.Length >= 300000) { jsdata.Message = "发布内容过多~"; } else if (string.IsNullOrEmpty(title)) { jsdata.Message = "标题不能为空~"; } else if (title.Length >= 100) { jsdata.Message = "标题过长~"; } if (!string.IsNullOrEmpty(jsdata.Message)) { jsdata.State = EnumState.失败; return(jsdata.ToJson()); } #endregion BLL.BlogsBLL blogbll = new BLL.BlogsBLL(); var blogtemp = blogbll.GetList(t => t.BlogId == numblogid, isAsNoTracking: false).FirstOrDefault(); var userid = numblogid > 0 ? blogtemp.UserId : BLLSession.UserInfoSessioin.UserId;//如果numblogid大于〇证明 是编辑修改 var sessionuserid = BLLSession.UserInfoSessioin.UserId; //获取得 文章 类型 BlogTypes myBlogType; if (type == null) { myBlogType = new BlogTypesBLL().GetList(t => (t.TypeName == "未分类" && t.UserId == BLLSession.UserInfoSessioin.UserId), isAsNoTracking: false).FirstOrDefault(); } else { var blogtype = int.Parse(type); myBlogType = new BLL.BlogTypesBLL().GetList(t => t.BlogTypeId == blogtype, isAsNoTracking: false).ToList().FirstOrDefault(); } //获取得 文章 tag标签集合 对象 //old var oldtaglist = oldtag.Split(',').ToList(); var myOldTag = new BLL.BlogTagsBLL().GetList(t => t.UserId == userid && oldtaglist.Contains(t.BlogTagName), isAsNoTracking: false).ToList(); //new var newtaglistname = newtag.Split(',').ToList(); //保存newtags到数据库 BlogTagsBLL tagBLL = new BlogTagsBLL(); List <string> distinctTemp = new List <string>(); foreach (string tagName in newtaglistname) { if (String.IsNullOrEmpty(tagName.Trim())) { continue; } if (distinctTemp.Contains(tagName.Trim())) { continue; } tagBLL.Add(new BlogTags { BlogTagName = tagName.Trim(), UserId = userid }); try { tagBLL.save(); } catch (Exception ex) { jsdata.Message = ex.ToString(); jsdata.State = EnumState.失败; return(jsdata.ToJson()); } distinctTemp.Add(tagName.Trim()); BLL.DataCache.GetAllTag(true); } ////////////////////// var myTags = new BLL.BlogTagsBLL().GetList(t => t.UserId == userid && newtaglistname.Contains(t.BlogTagName), isAsNoTracking: false).ToList(); myOldTag.ForEach(t => myTags.Add(t)); //ModelDB.Blogs blogtemp = new ModelDB.Blogs(); if (numblogid > 0) //如果有 blogid 则修改 { //blog = blogbll.GetList(t => t.Id == numblogid, isAsNoTracking: false).FirstOrDefault(); if (sessionuserid == blogtemp.UserId || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户 { blogtemp.Content = content; blogtemp.BlogRemarks = MyHtmlHelper.GetHtmlText(content); blogtemp.Title = title; blogtemp.IsShowHome = isshowhome == "true"; blogtemp.BlogTypes = myBlogType; blogtemp.BlogTags.Clear();//更新之前要清空 否则会存在主外键约束异常 blogtemp.BlogTags = myTags; blogtemp.IsDel = false; blogtemp.IsForwarding = false; jsdata.Message = "修改成功~"; } else { jsdata.Message = "您没有编辑此博文的权限~"; jsdata.JSurl = "/"; jsdata.State = EnumState.失败; return(jsdata.ToJson()); } } else //否则是新发布 { var blogfirst = blogbll.GetList(t => t.UserId == sessionuserid).OrderByDescending(t => t.BlogId).FirstOrDefault(); //var blogtitle = blogtemp.BlogTitle; //if (blogfirst != null) // blogtitle = blogtemp.BlogTitle; if (null != blogfirst && blogfirst.Title == title) { jsdata.Message = "不能同时发表两篇一样标题的文章~"; } else { blogtemp = new Blogs() { UserId = sessionuserid, Content = content, BlogRemarks = MyHtmlHelper.GetHtmlText(content), Title = title, IsShowHome = isshowhome == "true", BlogTypes = myBlogType, BlogTags = myTags, IsDel = false, IsForwarding = false }; blogbll.Add(blogtemp); jsdata.Message = "发布成功~"; } } // try { if (blogbll.save(false) > 0) { blogtemp.BlogUrl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.BlogId + ".html"; blogbll.save(); BLL.DataCache.GetAllType(true); #region 添加 或 修改搜索索引 var newtagList = string.Empty; blogtemp.BlogTags.Where(t => true).ToList().ForEach(t => newtagList += t.BlogTagName + " "); var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.BlogId + ".html"; // SearchResult search = new SearchResult() // { // flag = blogtemp.UsersId, // id = blogtemp.Id, // title = blogtemp.BlogTitle, // clickQuantity = 0, // blogTag = newtagList, // content = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.BlogContent), // url = newblogurl // }; // SafetyWriteHelper<SearchResult>.logWrite(search, PanGuLuceneHelper.instance.CreateIndex); // #endregion jsdata.State = EnumState.成功; jsdata.JSurl = "/" + DataCache.GetUsersInfo().Where(t => t.UserId == blogtemp.UserId).First().UserName + "/" + blogtemp.BlogId + ".html"; return(jsdata.ToJson()); } } catch (Exception ex) { jsdata.State = EnumState.失败; jsdata.Message = ex.ToString(); return(jsdata.ToJson()); } jsdata.State = EnumState.失败; return(jsdata.ToJson()); }
/// <summary> /// 新增文章类型 /// </summary> /// <param name="newtypename"></param> /// <param name="userid"></param> /// <returns></returns> public ActionResult NewAddType(string newtypename) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLLSession.UserInfoSessioin) jsdata.Messg = "您还未登录~"; else if (string.IsNullOrEmpty(newtypename)) jsdata.Messg = "类型不能为空~"; if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return Json(jsdata); } #endregion int userid = BLLSession.UserInfoSessioin.Id; BLL.BlogTypesBLL bll = new BlogTypesBLL(); bll.Add( new ModelDB.BlogTypes() { TypeName = newtypename, UsersId = userid, IsDel = false } ); if (bll.save() > 0)//保存 { BLL.Common.CacheData.GetAllType(true);//更新缓存 jsdata.State = EnumState.成功; jsdata.Messg = "新增成功~"; } else { jsdata.State = EnumState.失败; jsdata.Messg = "新增失败~"; } return Json(jsdata); }
/// <summary> /// 编辑文章类型 /// </summary> /// <param name="typename"></param> /// <param name="typeid"></param> /// <returns></returns> public ActionResult EditType(string typename, int typeid) { JSData jsdata = new JSData(); #region 数据验证 if (null == BLLSession.UserInfoSessioin) jsdata.Messg = "您还未登录~"; else if (string.IsNullOrEmpty(typename)) jsdata.Messg = "类型不能为空~"; else if (null == typeid) jsdata.Messg = "未取到文章ID~"; if (!string.IsNullOrEmpty(jsdata.Messg)) { jsdata.State = EnumState.失败; return Json(jsdata); } #endregion BLL.BlogTypesBLL bll = new BlogTypesBLL(); var blogtype = new ModelDB.BlogTypes() { Id = typeid, TypeName = typename }; bll.Up(blogtype, "TypeName"); if (bll.save() > 0)//保存 { BLL.Common.CacheData.GetAllType(true);//更新缓存 jsdata.State = EnumState.成功; // jsdata.Messg = "修改成功~"; } else { jsdata.State = EnumState.失败; jsdata.Messg = "操作失败~"; } return Json(jsdata); }
private int GetTypeId(string typename, string userName) { BlogTypesBLL blogtype = new BlogTypesBLL(); var blogtagmode = blogtype.GetList(t => t.TypeName == typename); if (blogtagmode.Count() >= 1) return blogtagmode.FirstOrDefault().Id; else { blogtype.Add(new ModelDB.BlogTypes() { TypeName = typename, CreateTime = DateTime.Now, IsDel = false, UsersId = GetUserId(userName) }); blogtype.save(); return GetTypeId(typename, userName); } }