Basic array/ collections question.
Say I want my users to be able to store multiple movie lists with their account. So the user might create and save a "Bob's Comedies" list and a "Bob's Classics" list etc. that he's built from a master list of movies.
So I've got a MoviesList class, of which there will be multiple instances per user, and the movielist class will contain one or more movie class objects.
At some point, the user will want to view his movielist with all his movies and their metadata.
When this is instantiated, how do I associate the movies with the list? Do I have a collection of movies within the movielist class? Or do I have an array of movies within the movielist class? Or does my movielist class contain nothing more than an array of indexes to the movies?
Loading
Sam HobbsPosted Mar 20, 2010, 1:26 PM
Assuming you will use the same genres used by other sites, you could have a table of genres and/or other categories. So you would have at least the following tables:
- Movie
- Category
- User
I think you would need two more tables; one that lists the categories of a movie and another that lists the movies for a user.You could use a SQL database for the data, instead of arrays. The .Net has extensive support of databases and database tables so most of what you would do can be done efficiently using a database and database tables.
Jaish MathewsPosted Mar 20, 2010, 9:08 AM
You need to try with custom collection class. This custom class needs to bind with specific user rofile class. It's something like below.
public class Movie
{
public string MovieName
{
get;
set;
}
public string MovieType
{
get;
set;
}
}
public class MoviesCollection : CollectionBase
{
public IList GetList
{
get
{
return List;
}
}
public void Add(Movie movie)
{
List.Add(movie);
}
}
public class UserProfile
{
public MoviesCollection UserCollectionType
{
get;
set;
}
}
public class Client
{
public void FillMovieList()
{
//User1
Movie user1Movies = null;
UserProfile user1 = new UserProfile();
user1.UserCollectionType = new MoviesCollection();
user1Movies = new Movie();
user1Movies.MovieType = "Comody";
user1Movies.MovieName = "Some Comody";
user1.UserCollectionType.Add( user1Movies);
user1Movies = new Movie();
user1Movies.MovieType = "Horror";
user1Movies.MovieName = "Some Horror";
user1.UserCollectionType.Add(user1Movies);
//User2
Movie user2Movies = null;
UserProfile user2 = new UserProfile();
user2.UserCollectionType = new MoviesCollection();
user2Movies = new Movie();
user2Movies.MovieType = "Family";
user2Movies.MovieName = "Some Family";
user2.UserCollectionType.Add(user2Movies);
user2Movies = new Movie();
user2Movies.MovieType = "War";
user2Movies.MovieName = "Some War";
user2.UserCollectionType.Add(user2Movies);
//User1 seeing his collection
foreach(Movie movie in user1.UserCollectionType.GetList)
{
Console.WriteLine(movie.MovieName);
Console.WriteLine(movie.MovieType);
}
foreach (Movie movie in user2.UserCollectionType.GetList)
{
Console.WriteLine(movie.MovieName);
Console.WriteLine(movie.MovieType);
}
//LIKE THAT EACH USER CAN ADD THEIR OWN
}