public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { IValidationResultHelper <SubjectModel> helper = new ValidationResultHelper <SubjectModel>(this); helper.Validate(model => model.Code).Required(true).ErrorMsg("Code field is required"); helper.Validate(model => model.Level).Required(true).GreaterThan(0).ErrorMsg("Year level field is required"); helper.Validate(model => model.Units).Required(true).GreaterThan(0).ErrorMsg("Units field is required"); helper.Validate(model => model.Status).Required(true).GreaterThan(0).ErrorMsg("Status field is required"); if (!helper.Failed) { Transaction.Scope(scope => scope.Service <SubjectValidatorService>(service => { helper.Validate(model => model.Code).Required(true).IF(service.CheckSubjectCodeExists(Id, Code)).ErrorMsg(string.Format("Subject \"{0}\" is already exists!", Code)); })); } if (helper.Failed) { foreach (var error in helper.Errors) { yield return(error); } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { IValidationResultHelper <InstructorModel> helper = new ValidationResultHelper <InstructorModel>(this); helper.Validate(model => model.FirstName).Required(true).NotEmpty().ErrorMsg("First Name field is required"); helper.Validate(model => model.LastName).Required(true).NotEmpty().ErrorMsg("Last Name field is required"); helper.Validate(model => model.BirthDate).Required(true).LessThan(DateTime.Now).ErrorMsg("Invalid date of birth"); helper.Validate(model => model.Gender).Required(true).GreaterThan(0).ErrorMsg("Gender field is required"); helper.Validate(model => model.Status).Required(true).GreaterThan(0).ErrorMsg("Status field is required"); helper.Validate(model => model.Email).Required(false).EmailAddress().ErrorMsg("Invalid email address"); helper.IF(string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Telephone) && string.IsNullOrEmpty(Mobile)).ErrorMsg("Please fill atleast one of the contact information"); if (!helper.Failed) { Transaction.Scope(scope => scope.Service <ValidatorService>(service => { helper.Validate(model => model.FirstName).Required(true).IF(service.CheckPersonExists(Id, FirstName, LastName, BirthDate)) .ErrorMsg(string.Format("Person with name \"{0} {1}\" and birth date \"{2}\" is already exists!", FirstName, LastName, ((DateTime)BirthDate).ToShortDateString())); helper.Validate(model => model.Email).Required(false).IF(service.CheckEmailExists(ContactInfoId, Email)) .ErrorMsg(string.Format("Email address \"{0}\" is already exists!", Email)); })); } if (helper.Failed) { foreach (var error in helper.Errors) { yield return(error); } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (DayId != 0) { Days[0] = DayId; } IValidationResultHelper <ClassScheduleModel> helper = new ValidationResultHelper <ClassScheduleModel>(this); helper.Validate(model => model.TimeStart).Required(true).ErrorMsg("Time Start field is required"); helper.Validate(model => model.TimeEnd).Required(true).ErrorMsg("Time End field is required") .IF(TimeStart >= TimeEnd).ErrorMsg("Time End field must be greater than Time Start"); helper.Validate(model => model.DayId).Required(true).IF(Days == null || Days.Length <= 0 || (Days.Length == 1 && Days[0] == null)).ErrorMsg("Status field is required"); helper.Validate(model => model.RoomId).Required(true).GreaterThan(0).ErrorMsg("Room field is required"); helper.Validate(model => model.SectionId).Required(true).GreaterThan(0).ErrorMsg("Section field is required"); helper.Validate(model => model.SubjectId).Required(true).GreaterThan(0).ErrorMsg("Subject field is required"); helper.Validate(model => model.InstructorId).Required(true).GreaterThan(0).ErrorMsg("Instructor field is required"); helper.Validate(model => model.Capacity).Required(true).GreaterThan(0).ErrorMsg("Capacity field is required and must be greater than to 0(Zero)"); if (!helper.Failed) { Transaction.Scope(scope => { foreach (DayOfWeek day in Days) { helper.Validate(model => model.RoomId).IF(!scope.Service <RoomValidatorService, bool>(service => service.CheckRoomAvailavility( Id, RoomId, (DateTime)TimeStart, (DateTime)TimeEnd, day))) .ErrorMsg(string.Format("Room is not available, between {0} to {1}", ((DateTime)TimeStart).ToShortTimeString(), ((DateTime)TimeEnd).ToShortTimeString()) ); helper.Validate(model => model.SectionId).IF(!scope.Service <SectionValidatorService, bool>(service => service.CheckSectionAvailability( Id, SectionId, (DateTime)TimeStart, (DateTime)TimeEnd, day))) .ErrorMsg(string.Format("Section is not available, between {0} to {1}", ((DateTime)TimeStart).ToShortTimeString(), ((DateTime)TimeEnd).ToShortTimeString()) ); helper.Validate(model => model.InstructorId).IF(!scope.Service <InstructorValidatorService, bool>(service => service.CheckInstructorAvailability( Id, InstructorId, (DateTime)TimeStart, (DateTime)TimeEnd, day))) .ErrorMsg(string.Format("Instructor is not available, between {0} to {1}", ((DateTime)TimeStart).ToShortTimeString(), ((DateTime)TimeEnd).ToShortTimeString()) ); if (helper.Failed) { break; } } }); } if (helper.Failed) { foreach (var error in helper.Errors) { yield return(error); } } }