コード例 #1
0
        public async Task <IActionResult> GetAllDealersAsync(string name)
        {
            var result = await _source.GetAllAsync();

            if (!string.IsNullOrEmpty(name))
            {
                return(View(result
                            .Where(x => x.Name.Contains(name, StringComparison.InvariantCultureIgnoreCase))
                            .ToList()));
            }
            else
            {
                return(View(result));
            }
        }
コード例 #2
0
        public async Task Add([FromServices] ICommonActions <Dealer> dealerSource, [FromBody] CarInfoViewModel model)
        {
            if (model == null)
            {
                return;
            }

            var dealerList = await dealerSource.GetAllAsync();

            var dealer = dealerList
                         .Where(x => x.Id == model.DealerId)
                         .FirstOrDefault();

            if (dealer == null)
            {
                return;
            }

            Car car = new Car()
            {
                Id            = model.Id,
                CarState      = model.CarState.Equals("new", StringComparison.InvariantCultureIgnoreCase) ? CarState.New : CarState.IsStock,
                ColorExterior = model.ColorExterior,
                ColorInterior = model.ColorInterior,
                Dealer        = dealer,
                Name          = model.Name,
                Price         = model.Price,
                VinCode       = model.VinCode,
                CarStatus     = CarStatus.Active,
                NativeId      = "None"
            };
            await _carinfo.AddAsync(car);
        }
コード例 #3
0
        public async Task AddAsync([FromServices] ICommonActions <Country> countrySource, [FromBody] DealerInfoViewModel model)
        {
            if (model == null)
            {
                return;
            }

            var countryList = await countrySource.GetAllAsync();

            var country = countryList
                          .Where(x => x.Name.Equals(model.CountryName, StringComparison.InvariantCultureIgnoreCase))
                          .FirstOrDefault();

            if (country == null)
            {
                return;
            }

            Dealer dealer = new Dealer()
            {
                Id           = model.Id,
                Name         = model.Name,
                ContactPhone = model.ContactPhone,
                Status       = model.Status.Equals("Active", StringComparison.InvariantCultureIgnoreCase) ? DealerStatus.Active : DealerStatus.Unknown,
                Street       = model.Street,
                City         = model.City,
                CountryState = model.CountryState,
                Country      = country,
                WebSite      = model.WebSite,
                Zip          = model.Zip
            };
            await _dealerInfo.AddAsync(dealer);
        }
コード例 #4
0
        public async Task <IActionResult> GetDealersByCountryAsync(string name, [FromHeader] int rowCounter = 10)
        {
            var dealerList = await _dealerInfo.GetAllAsync();

            var infolist = new List <DealerInfoViewModel>();

            if (!string.IsNullOrEmpty(name))
            {
                infolist.AddRange(dealerList
                                  .Where(x => x.Country.Name.Contains(name, StringComparison.InvariantCultureIgnoreCase))
                                  .Take(rowCounter)
                                  .Select(x => new DealerInfoViewModel()
                {
                    Id           = x.Id,
                    Name         = x.Name,
                    ContactPhone = x.ContactPhone,
                    Status       = x.Status.ToString(),
                    Street       = x.Street,
                    City         = x.City,
                    CountryState = x.CountryState,
                    CountryName  = x.Country.Name,
                    WebSite      = x.WebSite,
                    Zip          = x.Zip
                }));
            }
            else
            {
                infolist.AddRange(dealerList
                                  .Take(rowCounter)
                                  .Select(x => new DealerInfoViewModel()
                {
                    Id           = x.Id,
                    Name         = x.Name,
                    ContactPhone = x.ContactPhone,
                    Status       = x.Status.ToString(),
                    Street       = x.Street,
                    City         = x.City,
                    CountryState = x.CountryState,
                    CountryName  = x.Country.Name,
                    WebSite      = x.WebSite,
                    Zip          = x.Zip
                }));
            }
            var result = JsonConvert.SerializeObject(infolist);

            return(new ObjectResult(result));
        }
