public RegistrationContext(DbContextOptions <RegistrationContext> options) : base(options) { Database.EnsureCreated(); if (!Colors.Any()) { Colors.Add(new Color { name = "Красный" }); Colors.Add(new Color { name = "Синий" }); Colors.Add(new Color { name = "Желтый" }); this.SaveChanges(); } if (!Drinks.Any()) { Drinks.Add(new Drink { name = "Чай" }); Drinks.Add(new Drink { name = "Кофе" }); Drinks.Add(new Drink { name = "Вода" }); Drinks.Add(new Drink { name = "Сок" }); this.SaveChanges(); } }
public void AddDrinks(List <Drink> drinks) { Drinks.Clear(); foreach (var drink in drinks) { Drinks.Add(drink); } }
public void MakeCoffee() { // Execute all commands and take the result Commands.ForEach(command => { command.Execute(); Drinks.Add(command.GetResult()); }); }
private async Task Refresh() { Drinks.Clear(); var drinks = await _drinkSerice.RefreshAll(); foreach (var drink in drinks) { Drinks.Add(drink); } }
public MainViewModel() { Console.WriteLine("MainViewModel says Hello World! "); #region Commands NewCommand = new Command( execute: () => { DrinkEdit = new DrinkViewModel(); DrinkEdit.PropertyChanged += OnDrinkEditPropertyChanged; IsEditing = true; RefreshCanExecutes(); }, canExecute: () => { return(!IsEditing); }); SubmitCommand = new Command( execute: () => { DrinkEdit.PropertyChanged -= OnDrinkEditPropertyChanged; Drinks.Add(DrinkEdit); var temp = ConvertEditToDrink(DrinkEdit); if (temp.Count > 0) { temp.ForEach(it => { App.Database.SaveItemAsync(it); }); } DrinkEdit = null; IsEditing = false; RefreshCanExecutes(); }, canExecute: () => { return(DrinkEdit != null && (DrinkEdit.CoffeeCount > 0 || DrinkEdit.WaterCount > 0)); }); CancelCommand = new Command( execute: () => { DrinkEdit.PropertyChanged -= OnDrinkEditPropertyChanged; DrinkEdit = null; IsEditing = false; RefreshCanExecutes(); }, canExecute: () => { return(IsEditing); }); #endregion }
public override async Task InitProperties() { if (CurrentUser != null) { var drink = await dataService.GetUserLastChoiceAsync(CurrentUser); if (drink != null) { SelectedDrink = drinks.Where(x => x.DrkID == drink.DrkID).Select(x => { x.IsDrinkSelected = true; return(x); }).FirstOrDefault(); Drinks.Remove(Drinks.Where(x => x.DrkID == drink.DrkID).FirstOrDefault()); Drinks.Add(SelectedDrink); SugarQty = drink.SugarQty; } } }
private async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { App.Current.Properties.TryGetValue("token", out object tokenObject); var user = await userService.GetUser(tokenObject.ToString()); App.Current.Properties["coctelesFav"] = user.CoctelesFavList; App.Current.Properties["ingredientesFav"] = user.IngredientesFavList; var cocteles = await CoctelService.RetrieveDrinks(); var ingredientes = await CoctelService.RetrieveIngredients(); Drinks.Clear(); foreach (var coctelFav in user.CoctelesFavList) { var d = cocteles.FirstOrDefault(x => int.Parse(x.Id) == coctelFav); if (d != null) { Drinks.Add(d); } } Ingredients.Clear(); foreach (var ingredientFav in user.IngredientesFavList) { Ingredients.Add(ingredientes.FirstOrDefault(x => x.Name.Equals(ingredientFav))); } } catch (Exception ex) { Debug.WriteLine(ex); DependencyService.Get <IMessage>().ShortAlert("No se han podido recuperar los datos de usuario. Compruebe la conexion de red"); } finally { IsBusy = false; } }
public async Task AddDrinkAsync() { var drink = new Drink { Name = AddName, Price = AddPrice, Volume = AddVolume, Restaurant = username }; var response = await client.PostAsJsonAsync($"api/drinks", drink); if (response.IsSuccessStatusCode) { Drinks.Add(drink); } }
private async Task LoadDrinks() { try { Drinks.Clear(); await Task.Delay(2000); var drinks = GetDrinks(); drinks.ForEach(d => Drinks.Add(d)); this.smwMachine.TryFireTrigger(SMWorkflowMachine.Trigger.SelectedDrink); if (Drinks.Count > 0) { SelectedDrink = Drinks.First(); } } catch (Exception) { this.smwMachine.TryFireTrigger(SMWorkflowMachine.Trigger.NotFound); } }
public void addDrink(Drink d) { Drinks.Add(d); }
/// <summary> /// This is the OnGet method for the data model. This handles what to do when the client tries to get data from the website. /// </summary> /// <param name="Terms">The search terms that were sent by the client.</param> /// <param name="CaloriesMin">The minimum caloires that was sent by the client.</param> /// <param name="CaloriesMax">The maximum calories that was sent by the client.</param> /// <param name="PriceMin">The minimum price that was sent by the client.</param> /// <param name="PriceMax">The maximum price that was sent by the client.</param> /// <param name="ShowEntrees">Whether or not to show the entrees tab as sent by the client.</param> /// <param name="ShowDrinks">Whether or not to show the drinks tab as sent by the client.</param> /// <param name="ShowSides">Whether or not to show the sides tab as sent by the client.</param> public void OnGet(string Terms, uint?CaloriesMin, uint?CaloriesMax, double?PriceMin, double?PriceMax, bool ShowEntrees, bool ShowDrinks, bool ShowSides) { this.Terms = Terms; this.CaloriesMin = CaloriesMin; this.CaloriesMax = CaloriesMax; this.PriceMin = PriceMin; this.PriceMax = PriceMax; //Since the request only contains the key if they are checked, and only time query count is 0 is on first load to prevent from auto-disabling. if (Request.Query.Count != 0) { this.ShowEntrees = Request.Query.ContainsKey("ShowEntrees"); this.ShowDrinks = Request.Query.ContainsKey("ShowDrinks"); this.ShowSides = Request.Query.ContainsKey("ShowSides"); } //Add all items to the bases here. if (this.ShowEntrees) { Entrees = Menu.Entrees(); Entrees = Menu.FilterByCalories(Entrees, CaloriesMin, CaloriesMax); Entrees = Menu.FilterByPrice(Entrees, PriceMin, PriceMax); Entrees = Menu.Search(Entrees, Terms); } Dictionary <string, List <IOrderItem> > TempDrinks = new Dictionary <string, List <IOrderItem> >(); Dictionary <string, List <IOrderItem> > TempSides = new Dictionary <string, List <IOrderItem> >(); //Drinks if (this.ShowDrinks) { //Generate a temp dictionary of all possible drink items. foreach (IOrderItem drink in Menu.Drinks()) { List <IOrderItem> res; string key = ""; if (drink is SailorSoda) { key = drink.ItemName.Substring(drink.ItemName.IndexOf(" ") + 1 + drink.ItemName.Substring(drink.ItemName.IndexOf(" ") + 1).IndexOf(" ") + 1); } else { key = drink.ItemName.Substring(drink.ItemName.IndexOf(" ") + 1); } if (TempDrinks.TryGetValue(key, out res)) { //Handle the multiple types of Sailor Soda if (res.Count != Enum.GetNames(typeof(Size)).Length) { res.Add(drink); } } else { List <IOrderItem> t = new List <IOrderItem>(); t.Add(drink); TempDrinks.Add(key, t); } } //Filter the items from the temp drinks dictionary and add the ones that make it through the filters into the real drinks dictionary. foreach (string key in TempDrinks.Keys) { List <IOrderItem> outList; if (TempDrinks.TryGetValue(key, out outList)) { outList = Menu.FilterByCalories(outList, CaloriesMin, CaloriesMax).ToList(); outList = Menu.FilterByPrice(outList, PriceMin, PriceMax).ToList(); outList = Menu.Search(outList, Terms).ToList(); if (outList.Count != 0) { Drinks.Add(key, outList); } } } } //Sides if (this.ShowSides) { //Generate a temp dictionary of all possible side items. foreach (IOrderItem side in Menu.Sides()) { List <IOrderItem> res; string key = side.ItemName.Substring(side.ItemName.IndexOf(" ") + 1); if (TempSides.TryGetValue(key, out res)) { res.Add(side); } else { List <IOrderItem> t = new List <IOrderItem>(); t.Add(side); TempSides.Add(key, t); } } //Filter the items from the temp drinks dictionary and add the ones that make it through the filters into the real sides dictionary. foreach (string key in TempSides.Keys) { List <IOrderItem> outList; if (TempSides.TryGetValue(key, out outList)) { outList = Menu.FilterByCalories(outList, CaloriesMin, CaloriesMax).ToList(); outList = Menu.FilterByPrice(outList, PriceMin, PriceMax).ToList(); outList = Menu.Search(outList, Terms).ToList(); if (outList.Count != 0) { Sides.Add(key, outList); } } } } }
public void AddDrink(Drink drink) { Drinks.Add(drink); }