public async Task <IActionResult> CreateNewPrice(int productId, [Bind("ProductId, Price")] PriceHistory newPrice) { if (productId != newPrice.ProductId) { return(NotFound()); } newPrice.EffectiveFrom = DateTime.Now; if (ModelState.IsValid) { try { _context.Add(newPrice); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(newPrice.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } PriceHistoriesDTO priceHistories = new PriceHistoriesDTO { Id = newPrice.Id, Price = newPrice.Price, }; try { var response = await _productsService.PushPrice(priceHistories); } catch (Exception e) { //_logger.LogWarning(e); } return(View(newPrice)); }
public async Task <IActionResult> Create([Bind("Id,Name,Quantity")] ProductRequestProductsDTO productRequest) { var product = _productRequestsService.GetProductRequestProducts();//Pull data from api again ProductRequest request = new ProductRequest { Confirmed = false, Quantity = productRequest.Quantity, ProductName = productRequest.Name, Price = product.Result.First(p => p.Name == productRequest.Name).Price }; ProductRequestDTO requestAPI = new ProductRequestDTO { Confirmed = false, Quantity = productRequest.Quantity, ProductName = productRequest.Name, Price = product.Result.First(p => p.Name == productRequest.Name).Price }; if (ModelState.IsValid) { _context.Add(request); await _context.SaveChangesAsync(); } try { var response = _productRequestsService.PushProductRequest(requestAPI); } catch (Exception e) { //_logger.LogWarning(e); } return(RedirectToAction(nameof(Index))); }