public int PutUserPet(int id, [FromBody] UserPetsTransferObject UserPetsTransferObject) { int result = -1; try { using (SQLiteConnection connection = new SQLiteConnection(connectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(connection)) { command.CommandText = @"INSERT INTO UserPets(UserId, PetId) SELECT @userId, ID FROM PETS WHERE NAME = @name "; command.Parameters.AddWithValue("@userId", id); command.Parameters.AddWithValue("@name", UserPetsTransferObject.PetName); try { result = command.ExecuteNonQuery(); } catch (Exception) { throw; } } } } catch (Exception) { } return(result); }
public int DeleteUserPet(int id, [FromBody] UserPetsTransferObject UserPetsTransferObject) { int result = -1; try { using (SQLiteConnection connection = new SQLiteConnection(connectionString)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(connection)) { command.CommandText = @" DELETE FROM USERPETS WHERE (userid=@userid and petid=@petid) "; command.Parameters.AddWithValue("@userId", id); command.Parameters.AddWithValue("@petId", UserPetsTransferObject.PetId); try { result = command.ExecuteNonQuery(); } catch (SQLiteException) { throw; } } } } catch (Exception) { } return(result); }