public void StartLoadingProductPrice(string sku) { var thisProduct = _products.FirstOrDefault(x => x.Sku == sku); if (thisProduct != null && thisProduct.PriceState == Enums.RequestState.Succseeded) { OnProductPriceReceived?.Invoke(sku, thisProduct.Price); } var tiket = _catalogRepository.GetPriceTicket(sku); tiket.OnSuccess += (response) => { if (response.Data?.Sku != null) { if (thisProduct == null) { thisProduct = new CatalogueProduct() { Sku = sku }; _products.Add(thisProduct); } thisProduct.Price = response.Data.Price; thisProduct.PriceState = Enums.RequestState.Succseeded; OnProductPriceReceived?.Invoke(thisProduct.Sku, thisProduct.Price); return; } OnProductPriceReceived?.Invoke(null, null); }; }
public CatalogueProduct AddProductToCatalogue(Catalogue catalogue, Product product) { //using (ProductsDbContext context = new ProductsDbContext()) { CatalogueProduct existingCatalogueProduct = _context.CatalogueProducts .Where(cp => cp.CatalogueId == catalogue.Id && cp.ProductId == product.Id) .FirstOrDefault(); if (existingCatalogueProduct == null) { CatalogueProduct newCatalogueProduct = new CatalogueProduct(); newCatalogueProduct.ProductId = product.Id; newCatalogueProduct.CatalogueId = catalogue.Id; _context.CatalogueProducts.Add(newCatalogueProduct); _context.SaveChanges(); return(newCatalogueProduct); } return(existingCatalogueProduct); } }