private void AddProductToDatabase(DatabaseProductModel model) { List <DatabaseProductModel> products = _model.Products.Where(p => p.Id == model.Id).ToList(); if (products.Count != 0) { DatabaseProductModel existingProduct = products[0]; if (existingProduct.Expire == 0) { return; } DateTime existingProductExpire = DateTime.FromBinary(existingProduct.Expire); DateTime newProductExpire = DateTime.FromBinary(model.Expire); if (existingProductExpire > newProductExpire) { return; } } _model.Products.Add(model); WriteDatabase(); Common.Delegate.Call <int>(ProductAdded, model.Id); }
public void AddProduct(int productId) { _locker.WaitOne(); lock (_locker) { DatabaseProductModel newProduct = new DatabaseProductModel(); newProduct.Id = productId; newProduct.Date = DateTime.UtcNow.ToBinary(); AddProductToDatabase(newProduct); } }
private bool ValidateProduct(DatabaseProductModel model) { if (model.Expire != 0) { DateTime productExpire = DateTime.FromBinary(model.Expire); if (productExpire < DateTime.UtcNow) { _model.Products.Remove(model); WriteDatabase(); Common.Delegate.Call(ProductExpired, model.Id); return(false); } } return(true); }