Exemplo n.º 1
0
        public VehicleValidationResult Validate(IVehicleModel model)
        {
            if (!(model is BikeModel))
            {
                return(next.Validate(model));
            }

            var result = new VehicleValidationResult();

            if (model.Wheels != 4)
            {
                result.Messages.Add("A bike must have 2 wheels");
            }
            if (model.HasEngine)
            {
                result.Messages.Add("A bike cannot have an engine");
            }
            result.IsValid = !result.Messages.Any();
            return(result);
        }
Exemplo n.º 2
0
        public VehicleValidationResult Validate(IVehicleModel model)
        {
            if (!(model is BoatModel))
            {
                return(next.Validate(model));
            }

            var result = new VehicleValidationResult();

            if (model.Wheels > 0)
            {
                result.Messages.Add("A boat cannot have wheels");
            }
            if (!model.CanFloat)
            {
                result.Messages.Add("A boat must float");
            }
            result.IsValid = !result.Messages.Any();
            return(result);
        }