//添加相册 public ActionResult photoadd(string title, string back) { try { using (BlognEntities blog = new BlognEntities()) { if (title == "" || back == "") { return(Json(new { date = "请填写完整", type = 0 }, JsonRequestBehavior.AllowGet)); } int count = blog.Phabum.Where(a => a.phtitle == title).ToList().Count(); if (count > 0) { return(Json(new { date = "相册已经存在", type = 0 }, JsonRequestBehavior.AllowGet)); } //创建文件夹 string filePhysicalPath = Server.MapPath("~/images/" + title + "/"); if (!Directory.Exists(filePhysicalPath)) //判断上传文件夹是否存在,若不存在,则创建 { Directory.CreateDirectory(filePhysicalPath); //创建文件夹 } Phabum plu = new Phabum(); plu.phtitle = title; plu.phback = back; plu.phdate = DateTime.Now; blog.Phabum.Add(plu); blog.SaveChanges(); return(Json(new { date = "请填写完整", type = 1 }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { date = "保存出错,原因是:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
public ActionResult esdisde(string idd) { try { using (BlognEntities blog = new BlognEntities()) { if (idd == null || idd == "") { return(Json(new { data = "没有相应的编号", type = 0 }, JsonRequestBehavior.AllowGet)); } else { int id = int.Parse(idd); var ph = blog.Discuss.Where(a => a.diid == id).FirstOrDefault(); blog.Discuss.Remove(ph); blog.SaveChanges(); return(Json(new { data = "已删除", type = 1 }, JsonRequestBehavior.AllowGet)); } } } catch (Exception e) { return(Json(new { data = "删除失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
public ActionResult eayadd(string title, string titcount, bool ko) { try { using (BlognEntities blog = new BlognEntities()) { if (title == "" || titcount == "") { return(Json(new { date = "请填写完整", type = 0 }, JsonRequestBehavior.AllowGet)); } int count = blog.Essay.Where(a => a.estitle == title).ToList().Count(); if (count > 0) { return(Json(new { date = "文章名已经存在", type = 0 }, JsonRequestBehavior.AllowGet)); } Essay es = new Essay(); es.estitle = title; es.esconter = titcount; es.esdate = DateTime.Now; es.eisno = ko; blog.Essay.Add(es); blog.SaveChanges(); return(Json(new { date = "已添加", type = 1 }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { date = "保存出错,原因是:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
public ActionResult eayup(bool ko, string id) { try { using (BlognEntities blog = new BlognEntities()) { if (id == "" || id == null) { return(Json(new { date = "请输入编号", type = 0 }, JsonRequestBehavior.AllowGet)); } int idd = int.Parse(id); int count = blog.Essay.Where(a => a.esid == idd).ToList().Count(); if (count == 0) { return(Json(new { date = "没有此编号的文章哦", type = 0 }, JsonRequestBehavior.AllowGet)); } Essay es = blog.Essay.Where(a => a.esid == idd).FirstOrDefault(); es.eisno = ko; blog.SaveChanges(); return(Json(new { date = "已修改", type = 1, isno = es.eisno }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { date = "保存出错,原因是:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 添加留言 /// </summary> /// <returns></returns> public ActionResult messageadd(string count) { try { if (Session["name"] == null || Session["name"].ToString() == "") { return(Json(new { data = "请先登录", type = 0 }, JsonRequestBehavior.AllowGet)); } using (BlognEntities blog = new BlognEntities()) { var name = Session["name"].ToString(); var user = blog.Usersd.Where(a => a.usname == name).FirstOrDefault(); int uid = user.usid; //评论 Message dis = new Message(); dis.meconter = count; dis.mesdate = DateTime.Now; dis.usid = uid; blog.Message.Add(dis); blog.SaveChanges(); return(Json(new { data = "已评论", type = 1 }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { data = "评论失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
//文章评论点赞 public ActionResult plikead(string idd) { try { if (idd == null || idd == "") { return(Json(new { data = "编号不能为空", type = 0 }, JsonRequestBehavior.AllowGet)); } if (Session["name"] == null || Session["name"].ToString() == "") { return(Json(new { data = "请先登录", type = 0 }, JsonRequestBehavior.AllowGet)); } using (BlognEntities blog = new BlognEntities()) { int id = int.Parse(idd); var name = Session["name"].ToString(); var user = blog.Usersd.Where(a => a.usname == name).FirstOrDefault(); int uid = user.usid; //判断该用户是否点过赞 int i = blog.Pclike.Where(a => a.usid == uid && a.pcid == id).ToList().Count(); if (i > 0) { return(Json(new { data = "您已经点过赞了", type = 0 }, JsonRequestBehavior.AllowGet)); } //评论 Photocuss text = blog.Photocuss.Where(a => a.pcid == id).FirstOrDefault(); if (text == null) { return(Json(new { data = "评论不存在", type = 0 }, JsonRequestBehavior.AllowGet)); } //点赞 var eslike = new Pclike(); eslike.usid = user.usid; eslike.pcid = text.pcid; eslike.plcdate = DateTime.Now; blog.Pclike.Add(eslike); text.pcliang = text.pcliang + 1; blog.SaveChanges(); return(Json(new { data = "谢谢客官", type = 1, liang = text.pcliang }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { data = "点赞失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
//留言删除 public ActionResult mesdelete(string idd) { using (BlognEntities blog = new BlognEntities()) { if (idd == null || idd == "") { return(Json(new { data = "没有编号", type = 0 }, JsonRequestBehavior.AllowGet)); } else { int id = int.Parse(idd); var ph = blog.Message.Where(a => a.meid == id).FirstOrDefault(); blog.Message.Remove(ph); blog.SaveChanges(); return(Json(new { data = "已删除", type = 1 }, JsonRequestBehavior.AllowGet)); } } }
/// <summary> /// 添加相册评论 /// </summary> /// <returns></returns> public ActionResult phcsadd(string idd, string count) { try { if (idd == null || idd == "") { return(Json(new { data = "编号不能为空", type = 0 }, JsonRequestBehavior.AllowGet)); } if (Session["name"] == null || Session["name"].ToString() == "") { return(Json(new { data = "请先登录", type = 0 }, JsonRequestBehavior.AllowGet)); } using (BlognEntities blog = new BlognEntities()) { int id = int.Parse(idd); var name = Session["name"].ToString(); var user = blog.Usersd.Where(a => a.usname == name).FirstOrDefault(); int uid = user.usid; //相册 Phabum text = blog.Phabum.Where(a => a.phid == id).FirstOrDefault(); if (text == null) { return(Json(new { data = "相册不存在", type = 0 }, JsonRequestBehavior.AllowGet)); } //评论 Photocuss dis = new Photocuss(); dis.pccount = count; dis.pcdate = DateTime.Now; dis.phid = id; dis.usid = uid; blog.Photocuss.Add(dis); blog.SaveChanges(); return(Json(new { data = "已评论", type = 1 }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { data = "评论失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 相册点赞 /// </summary> /// <returns></returns> public ActionResult photoimgs(string id) { if (id == "" || id == null) { return(Json(new { data = "没有相应的编号", type = 0 }, JsonRequestBehavior.AllowGet)); } var name = Session["name"]; if (name == null || name.ToString() == "") { return(Json(new { data = "请先登录", type = 0 }, JsonRequestBehavior.AllowGet)); } using (BlognEntities blo = new BlognEntities()) { int idd = int.Parse(id); var pum = blo.Phabum.Where(a => a.phid == idd).FirstOrDefault(); if (pum == null) { return(Json(new { data = "没有相应的编号", type = 0 }, JsonRequestBehavior.AllowGet)); } var user = blo.Usersd.Where(a => a.usname == name.ToString()).FirstOrDefault(); int naid = user.usid; //判断用户是否点赞 int uslike = blo.Phlike.Where(a => a.usid == naid && a.phid == idd).ToList().Count(); if (uslike >= 1) { return(Json(new { data = "您已经点过赞喽", type = 0 }, JsonRequestBehavior.AllowGet)); } //添加相册点赞 Phlike phk = new Phlike(); phk.usid = naid; phk.phid = idd; phk.pldate = DateTime.Now; blo.Phlike.Add(phk); //修改相册点击量 pum.phliang = pum.phliang + 1; blo.SaveChanges(); return(Json(new { data = "点赞成功", type = 1, liang = pum.phliang }, JsonRequestBehavior.AllowGet)); } }
//保存图片 public ActionResult imgadd(HttpPostedFileBase file, string name, string idd) { try { if (file == null || name == null || name == "") { return(Json(new { data = "请填写完整", type = 0 }, JsonRequestBehavior.AllowGet)); } else { using (BlognEntities blog = new BlognEntities()) { int id = int.Parse(idd); var i = blog.Photograph.Where(a => a.otoname == name && a.phid == id).Count(); if (i > 0) { return(Json(new { data = "这个名称已经有了", type = 0 }, JsonRequestBehavior.AllowGet)); } var hu = name + file.FileName.Substring(file.FileName.LastIndexOf(".")); var kl = blog.Phabum.Where(a => a.phid == id).FirstOrDefault(); var j = Server.MapPath("~/images/" + kl.phtitle + "/") + hu; file.SaveAs(j); Photograph pimg = new Photograph(); pimg.otoname = name; pimg.phid = id; pimg.otodate = DateTime.Now; pimg.photos = hu; blog.Photograph.Add(pimg); blog.SaveChanges(); return(Redirect("/Blogback/photoimg?id=" + idd));; } } } catch (Exception e) { return(Json(new { data = "添加失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
//删除图片 public ActionResult imgeremove(string idd) { try { using (BlognEntities blog = new BlognEntities()) { if (idd == null || idd == "") { return(Json(new { data = "没有相应的编号", type = 0 }, JsonRequestBehavior.AllowGet)); } else { int id = int.Parse(idd); var ph = blog.Photograph.Where(a => a.otoid == id).FirstOrDefault(); int idf = ph.phid; var phm = blog.Phabum.Where(a => a.phid == idf).FirstOrDefault(); string path = "~/images/" + phm.phtitle + "/" + ph.photos; string paths = Server.MapPath(path); bool sta = System.IO.File.Exists(paths); if (sta) { System.IO.File.Delete(paths); } else { return(Json(new { data = "删除失败", type = 0 }, JsonRequestBehavior.AllowGet)); } blog.Photograph.Remove(ph); blog.SaveChanges(); return(Json(new { data = "已删除", type = 1 }, JsonRequestBehavior.AllowGet)); } } } catch (Exception e) { return(Json(new { data = "删除失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
//删除相册 public ActionResult phremoe(string id) { try { using (BlognEntities blog = new BlognEntities()) { int idd = int.Parse(id); var photo = blog.Phabum.Where(a => a.phid == idd).FirstOrDefault(); //删除图片 var photoimg = blog.Photograph.Where(a => a.phid == idd).ToList(); if (photoimg.Count() > 0) { foreach (var item in photoimg) {//删除图片 blog.Photograph.Remove(item); string path = "~/images/" + photo.phtitle + "/" + item.photos; string paths = Server.MapPath(path); bool sta = System.IO.File.Exists(paths); if (sta) { System.IO.File.Delete(paths); } } } //删除文件夹 string pathn = Server.MapPath("~/images/" + photo.phtitle); if (Directory.Exists(pathn)) //判断上传文件夹是否存在,若不存在,则创建 { Directory.Delete(pathn); //创建文件夹 } //删除相册点赞 var phlike = blog.Phlike.Where(a => a.phid == idd).ToList(); if (phlike.Count() > 0) { foreach (var item in phlike) { blog.Phlike.Remove(item); } } //删除评论点赞 var phc = blog.Photocuss.Where(a => a.phid == idd).ToList(); if (phc.Count() > 0) { foreach (var item in phc) { int i = item.pcid; var phcs = blog.Pclike.Where(a => a.plcid == i).ToList(); if (phcs.Count() > 0) { foreach (var items in phcs) { blog.Pclike.Remove(items); } } blog.Photocuss.Remove(item); } } blog.Phabum.Remove(photo); blog.SaveChanges(); return(Json(new { data = "已删除", type = 1 }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { return(Json(new { data = "删除失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 修改用户信息 /// </summary> public ActionResult usersd() { var id = Request.Form["id"]; if (id == null || id == "") { return(Json(new { data = "编号不能为空", type = 0 }, JsonRequestBehavior.AllowGet)); } using (BlognEntities blog = new BlognEntities()) { //名字 var name = Request.Form["usname"].ToString(); //密码 var pwd = Request.Form["pwd"].ToString(); //邮箱验证码 var emialyan = Request.Form["emialyan"].ToString(); //邮箱 var emial = Request.Form["emial"].ToString(); //手机号 var phone = Request.Form["usphone"].ToString(); var code = Session["code"].ToString(); if (code.ToLower() != emialyan.ToLower()) { return(Json(new { data = "验证码错误", type = 0 }, JsonRequestBehavior.AllowGet)); } else { var usesr = blog.Usersd.Where(a => a.usemal == emial).FirstOrDefault(); int idd = int.Parse(id); var user = blog.Usersd.Where(a => a.usid == idd).FirstOrDefault(); if (emial != user.usemal) { if (usesr != null) { return(Json(new { data = "此邮箱已经被使用", type = 0 }, JsonRequestBehavior.AllowGet)); } } user.usname = name; user.usphono = phone; user.usemal = emial; user.uspwd = pwd; //图片 HttpPostedFileBase post = Request.Files["file"]; if (post.FileName != "") { //删除当前头像 string path = "~/images/users/" + user.uspic; string paths = Server.MapPath(path); bool sta = System.IO.File.Exists(paths); if (sta) { System.IO.File.Delete(paths); } else { return(Json(new { data = "头像删除失败", type = 0 }, JsonRequestBehavior.AllowGet)); } //保存当前头像 var hu = name + post.FileName.Substring(post.FileName.LastIndexOf(".")); var j = Server.MapPath("~/images/users/") + hu; post.SaveAs(j); user.uspic = hu; } blog.SaveChanges(); Session["name"] = user.usname; Session["img"] = user.uspic; Session["phone"] = user.usphono; return(Json(new { data = "修改成功", type = 1 }, JsonRequestBehavior.AllowGet)); } } }
/// <summary> /// 注册 /// </summary> public ActionResult signin() { try { //名字 var name = Request.Form["usname"].ToString(); //密码 var pwd = Request.Form["pwd"].ToString(); //邮箱验证码 var emialyan = Request.Form["emialyan"].ToString(); //邮箱 var emial = Request.Form["emial"].ToString(); //手机号 var phone = Request.Form["usphone"].ToString(); //图片 HttpPostedFileBase post = Request.Files["file"]; if (post.FileName == "") { return(Json(new { data = "请选择头像", type = 0 }, JsonRequestBehavior.AllowGet)); } var code = Session["code"].ToString(); if (code.ToLower() != emialyan.ToLower()) { return(Json(new { data = "验证码错误", type = 0 }, JsonRequestBehavior.AllowGet)); } else { using (BlognEntities blo = new BlognEntities()) { var uname = blo.Usersd.Where(a => a.usname == name).FirstOrDefault(); if (uname != null) { return(Json(new { data = "名字已存在请重新输入", type = 0 }, JsonRequestBehavior.AllowGet)); } var emal = blo.Usersd.Where(a => a.usemal == emial).FirstOrDefault(); if (emal != null) { return(Json(new { data = "邮箱已存在,建议进行邮箱登录", type = 0 }, JsonRequestBehavior.AllowGet)); } var uphono = blo.Usersd.Where(a => a.usphono == phone).FirstOrDefault(); if (uphono != null) { return(Json(new { data = "手机号已存在,建议进行手机号登录", type = 0 }, JsonRequestBehavior.AllowGet)); } var hu = name + post.FileName.Substring(post.FileName.LastIndexOf(".")); var j = Server.MapPath("~/images/users/") + hu; post.SaveAs(j); Usersd user = new Usersd(); user.usname = name; user.usphono = phone; user.uspic = hu; user.usemal = emial; user.uspwd = pwd; blo.Usersd.Add(user); blo.SaveChanges(); Session["name"] = name; Session["img"] = hu; Session["phone"] = phone; return(Json(new { data = "注册完成", type = 1 }, JsonRequestBehavior.AllowGet)); } } } catch (Exception e) { return(Json(new { data = "注册失败:" + e.Data, type = 0 }, JsonRequestBehavior.AllowGet)); } }