public bool Validate(CustomValidationService service) { ValidationErrors = new SerializableDictionary <string, string>(); //if (service != null) //{ // bool valid = service.Validate(this, this.GetType()); // if (!valid) // ValidationErrors = service.ValidationErrors; //} if (string.IsNullOrWhiteSpace(ExternalItemId)) { ValidationErrors.Add(LambdaHelper <VideoItem> .GetPropertyName(x => x.ExternalItemId), "VideoItem.ExternalOrderId is a mandatory field."); } if (Priority == null || Priority < 1) { ValidationErrors.Add(LambdaHelper <VideoItem> .GetPropertyName(x => x.Priority), "VideoItem.Priority is a mandatory field."); } if (ProvisionSequence == null || ProvisionSequence < 1) { ValidationErrors.Add(LambdaHelper <VideoItem> .GetPropertyName(x => x.ProvisionSequence), "VideoItem.ProvisionSequence is a mandatory field and must be greater then 0."); } if (ProvisionDate == null || ProvisionDate == DateTime.MinValue) { ValidationErrors.Add(LambdaHelper <VideoItem> .GetPropertyName(x => x.ProvisionDate), "VideoItem.ProvisionDate is a mandatory field."); } return(ValidationErrors.Count > 0); }
public bool Validate(CustomValidationService service) { ValidationErrors = new SerializableDictionary <string, string>(); if (string.IsNullOrWhiteSpace(ExternalServiceId)) { ValidationErrors.Add(LambdaHelper <Service> .GetPropertyName(x => x.ExternalServiceId), "Service.ExternalServiceId is a mandatory field."); } if (Priority == null || Priority < 1) { ValidationErrors.Add(LambdaHelper <Service> .GetPropertyName(x => x.Priority), "Service.Priority is a mandatory field."); } if (ProvisionSequence == null || ProvisionSequence < 1) { ValidationErrors.Add(LambdaHelper <Service> .GetPropertyName(x => x.ProvisionSequence), "Service.ProvisionSequence is a mandatory field and must be greater then 0."); } if (ProvisionDate == null || ProvisionDate == DateTime.MinValue) { ValidationErrors.Add(LambdaHelper <Service> .GetPropertyName(x => x.ProvisionDate), "Service.ProvisionDate is a mandatory field."); } //Note: Validation the child class as well. if (Locations == null) { ValidationErrors.Add(LambdaHelper <Service> .GetPropertyName(x => x.Locations), "Service.Locations is a mandatory field."); } else { foreach (var location in Locations) { if (location.Validate(service)) { foreach (var validationError in location.ValidationErrors) { if (!ValidationErrors.ContainsKey(validationError.Key)) { ValidationErrors.Add(validationError.Key, validationError.Value); } } } } } return(ValidationErrors.Count > 0); }
public bool Validate(CustomValidationService customValidationService) { ValidationErrors = new SerializableDictionary <string, string>(); if (string.IsNullOrWhiteSpace(ExternalOrderId)) { ValidationErrors.Add(LambdaHelper <Order> .GetPropertyName(x => x.ExternalOrderId), "Order.ExternalOrderId is a mandatory field."); } if (string.IsNullOrWhiteSpace(ExternalAccountId)) { ValidationErrors.Add(LambdaHelper <Order> .GetPropertyName(x => x.ExternalAccountId), "Order.ExternalAccountId is a mandatory field."); } if (String.IsNullOrWhiteSpace(ExternalCompanyId)) { ValidationErrors.Add(LambdaHelper <Order> .GetPropertyName(x => x.ExternalCompanyId), "Order.ExternalCompanyId is a mandatory field."); } else { //ToDo: probably want to call a repo method to make sure that the company exists in the Companies table. Then again the FK in the database will enforce this as well. //Would this be a wastefully database hit? } if (Priority == null || Priority < 1) { ValidationErrors.Add(LambdaHelper <Order> .GetPropertyName(x => x.Priority), "Order.Priority is a mandatory field."); } if (ProvisionDate == null || ProvisionDate == DateTime.MinValue) { ValidationErrors.Add(LambdaHelper <Order> .GetPropertyName(x => x.ProvisionDate), "Order.ProvisionDate is a mandatory field."); } if (Account == null) { ValidationErrors.Add(LambdaHelper <Order> .GetPropertyName(x => x.Account), "Order.Account is a mandatory field."); } else { if (Account.Validate()) { foreach (var validationError in Account.ValidationErrors) { if (!ValidationErrors.ContainsKey(validationError.Key)) { ValidationErrors.Add(validationError.Key, validationError.Value); } } } } if (Services == null) { ValidationErrors.Add(LambdaHelper <Order> .GetPropertyName(x => x.Services), "Order.Services is a mandatory field."); } else { foreach (var service in Services) { if (service.Validate(customValidationService)) { foreach (var validationError in service.ValidationErrors) { if (!ValidationErrors.ContainsKey(validationError.Key)) { ValidationErrors.Add(validationError.Key, validationError.Value); } } } } } return(ValidationErrors.Count > 0); }
public bool Validate(CustomValidationService service) { ValidationErrors = new SerializableDictionary <string, string>(); if ((PhoneItems == null || PhoneItems.Count < 1) && (InternetItems == null || InternetItems.Count < 1) && (VideoItems == null || VideoItems.Count < 1)) { ValidationErrors.Add(LambdaHelper <Location> .GetPropertyName(x => x.PhoneItems), "Location.PhoneItems is a mandatory field."); ValidationErrors.Add(LambdaHelper <Location> .GetPropertyName(x => x.InternetItems), "Location.InternetItems is a mandatory field."); ValidationErrors.Add(LambdaHelper <Location> .GetPropertyName(x => x.VideoItems), "Location.VideoItems is a mandatory field."); } if (PhoneItems != null && PhoneItems.Any()) { foreach (var item in PhoneItems) { if (item.Validate(service)) { foreach (var validationError in item.ValidationErrors) { if (!ValidationErrors.ContainsKey(validationError.Key)) { ValidationErrors.Add(validationError.Key, validationError.Value); } } } } } if (InternetItems != null) { if (InternetItems != null && InternetItems.Any()) { foreach (var item in InternetItems) { if (item.Validate(service)) { foreach (var validationError in item.ValidationErrors) { if (!ValidationErrors.ContainsKey(validationError.Key)) { ValidationErrors.Add(validationError.Key, validationError.Value); } } } } } } if (VideoItems != null) { if (VideoItems != null && VideoItems.Any()) { foreach (var item in VideoItems) { if (item.Validate(service)) { foreach (var validationError in item.ValidationErrors) { if (!ValidationErrors.ContainsKey(validationError.Key)) { ValidationErrors.Add(validationError.Key, validationError.Value); } } } } } } if (Address == null) { ValidationErrors.Add(LambdaHelper <Location> .GetPropertyName(x => x.Address), "Location.Address is a mandatory field."); } else { if (Address.Validate()) { foreach (var validationError in Address.ValidationErrors) { if (!ValidationErrors.ContainsKey(validationError.Key)) { ValidationErrors.Add(validationError.Key, validationError.Value); } } } } return(ValidationErrors.Count > 0); }