public bool UpdatePersonalInfo(EmployeePersonalInfoDTO employee) { if (employeeRepository.HasBeenUpdated(employee)) { employee.AddError(new Error(employee.Errors.Count() + 1, "This employee record has been updated after you retrieved it. Please reload before updated", "Business")); } return(IsValid(employee) ? employeeRepository.UpdatePersonalInfo(employee) : false); }
private bool IsValidEntity(EmployeePersonalInfoDTO employee) { ValidationContext context = new ValidationContext(employee); List <ValidationResult> results = new List <ValidationResult>(); bool isValid = Validator.TryValidateObject(employee, context, results, true); foreach (ValidationResult r in results) { employee.AddError(new Error(employee.Errors.Count + 1, r.ErrorMessage, "Model")); } return(isValid); }