private void SetPriceForPortition(PortionWithCheckDish model) { var saladSelectedCount = model.Portion.SaladList.Where(x => x.IsSelected).Count(); if (model.Dish.IsSelected && (model.Dish.IsHightPrice || saladSelectedCount == 2)) { model.Portion.PriceStr = ((decimal)DishOrderPriceType.HightPrice).ToString() + PricePostFix; model.Portion.Price = (decimal)DishOrderPriceType.HightPrice; } else { model.Portion.PriceStr = ((decimal)DishOrderPriceType.UsualPrice).ToString() + PricePostFix; model.Portion.Price = (decimal)DishOrderPriceType.UsualPrice; } }
private async void OnChangeCheckboxBreadCommandAsync(PortionWithCheckDish model) { if (model.Portion.BreadList.Any(x => x.IsSelected && x.Id != model.Dish.Id)) { await _userDialog.AlertAsync(YouCanSelectOnlyOneBreadInThisPortition); } else { model.Dish.IsSelected = !model.Dish.IsSelected; model.Portion.PortionInfo.BreadName = model.Dish.Name; model.Portion.PortionInfo.IsBreadVisible = model.Dish.IsSelected; SetPriceForPortition(model); CalculateTotolPrice(); } }
private async void OnChangeCheckboxMeatCommandAsync(PortionWithCheckDish model) { if (model.Portion.MeatList.Any(x => x.IsSelected && x.Id != model.Dish.Id)) { await _userDialog.AlertAsync(YouCanSelectOnlyOneMeatInThisPortition); } else { model.Dish.IsSelected = !model.Dish.IsSelected; model.Portion.PortionInfo.MeatName = model.Portion.IsDuplicate ? DuplicatePrefix + model.Dish.Name : model.Dish.Name; model.Portion.PortionInfo.IsMeatVisible = model.Dish.IsSelected; SetPriceForPortition(model); CalculateTotolPrice(); } }
private async void OnChangeCheckboxGarnishCommandAsync(PortionWithCheckDish model) { if (model.Portion.SaladList.Where(x => x.IsSelected).Count() >= 2) { await _userDialog.AlertAsync(YouCanSelectOnlyOneSaladInThisPortition); } else if (model.Portion.GarnishList.Any(x => x.IsSelected && x.Id != model.Dish.Id)) { await _userDialog.AlertAsync(YouCanSelectOnlyOneGarnishInThisPortition); } else { model.Dish.IsSelected = !model.Dish.IsSelected; model.Portion.PortionInfo.GarnishName = model.Portion.IsDuplicate ? DuplicatePrefix + model.Dish.Name : model.Dish.Name; model.Portion.PortionInfo.IsGarnishVisible = model.Dish.IsSelected; SetPriceForPortition(model); CalculateTotolPrice(); } }
private StackLayout GetDishItemView(PortionWithCheckDish model) { var template = new StackLayout() { Orientation = StackOrientation.Horizontal, Margin = new Thickness(0, 10) }; var titleLabel = new Label() { Text = model.Dish.Name, HorizontalOptions = LayoutOptions.StartAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }; var checkImage = new Image() { WidthRequest = 20, HeightRequest = 20, BindingContext = model.Dish }; checkImage.SetBinding(Image.SourceProperty, new Binding(nameof(model.Dish.IsSelected), BindingMode.OneWay, new IsAvailableUpdateToCheckBoxIconConverter(Constants.CheckboxOnImageSource, Constants.CheckboxOffImageSource))); var checkClickableView = new ClickableContentView() { HorizontalOptions = LayoutOptions.EndAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand, CommandParameter = model, BindingContext = model.Dish, Content = checkImage }; checkClickableView.SetBinding(ClickableContentView.CommandProperty, nameof(model.Dish.ChangeCheckboxCommand)); template.Children.Add(titleLabel); template.Children.Add(checkClickableView); return(template); }
private async void OnChangeCheckboxSaladCommandAsync(PortionWithCheckDish model) { var countSaladSelected = model.Portion.SaladList.Where(x => x.IsSelected && x.Id != model.Dish.Id).Count(); if ((model.Portion.GarnishList.Any(x => x.IsSelected) && model.Portion.SaladList.Any(x => x.IsSelected && x.Id != model.Dish.Id)) || (!model.Portion.GarnishList.Any(x => x.IsSelected) && countSaladSelected >= 2)) { await _userDialog.AlertAsync(YouCanSelectOnlyOneSaladInThisPortition); } else { model.Dish.IsSelected = !model.Dish.IsSelected; var selectedSalad = model.Portion.SaladList.Where(x => x.IsSelected).ToList(); if (selectedSalad.Count() == 1) { model.Portion.PortionInfo.FirstSaladName = model.Portion.IsDuplicate ? DuplicatePrefix + selectedSalad.First().Name : selectedSalad.First().Name; model.Portion.PortionInfo.IsFirstSaladVisible = model.Dish.IsSelected; model.Portion.PortionInfo.IsSecondSaladVisible = !model.Dish.IsSelected; } else if (selectedSalad.Count() == 2) { model.Portion.PortionInfo.FirstSaladName = model.Portion.IsDuplicate ? DuplicatePrefix + selectedSalad.First().Name : selectedSalad.First().Name; model.Portion.PortionInfo.IsFirstSaladVisible = model.Dish.IsSelected; model.Portion.PortionInfo.SecondSaladName = model.Portion.IsDuplicate ? DuplicatePrefix + selectedSalad.Last().Name : selectedSalad.Last().Name; model.Portion.PortionInfo.IsSecondSaladVisible = model.Dish.IsSelected; } else { model.Portion.PortionInfo.IsFirstSaladVisible = model.Dish.IsSelected; model.Portion.PortionInfo.IsSecondSaladVisible = model.Dish.IsSelected; } SetPriceForPortition(model); CalculateTotolPrice(); } }