//添加相册 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)); } }
/// <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)); } }