Esempio n. 1
0
        public async Task <CreateOrderResponse> CreateOrder(
            string urlBase,
            string accessToken,
            int address,
            CartDataService listCart
            )
        {
            try
            {
                var request = JsonConvert.SerializeObject(listCart);
                var content = new StringContent(
                    request, Encoding.UTF8,
                    "application/json");
                var client = new HttpClient();
                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue("Bearer", accessToken);
                client.BaseAddress = new Uri(urlBase);
                var response = await client.PostAsync("/api/products/create-order/address/" + address, content);

                var resultJSON = await response.Content.ReadAsStringAsync();

                var result = JsonConvert.DeserializeObject <CreateOrderResponse>(resultJSON);

                return(result);
            }
            catch
            {
                return(null);
            }
        }
        // { "tokenData" , "oGeDb2sML1YU8EcNOKsLHurG/H86MFoAws/cb7+1FUY="},

        #region Constructor
        public CheckoutPageViewModel(ProfileDataService userDataService, CartDataService cartDataService,
                                     CatalogDataService catalogDataService)
        {
            ButtonActive            = true;
            this.userDataService    = userDataService;
            this.cartDataService    = cartDataService;
            this.catalogDataService = catalogDataService;
            var app = Application.Current as App;

            DeliveryAddress    = new ObservableCollection <Address>();
            PaymentModes       = new ObservableCollection <Payment>();
            MinimumOrderAmount = (double)app.MinimumOrderAmount;
            Device.BeginInvokeOnMainThread(() =>
            {
                FetchPaymentOptions();
                FetchCartList();
                GetPaymentAndPriceMessage();
                GetPaymentCredentials();
                CheckLocationPermissions();
            });
            EditCommand           = new Command(EditClicked);
            AddAddressCommand     = new Command(AddAddressClicked);
            PlaceOrderCommand     = new Command(PlaceOrderClicked);
            PaymentOptionCommand  = new Command(PaymentOptionClicked);
            ApplyCouponCommand    = new Command(ApplyCouponClicked);
            AddressChanged        = new Command(addressChangedClicked);
            DeliveryOptionCommand = new Command(GetSelectedDeliveryAddressId);
            StateChangedCommand   = new Command(GetSelectedPaymentOption);
            //Task.Run(() => CheckLocationPermissions());
        }
Esempio n. 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here

            SetContentView(Resource.Layout.CartView);

            _cartDataService      = new CartDataService();
            _cartListView         = FindViewById <ListView>(Resource.Id.cartListView);
            _cartItems            = _cartDataService.GetCart().CartItems;
            _cartListView.Adapter = new CartAdapter(this, _cartItems);
        }
Esempio n. 4
0
        private async void CalculateDelivery()
        {
            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    connection.Message,
                    "Aceptar");

                return;
            }

            var mainViewModel = MainViewModel.GetInstance();
            var data          = new CartDataService();

            data.Products = mainViewModel.CartList;


            var response = await this.apiService.CalculateDelivery(
                "https://thenuap.com",
                mainViewModel.User.api_token,
                data);

            if (response == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Ha ocurrido un error",
                    "Aceptar");

                return;
            }

            if (response.Errors != null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    response.Errors.First().Detail,
                    "Aceptar");

                return;
            }

            this.Delivery = response.Data.Discount;
        }
Esempio n. 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.CartView);

            cartDataService = new CartDataService();

            FindViews();

            cartItems            = cartDataService.GetCart().CartItems;
            cartListView.Adapter = new CartAdapter(this, cartItems);

            BindData();

            HandleEvents();
        }
Esempio n. 6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.CartView);

            cartDataService = new CartDataService();

            cartListView = FindViewById <ListView>(Resource.Id.cartListView);

            var orderButton = FindViewById <Button>(Resource.Id.placeOrderButton);

            orderButton.Click += OrderButton_Click;

            cartItems            = cartDataService.GetCart().CartItems;
            cartListView.Adapter = new CartAdapter(this, cartItems);
        }
