public OverallValidationResult Validate(Email email)
 {
     return(_emailValidator.Validate(email).ApplyResultsTo(_emailValidatables));
 }
        public static ValidationResult ValidateFields <T>(this AbstractValidator <T> validation, T instance, params string[] fields)
        {
            var context = new ValidationContext <T>(instance, new PropertyChain(), new MemberNameValidatorSelector(fields));

            return(validation.Validate(context));
        }
Esempio n. 3
0
        protected bool Validate <T>(AbstractValidator <T> validator) where T : Command <RT>
        {
            var validationResult = validator.Validate((T)this);

            return(validationResult.IsValid);
        }
 protected bool OnValidate <TEntity>(TEntity entity, AbstractValidator <TEntity> validator)
 {
     ValidationResult = validator.Validate(entity);
     return(IsValid);
 }
 public bool Validate <TModel>(TModel model, AbstractValidator <TModel> validator)
 {
     ValidationResult = validator.Validate(model);
     return(Valid = ValidationResult.IsValid);
 }
Esempio n. 6
0
 protected void Validate <TEntity>(TEntity entity, AbstractValidator <TEntity> validator) =>
 ValidationResult = validator.Validate(entity);
Esempio n. 7
0
 public ValidationResult SelfValidate()
 {
     return(isDirty ? TaskValidator.Validate(this) : null);
 }
Esempio n. 8
0
        public void ValidateNow <T>(AbstractValidator <T> validator, T instance)
        {
            var falhaValidacao = validator.Validate(instance);

            setValidation(falhaValidacao);
        }
Esempio n. 9
0
 protected bool Validate <TModel>(TModel model, AbstractValidator <TModel> validator)
 {
     this.ValidationResult = validator.Validate(model);
     return(IsValid = ValidationResult.IsValid);
 }
Esempio n. 10
0
 public ValidationResult Validate()
 {
     return(_validator.Validate(this));
 }
Esempio n. 11
0
        public async Task <CardViewDTO> UpdateContent(CardContentDTO updatedCard, Guid userId)
        {
            var validationResult = _cardContentValidator.Validate(updatedCard);

            if (!validationResult.IsValid)
            {
                throw new Exception(validationResult.ToString());
            }
            else
            {
                Card card = await _cardRepository.GetOne(updatedCard.Id);

                Column column = await _columnRepository.GetOne(card.ColumnId);

                var oldCard = await _cardRepository.GetOne(updatedCard.Id);

                card.UpdatedDate = DateTime.Now;

                if (oldCard.Text == null && updatedCard.Text != null)
                {
                    card.Text = updatedCard.Text;
                    var historyObject = await _historyService.CreateHistoryObject(
                        UserActions.AddedDescription,
                        userId,
                        card.Title,
                        null,
                        null,
                        column.BoardId
                        );
                }
                if (oldCard.Text != null && updatedCard.Text != oldCard.Text)
                {
                    card.Text = updatedCard.Text;
                    var historyObject = await _historyService.CreateHistoryObject(
                        UserActions.EditedDescription,
                        userId,
                        card.Title,
                        null,
                        null,
                        column.BoardId
                        );
                }
                if (oldCard.ExecutionPeriod != updatedCard.ExecutionPeriod)
                {
                    card.ExecutionPeriod = updatedCard.ExecutionPeriod;
                    var historyObject = await _historyService.CreateHistoryObject(
                        UserActions.ChangeExecutionPeriod,
                        userId,
                        card.Title,
                        null,
                        null,
                        column.BoardId
                        );
                }

                var result = await _cardRepository.Update(card);

                var mapperResult = _mapper.Map <Card, CardViewDTO>(result);
                return(mapperResult);
            }
        }
Esempio n. 12
0
 public ValidationResult Validate(TModel instance)
 {
     return(_validator.Validate(instance));
 }
Esempio n. 13
0
 protected void InsertValidation <TViewModel>(TViewModel model, AbstractValidator <TViewModel> validator) where TViewModel : ViewModel
 => ValidationResult = validator.Validate(model);
Esempio n. 14
0
        protected override async Task HandleCore(CreateApprenticeshipUpdateCommand command)
        {
            var validationResult = _validator.Validate(command);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }

            if (await _apprenticeshipUpdateRepository.GetPendingApprenticeshipUpdate(command.ApprenticeshipUpdate.ApprenticeshipId) != null)
            {
                throw new ValidationException("Unable to create an ApprenticeshipUpdate for an Apprenticeship with a pending update");
            }

            var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(command.ApprenticeshipUpdate.ApprenticeshipId);

            var commitment = await _commitmentRepository.GetCommitmentById(apprenticeship.CommitmentId);

            if (!ValidateStartedApprenticeship(apprenticeship, command.ApprenticeshipUpdate))
            {
                throw new ValidationException("Unable to create an update for an apprenticeship that is already started ");
            }

            CheckAuthorisation(command, apprenticeship);

            await Task.WhenAll(
                CheckOverlappingApprenticeships(command, apprenticeship),
                CheckReservation(command.ApprenticeshipUpdate, apprenticeship));

            Apprenticeship       immediateUpdate = null;
            ApprenticeshipUpdate pendingUpdate   = null;

            if (HasImmediateUpdate(command))
            {
                StartHistoryTracking(commitment, apprenticeship, command.Caller.CallerType, command.UserId, command.UserName);
                MapImmediateApprenticeshipUpdate(apprenticeship, command);
                immediateUpdate = apprenticeship;
            }

            if (apprenticeship.StartDate == null)
            {
                throw new InvalidOperationException($"The start date on apprenticeship {apprenticeship.Id} is null when calling {nameof(CreateApprenticeshipUpdateCommand)} command handler");
            }

            if (command.ApprenticeshipUpdate.HasChanges)
            {
                pendingUpdate = command.ApprenticeshipUpdate;
                pendingUpdate.EffectiveFromDate = apprenticeship.StartDate.Value;
                await SendApprenticeshipUpdateCreatedEvent(apprenticeship);
            }

            await Task.WhenAll(
                _apprenticeshipUpdateRepository.CreateApprenticeshipUpdate(pendingUpdate, immediateUpdate),
                SaveHistory(),
                _v2EventsPublisher.PublishApprenticeshipUlnUpdatedEvent(immediateUpdate)
                );

            if (command.ApprenticeshipUpdate.ULN != null)
            {
                _apprenticeshipEventsList.Add(commitment, apprenticeship, "APPRENTICESHIP-UPDATED", _currentDateTime.Now);
                await _apprenticeshipEventsPublisher.Publish(_apprenticeshipEventsList);
            }
        }
