public string Dianzan() { if (Session["user"] != null) { int id = (int)Session["Fs_id"]; FoodShare fs1 = db.FoodShare.Where(n => n.Fs_id == id).First(); fs1.ReadCount = fs1.ReadCount + 1; string a = (fs1.ReadCount).ToString(); db.SaveChanges(); return(a); } else { return("<script>;alert('请先登录!');</script>"); } }
public ActionResult Menu(FoodShare fs) { try { HttpPostedFileBase postimageBase = Request.Files["img"]; if (Session["user"] != null) { if (postimageBase != null) { string filePath = postimageBase.FileName; string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath(@"/images/Food/") + filename; string relativepath = @"/images/Food/" + filename; postimageBase.SaveAs(serverpath); fs.Fs_img = relativepath; fs.User_id = (int)Session["userid"]; if (fs.Fs_detail != null && fs.Fs_title != null && fs.Fs_lable != null) { db.FoodShare.Add(fs); db.SaveChanges(); return(Content("<script> alert('发布菜谱成功!'); history.go(-1)</script>")); } else { return(Content("发布内容有为空!")); } } else { return(Content("<script>;alert('请先上传菜品图片!');history.go(-1)</script>")); } } else { return(Content("<script> alert('您还没有登录!'); history.go(-1);</script>")); } } catch (Exception ex) { return(Content(ex.Message)); } }
public ActionResult Edit(FoodShare us) { FoodShare user1 = db.FoodShare.Where(n => n.Fs_id == us.Fs_id).First(); user1.Fs_title = us.Fs_title; user1.Fs_lable = us.Fs_lable; user1.Fs_detail = us.Fs_detail; int result = db.SaveChanges(); if (result > 0) { return(RedirectToAction("Index", "User")); } else { return(Content("<script> alert('没有修改');history.go(-1); </script>")); } }
public ActionResult Detail(int id, FoodShare fs) { //var food = db.FoodShare.Where(n => n.Fs_id == id).FirstOrDefault(); //Session["Fs_img"] = food.Fs_img; var list = from n in db.FoodShare.Where(n => n.Fs_id == id) select n; int id1 = Convert.ToInt32(Session["userid"]); Session["Fs_id"] = id; var list2 = from m in db.FoodShareReply join n in db.FoodShareComment on m.FsComment_id equals n.FsComment_id //where m.FsComment_id==id select new UserReplyModel { REPLY = m.FsReply_content, ADDTIME = (m.Addtime).ToString(), USER_IMG = m.UserInfo.User_img, }; var list1 = from n in db.FoodShareComment where n.Fs_id == id select new UserCommentModel { FS_COMMENTID = n.FsComment_id, COMMENT = n.FsComment_content, USER_ID = n.UserInfo.User_id, USER_IMG = n.UserInfo.User_img, USER_NAME = n.UserInfo.User_name, }; int comment_id = Convert.ToInt32(Request["comment_id"]); var index = new WebApplication6.Models.UserCommentDetailModel() { FOODSHARE = list, USERCOMMENT = list1, FOODSHAREREPLY = list2 }; return(View(index)); }
public ActionResult Edit(int id) { FoodShare fs = db.FoodShare.Where(n => n.Fs_id == id).FirstOrDefault(); return(View(fs)); }