Esempio n. 7
0
        public CartViewPage()
        {
            InitializeComponent();

            cartDataService = new CartDataService();
            Items           = new ObservableCollection <Models.CartItem>();

            MyListView.ItemsSource = cartDataService.GetCart().CartItems;

            MyListView.HasUnevenRows = true;

            TotalLabel.Text = cartDataService.GetCartTotal().ToString("C2");

            CheckoutButton.Clicked += CheckoutButton_Clicked;

            ContinueOrderingButton.Clicked += ContinueOrderingButton_Clicked;
        }
Esempio n. 8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.CheckoutView);

            dataService = new CartDataService();

            FindViews();

            BindData();

            HandleEvents();

            Spinner stateSpinner = FindViewById <Spinner>(Resource.Id.stateSpinner);
            var     adapter      = new ArrayAdapter <string>(this, Resource.Layout.list_item, ResourceHelper.StateList);

            stateSpinner.Adapter = adapter;
        }
Esempio n. 9
0
        private void RegisterIoc(IServiceCollection services)
        {
            services.AddSingleton <IContextFactory>(new ContextFactory());

            var productDataService = new ProductDataService();

            services.AddSingleton <IProductObservable>(productDataService);
            services.AddSingleton <IProductDataService>(productDataService);

            services.AddSingleton <IProductDbService, ProductDbService>();
            services.AddSingleton <IProductPublishService, ProductPublishService>();


            var cartDataService = new CartDataService();

            services.AddSingleton <ICartObservable>(cartDataService);
            services.AddSingleton <ICartDataService>(cartDataService);

            services.AddSingleton <ICartDbService, CartDbService>();
            services.AddSingleton <ICartPublishService, CartPublishService>();
        }
Esempio n. 10
0
 public CartDataSource()
 {
     cartDataService = new CartDataService();
     cartItems       = cartDataService.GetCart().CartItems;
 }
Esempio n. 11
0
        public void AddToCart(Deal deal, int amount)
        {
            CartDataService cartDataService = new CartDataService();

            cartDataService.AddCartItem(deal, amount);
        }
Esempio n. 12
0
        public void AddToCart(Pho pho, int amount)
        {
            CartDataService cartDataService = new CartDataService();

            cartDataService.AddCartItem(pho, amount);
        }
Esempio n. 13
0
        private void AddToCart(Models.MenuItem item, int amount, double price)
        {
            CartDataService cartDataService = new CartDataService();

            cartDataService.AddCartItem(item, amount, price);
        }
Esempio n. 14
0
 private void OnAddToCart(object obj)
 {
     CartDataService.AddCartItem(SelectedBurger, Amount);
 }
        public void AddToCart(HotDog hotDog, int amount)
        {
            CartDataService cartDataService = new CartDataService();

            cartDataService.AddCartItem(hotDog, amount);
        }
Esempio n. 16
0
        private async void CreateOrder()
        {
            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    connection.Message,
                    "Aceptar");

                return;
            }

            var mainViewModel = MainViewModel.GetInstance();
            var data          = new CartDataService();

            data.Products = mainViewModel.CartList;

            var response = await this.apiService.CreateOrder(
                "https://thenuap.com",
                mainViewModel.User.api_token,
                19,
                data);

            if (response == null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    "Ha ocurrido un error",
                    "Aceptar");

                return;
            }

            if (response.Errors != null)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Error",
                    response.Errors.First().Detail,
                    "Aceptar");

                return;
            }

            List <int> orders = response.Data.Orders;
            string     url    = "https://thenuap.com/payment-gateway?";
            string     user   = "******" + mainViewModel.User.id;
            int        count  = 0;

            foreach (var item in orders)
            {
                url += "orders[" + count + "]=" + item + "&";
                count++;
            }

            url += user;

            mainViewModel.PaymentGateway = new PaymentGatewayViewModel(url);
            await Application.Current.MainPage.Navigation.PushAsync(new PaymentGatewayPage());
        }
Esempio n. 17
0
 private void InitializeData()
 {
     CartItems = CartDataService.GetCart().CartItems.ToObservableCollection();
 }