コード例 #5
0
        public async Task <IActionResult> GetHistoryByVinAsync([FromQuery] string vin)
        {
            var vinList = await _source.GetAllAsync();

            var result = vinList
                         .Where(x => x.Car.VinCode.Equals(vin, System.StringComparison.OrdinalIgnoreCase))
                         .ToList();

            return(View(result));
        }
コード例 #6
0
        public async Task <IActionResult> IndexAsync()
        {
            var cars = await _carSource.GetAllAsync();

            var result = cars
                         .OrderByDescending(x => x.DateUpdateInfo)
                         .Take(20)
                         .ToList();

            return(View(result));
        }
コード例 #7
0
        public async Task <IActionResult> GetCarInfoAsync(string name, [FromHeader] int rowCounter = 10)
        {
            var carList = await _carinfo.GetAllAsync();

            var infolist = carList
                           .Where(x => x.Name.Contains(name, StringComparison.InvariantCultureIgnoreCase))
                           .Take(rowCounter)
                           .Select(x => new CarInfoViewModel()
            {
                Id            = x.Id,
                CarState      = x.CarState.ToString(),
                ColorExterior = x.ColorExterior,
                ColorInterior = x.ColorInterior,
                DealerId      = x.DealerId,
                DealerName    = x.Dealer.Name,
                Name          = x.Name,
                Price         = x.Price,
                VinCode       = x.VinCode
            }).ToList();
            var result = JsonConvert.SerializeObject(infolist);

            return(new ObjectResult(result));
        }
コード例 #8
0
        public async Task DoWorkAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                //Default countries
                var result = await _dbCountry.GetAllAsync();

                if (!result.Any())
                {
                    var countriesInfo = await _client.GetCountryInfoByRegion(CountryRegions.Europe);

                    var countries = countriesInfo
                                    .Where(x => !string.IsNullOrEmpty(x.Code) && string.IsNullOrEmpty(x.Name))
                                    .Select(x => new Country()
                    {
                        Code = x.Code,
                        Name = x.Name
                    }).ToList();
                    countriesInfo = await _client.GetCountryInfoByRegion(CountryRegions.Americas);

                    countries.AddRange(countriesInfo
                                       .Select(x => new Country()
                    {
                        Code = x.Code,
                        Name = x.Name
                    }));

                    await _dbCountry.AddRangeAsync(countries);
                }

                //Dealers
                var dealers = await _dbDealer.GetAllAsync();

                if (!dealers.Any())
                {
                    var dealersInfo = await _client.GetAllCarDealersAsync();
                    await SetDealerAsync(dealersInfo.ToList());

                    int rowCount      = dealers.Count;
                    var dealersAmount = Convert.ToInt32(_keeper.GetVariableByKey("DealerContainerCounter"));

                    var circlesValues = Convert.ToInt32(Math.Round(dealersAmount / (decimal)rowCount, MidpointRounding.AwayFromZero));
                    //for (int i = 1; i < circlesValues; i++)
                    for (int i = 1; i < 2; i++)
                    {
                        dealersInfo = await _client.GetAllCarDealersAsync(rowCount *i + 1);

                        await SetDealerAsync(dealersInfo.ToList());
                    }
                }

                //Cars
                var cars = await _dbCar.GetAllAsync();

                if (!cars.Any())
                {
                    dealers = await _dbDealer.GetAllAsync();

                    foreach (var dealer in dealers)
                    {
                        var carsInfoList = await _client.GetActiveCarAsync(dealer.NativeId);
                        await SetCarAsync(dealer, carsInfoList.ToList());
                    }
                }
                //VinHistory
                var histories = await _dbCarHistory.GetAllAsync();

                if (!histories.Any())
                {
                    cars = await _dbCar.GetAllAsync();

                    dealers = await _dbDealer.GetAllAsync();

                    foreach (var car in cars)
                    {
                        var carsInfoList = await _client.GetCarHistoryByVinCodeAsync(car.VinCode);
                        await SetCarHistoryAsync(car, dealers, carsInfoList.ToList());
                    }
                }

                await Task.Delay(TimeSpan.FromDays(1));
            }
        }
コード例 #9
0
        public async Task <IActionResult> GetAllCountriesAsync()
        {
            var result = await _source.GetAllAsync();

            return(View(result));
        }