示例#1
0
        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);
        }
示例#2
0
        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);
        }