public ActionResult ExchangeCoupon(string couponID) { Coupon c = db.Coupons.Find(couponID); Player p = db.Players.Find(Session["PlayerID"]); //排除不能兌換、已經兌換過的優惠券 if (c.IsExchangable && !p.PlayerCouponDetails.Any(m => m.Coupon.Equals(c))) { //從玩家扣除使用的點數 p.Points -= c.PointsRequired; //產生點數使用明細 UsefulTools.PointRecord(p.ID, "兌換優惠券", -c.PointsRequired); //產生玩家優惠券明細 PlayerCouponDetail couponDetail = new PlayerCouponDetail { CouponID = c.ID, PlayerID = p.ID, ExchangedDate = DateTime.Now, IsUsed = false }; db.PlayerCouponDetails.Add(couponDetail); db.SaveChanges(); return(RedirectToAction("ShopDetailForPlayer", "Shop", new { id = c.ShopID })); //應該要前往店家詳細頁(shopdetailforplayer),同時更動nav的active } //優惠券已無法兌換則顯示錯誤訊息 return(HttpNotFound()); }
// 玩家新增評論 public ActionResult CreateTGComment(string tId, string comment) { if (Session["PlayerID"] != null) { if (ModelState.IsValid && comment.Trim() != "") { var pId = Session["PlayerID"].ToString(); TableGameComment tgc = new TableGameComment(); tgc.PlayerID = pId; tgc.TableGameID = tId; tgc.CommentDate = DateTime.Today; tgc.Content = comment; tgc.IsHidden = false; db.TableGameComments.Add(tgc); UsefulTools.PointRecord((string)Session["PlayerID"], "評論桌遊", 1); Player player = db.Players.Find(pId); player.Points += 1; db.SaveChanges(); } return(RedirectToAction("ShowTableGameDetail", "TableGame", new { tableGameID = tId })); } return(RedirectToAction("LoginForPlayer", "Login")); }