public async Task <double> GetSaleListingScore(int id)
        {
            SaleListingModel saleListing = await _context.Set <SaleListingModel>()
                                           .Where(s => s.Id == id)
                                           .Include(s => s.Vehicle)
                                           .FirstOrDefaultAsync();

            VehicleModel vehicle = await _context.Set <VehicleModel>()
                                   .Where(v => v.Vin == saleListing.Vehicle.Vin)
                                   .Include(v => v.VehicleSpecification)
                                   .Include(v => v.Services)
                                   .Include(v => v.Accidents)
                                   .FirstOrDefaultAsync();

            float averageAskingPriceForModel = _context.Set <SaleListingModel>().Where(s => s.Vehicle.Make == vehicle.Make).Where(s => s.Vehicle.Model == vehicle.Model).Average(s => s.Price);
            int   numberOfServices           = vehicle.Services.Count;
            int   numberOfAccidents          = vehicle.Accidents.Count;

            int numberOfAuthorizedServices = _context.Set <VehicleServiceModel>().Where(s => s.Vehicle.Vin == vehicle.Vin).Where(s => s.ServicedBy.ServiceType == Enums.UserEnums.ServiceType.AUTHORIZED).Count();

            DateTime today = DateTime.Now;

            double priceScore = (-((averageAskingPriceForModel - saleListing.Price) / averageAskingPriceForModel) + 0.5) * 30;

            int yearDifference     = today.Year - vehicle.VehicleSpecification.MakeDate.Year;
            int servicesDifference = numberOfServices - numberOfAuthorizedServices;

            double serviceScore = (numberOfServices / (RECOMMENDED_SERVICE_COUNT_PER_YEAR * (yearDifference > 0 ? yearDifference : 1))) * 40 * (numberOfServices / (servicesDifference > 0 ? servicesDifference : 1));

            double accidentScore = (MAXIMUM_ACCIDENT_COUNT - numberOfAccidents) / MAXIMUM_ACCIDENT_COUNT;

            return(priceScore + serviceScore + accidentScore);
        }
        public async Task DeleteSaleListing(SaleListingModel saleListing)
        {
            SaleListingModel res = await _context.Set <SaleListingModel>().FindAsync(saleListing.Id);

            _context.Set <SaleListingModel>().Remove(res);
            await _context.SaveChangesAsync();
        }
        public async Task <SaleListingModel> CreateSaleListing(SaleListingModel saleListing)
        {
            var res = _context.Set <SaleListingModel>().Add(saleListing);
            await _context.SaveChangesAsync();

            return(res);
        }
        public async Task <SaleListingModel> UpdateSaleListing(SaleListingModel saleListingModel)
        {
            _context.Set <SaleListingModel>().AddOrUpdate(saleListingModel);
            await _context.SaveChangesAsync();

            return(saleListingModel);
        }
 public SaleListingViewModel(
     IEventAggregator eventAggregator,
     SaleListingModel saleListing,
     PersonUserService personUserService,
     VehicleService vehicleService)
 {
     _eventAggregator   = eventAggregator;
     _saleListing       = saleListing;
     _personUserService = personUserService;
     _vehicleService    = vehicleService;
 }
예제 #6
0
 public void SetVehicleSaleListing(SaleListingModel saleListing)
 {
     _vehicle.SaleListing = saleListing;
     NotifyOfPropertyChange(SaleListingActionLabel);
     Refresh();
 }