I am currently working on a cinema booking system for a school project and have run into a problem.
I have a Movie model which contains a list of show models(date and time for the viewing of the movie). I need to get all the movie objects that are shown on a specific date with a list containing only the Show objects which date is equal to the specific date. I have tried various ways to do it in entity but cant seem to get it to work.
Here is the Movie class:
[DataContract]
public class Movie
{
[Key, Required, DataMember]
public Guid Id { get; set; }
[Required, DataMember]
public string Name { get; set; }
[Required, DataMember]
public string Info { get; set; }
[Required, DataMember]
public DateTime Premiere { get; set; }
[Required, DataMember]
public MovieType Type { get; set; }
[DataMember]
public ICollection<Show> Shows { get; set; }
[DataMember]
public string IMDBID { get; set; }
}
public enum MovieType
{
Movie2D = 0,
Movie3D = 1,
KidsMovie = 2
}
Here is the Show class:
[DataContract]
public class Show
{
[Key, Required, DataMember]
public Guid Id { get; set; }
[Required, DataMember]
public Guid MovieId { get; set; }
[Required, DataMember]
public Guid ScreenId { get; set; }
[Required, DataMember]
public DateTime DateTime { get; set; }
[Required, DataMember]
public ShowType Type { get; set; }
[DataMember]
public Screen Screen { get; set; }
[DataMember]
public Movie Movie { get; set; }
}
public enum ShowType
{
Standard = 0,
Premiere = 1,
}
Here is the GetMovies(DateTime date) method:
public List<Movie> GetMovies(DateTime date)
{
using (EntityContext db = new EntityContext())
{
List<Movie> movieList = db.Movies
.Include("Show")
.Where(x => x.Shows.Where(x => x.DateTime.Date == date.Date)).ToList();
return movieList;
}
}
I know that this function isn't working but hope it would show what I am trying to do.