Пример #1
0
        public PortionModel GetPortion(int id)
        {
            PortionModel portionModel = new PortionModel();
            var          portion      = portionRepository.GetById(id);

            if (portion != null)
            {
                portionModel.Id              = portion.Id;
                portionModel.WaterGram       = portion.WaterGram;
                portionModel.CoffeeBeansGram = portion.CoffeeBeansGram;
                portionModel.SugarGram       = portion.SugarGram;
            }
            return(portionModel);
        }
Пример #2
0
        public Frame GetFrameIsDuplicate(PortionModel model)
        {
            var frame = new Frame()
            {
                Margin = new Thickness(10, 10)
            };

            var stackTemplate = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal
            };

            var checkImage = new Image()
            {
                WidthRequest   = 20,
                HeightRequest  = 20,
                BindingContext = model
            };

            checkImage.SetBinding(Image.SourceProperty, new Binding(nameof(model.IsDuplicate), BindingMode.OneWay, new IsAvailableUpdateToCheckBoxIconConverter(Constants.CheckboxOnImageSource, Constants.CheckboxOffImageSource)));

            var checkClickableView = new ClickableContentView()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                CommandParameter  = model,
                BindingContext    = model,
                Content           = checkImage
            };

            checkClickableView.SetBinding(ClickableContentView.CommandProperty, nameof(model.ChangeCheckboxIsDuplicateCommand));

            var titleLable = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = "Дублировать порцию",
            };

            stackTemplate.Children.Add(checkClickableView);
            stackTemplate.Children.Add(titleLable);

            frame.Content = stackTemplate;
            return(frame);
        }
Пример #3
0
        public async Task CreatePortitionAsync()
        {
            PortionModel portitionModel = new PortionModel();

            portitionModel.GarnishList = new ObservableCollection <DishModel>(_dishes.Where(x => x.CategoryType == DishCategory.Garnish).Select(x => CreateNewModel(x)));
            portitionModel.MeatList    = new ObservableCollection <DishModel>(_dishes.Where(x => x.CategoryType == DishCategory.Meat).Select(x => CreateNewModel(x)));
            portitionModel.SaladList   = new ObservableCollection <DishModel>(_dishes.Where(x => x.CategoryType == DishCategory.Salad).Select(x => CreateNewModel(x)));
            portitionModel.BreadList   = new ObservableCollection <DishModel>(_dishes.Where(x => x.CategoryType == DishCategory.Bread).Select(x => CreateNewModel(x)));

            portitionModel.ChangeVisiblePortitionCommand    = new Command <PortionModel>(OnChangeVisiblePortitionCommandAsync);
            portitionModel.ChangeCheckboxIsDuplicateCommand = new Command <PortionModel>(OnChangeCheckboxIsDuplicateCommandAsync);
            portitionModel.DeletePortionCommand             = new Command <PortionModel>(OnDeletePortionCommandAsync);

            portitionModel.PortionInfo           = new OrderDishModel();
            portitionModel.PortionInfo.Portition = portitionModel;

            portitionModel.PriceStr = ((decimal)DishOrderPriceType.UsualPrice).ToString() + PricePostFix;
            portitionModel.Price    = (decimal)DishOrderPriceType.UsualPrice;

            foreach (var dish in portitionModel.GarnishList)
            {
                dish.ChangeCheckboxCommand = new Command <PortionWithCheckDish>(OnChangeCheckboxGarnishCommandAsync);
            }

            foreach (var dish in portitionModel.MeatList)
            {
                dish.ChangeCheckboxCommand = new Command <PortionWithCheckDish>(OnChangeCheckboxMeatCommandAsync);
            }

            foreach (var dish in portitionModel.SaladList)
            {
                dish.ChangeCheckboxCommand = new Command <PortionWithCheckDish>(OnChangeCheckboxSaladCommandAsync);
            }

            foreach (var dish in portitionModel.BreadList)
            {
                dish.ChangeCheckboxCommand = new Command <PortionWithCheckDish>(OnChangeCheckboxBreadCommandAsync);
            }

            PortionModels.Add(portitionModel);
            CalculateTotolPrice();
        }
