public async Task <ActionResult <AdModel> > CreateByAdmin(AdModel adModel) { if (adModel.AdPrice == null) { var price = (await functionalUnitOfWork.AdPriceRepository.All()).FirstOrDefault(p => p.PriceName == "free"); if (price == null) { price = new AdPrice { Value = 0, DelayToDisplay = 2, DisplayDuration = 2, PriceName = "free" }; await functionalUnitOfWork.AdPriceRepository.Add(price); } adModel.AdPrice = price; adModel.AdPriceId = price.Id; } return(Ok(await functionalUnitOfWork.AdRepository.Add(adModel))); }
private async Task SelectPrice(AdPrice currentPrice) { CurrentPrice = currentPrice; Step = "Step3"; await InvokeAsync(StateHasChanged); }
private static void FillAd(IDbContextTransaction transaction, RealEstateContext reContext, HtmlNode node, int newFetchId) { //using var priceContext = new AdPriceContext(); var ad = new RealEstate(); var adId = node.GetAttributeValue("data-id", "").ToString(); var address = node.SelectSingleNode(".//div[@class = 'listing__address']"); var findAd = reContext.RealEstates.FirstOrDefault(r => r.AdId == adId && r.Address == address.InnerText.Trim()); if (findAd == null) { ad.RealEstateId = Guid.NewGuid(); ad.AdId = adId; ad.AdType = "lakás"; ad.AdType = "telek"; if (address != null) { ad.Address = address.InnerText.Trim(); var commaIndex = address.InnerText.LastIndexOf(","); if (commaIndex == -1) { ad.City = address.InnerText.Trim(); } else { ad.City = address.InnerText.Substring(commaIndex + 1).Trim(); } } var price = node.SelectSingleNode(".//div[@class = 'price']"); if (price != null) { var newPrince = new AdPrice() { AdPriceId = new Guid(), RealEstateId = ad.RealEstateId, AdId = ad.AdId, OldPrice = Convert.ToDecimal(price.InnerText.Split(" ")[1]), NewPrice = Convert.ToDecimal(price.InnerText.Split(" ")[1]), EntryDate = DateTime.UtcNow, FetchId = newFetchId }; reContext.Add(newPrince); reContext.SaveChanges(); } var area = node.SelectSingleNode(".//div[contains(@class , 'listing__data--area-size')]"); if (area != null) { ad.Area = Convert.ToDecimal(area.InnerText.Split(" ")[1]); } var plotSize = node.SelectSingleNode(".//div[contains(@class , 'listing__data--plot-size')]"); if (plotSize != null) { var plotSizeTxt = plotSize.InnerText.ToString(); ad.PlotSize = Convert.ToInt32(plotSizeTxt.Substring(0, plotSizeTxt.Count() - 9).Replace(" ", "")); } //ad.PricePerSqm = Math.Round((ad.Price.Value / ad.Area.Value) * 1000000, 2); var balcony = node.SelectSingleNode(".//div[contains(@class,'listing__data--balcony-size')]"); if (balcony != null) { ad.Balcony = balcony.InnerText; } var leasing = node.SelectSingleNode(".//div[contains(@class , 'label--alert')]"); ad.LeaseRights = leasing == null ? false : true; ad.Date = DateTime.UtcNow; Console.WriteLine($"{ad.AdId} added"); reContext.RealEstates.Add(ad); reContext.Entry(ad).State = EntityState.Added; reContext.SaveChanges(); var e = reContext.ChangeTracker.Entries(); DisplayStates(e); } else { var adPrice = reContext.AdPrices .Where(a => a.AdId == findAd.AdId) .OrderByDescending(a => a.EntryDate) .Take(1) .ToList(); var price = node.SelectSingleNode(".//div[@class = 'price']"); if (price != null) { var actualPrice = Convert.ToDecimal(price.InnerText.Split(" ")[1]); if (adPrice[0].NewPrice != actualPrice) { var newPrice = new AdPrice() { AdPriceId = new Guid(), RealEstateId = findAd.RealEstateId, AdId = findAd.AdId, OldPrice = adPrice[0].NewPrice, NewPrice = actualPrice, EntryDate = DateTime.UtcNow, FetchId = newFetchId }; Console.WriteLine($"Price update of : {findAd.RealEstateId}"); reContext.Add(newPrice); reContext.SaveChanges(); } } } }
public Task Update(AdPrice ad) { return(Task.Run(() => _context.AdPrices.Update(ad))); }
public Task <AdPrice> Add(AdPrice current) { return(Task.Run(() => _context.AdPrices.Add(current))); }
public async Task <IActionResult> Update(AdPrice adPrice) { await _functionalUnitOfWork.AdPriceRepository.Update(adPrice); return(Ok()); }
public async Task <IActionResult> Create(AdPrice adPrice) { var entity = await _functionalUnitOfWork.AdPriceRepository.Add(adPrice); return(Ok(entity)); }