public ActionResult AddWishlist(tWishlist wishlist) { //TempData["insertMessage"] = ""; tWishlist w = new tWishlist(); int MemberID = Convert.ToInt32(Request.Cookies["account"].Value); w.fMemberID = MemberID; w.fGameID = wishlist.fGameID; if (wishlist.fWantToPlay == true) { w.fWantToPlay = true; } if (wishlist.fWantToBuy == true) { w.fWantToBuy = true; } if (wishlist.fWantToSale == true) { w.fWantToSale = true; } if (wishlist.fOwn == true) { w.fOwn = true; } var q = db.tWishlist.Where(c => c.fMemberID == MemberID && c.fGameID == wishlist.fGameID).FirstOrDefault(); if (q == null) { db.tWishlist.Add(w); db.SaveChanges(); } else { tWishlist _wishlist = db.tWishlist.Find(q.fWishlistID); if (w.fWantToPlay == true) { _wishlist.fWantToPlay = true; } if (w.fWantToBuy == true) { _wishlist.fWantToBuy = true; } if (w.fWantToSale == true) { _wishlist.fWantToSale = true; } if (w.fOwn == true) { _wishlist.fOwn = true; } db.Entry(_wishlist).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } TempData["gamename"] = db.tGame.Select(c => c.fGameName_TC).ToList(); //TempData["insertMessage"] = "已存在"; return(RedirectToAction("LoginAfter", "Home", new { area = "Member" })); }
public ActionResult UpdateWishlist() { int MemberID = Convert.ToInt32(Request.Cookies["account"].Value); int gameid = Convert.ToInt32(Request.QueryString["gameid"]); string want = Request.QueryString["want"]; var q = db.tWishlist.ToList().Where(c => c.fMemberID == MemberID && c.fGameID == gameid).FirstOrDefault(); tWishlist _wishlist = db.tWishlist.Find(q.fWishlistID); if (want == "play") { _wishlist.fWantToPlay = false; db.Entry(_wishlist).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } if (want == "buy") { _wishlist.fWantToBuy = false; db.Entry(_wishlist).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } if (want == "sale") { _wishlist.fWantToSale = false; db.Entry(_wishlist).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } if (want == "own") { _wishlist.fOwn = false; db.Entry(_wishlist).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } TempData["gamename"] = db.tGame.Select(c => c.fGameName_TC).ToList(); return(RedirectToAction("LoginAfter", "Home", new { area = "Member" })); }