public void AddProduct(string name) { string key = KeyGenerator.GenerateProductKey(name); _logger.LogInformation($"Created product key = '{key}' for product = '{name}'"); Product product = new Product(key, name, DateTime.Now); AddProduct(product); }
public string GetProductNameByKey(string key) { Product product = null; lock (_productsLock) { product = _products.FirstOrDefault(p => p.Key.Equals(key)); } return(product?.Name); }
public string GetProductKeyByName(string name) { Product product = null; lock (_productsLock) { product = _products.FirstOrDefault(p => p.Name.Equals(name)); } return(product?.Key); }
private void AddProduct(Product product) { try { _databaseAdapter.AddProduct(product); lock (_productsLock) { _products.Add(product); } lock (_dictionaryLock) { _productSensorsDictionary[product.Name] = new List <SensorInfo>(); } } catch (Exception e) { _logger.LogError(e, $"Failed to add new product, name = {product.Name}"); } }
public void UpdateProduct(Product product) { Product currentProduct; lock (_productsLock) { currentProduct = _products.FirstOrDefault(p => p.Key.Equals(product.Key) && p.Name.Equals(product.Name, StringComparison.InvariantCultureIgnoreCase)); } if (currentProduct == null) { AddProduct(product); return; } currentProduct.Update(product); Task.Run(() => { _databaseAdapter.UpdateProduct(currentProduct); }); }
private void AddDefaultProduct() { Product product = new Product(TextConstants.DefaultProductName, TextConstants.DefaultProductName, DateTime.Now); AddProduct(product); }