public ActionResult Add(ShoppingCart cart, int?id) { int UserID = Convert.ToInt32(Session["UserID"].ToString()); Goods goods = db.Goods.Find(id); if (goods == null) { return(HttpNotFound()); } var Cart = db.ShoppingCart.Where(o => o.GID == id).Where(o => o.UserID == UserID).FirstOrDefault(); if (Cart != null) { Cart.Count++; } else { cart.Count = 1; cart.GID = id; cart.UserID = Convert.ToInt32(Session["UserID"].ToString()); cart.SCTime = DateTime.Now; db.ShoppingCart.Add(cart); } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DelectComment(int id) { NewsComment newsComment = db.NewsComment.Find(id); int UserID = Convert.ToInt32(Session["UserID"].ToString()); var delc = db.NewsComment.Where(c => c.NCID == id).Where(c => c.UserID == UserID).SingleOrDefault(); db.NewsComment.Remove(newsComment); db.SaveChanges(); return(RedirectToAction("MyComment")); }
public ActionResult Create(News news) { if (Session["MGID"] != null) { HttpPostedFileBase postimageBase = Request.Files["NImage"]; if (ModelState.IsValid) { try { if (ModelState.IsValid) { if (postimageBase != null) { string filePath = postimageBase.FileName; string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath(@"/Images/NImage/") + filename; string relativepath = @"/Images/NImage/" + filename; postimageBase.SaveAs(serverpath); news.NImage = relativepath; } else { return(Content("<script>;alert('请先封面上传图片!');history.go(-1)</script>")); } if (ModelState.IsValid) { news.NTime = System.DateTime.Now; db.News.Add(news); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.NCID = new SelectList(db.NewsComment, "NCID", "NCContent", news.NCID); ViewBag.VID = new SelectList(db.Video, "VID", "VName", news.VID); } } catch (Exception ex) { return(Content(ex.Message)); } } return(View()); } else { return(RedirectToAction("ManagerLogin", "Manager")); } }
public ActionResult Finish(Orders orders, int id) { int UserID = Convert.ToInt32(Session["UserID"].ToString()); Goods goods = db.Goods.Find(id); if (goods == null) { return(HttpNotFound()); } var cart = db.ShoppingCart.Where(o => o.GID == id).Where(o => o.UserID == UserID); if (cart != null) { orders.GID = id; orders.UserID = Convert.ToInt32(Session["UserID"].ToString()); orders.OTime = DateTime.Now; db.Orders.Add(orders); db.SaveChanges(); } else { return(RedirectToAction("Index", "ShoppingCart")); } return(Content("<script>;alert('恭喜您,购买成功!');window.location.href='/Home/Index'</script>")); }
public ActionResult Create([Bind(Include = "GID,GName,GPrice,GPhoto,GColor,GSize,GSaled,GBiaoshi,GDetails,GCID")] Goods goods) { if (Session["MGID"] != null) { HttpPostedFileBase postimageBase = Request.Files["GImage"]; if (ModelState.IsValid) { try { if (ModelState.IsValid) { if (postimageBase != null) { string filePath = postimageBase.FileName; string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath(@"/Images/GImage/") + filename; string relativepath = @"/Images/GImage/" + filename; postimageBase.SaveAs(serverpath); goods.GPhoto = relativepath; } else { return(Content("<script>;alert('请先上传商品图片!');history.go(-1)</script>")); } if (ModelState.IsValid) { db.Goods.Add(goods); db.SaveChanges(); return(RedirectToAction("Index")); } } } catch (Exception ex) { return(Content(ex.Message)); } } return(View()); } else { return(RedirectToAction("ManagerLogin", "Manager")); } }
public ActionResult Edit([Bind(Include = "UserID,UserName,UserPassword,UserTpl,UserSex,UserAvatar,UserEmail,UserAge,UserHeight,UserWeight")] Users users) { if (Session["MGID"] != null) { if (ModelState.IsValid) { db.Entry(users).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(users)); } else { return(RedirectToAction("ManagerLogin", "Manager")); } }
public ActionResult Comment(GoodsComment goodsComment) { string Commenttextarea = Request["Commenttextarea"]; int gid = Convert.ToInt32(Request["gid"]); int UserID = Convert.ToInt32(Session["UserID"].ToString()); Users users = db.Users.Find(UserID); int id = gid; if (ModelState.IsValid) { goodsComment.GID = gid; goodsComment.UserID = Convert.ToInt32(Session["UserID"].ToString()); goodsComment.GCContent = Commenttextarea; goodsComment.GCTime = System.DateTime.Now; db.GoodsComment.Add(goodsComment); db.SaveChanges(); } return(RedirectToAction("GoodsDetails", "Goods", new { id })); }
public ActionResult Comment(PostsComment postsComment) { string Commenttextarea = Request["Commenttextarea"]; int pid = Convert.ToInt32(Request["pid"]); int UserID = Convert.ToInt32(Session["UserID"].ToString()); Users users = db.Users.Find(UserID); int id = pid; if (ModelState.IsValid) { postsComment.PID = pid; postsComment.UserID = Convert.ToInt32(Session["UserID"].ToString()); postsComment.PCContent = Commenttextarea; postsComment.PCTime = System.DateTime.Now; db.PostsComment.Add(postsComment); db.SaveChanges(); } return(RedirectToAction("Details", "Posts", new { id })); }
public ActionResult Comment(NewsComment newsComment) { string Commenttextarea = Request["Commenttextarea"]; int nid = Convert.ToInt32(Request["nid"]); int UserID = Convert.ToInt32(Session["UserID"].ToString()); Users users = db.Users.Find(UserID); int id = nid; if (ModelState.IsValid) { newsComment.NID = nid; newsComment.UserID = Convert.ToInt32(Session["UserID"].ToString()); newsComment.NCContent = Commenttextarea; newsComment.NCTime = System.DateTime.Now; db.NewsComment.Add(newsComment); db.SaveChanges(); } return(RedirectToAction("Details", "News", new { id })); }
public ActionResult Publish(Match match) { if (Session["UserID"] != null) { if (ModelState.IsValid) { match.UserID = Convert.ToInt32(Session["UserID"].ToString()); match.MTime = System.DateTime.Now; db.Match.Add(match); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(match)); } else { return(RedirectToAction("Index", "Login")); } }
public ActionResult Create([Bind(Include = "PID,UserID,PTitle,PTime,PContent,PViewnum,VID,PCID,PCommentnum")] Posts posts) { if (Session["MGID"] != null) { if (ModelState.IsValid) { posts.PTime = System.DateTime.Now; db.Posts.Add(posts); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PCID = new SelectList(db.PostsComment, "PCID", "PCContent", posts.PCID); ViewBag.UserID = new SelectList(db.Users, "UserID", "UserName", posts.UserID); ViewBag.VID = new SelectList(db.Video, "VID", "VName", posts.VID); return(View(posts)); } else { return(RedirectToAction("ManagerLogin", "Manager")); } }
public ActionResult Register(Users user) { HttpPostedFileBase postimageBase = Request.Files["AvatarFile"]; var chk_member = db.Users.Where(o => o.UserName == user.UserName).FirstOrDefault(); if (chk_member != null) { return(Content("<script>;alert('该账号已经有人注册了!');history.go(-1)</script>")); } try { if (postimageBase != null) { string filePath = postimageBase.FileName; string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath(@"/Images/Users/") + filename; string relativepath = @"/Images/Users/" + filename; postimageBase.SaveAs(serverpath); user.UserAvatar = relativepath; } else { return(Content("<script>;alert('请先上传图片!');history.go(-1)</script>")); } if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(Content("<script>;alert('注册成功!跳转登录!');window.location.href='/Login/Index'</script>")); } else { return(Content("<script>;alert('注册失败!');history.go(-1)</script>")); } } catch (Exception ex) { return(Content(ex.Message)); } }
public ActionResult AddVideos(Video video) { if (Session["UserID"] != null) { HttpPostedFileBase postimageBase = Request.Files["Vimage"]; HttpPostedFileBase postvideoBase = Request.Files["VideoFile"]; if (ModelState.IsValid) { try { if (ModelState.IsValid) { if (postimageBase != null) { string filePath = postimageBase.FileName; string filename = filePath.Substring(filePath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath(@"/Images/VSrcimg/") + filename; string relativepath = @"/Images/VSrcimg/" + filename; postimageBase.SaveAs(serverpath); video.VSrcimg = relativepath; } else { return(Content("<script>;alert('请先封面上传图片!');history.go(-1)</script>")); } if (postvideoBase != null) { string filePath = postvideoBase.FileName; string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath(@"/Video/") + fileName; string relativepath = @"/Video/" + fileName; postvideoBase.SaveAs(serverpath); video.VSavepath = relativepath; } else { return(Content("<script>;alert('视频没有上传!');history.go(-1)</script>")); } video.VTime = System.DateTime.Now; db.Video.Add(video); db.SaveChanges(); return(Content("<script>;alert('上传成功!');window.location.href='/VideosManager/Index'</script>")); } else { return(Content("<script>;alert('添加失败!');history.go(-1)</script>")); } } catch (Exception ex) { return(Content(ex.Message)); } } return(View()); } else { return(RedirectToAction("Index", "Login")); } }