public void AddEquity(decimal price, decimal quantity) { if (price <= 0) { throw new ArgumentOutOfRangeException(nameof(price)); } if (quantity <= 0) { throw new ArgumentOutOfRangeException(nameof(quantity)); } stockRepository.AddStock( new EquityDTO { Name = GetStockName <EquityDTO>(), Price = price, Quantity = quantity }); }
public void Post([FromBody] InboundManifestRequestModel requestModel) { log.Info("Processing manifest: " + requestModel); var gtins = new List <string>(); foreach (var orderLine in requestModel.OrderLines) { if (gtins.Contains(orderLine.gtin)) { throw new ValidationException(String.Format("Manifest contains duplicate product gtin: {0}", orderLine.gtin)); } gtins.Add(orderLine.gtin); } IEnumerable <ProductDataModel> productDataModels = productRepository.GetProductsByGtin(gtins); Dictionary <string, Product> products = productDataModels.ToDictionary(p => p.Gtin, p => new Product(p)); log.Debug(String.Format("Retrieved products to verify manifest: {0}", products)); var lineItems = new List <StockAlteration>(); var errors = new List <string>(); foreach (var orderLine in requestModel.OrderLines) { if (!products.ContainsKey(orderLine.gtin)) { errors.Add(String.Format("Unknown product gtin: {0}", orderLine.gtin)); continue; } Product product = products[orderLine.gtin]; if (!product.Gcp.Equals(requestModel.Gcp)) { errors.Add(String.Format("Manifest GCP ({0}) doesn't match Product GCP ({1})", requestModel.Gcp, product.Gcp)); } else { lineItems.Add(new StockAlteration(product.Id, orderLine.quantity)); } } if (errors.Count() > 0) { log.Debug(String.Format("Found errors with inbound manifest: {0}", errors)); throw new ValidationException(String.Format("Found inconsistencies in the inbound manifest: {0}", String.Join("; ", errors))); } log.Debug(String.Format("Increasing stock levels with manifest: {0}", requestModel)); stockRepository.AddStock(requestModel.WarehouseId, lineItems); log.Info("Stock levels increased"); }
public void Post([FromBody] InboundManifestRequestModel requestModel) { Log.Info("Processing manifest: " + requestModel); var gtins = new List <string>(); foreach (var orderLine in requestModel.OrderLines) { if (gtins.Contains(orderLine.Gtin)) { throw new ValidationException($"Manifest contains duplicate product gtin: {orderLine.Gtin}"); } gtins.Add(orderLine.Gtin); } var productDataModels = _productRepository.GetProductsByGtin(gtins); var products = productDataModels.ToDictionary(p => p.Gtin, p => new Product(p)); Log.Debug($"Retrieved products to verify manifest: {products}"); var lineItems = new List <StockAlteration>(); var errors = new List <string>(); foreach (var orderLine in requestModel.OrderLines) { if (!products.ContainsKey(orderLine.Gtin)) { errors.Add($"Unknown product gtin: {orderLine.Gtin}"); continue; } var product = products[orderLine.Gtin]; if (!product.Gcp.Equals(requestModel.Gcp)) { errors.Add($"Manifest GCP ({requestModel.Gcp}) doesn't match Product GCP ({product.Gcp})"); } else { lineItems.Add(new StockAlteration(product.Id, orderLine.Quantity)); } } if (errors.Count() > 0) { Log.Debug($"Found errors with inbound manifest: {errors}"); throw new ValidationException( $"Found inconsistencies in the inbound manifest: {string.Join("; ", errors)}"); } Log.Debug($"Increasing stock levels with manifest: {requestModel}"); _stockRepository.AddStock(requestModel.WarehouseId, lineItems); Log.Info("Stock levels increased"); }
async private void AddStockMethod() { if (AddStock.Price < 1 || AddStock.Quantity < 1 || (AddStock.Name?.Length ?? 0) == 0) { return; } var stock = await _stockRepository.AddStock(AddStock.Selected.Type, AddStock.Price, AddStock.Quantity, AddStock.NextOccurence); GetAllStockCommand.Execute(null); GetAllStockTypeCommand.Execute(null); }
public void AddStock(Stock stock) { _stocks.AddStock(stock); if (stock == null) { return; } stock.Price += GetRandomPriceChange(stock); if (StockChanged != null) { StockChanged(this, new EventArgs <Stock>(stock)); } }
public void Handle(IStockChangeEvent message) { var symbol = message.Symbol; var stock = _stocks.GetStockBySymbol(symbol); if (stock == null) { stock = new Stock { Symbol = symbol, Price = message.Price }; _stocks.AddStock(stock); GetClients().addStock(message); } else { stock.Price = message.Price; GetClients().updateStockPrice(message); } }
public async Task <ActionResult <Stock> > Create(Stock stock) { return(await _repos.AddStock(stock)); }
public Task <Company> AddStock(int stockQuantity) { return(_stockRepository.AddStock(stockQuantity)); }
public IActionResult Post([FromBody] Stock stock) { _stockRepository.AddStock(stock); return(Ok(stock)); }
public async Task AddStock(StockRespons stock) { var stockIn = _mapper.ToDocument(stock); await _stockRepository.AddStock(stockIn); }