Пример #4
0
 private async void OnChangeCheckboxIsDuplicateCommandAsync(PortionModel model)
 {
     model.IsDuplicate = !model.IsDuplicate;
     if (model.IsDuplicate)
     {
         model.PortionInfo.GarnishName     = model.PortionInfo.IsGarnishVisible ? DuplicatePrefix + model.PortionInfo.GarnishName : string.Empty;
         model.PortionInfo.MeatName        = model.PortionInfo.IsMeatVisible ? DuplicatePrefix + model.PortionInfo.MeatName : string.Empty;
         model.PortionInfo.FirstSaladName  = model.PortionInfo.IsFirstSaladVisible ? DuplicatePrefix + model.PortionInfo.FirstSaladName : string.Empty;
         model.PortionInfo.SecondSaladName = model.PortionInfo.IsSecondSaladVisible ? DuplicatePrefix + model.PortionInfo.SecondSaladName : string.Empty;
         model.PortionInfo.BreadName       = model.PortionInfo.IsBreadVisible ? DuplicatePrefix + model.PortionInfo.BreadName : string.Empty;
     }
     else
     {
         model.PortionInfo.GarnishName    = model.PortionInfo.GarnishName.Replace(DuplicatePrefix, "");
         model.PortionInfo.MeatName       = model.PortionInfo.MeatName.Replace(DuplicatePrefix, "");
         model.PortionInfo.FirstSaladName = model.PortionInfo.FirstSaladName.Replace(DuplicatePrefix, "");
         model.PortionInfo.BreadName      = model.PortionInfo.BreadName.Replace(DuplicatePrefix, "");
     }
     CalculateTotolPrice();
 }
Пример #5
0
        private ContentView GetView(PortionModel model)
        {
            var mainContent = new ContentView();
            var template    = new StackLayout()
            {
                Orientation = StackOrientation.Vertical
            };

            var templateShowPortition = new StackLayout()
            {
                Orientation     = StackOrientation.Horizontal,
                BackgroundColor = Color.LightCoral,
                HeightRequest   = 40,
                Margin          = new Thickness(10)
            };

            var titleShowPortitionLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text = "Порция",
            };

            var showPortitionImage = new Image()
            {
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model,
                Margin            = new Thickness(0, 0, 30, 0)
            };

            showPortitionImage.SetBinding(Image.SourceProperty, new Binding(nameof(model.IsVisible), BindingMode.OneWay, new IsAvailableUpdateToCheckBoxIconConverter(Constants.MoreImageSource, Constants.LessImageSource)));

            templateShowPortition.Children.Add(titleShowPortitionLabel);
            templateShowPortition.Children.Add(showPortitionImage);

            var contentPortitionView = new ContentView()
            {
                BindingContext = model,
            };
            var templatePotition = new StackLayout()
            {
                BindingContext = model
            };

            contentPortitionView.SetBinding(ContentView.IsVisibleProperty, new Binding(nameof(model.IsVisible)));

            var showPortitionClickableView = new ClickableContentView()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Content           = templateShowPortition,
                CommandParameter  = model,
                BindingContext    = model
            };

            showPortitionClickableView.SetBinding(ClickableContentView.CommandProperty, nameof(model.ChangeVisiblePortitionCommand));


            templatePotition.Children.Add(GetDishFream(model, "side_dish", "Гарнир", DishCategory.Garnish));
            templatePotition.Children.Add(GetDishFream(model, "meat", "Мясное", DishCategory.Meat));
            templatePotition.Children.Add(GetDishFream(model, "salad", "Салат", DishCategory.Salad));
            templatePotition.Children.Add(GetDishFream(model, "bread", "Хлеб", DishCategory.Bread));
            templatePotition.Children.Add(GetFrameIsDuplicate(model));


            template.Children.Add(showPortitionClickableView);
            contentPortitionView.Content = templatePotition;
            template.Children.Add(contentPortitionView);
            mainContent.Content = template;
            return(mainContent);
        }