Esempio n. 15
0
 protected ValidationResult Validate(T entity, AbstractValidator <T> validator)
 => validator.Validate(entity);
Esempio n. 16
0
 public void Validate <TEntity>(TEntity entity, AbstractValidator <TEntity> validator) where TEntity : Entity
 {
     ValidationResult = validator.Validate(entity);
     Valid            = ValidationResult.IsValid;
 }
Esempio n. 17
0
 public bool Validate <TEntity>(TEntity model, AbstractValidator <TEntity> validator)
 {
     ValidationResult = validator.Validate(model);
     return(IsValid = ValidationResult.IsValid);
 }
Esempio n. 18
0
        private bool ValidateCommand()
        {
            var validationResult = _commandValidator.Validate(_command);

            return(validationResult.IsValid);
        }
 public OverallValidationResult Validate(T login)
 {
     return(ValidationRules.Validate(login).ApplyResultsTo(RefrenceTypeValidatables));
 }
Esempio n. 20
0
 /// <summary>
 /// Performs validation on this exchange visitor and returns the validation result.
 /// </summary>
 /// <returns>The validation result.</returns>
 public ValidationResult Validate(AbstractValidator <ExchangeVisitor> validator)
 {
     Contract.Requires(validator != null, "The validator must not be null.");
     return(validator.Validate(this));
 }
Esempio n. 21
0
        public T Create(T entidad)
        {
            string id = Guid.NewGuid().ToString();

            entidad.Id = id;
            ValidationResult validationResult = validator.Validate(entidad);

            if (validationResult.IsValid)
            {
                string sql1 = $"INSERT INTO {typeof(T).Name} (";
                string sql2 = ") VALUES (";
                string sql3 = ");";

                var  campos = typeof(T).GetProperties();
                T    dato   = (T)Activator.CreateInstance(typeof(T));
                Type tTipo  = typeof(T);
                for (int i = campos.Length - 1; i >= 0; i--)
                {
                    var propiedad = tTipo.GetProperty(campos[i].Name);
                    var valor     = propiedad.GetValue(entidad);
                    if (valor == null)
                    {
                        continue;
                    }
                    sql1 += " " + campos[i].Name;
                    switch (propiedad.PropertyType.Name)
                    {
                    case "String":
                        sql2 += "'" + valor + "'";
                        break;

                    case "DateTime":
                        DateTime dateTime = (DateTime)valor;
                        sql2 += $"'{dateTime.Year}-{dateTime.Month}-{dateTime.Day} {dateTime.Hour}: {dateTime.Minute}: {dateTime.Second}'";
                        break;

                    case "Boolean":
                        sql2 += ((bool)valor) ? "1" : "0";
                        break;

                    default:
                        sql2 += " " + valor;
                        break;
                    }
                    if (i != 0)
                    {
                        sql1 += ", ";
                        sql2 += ", ";
                    }
                }
                if (db.Comando(sql1 + sql2 + sql3) == 1)
                {
                    Error = "";
                    return(SearchById(id));
                }
                else
                {
                    Error = $"Error al construir el sql:{ db.Error}";
                    return(null);
                }
            }
            else
            {
                Error = "Error de validacion:";
                foreach (var item in validationResult.Errors)
                {
                    Error += item.ErrorMessage + ". ";
                }
                return(null);
            }
        }
Esempio n. 22
0
        public EntityValidationResult ValidateUserNotificationPreferences(UserNotificationPreferences preferences)
        {
            var fluentResult = _userNotificationPreferencesValidator.Validate(preferences);

            return(EntityValidationResult.FromFluentValidationResult(fluentResult));
        }
Esempio n. 23
0
 public bool Validate <TValueObject>(TValueObject valueObject, AbstractValidator <TValueObject> validator)
 {
     ValidationResult = validator.Validate(valueObject);
     return(IsValid = ValidationResult.IsValid);
 }
Esempio n. 24
0
        public EntityValidationResult ValidateQualification(Qualification qualification)
        {
            ValidationResult fluentResult = _qualificationValidator.Validate(qualification);

            return(EntityValidationResult.FromFluentValidationResult(fluentResult));
        }
Esempio n. 25
0
 public bool Validate <T> (T entity, AbstractValidator <T> validator)
 {
     ValidationResult = validator.Validate(entity);
     return(Valid = ValidationResult.IsValid);
 }
Esempio n. 26
0
 public bool Validade <T>(T command, AbstractValidator <T> validator)
 {
     ValidationResult = validator.Validate(command);
     return(IsValid = ValidationResult.IsValid);
 }