I am building a library using mvc, mongodb and asp.net membership.
When a user browses the site logged in (logged out is auto set to preview) I need to check if they have purchased the current movie and if they have they can see the full set of features otherwise they have to purchase the video or watch the preview.
I have a Movie model below:
public Guid Id { get; set; }
public string Slug { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public double Price { get; set; }
public string PreviewUrl { get; set; }
public string MovieUrl { get; set; }
public DateTime CreatedOn { get; set; }
public string CreatedBy { get; set; }
public DateTime ModifiedOn { get; set; }
public IEnumerable<User> Users;
public Movie() {
Id = Guid.NewGuid();
CreatedOn = DateTime.Now;
ModifiedOn = DateTime.Now;
}
Maybe there is a better method to approach this. Maybe an order or something?
I’m going to suggest a very basic solution. Assuming that you keep track of purchases somewhere in the DB (be it MongoDB or not) you could write a routine that queries the purchases by the id of the user and the id of the movie. So essentially you always keep track of who has purchased what thus giving yourself the ability to know if a person has purchased a movie using on simple query like I’ve illustrated bellow:
Purchases table:
Query
Should return