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); }
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); }
private async Task SetCarHistoryAsync(Car car, List <Dealer> dealers, List <CarVinCodeHistory> list) { foreach (var item in list) { var dealer = dealers.Where(x => x.Name.Equals(item.SellerName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (dealer != null) { CarHistory history = new CarHistory() { Price = item.Price, PageUrl = item.PageUrl, CarState = item.CarState.Equals("new", StringComparison.InvariantCultureIgnoreCase) ? CarState.New : CarState.IsStock, DateFirstSeen = item.DateFirstSeen, DateLastSeen = item.DateLastSeen, DateScraped = item.DateScraped, Car = car, Dealer = dealer }; await _dbCarHistory.AddAsync(history); } } ; }
private async Task SetCarAsync(Dealer dealer, List <CarInfo> list) { foreach (var item in list) { Car car = new Car() { NativeId = item.Id, VinCode = item.VinCode, Name = item.ModelName, Price = item.Price, UrlPage = item.UrlPage, ColorExterior = item.ColorExterior, ColorInterior = item.ColorInterior, DateUpdateInfo = item.DateUpdateInfo, CarState = item.CarState.Equals("new", StringComparison.InvariantCultureIgnoreCase)? CarState.New : CarState.IsStock, CarStatus = CarStatus.Active, Dealer = dealer }; await _dbCar.AddAsync(car); var carEntity = _dbCar.GetAllAsync().Result.Where(x => x.NativeId.Equals(item.Id, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); foreach (var link in item.Media.Photos) { CarPhotoLink carPhoto = new CarPhotoLink() { Url = link, Car = carEntity }; await _dbCarPhotoLink.AddAsync(carPhoto); } } ; /*public int Id { get; set; } * * [MaxLength(50)] * public string DealerCode { get; set; } * * [MaxLength(30)] * public string VinCode { get; set; } * * [Required, * MaxLength(50)] * public string Name { get; set; } * * [Column(TypeName = "smallmoney"), * Range(0, double.MaxValue)] * public decimal Price { get; set; } * * [MaxLength(50)] * public string UrlPage { get; set; } * * [MaxLength(20)] * public string ColorExterior { get; set; } * * [MaxLength(20)] * public string ColorInterior { get; set; } * * public DateTime DateUpdateInfo { get; set; } * * public CarState CarState { get; set; } = CarState.New; * * public CarStatus CarStatus { get; set; } = CarStatus.Active; * * public int DealerId { get; set; } * public virtual Dealer Dealer { get; set; } * * public virtual List<CarHistory> CarHistories { get; set; }*/ }
private async Task SetDealerAsync(List <DealerInfo> list) { Dictionary <string, Country> countries = new Dictionary <string, Country>(); list .Select(x => x.Country) .Distinct() .ToList() .ForEach(x => { Country country = _dbCountry.GetAllAsync().Result .Where(c => c.Code.Equals(x, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); countries.Add(x, country); } ); foreach (var item in list) { Dealer dealer = new Dealer() { NativeId = item.Id, Name = item.SellerName, Status = GetDealerStates(item.Status.ToLower()), Street = item.Street, City = item.City, CountryState = item.CountryState, Zip = item.Zip, ContactPhone = item.ContactPhone, Country = countries[item.Country] }; await _dbDealer.AddAsync(dealer); //country.Dealers.Add(dealer); /*foreach (var item in list) * { * Country country = _dbCountry.GetAllAsync().Result * .Where(c => c.Code.Equals(item.Country, StringComparison.InvariantCultureIgnoreCase)) * .FirstOrDefault(); * Dealer dealer = new Dealer() * { * NativeId = item.Id, * Name = item.SellerName, * Status = DealerStatus.Active, //!!!!!!!!!!!! * Street = item.Street, * City = item.City, * CountryState = item.CountryState, * Zip = item.Zip, * ContactPhone = item.ContactPhone, * Country = country * }; * //country.Dealers.Add(dealer); * await _dbDealer.AddAsync(dealer); * //await _dbCountry.ModifyAsync(country.Id, country); * }*/ /*Dictionary<string, Country> countries = new Dictionary<string, Country>(); * list.Select(x => x.Country).Distinct().ToList().ForEach(x => * { * Country country = _dbCountry.GetAllAsync().Result * .Where(c => c.Code.Equals(x, StringComparison.InvariantCultureIgnoreCase)) * .FirstOrDefault(); * countries.Add(x, country); * } * ); * * var dealers = list * .Select(x =>new Dealer() * { * Id = x.Id, * Name = x.SellerName, * Status = DealerStatus.Active, //!!!!!!!!!!!! * Street = x.Street, * City = x.City, * CountryState = x.CountryState, * Zip = x.Zip, * ContactPhone = x.ContactPhone, * Country = _dbCountry * .GetAllAsync() * .Result * .Where(c=> c.Code.Equals(x.Country, StringComparison.InvariantCultureIgnoreCase)) * .FirstOrDefault() * //CountryId = _dbCountry.GetByName(x.Country).Result.Id * }).ToList(); * await _dbDealer.AddRangeAsync(dealers);*/ } }