Exemplo n.º 1
0
        public CheckoutPage()
        {
            InitializeComponent();
            var userDataService    = ProfileDataService.Instance;
            var cartDataService    = CartDataService.Instance;
            var catalogDataService = CatalogDataService.Instance;

            BindingContext = viewModel = new CheckoutPageViewModel(userDataService, cartDataService, catalogDataService);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddShippingAddress(CheckoutPageViewModel vm)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            currentUser.ShippingAddress = vm.ShippingAddress;
            await _userManager.UpdateAsync(currentUser);

            return(RedirectToAction("Index", "Checkout"));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckoutPage" /> class.
        /// </summary>
        public CheckoutPage()
        {
            InitializeComponent();
            var userDataService = App.MockDataService
                ? TypeLocator.Resolve <IUserDataService>()
                : DataService.TypeLocator.Resolve <IUserDataService>();
            var cartDataService = App.MockDataService
                ? TypeLocator.Resolve <ICartDataService>()
                : DataService.TypeLocator.Resolve <ICartDataService>();
            var catalogDataService = App.MockDataService
                ? TypeLocator.Resolve <ICatalogDataService>()
                : DataService.TypeLocator.Resolve <ICatalogDataService>();

            BindingContext = new CheckoutPageViewModel(userDataService, cartDataService, catalogDataService);
        }
Exemplo n.º 4
0
        public ActionResult Index(CheckoutPage currentPage)
        {
            //get all item in cards
            var _cartService = new CartService();
            var items        = _cartService.GetCartItems().ToList();
            //get all payment declare in BE
            var checkoutService = new CheckoutService();
            var paymentMethods  = checkoutService.GetPaymentMethods();

            CheckoutPageViewModel model = new CheckoutPageViewModel();

            model.CartItems = items;
            model.PaymentMethodViewModels = paymentMethods;
            return(View(model));
        }
Exemplo n.º 5
0
        public CheckoutPage(Showtime showtime, List <AuditoriumSeat> seats)
        {
            InitializeComponent();

            var connectionString = ConnectionStringBuilder.Build(
                Settings.Default.server,
                Settings.Default.database,
                Settings.Default.user,
                Settings.Default.password);

            var repository = new TicketRepository(connectionString);

            viewModel   = new CheckoutPageViewModel(this, repository, showtime, seats);
            DataContext = viewModel;

            SetUpAnimations();
        }
Exemplo n.º 6
0
        public IActionResult Checkout()
        {
            var userInfo = this.usersService.GetUserInfo(this.User.Identity.Name);
            var cart     = HttpContext.Session.GetObjectFromJson <List <CartViewModel> >(this.User.Identity.Name) ?? new List <CartViewModel>();

            if (cart.Count == 0)
            {
                this.TempData["Error"] = "You dont have any products in cart.";
                return(RedirectToAction(nameof(ProductsController.Index), "Products", new { area = "Shopping" }));
            }

            var model = new CheckoutPageViewModel
            {
                Products   = cart,
                UserInfo   = userInfo.Map <UserInfo, UserInfoViewModel>(),
                UserInfoId = userInfo?.Id.ToString()
            };

            return(View(model));
        }
Exemplo n.º 7
0
        // GET: /<controller>/
        public async Task <IActionResult> Index()
        {
            CheckoutPageViewModel vm = new CheckoutPageViewModel();
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            IEnumerable <ShoppingCart> allSavedProducts = _shoppingCartData.GetAllByUser(currentUser);
            List <Product>             allSavedProduct  = new List <Product>();

            foreach (var item in allSavedProducts)
            {
                item.Product.Quantity = item.Qty;
                vm.Total += item.Product.Quantity * item.Product.Price;
                allSavedProduct.Add(item.Product);
            }
            vm.Products = allSavedProduct;
            if (!string.IsNullOrEmpty(currentUser.ShippingAddress))
            {
                vm.ShippingAddress = currentUser.ShippingAddress;
            }

            return(View(vm));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Checkout(CheckoutPageViewModel model)
        {
            var cart = HttpContext.Session.GetObjectFromJson <List <CartViewModel> >(this.User.Identity.Name) ?? new List <CartViewModel>();

            if (!cart.Any())
            {
                this.TempData["Error"] = "Invalid operation.";
                return(RedirectToAction(nameof(ProductsController.Index), "Products", new { area = "Shopping" }));
            }

            if (!ModelState.IsValid)
            {
                model.Products = cart;

                return(View(model));
            }

            if (!model.IsTermsAccepted)
            {
                ModelState.AddModelError("All", "Terms should be accepted.");
                model.Products = cart;

                return(View(model));
            }

            var userInfo = model.UserInfo.Map <UserInfoViewModel, UserInfo>();

            if (!string.IsNullOrEmpty(model.UserInfoId))
            {
                var check = Guid.TryParse(model.UserInfoId, out Guid parsedId);
                if (!check)
                {
                    this.TempData["Error"] = "Invalid operation, please try again.";
                    return(RedirectToAction(nameof(Checkout)));
                }

                userInfo.Id = parsedId;
            }

            await this.usersService.UpdateUserInfo(userInfo, this.User.Identity.Name);

            var orders = new List <Order>();

            foreach (var product in cart)
            {
                orders.Add(new Order
                {
                    ProductId    = product.Id,
                    ProductName  = product.Name,
                    ProductImage = product.Image,
                    Size         = product.Size,
                    Quantity     = product.Quantity,
                    ProductPrice = product.Price
                });
            }

            try
            {
                await this.ordersService.CreateOrders(orders, this.User.Identity.Name);

                HttpContext.Session.SetObjectAsJson(this.User.Identity.Name, new List <CartViewModel>());
                this.TempData["Success"] = "Orders submitted, please wait for confirmation.";
                return(RedirectToAction(nameof(Index)));
            }
            catch (InvalidOperationException e)
            {
                this.TempData["Error"] = e.Message;
                return(RedirectToAction(nameof(Checkout)));
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeliveryView" /> class.
 /// </summary>
 public DeliveryView()
 {
     this.InitializeComponent();
     BindingContext = new CheckoutPageViewModel();
 }
Exemplo n.º 10
0
        public async Task <IActionResult> PlaceOrder(CheckoutPageViewModel vm)
        {
            //Find UserId
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            //Find User Object
            var currentUser = await _userManager.FindByIdAsync(userId);

            //Find all CartItem and ready to process checkout
            IEnumerable <ShoppingCart> allSavedProducts = _shoppingCartData.GetAllByUser(currentUser);
            //Find all Product Detail by viewing cart
            List <Product> allSavedProduct = new List <Product>();

            foreach (var item in allSavedProducts)
            {
                //Change Item.Product qty to user's intended purchase qty
                item.Product.Quantity = item.Qty;
                //add modified-Qty Product to list of products
                allSavedProduct.Add(item.Product);
            }
            ShoppingOrder newOrder = new ShoppingOrder();

            newOrder.User         = currentUser;
            newOrder.OrderAddress = vm.ShippingAddress;
            _checkoutData.SaveOrder(newOrder);

            foreach (var product in allSavedProduct)
            {
                OrderItem Item = new OrderItem();
                Item.CurrentPrice    = product.Price;
                Item.ProductId       = product.ProductId;
                Item.Qty             = product.Quantity;
                Item.ShoppingOrderId = newOrder.OrderId;
                //Modify Inventory of Product Qty

                product.Quantity -= Item.Qty;
                if (product.Quantity == 0)
                {
                    //If user bought all stocks, change property of availiablity to false
                    product.IsAvailiable = false;
                }
                _productData.EditQty(product);
                _checkoutData.SaveOrderItem(Item);
            }
            //Delete all item in shopping cart
            foreach (var product in allSavedProducts)
            {
                _shoppingCartData.Delete(product);
            }
            var myCharge = new StripeChargeCreateOptions();

            // always set these properties
            int total = (int)vm.Total;

            myCharge.Amount   = total * 100;;
            myCharge.Currency = "usd";

            // set this if you want to
            myCharge.Description = "Charge it like it's hot";

            myCharge.SourceTokenOrExistingSourceId = vm.StripeToken;

            // set this property if using a customer - this MUST be set if you are using an existing source!


            // (not required) set this to false if you don't want to capture the charge yet - requires you call capture later
            myCharge.Capture = true;


            var          StripeKey     = Environment.GetEnvironmentVariable("StripeSecretKey");
            var          chargeService = new StripeChargeService(StripeKey);
            StripeCharge stripeCharge  = chargeService.Create(myCharge);

            return(RedirectToAction("Index", "Cart"));
        }