示例#1
0
        /// <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));
        }
示例#2
0
        /// <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));
        }
示例#3
0
        /// <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);
        }
示例#4
0
        /// <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);
        }
示例#5
0
 /// <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));
 }
示例#6
0
        /// <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;
                        }
                    }
                }
            }
        }
示例#7
0
        /// <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);
        }
示例#8
0
 /// <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));
 }
示例#9
0
        /// <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);
            }
        }