Hello

I've got this Videorental code.

The flow:
1. Another user wants to rent a video.
2. Hes Videorental creates a new Video object with a Rent object,
which sets he the renter and the other user the owner of the Video.

The User object has Videorental object, it has Video objects and some Video objects have Rent object. There isn't any inheritance going on.

Now I don't know How could I get data from a higher object, in this case the User.
The creation of the Video object takes place in Videorental.
I need to get the info of the owner of this Videorental, specifically the id.

Thanks

You will need a reference to the UserId in your VideoRental class, then when you assign the VideoRental to the User you update the VideoRental object's UserId to match.

Here's how I would do it:

class User
{
  public GUID Id
  {
    get;
    set;
  }
  private VideoRental m_rental;
  public VideoRental VideoRental
  {
    get
    {
      return m_rental;
    }
    set
    {
      m_rental = value;
      m_rental.UserId = Id;
    }
  }
  // ...
}
class VideoRental
{
  public GUID UserId
  {
    get;
    set;
  }
  // ...
}

Thanks, it made me think.
I thought if I made the program scheme, the other way.
Instead of the User having a Videorental object, maybe it would benefit if the Videorental had a User object.
Since the Videorental is in central position in my program, not the user.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.