public IEnumerable<RuleViolation> GetRuleViolations() { if (String.IsNullOrEmpty(title)) yield return new RuleViolation("Movie title is a required field.", "title"); if (year == null) yield return new RuleViolation("Movie year is a required field.", "year"); if (year < 1910 || year > DateTime.Now.Year + 2) yield return new RuleViolation("Movie year must be between 1910 and " + (DateTime.Now.Year + 2).ToString() + ".", "year"); if (length <= 0 || length >= int.MaxValue) yield return new RuleViolation("Movie length must be greater than 0 minutes.", "length"); using (MovieDBDataContext db = new MovieDBDataContext()) { var existingMovies = db.Movies.Where(m => m.title.Equals(title)); if (existingMovies.Count() > 0 && existingMovies.First<Movie>().movie_id != this.movie_id) yield return new RuleViolation("Movie with title '" + title + "' already exists.", "title"); } //TODO: add more violations, director, genre, rating, etc yield break; }
public IEnumerable<RuleViolation> GetRuleViolations() { if (String.IsNullOrEmpty(fname)) yield return new RuleViolation("First name is a required field.", "fname"); if (String.IsNullOrEmpty(lname)) yield return new RuleViolation("Last name is a required field.", "lname"); using (MovieDBDataContext db = new MovieDBDataContext()) { if (db.Directors.Where(d => d.fname == fname && d.lname == lname).Count() > 0) yield return new RuleViolation("Director '" + FullName + "' already exists.", "FullName"); } yield break; }
public IEnumerable <RuleViolation> GetRuleViolations() { if (String.IsNullOrEmpty(fname)) { yield return(new RuleViolation("First name is a required field.", "fname")); } if (String.IsNullOrEmpty(lname)) { yield return(new RuleViolation("Last name is a required field.", "lname")); } using (MovieDBDataContext db = new MovieDBDataContext()) { if (db.Directors.Where(d => d.fname == fname && d.lname == lname).Count() > 0) { yield return(new RuleViolation("Director '" + FullName + "' already exists.", "FullName")); } } yield break; }
public IEnumerable <RuleViolation> GetRuleViolations() { if (String.IsNullOrEmpty(title)) { yield return(new RuleViolation("Movie title is a required field.", "title")); } if (year == null) { yield return(new RuleViolation("Movie year is a required field.", "year")); } if (year < 1910 || year > DateTime.Now.Year + 2) { yield return(new RuleViolation("Movie year must be between 1910 and " + (DateTime.Now.Year + 2).ToString() + ".", "year")); } if (length <= 0 || length >= int.MaxValue) { yield return(new RuleViolation("Movie length must be greater than 0 minutes.", "length")); } using (MovieDBDataContext db = new MovieDBDataContext()) { var existingMovies = db.Movies.Where(m => m.title.Equals(title)); if (existingMovies.Count() > 0 && existingMovies.First <Movie>().movie_id != this.movie_id) { yield return(new RuleViolation("Movie with title '" + title + "' already exists.", "title")); } } //TODO: add more violations, director, genre, rating, etc yield break; }