public CarPriceResponse GetCarPrice(ModelInput input) { var response = new CarPriceResponse { Errors = new List <string>(), Success = false }; if (input.Make == null || input.Model == null) { response.Errors.Add("Please insert a car make and/or model!"); response.Success = false; return(response); } if (input.Odometer > 900000 || input.Odometer < 0) { response.Errors.Add("Please enter a real odometer value"); response.Success = false; return(response); } if (input.Year > DateTime.Today.Year || input.Year < 1962) { response.Errors.Add("Please enter a correct year value"); response.Success = false; return(response); } response.Price = _carPriceRepository.GetCarPrice(input); response.Success = true; response.Errors = null; return(response); }
public AddCarDetailResponse AddCarDetail(AddCarDetailRequest request) { var response = new AddCarDetailResponse { Errors = new List <string>() }; var car = _carRepository.GetById(request.CarId); if (car == null) { response.Errors.Add("Car does not exist"); response.Success = false; return(response); } if (Convert.ToDateTime(request.Itp) > DateTime.Today && Convert.ToDateTime(request.RoadTax) > DateTime.Today) { response.Errors.Add("Dates invalid"); response.Success = false; return(response); } _repository.Add(new CarDetail { CarId = request.CarId, InsuranceValue = request.InsuranceValue, Itp = request.Itp, OilChange = request.OilChange, RoadTax = request.RoadTax, RoadTaxValue = request.RoadTaxValue, TaxValue = request.TaxValue, WinterTires = request.WinterTires, Price = Convert.ToInt32(_carPriceRepository.GetCarPrice(new ModelInput { Make = car.Make, Model = car.Model, Cc = float.Parse(car.Cc), Fuel = car.Fuel, Odometer = float.Parse(car.Odometer), Power = float.Parse(car.Power), Year = float.Parse(car.ModelYear) })) }); response.Success = true; return(response); }