Esempio n. 1
0
        //Checks if a user with that username exists and if not it writes the new user to the DB and creates a new playlist
        public HttpResponseMessage Post(UserApiModel user)
        {
            var queryData = this.databaseConnection.GetData($"SELECT * FROM user WHERE benutzername = '" + user.userName + "'");

            this.databaseConnection.CloseConnection();

            if (queryData.Count > 0)
            {
                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError));
            }

            try
            {
                var encryptedPassword = Crypting.EncryptPassword(user.password);

                this.databaseConnection.QueryInsert($"INSERT INTO user (`benutzername`, `vorname`, `nachname`, `passwort`) VALUES (\'{user.userName}\', \'{user.firstName}\' , \'{user.lastName}\', \'{encryptedPassword}\')");

                var queryUserId = this.databaseConnection.GetData($"SELECT iduser FROM user WHERE benutzername = '" + user.userName + "'");

                var userId = queryUserId[0].GetValue(0);

                this.databaseConnection.QueryInsert($"INSERT INTO playlist (`User_idUser`) VALUES (\'{userId}\')");
            }
            catch (Exception e)
            {
                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError));
            }

            return(this.Request.CreateResponse(HttpStatusCode.OK));
        }