Beispiel #1
0
        public void InsertVehicleModel(IVehicleModel model)
        {
            var validationResult = validator.Validate(model);

            if (!validationResult.IsValid)
            {
                logger.LogInformation(validationResult.ToString());
                return;
            }
            logger.LogInformation("vehicle inserted");
        }
Beispiel #2
0
        public int CreateVehicle(Vehicle vehicle)
        {
            var isValid = vehicleValidator.Validate(vehicle);

            if (!isValid)
            {
                throw new Exception("Vehicle data are not valid!");
            }

            var result = this.vehicleRepository.Create(vehicle);

            return(result);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }