/// <summary> /// Gets the plates by derivative id. /// </summary> /// <param name="derivative">The derivative.</param> /// <param name="section">The section.</param> /// <returns>List of year plates</returns> public List <IYearPlate> GetPlatesByDerivative(ICarDerivative derivative, CarValuationSection section) { int sectionYearFromPlateId = GetFromYearPlateIdForSection(section); int sectionYearToPlateId = GetToYearPlateIdForSection(section); if (derivative.FromYearPlate == null || derivative.ToYearPlate == null) { return(null); } int plateFrom = derivative.FromYearPlate.Id; int plateTo = derivative.ToYearPlate.Id; if (sectionYearFromPlateId > plateFrom) { plateFrom = sectionYearFromPlateId; } if (sectionYearToPlateId < plateTo) { plateTo = sectionYearToPlateId; } return(yearPlateProvider.GetRange(plateFrom, plateTo)); }
/// <summary> /// Gets the plates by model id. /// </summary> /// <param name="modelId">The model id.</param> /// <param name="section">The section.</param> /// <returns>List of year plates</returns> public List <IYearPlate> GetPlatesByModelId(int modelId, CarValuationSection section) { int sectionYearFromPlateId = GetFromYearPlateIdForSection(section); int sectionYearToPlateId = GetToYearPlateIdForSection(section); ICarModel model = CarModel.FromId(modelId); if (model.FromYearPlate == null || model.ToYearPlate == null) { return(null); } int plateFrom = model.FromYearPlate.Id; int plateTo = model.ToYearPlate.Id; if (sectionYearFromPlateId > plateFrom) { plateFrom = sectionYearFromPlateId; } if (sectionYearToPlateId < plateTo) { plateTo = sectionYearToPlateId; } return(yearPlateProvider.GetRange(plateFrom, plateTo)); }
/// <summary> /// Get the "from" year plate ID for a section /// </summary> /// <param name="section">The car valuation section</param> /// <returns>The from year plate id</returns> private static int GetFromYearPlateIdForSection(CarValuationSection section) { int result; switch (section) { case CarValuationSection.Free: result = yearPlateProvider.FromDate(new DateTime(GetFreeValuationCutOffYear(), 1, 1)).Id; break; default: result = yearPlateProvider.FromDate(new DateTime(ValuationsAvailableFromYear, 1, 1)).Id; break; } return(result); }
/// <summary> /// Get the "to" year plate ID for a section /// </summary> /// <param name="section">The car valuation section</param> /// <returns>The from year plate id</returns> private static int GetToYearPlateIdForSection(CarValuationSection section) { int result = 0; switch (section) { case CarValuationSection.Older: case CarValuationSection.ParkersPlus: result = yearPlateProvider.FromDate(new DateTime(GetFreeValuationCutOffYear() - 1, 12, 31)).Id; break; case CarValuationSection.Free: case CarValuationSection.AllYears: result = Int32.MaxValue; break; } return(result); }
/// <summary> /// Determines whether [is year plate available in section] [the specified plate id]. /// </summary> /// <param name="plateId">The plate id.</param> /// <param name="section">The section.</param> /// <returns> /// <c>true</c> if [is year plate available in section] [the specified plate id]; otherwise, <c>false</c>. /// </returns> public bool IsYearPlateAvailableInSection(int plateId, CarValuationSection section) { return(plateId >= GetFromYearPlateIdForSection(section) && plateId <= GetToYearPlateIdForSection(section)); }
/// <summary> /// Populates a valuation object based on the mileage /// </summary> /// <param name="derivId">The derivative id</param> /// <param name="plateId">The plate id</param> /// <param name="mileage">The mileage</param> /// <param name="section">The valuation section</param> /// <param name="valuation">The valuation</param> private static void PopulateMileageAdjustedValuation(int derivId, int plateId, int mileage, CarValuationSection section, Valuation valuation) { if (plateId >= GetFromYearPlateIdForSection(section) && plateId <= GetToYearPlateIdForSection(section)) { Sproc procedure = new Sproc("Used_Select_Valuation", DatabaseName); procedure.Parameters.Add("@CARDerId", SqlDbType.Int).Value = derivId; procedure.Parameters.Add("@YearPlateId", SqlDbType.Int).Value = plateId; if (mileage > 0) { procedure.Parameters.Add("@Mileage", SqlDbType.Int).Value = mileage; } else { procedure.Parameters.Add("@Mileage", SqlDbType.Int).Value = DBNull.Value; } valuation.Result = ValuationResultType.Error; using (SqlDataReader reader = procedure.ExecuteReader()) { if (reader != null && reader.Read()) { PopulateValuationFromDataReader(reader, valuation); if (mileage == 0) { valuation.Result = ValuationResultType.StandardMileage; } else if (mileage == valuation.Mileage) { valuation.Result = ValuationResultType.MileageAdjusted; } else if (mileage > valuation.Mileage) { valuation.Result = ValuationResultType.MaximumMileage; } else if (mileage < valuation.Mileage) { valuation.Result = ValuationResultType.MinimumMileage; } } } } }
/// <summary> /// Gets the option adjusted valuation. /// </summary> /// <param name="derivId">The derivative id.</param> /// <param name="plateId">The plate id.</param> /// <param name="mileage">The mileage.</param> /// <param name="optionCodes">The option codes.</param> /// <param name="section">The section.</param> /// <returns>The valuation (with options)</returns> public IValuationWithOptions GetOptionAdjustedValuation(int derivId, int plateId, int mileage, int[] optionCodes, CarValuationSection section) { ValuationWithOptions valuation = new ValuationWithOptions(); PopulateMileageAdjustedValuation(derivId, plateId, mileage, section, valuation); List <int> optionCodesList = new List <int>(optionCodes); List <IValuationOption> optionsList = this.GetAvailableOptions(derivId, plateId); if (optionsList != null) { foreach (IValuationOption option in optionsList) { if (optionCodesList.Contains(option.OptionCode)) { valuation.Options.Add(option); } } } return(valuation); }
/// <summary> /// Gets the valuation. /// </summary> /// <param name="derivId">The derivative id.</param> /// <param name="plateId">The plate id.</param> /// <param name="section">The section.</param> /// <returns>The valuation</returns> public IValuation GetValuation(int derivId, int plateId, CarValuationSection section) { return(this.GetMileageAdjustedValuation(derivId, plateId, 0, section)); }
/// <summary> /// Gets the mileage adjusted valuation. /// </summary> /// <param name="derivId">The derivative id.</param> /// <param name="plateId">The plate id.</param> /// <param name="mileage">The mileage.</param> /// <param name="section">The section.</param> /// <returns>The valuation</returns> public IValuation GetMileageAdjustedValuation(int derivId, int plateId, int mileage, CarValuationSection section) { Valuation valuation = new Valuation(); PopulateMileageAdjustedValuation(derivId, plateId, mileage, section, valuation); if (valuation.Result == ValuationResultType.Error) { return(null); } else { return(valuation); } }