Ejemplo n.º 1
0
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     if (value != null)
     {
         //create instance of object of type ApplicationDbContext to access database
         DBGroup1Entities db = new DBGroup1Entities();
         //check for the supplied email in database
         var query = db.Projects
                     .Where(p => p.Name.ToLower().Equals(value.ToString().ToLower()) && !p.IsDeleted)
                     .Select(p => new { Name = p.Name }
                             );
         //if query contains results
         if (query != null && query.Count() > 0)
         {
             var errorMessage = FormatErrorMessage(validationContext.DisplayName);
             return(new ValidationResult(errorMessage));
         }
         //if program reach this point, we know that all requirements were met,
         //therefore returning Success
         return(ValidationResult.Success);
     }
     return(base.IsValid(value, validationContext));
 }