コード例 #1
0
        public override bool IsValid(EValidationStage eValidationStage)
        {
            bool validationResult = true;

            if (Valor <= 0)
            {
                validationResult = false;
                this.ValidationErrors.Add(new Failure("IdContaOrigem", "Valor must be highter than R$ 0,00."));
            }
            if (!Enum.IsDefined(typeof(EOperacao), EOperacao))
            {
                validationResult = false;
                this.ValidationErrors.Add(new Failure("EOperacao", "EOperacao is invalid."));
            }
            if (EOperacao == EOperacao.Deposito)
            {
                if (string.IsNullOrWhiteSpace(IdContaDestino))
                {
                    validationResult = false;
                    this.ValidationErrors.Add(new Failure("IdContaDestino", "IdContaDestino can't be null."));
                }
            }
            if (EOperacao == EOperacao.Saque)
            {
                if (string.IsNullOrWhiteSpace(IdContaOrigem))
                {
                    validationResult = false;
                    this.ValidationErrors.Add(new Failure("IdContaOrigem", "IdContaOrigem can't be null."));
                }
            }
            if (EOperacao == EOperacao.Transferencia)
            {
                if (string.IsNullOrWhiteSpace(IdContaOrigem))
                {
                    validationResult = false;
                    this.ValidationErrors.Add(new Failure("IdContaOrigem", "IdContaOrigem can't be null."));
                }
                if (string.IsNullOrWhiteSpace(IdContaDestino))
                {
                    validationResult = false;
                    this.ValidationErrors.Add(new Failure("IdContaDestino", "IdContaDestino can't be null."));
                }
                if (!string.IsNullOrWhiteSpace(IdContaOrigem) && !string.IsNullOrWhiteSpace(IdContaDestino))
                {
                    if (IdContaOrigem == IdContaDestino)
                    {
                        validationResult = false;
                        this.ValidationErrors.Add(new Failure("IdContaOrigem", "IdContaOrigem can't be the same that IdContaDestino."));
                    }
                }
            }
            return(validationResult);
        }
コード例 #2
0
        public override bool IsValid(EValidationStage eValidationStage)
        {
            bool validationResult = true;

            if (Cliente == null)
            {
                validationResult = false;
                this.ValidationErrors.Add(new Failure("Cliente", "Cliente can't be null."));
            }
            if (string.IsNullOrWhiteSpace(Numero))
            {
                validationResult = false;
                this.ValidationErrors.Add(new Failure("Numero", "Numero can't be null."));
            }
            if (Cliente != null && string.IsNullOrWhiteSpace(Cliente.Nome))
            {
                validationResult = false;
                this.ValidationErrors.Add(new Failure("Cliente.Nome", "Cliente.Nome can't be null."));
            }
            if (Cliente != null && string.IsNullOrWhiteSpace(Cliente.Email))
            {
                validationResult = false;
                this.ValidationErrors.Add(new Failure("Cliente.Email", "Cliente.Email can't be null."));
            }
            if (eValidationStage == EValidationStage.Replace)
            {
                if (string.IsNullOrWhiteSpace(Id))
                {
                    validationResult = false;
                    this.ValidationErrors.Add(new Failure("Id", "Id can't be null."));
                }
            }
            if (!Enum.IsDefined(typeof(EContaTipo), EContaTipo))
            {
                validationResult = false;
                this.ValidationErrors.Add(new Failure("EContaTipo", "EContaTipo is invalid."));
            }

            return(validationResult);
        }
コード例 #3
0
ファイル: Entity.cs プロジェクト: bdiogoandre/FlightSchedule
 public abstract bool IsValid(EValidationStage eValidationStage);
コード例 #4
0
 public override bool IsValid(EValidationStage eValidationStage)
 {
     return(true);
 }
コード例 #5
0
        public override bool IsValid(EValidationStage eValidationStage)
        {
            bool validationResult = true;

            if (eValidationStage == EValidationStage.Insert)
            {
                if (string.IsNullOrWhiteSpace(Nome))
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(Nome), "Cannot be null or empty"));
                    validationResult = false;
                }

                if (DataHoraPartida.CompareTo(DateTime.Now) < 0)
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(DataHoraPartida), "A data e hora de partida não pode ser menor do que a data e hora atual"));
                    validationResult = false;
                }

                if (string.IsNullOrWhiteSpace(Origem))
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(Origem), "Cannot be null or empty"));
                    validationResult = false;
                }

                if (string.IsNullOrWhiteSpace(Destino))
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(Destino), "Cannot be null or empty"));
                    validationResult = false;
                }
            }

            if (eValidationStage == EValidationStage.Update)
            {
                if (string.IsNullOrWhiteSpace(Id))
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(Id), "Cannot be null or empty"));
                    validationResult = false;
                }
                if (string.IsNullOrWhiteSpace(Nome))
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(Nome), "Cannot be null or empty"));
                    validationResult = false;
                }
                if (DataHoraPartida.CompareTo(DateTime.Now) < 0)
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(DataHoraPartida), "A data e hora de partida não pode ser a data e hora atual"));
                    validationResult = false;
                }
                if (string.IsNullOrWhiteSpace(Origem))
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(Origem), "Cannot be null or empty"));
                    validationResult = false;
                }
                if (string.IsNullOrWhiteSpace(Destino))
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(Destino), "Cannot be null or empty"));
                    validationResult = false;
                }
            }

            if (eValidationStage == EValidationStage.Delete)
            {
                if (string.IsNullOrWhiteSpace(Id))
                {
                    Errors.Add(ProblemsDetail.GenerateError(nameof(Id), "Cannot be null"));
                    validationResult = false;
                }
            }

            return(validationResult);
        }