Beispiel #1
0
        public IHttpActionResult UpdatePlayer(PlayersAPIModels player)
        {
            IDbConnection con = new ApplicationDbContext().Database.Connection;

            string sql = "UPDATE dbo.Players " +
                         $"SET FirstName = '{player.FirstName}', LastName = '{player.LastName}', NickName = '{player.NickName}',City = '{player.City}'," +
                         $"BirthDay = '{player.BirthDay}',IsOnline = '{player.IsOnline}',LastLogin = '******',HourGameScene ='{player.HourGameScene}',IsBanned ='{player.IsBanned}'," +
                         $"BannedHour = '{player.BannedHour}' " +
                         $"WHERE Id = '{player.Id}'";

            try
            {
                con.Execute(sql);
            }
            catch (Exception e)
            {
                return(BadRequest("Error Update player in database, " + e.Message));
            }
            finally
            {
                con.Close();
            }

            return(Ok());
        }
Beispiel #2
0
 public bool InsertNewPlayer(PlayersAPIModels player)
 {
     using (IDbConnection cnn = new ApplicationDbContext().Database.Connection)
     {
         string sql = $"INSERT INTO dbo.Players(Id,FirstName,LastName,NickName,City,BirthDay)" +
                      $"VALUES ('{player.Id}','{player.FirstName}','{player.LastName}','{player.NickName}','{player.City}','{player.BirthDay}')";
         int rows = cnn.Execute(sql);
         if (rows != 1)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }