/// <summary> /// 彻底删除文章 /// </summary> /// <returns></returns> public JsonResult RealDelBlogManagerIndex(Write_blog wb) { MonkeyDBEntities db = new MonkeyDBEntities(); db.Entry(wb).State = System.Data.EntityState.Deleted;; //彻底删除博客 //查询该条博客下面的所有评论 List <Blog_Comment> bclist = db.Blog_Comment.Where(a => a.BC_ArticleID == wb.Write_blog_Id).ToList(); //遍历该博客下面的所评论 foreach (var item in bclist) { //删除评论 db.Entry(item).State = System.Data.EntityState.Deleted; } //先关闭验证实体有效性(ValidateOnSaveEnabled)这个开关(默认是开启的) db.Configuration.ValidateOnSaveEnabled = false; int count = db.SaveChanges();//保存到数据库 //在开启验证实体有效性(ValidateOnSaveEnabled)这个开关 db.Configuration.ValidateOnSaveEnabled = true; return(Json(count, JsonRequestBehavior.AllowGet)); }
public void SendMessage(string content, int comment_ID, int comment_user) { MonkeyDBEntities blog = new MonkeyDBEntities(); //向数据库添加信息 string dtime = DateTime.Now.ToString(); string dttime_two = dtime.Substring(dtime.LastIndexOf(" ") + 1); Comment comm_Window_Insert = new Comment() { Comment_Time = Convert.ToDateTime(dttime_two), Comment_Content = content, Parent_Comment_Id = comment_ID, Comment_User = comment_user, ULogin_Id = comment_user }; //添加信息 blog.Entry(comm_Window_Insert).State = System.Data.EntityState.Added; int count = blog.SaveChanges(); //获取头像 string img = blog.Users_Details.Where(a => a.Users_Details_ID == comment_user).Select(a => a.Users_Details_Photo).First(); Clients.Caller.getMessage(dtime, content, img); }
/// <summary> /// 前台发送消息 /// </summary> /// <param name="jsonstr">前台拼接json字符窜</param> /// <returns></returns> public ActionResult Message_ManySend(string jsonstr) { Comment Comm_New = JsonConvert.DeserializeObject <Comment>(jsonstr); //添加回复消息 string savedt = DateTime.Now.ToString().Substring(DateTime.Now.ToString().LastIndexOf(' ') + 1); Comment comm_insert = new Comment() { ULogin_Id = Comm_New.ULogin_Id, Write_blog_Id = Comm_New.Write_blog_Id, Comment_Content = Comm_New.Comment_Content, Comment_Time = Convert.ToDateTime(savedt), Parent_Comment_Id = Comm_New.Comment_Id, Comment_User = Comm_New.ULogin_Id }; _be.Entry(comm_insert).State = System.Data.EntityState.Added; int count = _be.SaveChanges(); return(RedirectToAction("Personal_Message")); }
/// <summary> /// 名称:修改自定义类别 /// 时间:1-18 /// 作者: /// </summary> /// <param name="_ca">修改后的对象</param> /// <returns>修改后受影响的行id</returns> public static int UpdateCategory(Category _ca) { //创建一个数据库上下文对象 MonkeyDBEntities _db = new MonkeyDBEntities(); var _upd = _db.Entry(_ca); //指定数据已更新 _upd.State = System.Data.EntityState.Unchanged; //指定修改的字段 _upd.Property("Category_Reception").IsModified = _ca.Category_Reception != null; _upd.Property("Category_Type").IsModified = !string.IsNullOrEmpty(_ca.Category_Type); return(_db.SaveChanges()); }
/// <summary> /// 名称:修改专栏信息 /// 时间:1-18 /// 作者: /// </summary> /// <param name="_sp">修改的数据</param> /// <returns>操作受影响的行数</returns> public static int UpdateSpecial(Special _sp) { //创建一个数据库上下文对象 MonkeyDBEntities _db = new MonkeyDBEntities(); var _upd = _db.Entry(_sp); //指定数据已更新 _upd.State = System.Data.EntityState.Unchanged; //指定修改的字段 _upd.Property("Special_Name").IsModified = !string.IsNullOrEmpty(_sp.Special_Name); _upd.Property("Special_Introduce").IsModified = !string.IsNullOrEmpty(_sp.Special_Introduce); return(_db.SaveChanges()); }
/// <summary> /// 名称:删除专栏信息 /// 时间:1-18 /// 作者: /// </summary> /// <param name="_spId">要删除的专栏编号</param> /// <returns>新添加的自定义类别自增id</returns> public static int DeleteSpecial(int _spId) { //创建一个数据库上下文对象 MonkeyDBEntities _db = new MonkeyDBEntities(); //编辑要删除的数据 Special _sp = new Special() { Special_Id = _spId }; //指定要删除的自定义类别 _db.Entry(_sp).State = System.Data.EntityState.Deleted; _db.Special.Remove(_sp); return(_db.SaveChanges()); }
/// <summary> /// 删除指定文章(真删,彻底清除文章) /// 时间:1-17 /// </summary> /// <param name="_blogId">文章编号</param> /// <returns></returns> public static int DeleteOneBlog(int _blogId) { MonkeyDBEntities _db = new MonkeyDBEntities(); //创建要删除的实体对象 Write_blog _wb = new Write_blog() { Write_blog_Id = _blogId }; //指定需要删除的数据 _db.Entry(_wb).State = System.Data.EntityState.Deleted; _db.Write_blog.Remove(_wb); //提交数据库并返回结果 return(_db.SaveChanges()); }
/// <summary> /// 删除评论的递归算法 /// </summary> /// <param name="db">数据库上下对象</param> /// <param name="querybc">该条评论所属文章的所有评论</param> /// <param name="bc">该条评论的信息</param> public void del(MonkeyDBEntities db, List <Blog_Comment> querybc, Blog_Comment bc) { //查询该条评论的二级评论 List <Blog_Comment> bclist1 = querybc.Where(a => a.BC_Comment_ParentId == bc.BC_CommentId).ToList(); //设置实体状态 db.Entry(bc).State = System.Data.EntityState.Deleted; //判断该条评论的二级评论条数是否大于等于1 if (bclist1.Count() >= 1) { //遍历该评论的二级评论的集合 foreach (var item in bclist1) { //递归调用 del(db, querybc, item); } } }
/// <summary> /// 名称:删除自定义类别 /// 时间:1-18 /// 作者: /// </summary> /// <param name="_caId">要删除的自定义类别编号</param> /// <returns>删除后受影响的行</returns> public static int DeleteCategory(int _caId) { //创建一个数据库上下文对象 MonkeyDBEntities _db = new MonkeyDBEntities(); //编辑要删除的数据 Category _ca = new Category() { Category_Id = _caId }; //指定要删除的自定义类别 _db.Entry(_ca).State = System.Data.EntityState.Deleted; _db.Category.Remove(_ca); return(_db.SaveChanges()); }
/// <summary> /// 将指定文章收入回收站 /// 时间:1-17 /// </summary> /// <param name="_blogId">文章编号</param> /// <returns></returns> public static int DeleteBlog(int _blogId) { MonkeyDBEntities _db = new MonkeyDBEntities(); //创建要删除的实体对象 Write_blog _wb = new Write_blog() { Write_blog_Id = _blogId, Write_Deletedate = DateTime.Now, Write_IsDel = 0 }; var _upd = _db.Entry(_wb); //指定数据已更新 _upd.State = System.Data.EntityState.Unchanged; //指定修改的字段 _upd.Property("Write_Deletedate").IsModified = true; _upd.Property("Write_IsDel").IsModified = true; //提交数据,并返回结果 return(_db.SaveChanges()); }
public JsonResult UpdateWriteBlog(bool Category_Type_way) { MonkeyDBEntities db = new MonkeyDBEntities(); try { //接收JSON串 string jsonstr = Request["json"]; //反序列化JSON串 Write_blog wb = JsonConvert.DeserializeObject <Write_blog>(jsonstr); //赋值 wb.Category_Id = Request["Category_Idstr"]; //接收自定义分类的字符串 wb.Write_Content = Request["Write_Content"]; //文章内容 wb.Write_Private = Convert.ToInt32(Request["Write_Private"]); wb.Write_IsDel = Convert.ToInt32(Request["Write_IsDel"]); wb.Write_State = 0; //审核状态 wb.Write_Createdate = DateTime.Now; //创建时间 if (wb.Write_IsDel == 1) { wb.Write_State = null; } //判断是否添加新的个人分类 if (Category_Type_way == true) { //反序列化字符串 Category ca = JsonConvert.DeserializeObject <Category>(jsonstr); //实力例集合 List <Category> calist = new List <Category>(); //分割字符串 string[] Category_Typelist = ca.Category_Type.Split(','); //查询所有自定义个人分类 List <Category> calist2 = db.Category.AsNoTracking().Where(a => a.ULogin_Id == 1).ToList(); //循环分割后的分类数组 for (int i = 0; i < Category_Typelist.Length; i++) { //根据类名查询是否有相同的自定义个人分类 Category ca2 = calist2.Where(a => a.Category_Type == Category_Typelist[i]).FirstOrDefault(); //判断该分类是否已经存在 if (ca2 != null) { return(Json("类名为'" + ca.Category_Type + "'的个人分类已经存在,重新添加或选择个人分类", JsonRequestBehavior.AllowGet)); } ca = new Category(); ca.ULogin_Id = 1; //用户编号 ca.Category_Reception = 0; //是否显示在前台0显示,1不显示 ca.Category_Type = Category_Typelist[i]; //添加对象到对象的集合 calist.Add(ca); } //便利集合 foreach (var item in calist) { db.Category.Add(item); //添加到上下文中 int row = db.SaveChanges(); //保存到数据库 if (row <= 0) { return(Json("添加新的个人分类有错", JsonRequestBehavior.AllowGet)); } if (wb.Category_Id == "" || wb.Category_Id == null) { wb.Category_Id += "" + item.Category_Id; } else { wb.Category_Id += "," + item.Category_Id;//得到新的个人分类字符串 } } } //获取给定实体 var update = db.Entry(wb); //设置给定实体的状态 update.State = System.Data.EntityState.Unchanged; //指定要修改的字段 update.Property("Write_Title").IsModified = true; update.Property("Write_ArticleType").IsModified = true; update.Property("Write_Content").IsModified = true; update.Property("Backstage_Category_Id").IsModified = true; update.Property("Write_Label").IsModified = true; update.Property("Category_Id").IsModified = true; update.Property("Write_Title").IsModified = true; update.Property("Write_Private").IsModified = true; update.Property("Write_Createdate").IsModified = true; update.Property("Write_State").IsModified = true; update.Property("Write_IsDel").IsModified = true; } catch (Exception ex) { string str = ex.Message; } //保存到数据库 int count = db.SaveChanges(); if (count <= 0) { return(Json("修改失败", JsonRequestBehavior.AllowGet)); } return(Json(count, JsonRequestBehavior.AllowGet)); }