public ObservableCollection<Drink> MockDrinks() { ObservableCollection<Drink> drinks = new ObservableCollection<Drink>(); Drink beer = new Drink() { Available = true, BigDecrease = 0.7, BigRise = 1.2, CurrentPrice = 13, Id = 1, InitialPrice = 13, MaximumPrice = 22, MiniumPrice = 10, Name = "Bier", OverrideFactor = 1, SmallDecrease = 0.9, SmallRise = 1.1 }; drinks.Add(beer); Drink water = new Drink() { Available = true, BigDecrease = 0.7, BigRise = 1.2, CurrentPrice = 10, Id = 1, InitialPrice = 10, MaximumPrice = 15, MiniumPrice = 10, Name = "Water", OverrideFactor = 1, SmallDecrease = 0.9, SmallRise = 1.1 }; drinks.Add(water); Drink coke = new Drink() { Available = true, BigDecrease = 0.6, BigRise = 1.1, CurrentPrice = 12, Id = 1, InitialPrice = 12, MaximumPrice = 20, MiniumPrice = 10, Name = "Water", OverrideFactor = 1, SmallDecrease = 0.9, SmallRise = 1.1 }; drinks.Add(coke); return drinks; }
private static void CalculateNewPrice(List<ClientDrinkOrder> allOrdersItems, bool predict, Interval currentInterval, Interval previousInterval, Interval nextInterval, int previousAllDrinkCount, int currentAllDrinkCount, int differenceAllDrinks, Drink[] drinksForNextInterval, int i) { Drink drink = drinksForNextInterval[i]; int previousDrinkCount = allOrdersItems.Where(x => x.DrinkId == drink.Id && x.IntervalId == previousInterval.Id).Sum(x => x.Count); int currentDrinkCount = allOrdersItems.Where(x => x.DrinkId == drink.Id && x.IntervalId == currentInterval.Id).Sum(x => x.Count); //1 in the excel int differenceDrinkCount = currentDrinkCount - previousDrinkCount; //3 in the excel double differenceProcentage = ((double)currentDrinkCount / (double)currentAllDrinkCount) - ((double)previousDrinkCount / (double)previousAllDrinkCount); if (differenceDrinkCount >= 0) { #region 1A //the drink has been drank more if (differenceAllDrinks >= 0) { #region 2AA //more drinks have been drunk in general if (differenceProcentage > 0) { //the drink has been drunk more procentually drink.PriceFactor = PriceFactor.BigRise; } else { //the drink has been drunk less procentually drink.PriceFactor = PriceFactor.BigDecrease; } #endregion } else { #region 2AB //less drinks have been drunk in general if (differenceProcentage > 0) { //the drink has been drunk more procentually drink.PriceFactor = PriceFactor.SmallRise; } else { //the drink has been drunk less procentually drink.PriceFactor = PriceFactor.SmallDecrease; } #endregion } #endregion } else { #region 1B //the drink has been drank less if (differenceAllDrinks > 0) { #region 2BA //more drinks have been drunk in general if (differenceProcentage > 0) { //the drink has been drunk more procentually drink.PriceFactor = PriceFactor.BigDecrease; } else { //the drink has been drunk less procentually drink.PriceFactor = PriceFactor.BigRise; } #endregion } else { #region 2BB //more drinks have been drunk in general if (differenceProcentage > 0) { //the drink has been drunk more procentually drink.PriceFactor = PriceFactor.SmallDecrease; } else { //the drink has been drunk less procentually drink.PriceFactor = PriceFactor.SmallRise; } #endregion } #endregion } //check if we need to use the override factor if (drink.OverrideFactor != 0 && !predict) drink.PriceFactor = PriceFactor.Override; Drink nextDrink = nextInterval.Drinks.FirstOrDefault(x => x.Id == drink.Id); double priceFactor = drink.GetPriceFactorValue(); double priceWithoutRouding = drink.CurrentPrice * priceFactor; int nextPrice = (int)Math.Round(priceWithoutRouding); if (nextPrice > nextDrink.MaximumPrice) nextPrice = nextDrink.MaximumPrice; if (nextPrice < nextDrink.MiniumPrice) nextPrice = nextDrink.MiniumPrice; nextDrink.CurrentPrice = nextPrice; if (predict) nextDrink.PriceFactor = drink.PriceFactor; }
private void InitCommands() { PointInCode("DrinkViewModel: InitCommands"); //It shouldn't be posible to remove a drink when the party is busy RemoveDrinkCommand = new RelayCommand<int>(DeleteDrink, (int id) => { return (!BeursfuifBusy && Drinks.Any(x => x.Id == id)); }); AddNewDrinkCommand = new RelayCommand(delegate() { NewEditDrink = new Drink() { Id = (Drinks != null && Drinks.Any() ? Drinks.Max(x => x.Id) + 1 : 1) }; }, () => { return (!BeursfuifBusy && NewEditDrink == null); }); DownloadImageCommand = new RelayCommand(DownloadImage, () => { return (!string.IsNullOrEmpty(DownloadUrl) && !Downloading); }); CancelCommand = new RelayCommand(ResetValues); ChooseLocalImageCommand = new RelayCommand(ChooseLocalImage); SaveDrinkCommand = new RelayCommand(SaveDrink); AvailableChangedCommand = new RelayCommand<int>(UpdateDrinkAvailability); }
private void UpdateDrink(Drink changed) { Interval currentInterval = _beursfuifData.CurrentInterval; if (currentInterval != null && currentInterval.Drinks != null) { if (currentInterval.Drinks.Any(x => x.Id == changed.Id)) { Drink currentIntervalDrink = currentInterval.Drinks.FirstOrDefault(x => x.Id == changed.Id); currentIntervalDrink.UpdateProperties(changed); } } if (_beursfuifData.Intervals != null) { int length = _beursfuifData.Intervals.Length; int index = Array.IndexOf(_beursfuifData.Intervals, currentInterval); for (int i = index; i < length; i++) { Drink drink = _beursfuifData.Intervals[i].Drinks.FirstOrDefault(x => x.Id == changed.Id); if (drink != null) { drink.UpdateProperties(changed); } } } if (BeursfuifBusy) { //send message to clients with the current interval MessengerInstance.Send<DrinkAvailableMessage>(new DrinkAvailableMessage()); } }
public void UpdateDrink(Drink drink) { if (Drinks == null) return; Drink dr = Drinks.FirstOrDefault(x => x.Id == drink.Id); if (dr != null) { int index = Array.IndexOf(Drinks, dr); Drinks[index] = drink; } }
//Because c# is always byRef on objects, that's why private void FillInDrinks(Interval interval, Drink[] drinks) { PointInCode("SettingsViewModel: FillInDrinks"); int length = drinks.Length; interval.Drinks = new Drink[length]; for (int i = 0; i < length; i++) { interval.Drinks[i] = drinks[i].Clone(); } }
public void RemoveDrink(Drink drink) { if (Drinks == null) return; List<Drink> currentDrinks = Drinks.ToList(); currentDrinks.Remove(currentDrinks.FirstOrDefault(x => x.Id == drink.Id)); Drinks = currentDrinks.ToArray(); }
public Interval Clone() { Interval clone = this.MemberwiseClone() as Interval; int drinkLength = this.Drinks.Length; Drink[] drinkClones = new Drink[drinkLength]; for (int i = 0; i < drinkLength; i++) { drinkClones[i] = this.Drinks[i].Clone(); } clone.Drinks = drinkClones; return clone; }
public void AddDrink(Drink drink) { if (Drinks == null) { Drinks = new Drink[] { drink }; return; } List<Drink> currentDrinks = Drinks.ToList(); currentDrinks.Add(drink); Drinks = currentDrinks.ToArray(); }
protected bool Equals(Drink other) { return _id == other._id && string.Equals(_name, other._name) && _available == other._available && _initialPrice == other._initialPrice && _minimumPrice == other._minimumPrice && _maximumPrice == other._maximumPrice && _currentPrice == other._currentPrice && _bigRise.Equals(other._bigRise) && _smallRise.Equals(other._smallRise) && _bigDecrease.Equals(other._bigDecrease) && _overrideFactor.Equals(other._overrideFactor); }
/// <summary> /// Updates properties that are allowed to be changed when the party is started /// </summary> /// <param name="changed"></param> public void UpdateProperties(Drink changed) { Name = changed.Name; Available = changed.Available; BigDecrease = changed.BigDecrease; BigRise = changed.BigRise; SmallDecrease = changed.SmallDecrease; SmallRise = changed.SmallRise; MiniumPrice = changed.MiniumPrice; MaximumPrice = changed.MaximumPrice; }