public bool Initialize(string vipno = null) { lock (_locker) { if (Wrapper.User == null) { return(Initialized = false); } ActivityLogService.Logger.LogFunctionCall(); try { _vipno = vipno; _previousSales = new List <SaleDiscount>(); _shoppingBag = new List <ShoppingItem>(); SaleDiscount.ResetCounter(); EngineRestarted?.Invoke(); return(Initialized = true); } catch (Exception ex) { ActivityLogService.Logger.LogError(ex); return(Initialized = false); } } }
private void evaluateChanges(List <SaleDiscount> newSales) { var previousSales = _previousSales; _previousSales = newSales; for (int i = 0; i < newSales.Count; i++) { SaleDiscount sd = newSales[i]; var removed = previousSales.FindAll(s => s == sd); if (removed.Count == 0) { sd.SetID(); SaleApplied?.Invoke(sd); } else if (removed.Count != 1) { //### multiple equal sales } else // (removed.Count == 1) { sd.SetID(removed[0].ID); previousSales.RemoveAll(s => s == sd); } } for (int i = 0; i < previousSales.Count; i++) { SaleDiscount sd = previousSales[i]; SaleCancelled?.Invoke(sd.ID); } }
internal bool Add(SaleDiscount sd) { if (Title == sd.Title && Discount == sd.Discount) { Quantity += sd.Quantity; return(true); } return(false); }
//### Testing purpose public bool InitializeForDebugging() { lock (_locker) { ActivityLogService.Logger.LogFunctionCall(); try { _previousSales = new List <SaleDiscount>(); AvailableSales = makeSalesForTester(); _shoppingBag = new List <ShoppingItem>(); SaleDiscount.ResetCounter(); EngineRestarted?.Invoke(); return(Initialized = true); } catch (Exception ex) { ActivityLogService.Logger.LogError(ex); return(Initialized = false); } } }