public RestaurantMenuItemModifierPage(RestaurantVM restaurantVM, MenuItemViewModel menuItemView, MenuGroupModifierItem menuGroupModifierItem = null) { RestaurantVM = restaurantVM; MenuItemView = menuItemView; MenuItemVM = menuItemView.RestaurantMenuItem.MenuItemVM; MenuGroupModifierItem = menuGroupModifierItem; Price = MenuItemVM.MenuItem.BasePrice; InitializeComponent(); NavigationPage.SetBackButtonTitle(this, AppResources.Back); //this.NumberEntryViewQuantity.Entry.Text = "1"; this.Quantity = 1; //this.ToolbarItems.Add(new ToolbarItem() //{ // Icon = "check_white.png", // Command = new Command(() => // { // SaveOrAddToCart(); // }), //}); if (MenuGroupModifierItem != null) { //this.NumberEntryViewQuantity.Entry.Text = Convert.ToString(MenuGroupModifierItem.Quantity); this.Quantity = MenuGroupModifierItem.Quantity; Feedback = MenuGroupModifierItem.Comment; ButtonAddToCart.Text = AppResources.Save; } ButtonAddToCart.Clicked += (sender, e) => { SaveOrAddToCart(); }; //ButtonFeedbackDone.Clicked += (sender, e) => //{ // EditorFeedback.Unfocus(); // GridFeedback.IsVisible = false; //}; //this.NumberEntryViewQuantity.Entry.TextChanged += (sender, e) => //{ // Device.BeginInvokeOnMainThread(() => // { // Price = UpdatePrice(this.MenuItemVM, this.MenuItemModifiers, this.Quantity); // }); //}; ListViewModifiers.ItemSelected += (sender, e) => { if (e.SelectedItem != null) { ListViewModifiers.SelectedItem = null; ModifierItemViewModel modifierItemView = e.SelectedItem as ModifierItemViewModel; if (modifierItemView.IsItem && modifierItemView.IsEnabled) { if (modifierItemView.MenuModifierVM.SubMenuModifiers.Count > 0) { RestaurantMenuItemSubModifierPage restaurantMenuItemSubModifierPage = new RestaurantMenuItemSubModifierPage(this, modifierItemView); Utils.PushAsync(Navigation, restaurantMenuItemSubModifierPage, true); } else { modifierItemView.IsSelected = !modifierItemView.IsSelected; modifierItemView.Save(); } } } }; }
public async void SaveOrAddToCart() { if (this.IsBusy) { return; } string error = string.Empty; foreach (var menuItemModifier in MenuItemModifiers) { var minApplied = menuItemModifier.MenuModifierGroup.MinApplied; var itemsSelected = menuItemModifier.MenuModifiers.Where(s => s.IsSelected).ToList(); var countApplied = itemsSelected.Sum(t => t.Quantity); if (countApplied < minApplied) { if (!string.IsNullOrEmpty(error)) { error += "\n"; } error += string.Format(AppResources.ChooseRequired, minApplied + " " + menuItemModifier.MenuModifierGroup.DisplayName + " -"); } foreach (var itemSelected in itemsSelected) { foreach (var subMenuModifierGroup in itemSelected.SubMenuModifierGroups) { minApplied = subMenuModifierGroup.MinApplied; itemsSelected = itemSelected.SubMenuModifiers .Where((t) => subMenuModifierGroup.ModifierIDs.Contains(t.MenuModifier.ID)) .Where(s => s.IsSelected).ToList(); countApplied = itemsSelected.Sum(t => t.Quantity); if (countApplied < minApplied) { if (!string.IsNullOrEmpty(error)) { error += "\n"; } error += string.Format(AppResources.ChooseRequired, minApplied + " " + subMenuModifierGroup.DisplayName + " -"); } } } } if (string.IsNullOrEmpty(error)) { var menuGroupModifierItem = new MenuGroupModifierItem(MenuItemView, MenuItemModifiers, Quantity, this.Feedback); if (MenuGroupModifierItem == null) { MenuGroupModifierItem = menuGroupModifierItem; MenuItemView.ListMenuGroupModifierItemSelected.Add(MenuGroupModifierItem); MenuItemView.IsSelected = true; } else { MenuGroupModifierItem.Comment = menuGroupModifierItem.Comment; MenuGroupModifierItem.ListRMenuGroupModifierVM = menuGroupModifierItem.ListRMenuGroupModifierVM.ToList(); MenuGroupModifierItem.Quantity = menuGroupModifierItem.Quantity; MenuGroupModifierItem.MenuItemView = menuGroupModifierItem.MenuItemView; } if (Saved != null) { Saved.Invoke(MenuGroupModifierItem); } await Navigation.PopAsync().ConfigureAwait(false); } else { Device.BeginInvokeOnMainThread(async() => { var notificator = DependencyService.Get <IToastNotificator>(); await notificator.Notify(ToastNotificationType.Error, AppResources.Error, error, TimeSpan.FromSeconds(5)); }); } }