public void CheckAppointmentBookingPeriod(ValidationResults results)
        {
            const string errorField = "AppointmentBookingPeriodLength";

            ClearValidationError(errorField);

            if (!IsPropertyChanged(() => ProvisioningPeriodUnit) &&
                !IsPropertyChanged(() => ProvisioningPeriodLength) &&
                !IsPropertyChanged(() => AppointmentBookingPeriodUnit) &&
                !IsPropertyChanged(() => AppointmentBookingPeriodLength))
            {
                return;
            }

            var date             = DateTime.Today;
            var provisioningDate = GetCalculatedDate(date, ProvisioningPeriodUnit, ProvisioningPeriodLength);

            provisioningDate = GetCalculatedDate(provisioningDate, ExecutionPeriodUnit, ExecutionPeriodLength);
            var appointmentDate = GetCalculatedDate(date, AppointmentBookingPeriodUnit, AppointmentBookingPeriodLength);

            if (appointmentDate > provisioningDate)
            {
                var validationResult = new ValidationResult(Translations.CapacityCycleConfigurationAppointmentBookingPeriodInvalid,
                                                            this, errorField, null, EntityValidator);

                results.AddResult(validationResult);
                SetValidationError(validationResult);
            }
        }
        public void CheckExecutionLength(ValidationResults results)
        {
            const string errorField = "ExecutionPeriodLength";

            ClearValidationError(errorField);

            if (!IsPropertyChanged(() => ExecutionPeriodUnit) &&
                !IsPropertyChanged(() => ExecutionPeriodLength))
            {
                return;
            }
            if (ValidTo == null)
            {
                return;
            }

            var executionDate = ValidFrom;

            executionDate = GetCalculatedDate(executionDate, ExecutionPeriodUnit, ExecutionPeriodLength);
            if (executionDate > ValidTo)
            {
                var validationResult = new ValidationResult(Translations.CapacityCycleConfigurationExecutionPeriodInvalid,
                                                            this, errorField, null, EntityValidator);

                results.AddResult(validationResult);
                SetValidationError(validationResult);
            }
        }
Exemplo n.º 3
0
        public void CheckLocationInfo(ValidationResults results)
        {
            const string errorFieldLatitude  = "Latitude";
            const string errorFieldLongitude = "Longitude";

            // only the coordinates or the address is obliged - but address
            // is member, when added if should be valid.
            if (Address != null ||
                (Latitude != null && Longitude != null))
            {
                ClearValidationError(errorFieldLatitude);
                ClearValidationError(errorFieldLongitude);
                return;
            }

            if (Latitude == null)
            {
                var validationResult = new ValidationResult(Translations.LocationLatitudeRequired,
                                                            this, errorFieldLatitude, null, EntityValidator);

                results.AddResult(validationResult);
                SetValidationError(validationResult);
            }
            if (Longitude == null)
            {
                var validationResult = new ValidationResult(Translations.LocationLongitudeRequired,
                                                            this, errorFieldLongitude, null, EntityValidator);

                results.AddResult(validationResult);
                SetValidationError(validationResult);
            }
        }
Exemplo n.º 4
0
        public void CheckActiveConfiguration(ValidationResults results)
        {
            if (CapacityCycleConfiguration == null)
            {
                var errorMessage = string.Format(Translations.CapacityCycleNoActiveConfiguration, ExecutionStart.ToString("d"));

                var validationResult = new ValidationResult(errorMessage, this, "ExecutionStart", null, EntityValidator);

                results.AddResult(validationResult);
                SetValidationError(validationResult);
            }
            ClearValidationErrors();
        }
Exemplo n.º 5
0
        public void CheckRemarkText(ValidationResults results)
        {
            const string errorField = "Text";

            ClearValidationError(errorField);

            if (!(this is BookingRemark) &&
                string.IsNullOrEmpty(Text))
            {
                var validationResult = new ValidationResult(Translations.RemarkTextRequired,
                                                            this, errorField, null, EntityValidator);

                results.AddResult(validationResult);
                SetValidationError(validationResult);
            }
        }
Exemplo n.º 6
0
        public void CheckCapacityCycles(ValidationResults results)
        {
            if (ContractModel?.AreOverlappingsAllowed ?? false)
            {
                return;
            }

            if (OtherCapacityCyles == null ||
                !OtherCapacityCyles.Any())
            {
                return;
            }

            bool hasOverlap = false;

            foreach (var capacityCycle in OtherCapacityCyles)
            {
                if (Equals(capacityCycle))
                {
                    continue;
                }
                hasOverlap = (capacityCycle.ExecutionStart <= ExecutionStart &&
                              capacityCycle.ExecutionEnd >= ExecutionStart) ||
                             (capacityCycle.ExecutionStart <= ExecutionEnd &&
                              capacityCycle.ExecutionEnd >= ExecutionEnd);
                if (hasOverlap)
                {
                    break;
                }
            }
            if (hasOverlap)
            {
                var errorMessage     = string.Format(Translations.CapacityCycleExecutionOverlap, ExecutionStart.ToString("d"));
                var validationResult = new ValidationResult(errorMessage, this, "ExecutionStart", null, EntityValidator);

                results.AddResult(validationResult);
                SetValidationError(validationResult);
            }
            ClearValidationErrors();
        }
Exemplo n.º 7
0
        public void CheckConfigurations(ValidationResults results)
        {
            if (AreOverlappingsAllowed)
            {
                return;
            }

            const string errorField   = "CapacityCycleConfigurations";
            string       errorMessage = Translations.ContractModelConfigurationsInvalid;

            var configurations = CapacityCycleConfigurations.OrderBy(c => c.ValidFrom);

            configurations.ForEach(c => c.ClearValidationError(errorField));

            bool overlaps = false;

            foreach (var configuration in configurations)
            {
                var currentPeriod = new TimeRange(configuration.ValidFrom.LocalDateTime,
                                                  configuration.ValidTo.HasValue ? configuration.ValidTo.GetValueOrDefault().LocalDateTime : DateTime.MaxValue);
                overlaps = configurations.Any(c => !c.Equals(configuration) &&
                                              currentPeriod.OverlapsWith(new TimeRange(c.ValidFrom.LocalDateTime,
                                                                                       c.ValidTo.HasValue ? c.ValidTo.GetValueOrDefault().LocalDateTime : DateTime.MaxValue)));
                if (overlaps)
                {
                    break;
                }
            }

            if (overlaps)
            {
                var validationResult = new ValidationResult(errorMessage, this, errorField, null, EntityValidator);

                results.AddResult(validationResult);
                SetValidationError(validationResult);
            }
        }