Пример #6
0
        private StackLayout GetDishMenuView(ObservableCollection <DishModel> dishModels, PortionModel portition)
        {
            var template = new StackLayout()
            {
                Orientation = StackOrientation.Vertical
            };

            foreach (var item in dishModels)
            {
                template.Children.Add(GetDishItemView(new PortionWithCheckDish()
                {
                    Portion = portition,
                    Dish    = item
                }));
            }
            return(template);
        }
Пример #7
0
        private Frame GetDishFream(PortionModel model, string imageSource, string titleLable, DishCategory category)
        {
            var frame = new Frame()
            {
                Margin = new Thickness(10, 10),
            };

            var template = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
            };

            var header = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal,
                Margin      = new Thickness(0, 0, 0, 10)
            };

            var titleImage = new Image()
            {
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Source            = imageSource,
            };

            var titleLabel = new Label()
            {
                Text = titleLable,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };

            header.Children.Add(titleImage);
            header.Children.Add(titleLabel);

            var itemSource = new ObservableCollection <DishModel>();

            template.Children.Add(header);

            switch (category)
            {
            case DishCategory.Garnish:
                itemSource = model.GarnishList;

                template.Children.Add(GetDishMenuView(itemSource, model));

                var sauceTemplete = new StackLayout()
                {
                    Orientation = StackOrientation.Horizontal
                };

                var sauceTitleLabel = new Label()
                {
                    HorizontalOptions = LayoutOptions.StartAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    Text = "Подлива"
                };

                var sauceSwith = new Switch()
                {
                    HorizontalOptions = LayoutOptions.EndAndExpand,
                    VerticalOptions   = LayoutOptions.CenterAndExpand,
                    BindingContext    = model,
                    BackgroundColor   = Color.LightGreen
                };
                sauceSwith.SetBinding(Switch.IsToggledProperty, new Binding(nameof(model.IsToggled)));

                sauceTemplete.Children.Add(sauceTitleLabel);
                sauceTemplete.Children.Add(sauceSwith);

                template.Children.Add(sauceTemplete);
                break;

            case DishCategory.Meat:
                itemSource = model.MeatList;
                template.Children.Add(GetDishMenuView(itemSource, model));

                break;

            case DishCategory.Salad:
                itemSource = model.SaladList;
                template.Children.Add(GetDishMenuView(itemSource, model));

                break;

            case DishCategory.Bread:
                itemSource = model.BreadList;
                template.Children.Add(GetDishMenuView(itemSource, model));

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            //addDishStackLayout.ItemsSource = itemSource;
            frame.Content = template;
            return(frame);
        }
