troubleshooting Question

Building an object from several other objects

Avatar of Eddie Shipman
Eddie ShipmanFlag for United States of America asked on
C#
4 Comments1 Solution140 ViewsLast Modified:
First off, this is not a homework assignment. It is to determine the best object building techniques. I am trying to wrap my head around building the bookSeller object below.
    public class bookSeller
    {
        public List<seller> sellers { get; set; }
    }

    // Resulting data sample:
    {
      "sellers": [
        {
          "sellerId": 6657742342,
          "name": "Tim's Booksellers",
          "books": [
            {
              "bookId": 7283137721,
              "year": 2014,
              "title": "Adventures of Laney"
            }
          ]
        },
        {
          "sellerId": 92081755410,
          "name": "All Old Books",
          "books": [
            {
             "bookId": 6941353265,
              "year": 2017,
              "title": "Signs of the Returning Pleistocene"
            }
          ]
        }
      ]
    }

Open in new window

The data comes from several web service calls. The first one gets a list of bookIds like this:
    public class bookIDs
    {
        public List<int> bookIds { get; set; }
    }

    // Resulting data sample:
    {
      "bookIds": [
        7283137721,
        6941353265
      ]
    }

Open in new window

I am looping through the returned list of bookIds and calling the second to get the information for each book like this:    
    public class bookInfo
    {
        public int bookId { get; set; }
        public int year { get; set; }
        public string title { get; set; }
        public int sellerId { get; set; }
    }

    // Resulting data sample:
    {
      "bookId": 7283137721,
      "year": 2014,
      "title": "Adventures of Laney",
      "sellerId": 1148459751
    }

Open in new window

I also need to get the seller information that returns info like this:
    
    public class sellerInfo
    {
        public int sellerId { get; set; }
        public string name { get; set; }
    }

    // Resulting data sample:
    {
      "sellerId": 6657742342,
      "name": "Tim's Booksellers"
    }

Open in new window

So...
    
    // This function call returns the list of bookIds
    bookIDs bkIds = GetBookIds(authKey); // authKey allows call to webservice function
    // Now we loop over them to get the bookInfo for each book and sellerInfo for each 
    // seller and build the resulting bookSeller object.
    for(int i=0; i< bkIds.bookIds.Count-1; i++)
    {
        book bookInfo = GetBookInfo(bkIds.bookIds[i]);
        // Here is where I need to get the sellerInfo and 
        // add the seller info and the book to the final bookSeller object.
        // Not sure how I should handle it.
        // Function to retrieve the sellerInfo takes the sellerId as parameter
    }

Open in new window

ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004