Losing value after calling method for use with another

I am trying to figure out why JAAAlbum.ProductID is null when passed to my AddNewProductRelationship_Album_Track method in my loop

http://www.webfound.net/forum_posts/addproduct.txt

Basicaly what's happening is the AddNewProduct is called for the album and JAAlbum product is created then values are saved to the database with the following lines:
JAAlbum.Save(1, TransactionAbstraction.GetTransaction());
TransactionAbstraction.CommitTransaction();

That's all fine and dandy but the problem is when it hits the if statement again, it then goes to add the track:
AddNewProduct(xl, row, host, fileExtWAV, "Track", filePathSourceWAV, fileName, moveFile, sstore);

Problem is line 131. I get an error saying JAAlbum.ProductID is null, so it's like I lost that after the first call to my AddNewProduct for the album the first time around. The JAATrack.ProductID is fine since it still holds its value in the "track" portion of my if statement.

so, how can I persist the last JAAlbum.ProductID to my AddNewProductRelationship_Album_Track once it hits this call



Answer this question

Losing value after calling method for use with another

  • Naveeeen

    What ways can get back that JAAlbum ID inside my AddNewProduct for Track can I somehow return the ProductID after the AddNewProduct for Album How would I do this or what other ways and why isn't it available in the first place after I call AddNewProduct for Track

  • DDarren

    Please post all the information required to answer you question. These forums are for people to reference solutions to problems. If all the information is not included with the post and some of it is ephemeral, people cannot accurately find solutions to problems.

  • Shaantu

    so should I just return somehow the JAAlbum.Product ID here

    I

         switch (ProductType)
         {
              case "Album":

              JAAlbum = ProductAbstraction.Load(prAudioID, sstore, out created, TransactionAbstraction.GetTransaction());

              JAAlbum.ProductSourceID = 1;
              JAAlbum.SellerProductID = prAudioID;                                             // Sellers product id
              JAAlbum.ProductName = productName;                                             // Product Name column
              ...etc. (Just know that JAAlbum.ProductID is included in this and contains the ProductID I need later on)


              if (created)
              {
                   return JAAlbum.ProductID;
              }

    Then (somehow...i need help with) grab it and pass it to my call here: AddNewProduct(xl, row, host, fileExtWAV, "Track", filePathSourceWAV, fileName, moveFile, sstore); 

    if this is a good way to do this, then I need to know syntax how...I need helpo with the simple stuff is what I'm saying here if this is a good way to go



  • Henry_Yang

    Lets explain again.

    Focus on this piece of code first:

    if ((String.Compare(lastAlbumTitle, currentAlbumTitle,true) == 0) || (firstAlbum == 1))
    {
    AddNewProduct(xl, row, host, fileExtWAV, "Album", filePathSourceWAV, fileName, moveFile, sstore); //Album WAV
    }
    else
    {
    AddNewProduct(xl, row, host, fileExtWAV, "Track", filePathSourceWAV, fileName, moveFile, sstore); //Track WAV
    }

    What's happening and where the probelm is:

    1) The loop starts.  Through first iteration of the Loop, this is called:

     AddNewProduct(xl, row, host, fileExtWAV, "Album", filePathSourceWAV, fileName, moveFile, sstore);

    it goes through and creates the JAAAlbum object, populates it with some values, and does it's thing as you can see and finishes

    2) Now we iterate through the loop to the 2nd Excel record, this time, it evaluates to the else in the if statement and runs this:

    AddNewProduct(xl, row, host, fileExtWAV, "Track", filePathSourceWAV, fileName, moveFile, sstore);

    Ok, all I'm saying is that in that in the call to AddNewProduct(xl, row, host, fileExtWAV, "Track", filePathSourceWAV, fileName, moveFile, sstore); the JAAlbum object is lost from #1 and it's values are lost including ProductID .

    So in other words I do not know why JAAProductID object is out of scope or is garbaged...I need it for my second call for the AddNewProduct for Track because I need to pass both the Track's ProductID and Album's ProductID to my AddNewProductRelationship_Album_Track method



  • mr4100

    pardon, but that is enough to solve my problem.  It starts with the l oop and only with that.  Inside the loop, I explained what's going on.  The problem is inside the loop which calls that method.  I  told you what's going on and what to focus on and there is nothing outside this code that's going to relate to any problems inside this loop.



  • CJ Clark

    Look, just view it in simple terms like this for example:

    foreach loop here
    {

    if ((String.Compare(lastAlbumTitle, currentAlbumTitle,true) == 0) || (firstAlbum == 1))
    {
    //This is called first
    AddNewProduct(xl, row, host, fileExtWAV, "Album", filePathSourceWAV, fileName, moveFile, sstore);
    }
    else
    {
    // Then this is called. I need to somehow still be able to get the JAAlbum.ProductID which was populated in
    // the first call above for Album
    AddNewProduct(xl, row, host, fileExtWAV, "Track", filePathSourceWAV, fileName, moveFile, sstore);
    }

    }


    private static void AddNewProduct(ExcelWrapper xl, int row, IWorkerDriver host, string FileExtension, string ProductType, string FilePath, string FileName, bool moveFile, int sstore)
    {
    bunch of code here, then....

    switch (ProductType)
    {
    case "Album":

    JAAlbum = ProductAbstraction.Load(prAudioID, sstore, out created, TransactionAbstraction.GetTransaction());

    JAAlbum.ProductSourceID = 1;
    JAAlbum.SellerProductID = prAudioID; // Sellers product id
    JAAlbum.ProductName = productName; // Product Name column
    ...etc. (Just know that JAAlbum.ProductID is included in this and contains the ProductID I need later on)


    if (created)
    {
    doing some stuff here...
    }

    break;

    case "Track":

    JATrack = ProductAbstraction.Load(prAudioID, sstore, out created, TransactionAbstraction.GetTransaction());

    JATrack.ProductSourceID = 1;
    JATrack.SellerProductID = prAudioID;
    JATrack.ProductName = productName;
    ...etc.

    if (created)
    {
    //HERE IS THE PROBLEM, I've lost JAAlbum.ProductID value from the first call to AddNewProduct for Album
    AddNewProductRelationship_Album_Track(JAAlbum.ProductID, JATrack.ProductID, albumDescription); <---- PROBLEM IS HERE, says that I am passing null value for JAAlbum.ProductID

    }

    break;

    }


  • Losing value after calling method for use with another