Пример #8
0
        private ContentView GetPortitionView(PortionModel model)
        {
            var mainContant = new ContentView();
            var template    = new StackLayout()
            {
                Orientation = StackOrientation.Vertical,
                Margin      = new Thickness(0, 10)
            };

            var titleTemplate = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal
            };

            var titleLabel = new Label()
            {
                Text              = "Порция:",
                TextColor         = Color.Black,
                FontAttributes    = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand
            };

            var checkImage = new Image()
            {
                WidthRequest      = 20,
                HeightRequest     = 20,
                Source            = "delete",
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model
            };

            var checkClickableView = new ClickableContentView()
            {
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                CommandParameter  = model,
                BindingContext    = model,
                Content           = checkImage
            };

            checkClickableView.SetBinding(ClickableContentView.CommandProperty, nameof(model.DeletePortionCommand));

            titleTemplate.Children.Add(titleLabel);
            titleTemplate.Children.Add(checkClickableView);

            var bodyTemplate = new StackLayout()
            {
                Orientation = StackOrientation.Vertical
            };


            var garnishLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model.PortionInfo,
            };

            garnishLabel.SetBinding(Label.TextProperty, new Binding(nameof(model.PortionInfo.GarnishName)));
            garnishLabel.SetBinding(Label.IsVisibleProperty, new Binding(nameof(model.PortionInfo.IsGarnishVisible)));

            var meatLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model.PortionInfo
            };

            meatLabel.SetBinding(Label.TextProperty, new Binding(nameof(model.PortionInfo.MeatName)));
            meatLabel.SetBinding(Label.IsVisibleProperty, new Binding(nameof(model.PortionInfo.IsMeatVisible)));

            var firstSaladLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model.PortionInfo
            };

            firstSaladLabel.SetBinding(Label.TextProperty, new Binding(nameof(model.PortionInfo.FirstSaladName)));
            firstSaladLabel.SetBinding(Label.IsVisibleProperty, new Binding(nameof(model.PortionInfo.IsFirstSaladVisible)));

            var secondSaladLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model.PortionInfo
            };

            secondSaladLabel.SetBinding(Label.TextProperty, new Binding(nameof(model.PortionInfo.SecondSaladName)));
            secondSaladLabel.SetBinding(Label.IsVisibleProperty, new Binding(nameof(model.PortionInfo.IsSecondSaladVisible)));

            var breadLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model.PortionInfo
            };

            breadLabel.SetBinding(Label.TextProperty, new Binding(nameof(model.PortionInfo.BreadName)));
            breadLabel.SetBinding(Label.IsVisibleProperty, new Binding(nameof(model.PortionInfo.IsBreadVisible)));

            var sauseLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                BindingContext    = model,
                Text = "Подлива"
            };

            sauseLabel.SetBinding(Label.IsVisibleProperty, new Binding(nameof(model.IsToggled)));

            var sumTempalte = new StackLayout()
            {
                Orientation = StackOrientation.Horizontal
            };
            var sumLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Text           = "Сумма:",
                TextColor      = Color.Black,
                FontAttributes = FontAttributes.Bold
            };

            var dublePriceLabel = new Label()
            {
                HorizontalOptions       = LayoutOptions.End,
                VerticalOptions         = LayoutOptions.CenterAndExpand,
                HorizontalTextAlignment = TextAlignment.End,
                Text           = "2x",
                BindingContext = model
            };

            dublePriceLabel.SetBinding(Label.IsVisibleProperty, new Binding(nameof(model.IsDuplicate)));

            var priceLabel = new Label()
            {
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                TextColor         = Color.FromHex("#47cfa5"),
                FontAttributes    = FontAttributes.Bold,
                BindingContext    = model
            };

            priceLabel.SetBinding(Label.TextProperty, new Binding(nameof(model.PriceStr)));

            var commentEntry = new Entry()
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                Placeholder       = "Введите свой коментарий",
                BindingContext    = model.Comment,
                FontSize          = 14
            };

            commentEntry.SetBinding(Entry.TextProperty, new Binding(nameof(model.Comment)));

            sumTempalte.Children.Add(sumLabel);
            sumTempalte.Children.Add(dublePriceLabel);
            sumTempalte.Children.Add(priceLabel);

            bodyTemplate.Children.Add(garnishLabel);
            bodyTemplate.Children.Add(meatLabel);
            bodyTemplate.Children.Add(firstSaladLabel);
            bodyTemplate.Children.Add(secondSaladLabel);
            bodyTemplate.Children.Add(breadLabel);
            bodyTemplate.Children.Add(sauseLabel);
            bodyTemplate.Children.Add(sumTempalte);
            bodyTemplate.Children.Add(commentEntry);

            template.Children.Add(titleTemplate);
            template.Children.Add(bodyTemplate);

            mainContant.Content = template;
            return(mainContant);
        }
Пример #9
0
 private async void OnDeletePortionCommandAsync(PortionModel model)
 {
     PortionModels.Remove(model);
     CalculateTotolPrice();
 }
Пример #10
0
 private async void OnChangeVisiblePortitionCommandAsync(PortionModel model)
 {
     model.IsVisible = !model.IsVisible;
 }