コード例 #1
0
 public IActionResult SaveGameRate(UserGameRateModel userRate)
 {
     userRate.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
     if (GameRateManager.SaveGameRate(userRate))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
コード例 #2
0
        public bool SaveGameRate(UserGameRateModel userRate)
        {
            GameRate userRateEntity = DbContext.GamesRates.Where(rate => rate.GameId == userRate.GameId && rate.UserId == userRate.UserId).FirstOrDefault();

            if (userRateEntity != null)
            {
                userRateEntity.Rate = userRate.UserRate;
            }
            else
            {
                DbContext.GamesRates.Add(new GameRate()
                {
                    Game = DbContext.Games.Find(userRate.GameId), User = DbContext.Users.Find(userRate.UserId), Rate = userRate.UserRate
                });
            }
            if (DbContext.SaveChanges() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }