public PlaceOrderPage(string comment, RestaurantDetailPage restaurantDetailPage, ExtendedAddress serviceAddress)
        {
            RestaurantDetailPage = restaurantDetailPage;
            mServiceAddress      = serviceAddress;

            InitializeComponent();

            mAppServices = DependencyService.Get <IAppServices>();

            this.Title = RestaurantDetailPage.Title;

            var listMenuItemViews = RestaurantDetailPage.ListMenuItemViews.Values.SelectMany(t => t);
            var listMenuGroupModifierItemSelected = listMenuItemViews.SelectMany(t => t.ListMenuGroupModifierItemSelected).ToList();

            SetupCreditCardFields();

            ButtonCheckout.Clicked += async(sender, e) =>
            {
                if (!cvvValidator.IsValid || !postalCodeValidator.IsValid || string.IsNullOrEmpty(creditCardNumberEntry.Text))
                {
                    return;
                }

                IsBusy = true;

                CreditCardData CardSelected = await SetupCreditCard();

                if (CardSelected != null)
                {
                    IsPauseTrigger = true;
                    var id = 0;

                    this.ButtonCheckout.Text = AppResources.PlacingOrder;
                    var totalPrice = LabelTotal.Text;
                    var serviceFee = LabelServiceFee.Text;
                    var salesTax   = LabelSalesTax.Text;

                    var scheduledService = new ColonyConcierge.APIData.Data.ScheduledRestaurantService();

                    await Task.Run(() =>
                    {
                        try
                        {
                            if (Services.FirstOrDefault() == null)
                            {
                                throw new Exception(AppResources.CanNotFoundService);
                            }

                            var paymentAccountData            = CardSelected;
                            scheduledService.PaymentMethodID  = paymentAccountData.ID;
                            scheduledService.Delivery         = restaurantDetailPage.IsDeliverySelected;
                            scheduledService.FrontEndSubtotal = SubPrice;
                            scheduledService.FrontEndTaxes    = SalesTax;
                            scheduledService.DiscountCodes    = discountEntry.Text;

                            scheduledService.RestaurantLocationID = restaurantDetailPage.RestaurantVM.LocationId;
                            scheduledService.Tip = Tips;
                            scheduledService.SpecialInstructions = comment;
                            scheduledService.ServiceID           = Services.FirstOrDefault().ID;

                            var menuIds = RestaurantDetailPage.ListMenuItemViews.Values.SelectMany(t => t)
                                          .SelectMany(t => t.ListMenuGroupModifierItemSelected)
                                          .Select(s => s.MenuItemView.RestaurantMenuItem.MenuId).Distinct().ToList();
                            var timeslots = restaurantDetailPage.RefreshMenuAvailables.Where((arg) => restaurantDetailPage.GetDateTimeRestaurantFromLocal(arg.StartTime.Time) == restaurantDetailPage.SelectedDate);
                            var timeslot  = timeslots
                                            .Where(s =>
                            {
                                return(!menuIds.Except(s.RelatedMenuIDs).Any());
                            }).FirstOrDefault();

                            if (timeslot != null)
                            {
                                scheduledService.SlotID = timeslot.ID;
                            }

                            scheduledService.ServiceDate    = new SimpleDate(restaurantDetailPage.SelectedDate.Year, restaurantDetailPage.SelectedDate.Month, restaurantDetailPage.SelectedDate.Day);
                            scheduledService.ServiceAddress = mServiceAddress;
                            if (restaurantDetailPage.GroupedDeliveryDestination != null)
                            {
                                scheduledService.DestinationID = restaurantDetailPage.GroupedDeliveryDestination.ID;
                            }

                            foreach (var menuGroupModifierItemSelected in listMenuGroupModifierItemSelected)
                            {
                                ScheduledRMenuItem scheduledRMenuItem  = new ScheduledRMenuItem();
                                scheduledRMenuItem.Quantity            = menuGroupModifierItemSelected.Quantity;
                                scheduledRMenuItem.DisplayName         = menuGroupModifierItemSelected.MenuItemView.RestaurantMenuItem.DisplayName;
                                scheduledRMenuItem.FrontEndPrice       = menuGroupModifierItemSelected.Price;
                                scheduledRMenuItem.RelatedMenuID       = menuGroupModifierItemSelected.MenuItemView.RestaurantMenuItem.MenuId;
                                scheduledRMenuItem.RelatedMenuItemID   = menuGroupModifierItemSelected.MenuItemView.RestaurantMenuItem.Id;
                                scheduledRMenuItem.SpecialInstructions = menuGroupModifierItemSelected.Comment;

                                foreach (var rMenuGroupModifierVM in menuGroupModifierItemSelected.ListRMenuGroupModifierVM)
                                {
                                    var menuModifiers = rMenuGroupModifierVM.MenuModifiers.Where(t => t.IsSelected).ToList();
                                    foreach (var menuModifier in menuModifiers)
                                    {
                                        var scheduledRMenuItemModifier              = new ScheduledRMenuItemModifier();
                                        scheduledRMenuItemModifier.DisplayName      = menuModifier.MenuModifier.DisplayName;
                                        scheduledRMenuItemModifier.Quantity         = menuModifier.Quantity;
                                        scheduledRMenuItemModifier.RelatedModiferID = menuModifier.MenuModifier.ID;
                                        scheduledRMenuItem.AppliedModifiers.Add(scheduledRMenuItemModifier);
                                        var subMenuModifiers = menuModifier.SubMenuModifiers.Where(t => t.IsSelected).ToList();
                                        foreach (var subMenuModifier in subMenuModifiers)
                                        {
                                            var scheduledRMenuSubItemModifier              = new ScheduledRMenuItemModifier();
                                            scheduledRMenuSubItemModifier.DisplayName      = subMenuModifier.MenuModifier.DisplayName;
                                            scheduledRMenuSubItemModifier.Quantity         = subMenuModifier.Quantity;
                                            scheduledRMenuSubItemModifier.RelatedModiferID = subMenuModifier.MenuModifier.ID;
                                            scheduledRMenuItem.AppliedModifiers.Add(scheduledRMenuSubItemModifier);
                                        }
                                    }
                                }
                                scheduledService.Items.Add(scheduledRMenuItem);
                            }

                            //id = Shared.APIs.IUsers.AddScheduledService(Shared.UserId, scheduledService);
                            Shared.APIs.IRestaurantBusiness.PlaceCustomOrder(Shared.RestaurantLocation, new CustomRestaurantOrderRequest
                            {
                                CustomerEmail         = "*****@*****.**",
                                CustomerFirstName     = "Ted",
                                CustomerLastName      = "Lindström",
                                CustomerPhoneNumber   = "555-555-1212",
                                WrappedServiceRequest = scheduledService
                            });
                        }
                        catch (Exception ex)
                        {
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                var message = string.IsNullOrEmpty(ex.Message) ? AppResources.SomethingWentWrong : ex.Message;
                                await Utils.ShowErrorMessage(message, 5);
                            });
                        }
                    }).ContinueWith(t =>
                    {
                        if (id > 0)
                        {
                            var notificator = DependencyService.Get <IToastNotificator>();
                            notificator.Notify(ToastNotificationType.Success, AppResources.PlaceOrder, AppResources.YourOrderSuccessfully, TimeSpan.FromSeconds(2));
                            var pages = Navigation.NavigationStack.Reverse().Skip(1).ToList();
                            Navigation.PopAsync(true).ConfigureAwait(false);
                        }
                        else
                        {
                            IsPauseTrigger = false;
                        }
                        this.ButtonCheckout.Text = AppResources.PlaceOrder;
                        IsBusy = false;
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    IsBusy = false;
                }
            };

            SubPrice = 0;
            foreach (var menuGroupModifierItemSelected in listMenuGroupModifierItemSelected)
            {
                menuGroupModifierItemSelected.UpdatePrice();
                SubPrice += menuGroupModifierItemSelected.Price;
            }
            LabelSubtotal.Text = "$" + SubPrice.ToString("0.00");

            calculateTax();

            PickerTips.SelectedIndexChanged += (sender, e) =>
            {
                if (PickerTips.SelectedIndex >= 0)
                {
                    if (PickerTips.Items[PickerTips.SelectedIndex] == AppResources.Other)
                    {
                        EntryServiceTips.IsEnabled             = true;
                        this.EntryServiceTips.NeedShowKeyboard = true;
                        Tips = 0;
                        decimal.TryParse(this.EntryServiceTips.Text, out Tips);
                    }
                    else
                    {
                        decimal percent = 0;
                        decimal.TryParse(PickerTips.Items[PickerTips.SelectedIndex].TrimEnd(new char[] { '%', ' ' }), out percent);
                        Tips = SubPrice * percent / 100;
                        EntryServiceTips.Text      = Math.Round(Tips, 2).ToString("0.00");
                        EntryServiceTips.IsEnabled = false;
                        //decimal.TryParse(this.EntryServiceTips.Text, out Tips);
                    }
                }
            };
            PickerTips.SelectedIndex = 0;

            EntryServiceTips.TextChanged += (sender, e) =>
            {
                if (PickerTips.SelectedIndex >= 0)
                {
                    if (PickerTips.Items[PickerTips.SelectedIndex] == AppResources.Other)
                    {
                        EntryServiceTips.IsEnabled             = true;
                        this.EntryServiceTips.NeedShowKeyboard = true;
                        Tips = 0;
                        decimal.TryParse(this.EntryServiceTips.Text, out Tips);
                    }
                    else
                    {
                        decimal percent = 0;
                        decimal.TryParse(PickerTips.Items[PickerTips.SelectedIndex].TrimEnd(new char[] { '%', ' ' }), out percent);
                        Tips = SubPrice * percent / 100;
                        EntryServiceTips.Text      = Math.Round(Tips, 2).ToString("0.00");
                        EntryServiceTips.IsEnabled = false;
                    }
                }
                UpdatePrice();
            };

            ButtonCheckout.Text = AppResources.PlaceOrder;
            LabelTotal.Text     = AppResources.Calculating;
        }
        public MyCartPage(RestaurantDetailPage restaurantDetailPage)
        {
            RestaurantDetailPage = restaurantDetailPage;

            InitializeComponent();

            NavigationPage.SetBackButtonTitle(this, AppResources.Back);

            var listMenuItemViews = RestaurantDetailPage.ListMenuItemViews.Values.SelectMany(t => t);

            listMenuGroupModifierItemSelected = listMenuItemViews
                                                .SelectMany(t => t.ListMenuGroupModifierItemSelected)
                                                .ToList();

            if (listMenuGroupModifierItemSelected.Count == 0)
            {
                ButtonCheckout.IsEnabled = false;
            }

            var cartItemsSource = new ObservableCollection <CartMenuGroupModifierItemViewModel>();
            var deleteAction    = new Action <CartMenuGroupModifierItemViewModel>((t) =>
            {
                cartItemsSource.Remove(t);
                listMenuGroupModifierItemSelected.Remove(t.Model);
                foreach (var listMenuItemView in listMenuItemViews)
                {
                    listMenuItemView.ListMenuGroupModifierItemSelected.Remove(t.Model);
                    listMenuItemView.IsSelected = listMenuItemView.ListMenuGroupModifierItemSelected.Count > 0;
                }
                UpdatePrice();

                if (listMenuGroupModifierItemSelected.Count == 0)
                {
                    ButtonCheckout.IsEnabled = false;
                }
            });
            var cartItems = listMenuGroupModifierItemSelected.Select(t => new CartMenuGroupModifierItemViewModel(t, deleteAction)).ToList();

            foreach (var cartItem in cartItems)
            {
                cartItemsSource.Add(cartItem);
            }
            ListViewCarts.ItemsSource = cartItemsSource;
            UpdatePrice();

            ListViewCarts.ItemTapped += (sender, e) =>
            {
                CartMenuGroupModifierItemViewModel cartMenuGroupModifierItem = e.Item as CartMenuGroupModifierItemViewModel;
                ListViewCarts.SelectedItem = null;
                RestaurantMenuItemModifierPage restaurantMenuItemModifierPage = new RestaurantMenuItemModifierPage(RestaurantDetailPage.RestaurantVM, cartMenuGroupModifierItem.Model.MenuItemView, cartMenuGroupModifierItem.Model);
                restaurantMenuItemModifierPage.Saved += (obj) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        obj.RaiseAllOnChanged();
                        UpdatePrice();
                    });
                };
                Utils.PushAsync(Navigation, restaurantMenuItemModifierPage, true);
            };

            ButtonCheckout.Clicked += async(sender, e) =>
            {
                UserFacade userFacade = new UserFacade();
                try
                {
                    var isSucceed = false;
                    this.IsBusy = true;
                    if (restaurantDetailPage.GroupedDeliveryDestination != null)
                    {
                        Shared.LocalAddress = restaurantDetailPage.GroupedDeliveryDestination.Address;
                    }

                    var serviceAddress = new AddressFacade().GetUserAddress();
                    var myCartPage     = new PlaceOrderPage(String.Empty, RestaurantDetailPage, serviceAddress);
                    await Utils.PushAsync(Navigation, myCartPage, true);

                    this.IsBusy = false;
                }
                catch (Exception ex)
                {
                    this.IsBusy = false;
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        var message = string.IsNullOrEmpty(ex.Message) ? AppResources.SomethingWentWrong : ex.Message;
                        await Utils.ShowErrorMessage(message, 5);
                    });
                }
            };
        }