Exemplo n.º 1
0
        public IActionResult OnGet([FromServices] GetCart getCart,
                                   [FromServices] GetCustomerInformation getCustomerInformation)
        {
            var cart = getCart.Exec();

            if (cart.Count() == 0)
            {
                return(RedirectToPage("/Cart"));
            }

            var information = getCustomerInformation.Exec();

            if (information == null)
            {
                if (_environment.IsDevelopment())
                {
                    CustomerInformation = new CustomerInformationDto
                    {
                        FirstName   = "Toko",
                        LastName    = "Goshadze",
                        Email       = "*****@*****.**",
                        PhoneNumber = "599744894",
                        Address     = "28 Amaghleba street",
                        City        = "Tbilisi",
                        PostCode    = "0105"
                    }
                }
                ;
                return(Page());
            }

            return(RedirectToPage("/Checkout/Payment"));
        }
Exemplo n.º 2
0
        //
        // GET: /Cart/
        public ActionResult GetCart()
        {
            Users user = (Users)Session["User"];

            if (user == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            var            carts    = db.Cart.Where(x => x.ClientId == user.Id).ToList();
            List <GetCart> getCarts = new List <GetCart>();

            ViewBag.TotalPrice = 0;
            foreach (var item in carts)
            {
                GetCart cart = new GetCart();
                cart.Id             = item.Id;
                cart.ProductId      = item.ProductId;
                cart.ClientId       = item.ClientId;
                cart.IsInCart       = item.IsInCart;
                cart.Amount         = item.Amount;
                cart.DatePurchased  = item.DatePurchased;
                cart.Product        = item.Product;
                cart.Users          = item.Users;
                cart.FullPrice      = cart.Amount * cart.Product.Price;
                ViewBag.TotalPrice += cart.FullPrice;
                getCarts.Add(cart);
            }
            return(View(getCarts));
        }
Exemplo n.º 3
0
        public IActionResult GetCartComponent([FromServices] GetCart getCart)
        {
            var totalValue = getCart.Do().Sum(x => x.RealValue * x.Qty);


            return(PartialView("Components/Cart/Small", $"${totalValue}"));
        }
Exemplo n.º 4
0
        public IActionResult GetCartMain([FromServices] GetCart getCart)
        {
            var cart = getCart.Do();


            return(PartialView("_CartPartial", cart));
        }
Exemplo n.º 5
0
        public ActionResult ReduceCartItem(int id)
        {
            GetCart.Reduce(id);
            var responseDTO = _responseService.Create(true, "");

            return(Json(Mapper.Map <ResponseVM>(responseDTO), JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        public IActionResult OnGet(
            [FromServices] GetCart getCart)
        {
            Cart = getCart.Do();

            return(Page());
        }
Exemplo n.º 7
0
        public IActionResult OnGet()
        {
            Cart  = new GetCart(HttpContext.Session, _context).Do();
            Stock = new GetStock(_context).Do();

            return(Page());
        }
Exemplo n.º 8
0
        public IActionResult GetCartComponent([FromServices] GetCart getCart)
        {
            var totalValue = getCart.Do()
                             ?.Sum(x => x?.RealValue * x?.Quantity);

            return(PartialView("Components/Cart/Small", $"{totalValue}$"));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> OnPostAsync(
            string paymentId,
            [FromServices] CreateOrder createOrder,
            [FromServices] GetCart getCart,
            [FromServices] PaymentIntentService paymentIntentService,
            [FromServices] ILogger <Payment> logger)
        {
            var userId = User.GetUserId();
            var cartId = await getCart.Id(userId);

            if (cartId == 0)
            {
                logger.LogWarning($"Cart not found for {userId} with payment id {paymentId}");
                return(RedirectToPage("/Checkout/Error"));
            }

            var payment = await paymentIntentService.CaptureAsync(paymentId);

            if (payment == null)
            {
                logger.LogWarning($"Payment Intent not found {paymentId}");
                return(RedirectToPage("/Checkout/Error"));
            }

            var order = new Domain.Models.Order
            {
                StripeReference = paymentId,
                CartId          = cartId,
            };
            await createOrder.Do(order);

            return(RedirectToPage("/Checkout/Success", new { orderId = order.Id }));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> AddToCart(AddToCart.Request Input)
        {
            Input.UserMark = GetCartUserMark();
            var stockAdded = await new AddToCart(_ctx, _discounts).Do(Input);
            var cart       = new GetCart(_ctx, _discounts).Do(GetCartUserMark());

            return(PartialView("/Pages/Components/Cart/Small.cshtml", cart));
        }
Exemplo n.º 11
0
 public IViewComponentResult Invoke([FromServices] GetCart getCart, string view = "Default")
 {
     if (view == "small")
     {
         var totalValue = _getCart.Do().Sum(x => x.RealValue * x.Qty);
         return(View(view, $"${totalValue}"));
     }
     return(View(_getCart.Do()));
 }
Exemplo n.º 12
0
 public IViewComponentResult Invoke(string view = "Huge")
 {
     if (view == "Smoll")
     {
         var totalValue = new GetCart(HttpContext.Session, _ctx).Do().Sum(x => x.ValueDec * x.Qty);
         return(View(view, $"$ {totalValue}"));
     }
     return(View(view, new GetCart(HttpContext.Session, _ctx).Do()));
 }
Exemplo n.º 13
0
 public IViewComponentResult Invoke(string view = "Default")
 {
     if (view == "Small")
     {
         var totalValue = new GetCart(HttpContext.Session, _ctx).Do().Sum(x => x.RealValue * x.Quantity);
         return(View(view, $"${totalValue}"));
     }
     return(View(view, new GetCart(HttpContext.Session, _ctx).Do()));
 }
Exemplo n.º 14
0
        //public Account account { get; set; }
        //public bool is30dayAccount { get; set; }



        public IActionResult OnGet()
        {
            Cart = new GetCart(_ctx, _discounts).Do(GetCartUserMark());

            //var user = GetUserId();
            //var accountId = _ctx.AccountUsers.FirstOrDefault(x => x.UserId == user);
            //account = _ctx.Accounts.FirstOrDefault(x => x.Id == accountId.AccountId);
            //is30dayAccount = account.ThirtyDayTermApproved;

            return(Page());
        }
Exemplo n.º 15
0
        public async Task <IActionResult> GetCartForComponent([FromServices] GetCart getCart)
        {
            var userId = User?.Claims?.FirstOrDefault(x => x.Type.Equals(ClaimTypes.NameIdentifier))?.Value;

            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest("Cookie Policy not accepted"));
            }

            return(Ok(await getCart.GetCartForComponent(userId)));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Cart()
        {
            // ilk ürün eklendiğinde kullanıcının kartı yoksa yeni cart oluşturacak

            var cart = new GetCart();

            cart.UserName = User.Identity.Name;
            var result = await getCartService.HandleAsync(cart);

            return(View(result.Value));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> OnPostAsync(
            string paymentId,
            [FromServices] CreateOrder createOrder,
            [FromServices] GetCart getCart)
        {
            var order = new Domain.Models.Order
            {
                StripeReference = paymentId,
                CartId          = await getCart.Id(User.GetUserId()),
            };
            await createOrder.Do(order);

            return(RedirectToPage("/Checkout/Success", new { orderId = order.Id }));
        }
Exemplo n.º 18
0
        public async Task <IActionResult> UpdateCart([FromBody] UpdateCartQty.Request Input)
        {
            Input.UserMark = GetCartUserMark();
            var stockadded = await new UpdateCartQty(_ctx).Do(Input);
            var cart       = new GetCart(_ctx, _discounts).Do(GetCartUserMark());

            var cartItems = await RenderViewAsync("Cart/_CartItems", cart, true);

            var cartSummary = await RenderViewAsync("Cart/_CartSummary", cart, true);

            var cartPartial = await RenderViewAsync("Cart/Small", cart, true);

            return(Ok(new { cartItems, cartSummary, cartPartial }));
            //return Ok(new { cartItems, cartSummary, qty = cart.Sum(x => x.Qty) });
        }
Exemplo n.º 19
0
        public IViewComponentResult Invoke(string view = "Default")
        {
            var userId    = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var sessionId = GetSessionId();

            if (view == "Small")
            {
                var cart = new GetCart(_ctx, _discounts).Do((userId, sessionId));

                var totalValue = cart.Sum(x => x.Value * x.Qty);
                var totalItems = cart.Sum(x => x.Qty);

                //return View(view, $"{totalItems}");
                return(View(view, cart));
            }

            return(View(view, new GetCart(_ctx, _discounts).Do((userId, sessionId))));
        }
        public async Task <IActionResult> Do(
            [FromServices] IOptionsMonitor <StripeSettings> optionsMonitor,
            [FromServices] GetCart getCart)
        {
            StripeConfiguration.ApiKey = optionsMonitor.CurrentValue.SecretKey;
            var userId  = User?.Claims?.FirstOrDefault(x => x.Type.Equals(ClaimTypes.NameIdentifier))?.Value;
            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },
                ShippingAddressCollection = new SessionShippingAddressCollectionOptions
                {
                    AllowedCountries = new List <string>
                    {
                        "CA",
                        "GB",
                    },
                },
                LineItems = (await getCart.Do(userId, x => new SessionLineItemOptions
                {
                    Amount = x.Stock.Value,
                    Currency = "gbp",
                    Name = x.Stock.Product.Name,
                    Description = x.Stock.Description,
                    Quantity = x.Qty,
                })).ToList(),
                Mode       = "payment",
                SuccessUrl = "https://localhost:5001/payment/success",
                CancelUrl  = "https://localhost:5001/payment/canceled",

                Metadata = new Dictionary <string, string>
                {
                    { "user_id", userId },
                },
            };

            var service = new SessionService();
            var session = service.Create(options);

            return(Ok(session.Id));
        }
Exemplo n.º 21
0
        public async Task <IActionResult> OnGet(
            [FromServices] IOptionsMonitor <StripeSettings> optionsMonitor,
            [FromServices] GetCart getCart,
            [FromServices] PaymentIntentService paymentIntentService)
        {
            var userId = User.GetUserId();

            StripeConfiguration.ApiKey = optionsMonitor.CurrentValue.SecretKey;

            var cart = await getCart.ByUserId(userId);

            if (cart == null || cart.Products.Count <= 0)
            {
                return(RedirectToPage("/Index"));
            }

            var paymentIntent = await paymentIntentService.CreateAsync(new PaymentIntentCreateOptions
            {
                CaptureMethod = "manual",
                Amount        = cart.Total(),
                Currency      = "gbp",
                ReceiptEmail  = cart.Email,
                Shipping      = new ChargeShippingOptions
                {
                    Name    = cart.Name,
                    Phone   = cart.Phone,
                    Address = new AddressOptions
                    {
                        Line1      = cart.Address1,
                        Line2      = cart.Address2,
                        City       = cart.City,
                        Country    = cart.Country,
                        PostalCode = cart.PostCode,
                        State      = cart.State,
                    },
                },
            });

            ClientSecret = paymentIntent.ClientSecret;

            return(Page());
        }
Exemplo n.º 22
0
        // Bu method tüm action lardan sonra çalışır.
        public override void  OnActionExecuted(ActionExecutedContext context)
        {
            var searchProductCategoryCommand = new SearchProductCategories();
            var sonuc = SearchProductCategoriesService.HandleAsync(searchProductCategoryCommand).Result;

            var cart = new GetCart();

            cart.UserName = User.Identity.Name;

            var cartItems = new List <CartItem>();

            var result = getCartService.HandleAsync(cart).Result;

            ViewBag.GetCartItems = (IList <CartItem>)result.Value.CartItems ?? cartItems;
            ViewBag.CartTotal    = (decimal?)result.Value.CartTotal;

            ViewBag.Categories = sonuc.Value;

            base.OnActionExecuted(context);
        }
        public async Task <IActionResult> OnGet(
            [FromServices] GetCart getCart,
            [FromServices] IWebHostEnvironment env)
        {
            var userId = User.GetUserId();
            var cart   = await getCart.Get(userId);

            if (cart.Products.Count <= 0)
            {
                return(RedirectToPage("/Index"));
            }

            Form = new CheckoutForm();

            if (env.IsDevelopment())
            {
                Form.Name     = "test";
                Form.Email    = "*****@*****.**";
                Form.Phone    = "7845556789";
                Form.Address1 = "Test";
                Form.Address2 = "";
                Form.City     = "City";
                Form.Country  = "Country";
                Form.PostCode = "QQ1 2RR";
                Form.State    = "";
            }
            else if (cart.DeliveryInformationComplete)
            {
                Form.Name     = cart.Name;
                Form.Email    = cart.Email;
                Form.Phone    = cart.Phone;
                Form.Address1 = cart.Address1;
                Form.Address2 = cart.Address2;
                Form.City     = cart.City;
                Form.Country  = cart.Country;
                Form.PostCode = cart.PostCode;
                Form.State    = cart.State;
            }

            return(Page());
        }
Exemplo n.º 24
0
        public async Task <ActionResult> AddToCart(int id)
        {
            var productDTO = await _productService.GetAsync(id);

            if (productDTO == null)
            {
                return(HttpNotFound());
            }

            var productVM = Mapper.Map <ProductVM>(productDTO);

            GetCart.Add(productVM);

            Thread.Sleep(400);
            return(Json(new
            {
                IsSuccess = true,
                Quantity = GetCart.Count
            },
                        JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 25
0
        public IActionResult OnGet([FromServices] GetCustomerInformation getCustomerInformation,
                                   [FromServices] GetCart getCart)
        {
            var information = getCustomerInformation.Exec();
            var totalValue  = getCart.Exec().Sum(x => x.RealValue * x.Quantity);

            TotalValue = $"${totalValue}";

            if (information == null)
            {
                return(RedirectToPage("/Checkout/CustomerInformation"));
            }

            var cart = getCart.Exec();

            if (cart.Count() == 0)
            {
                return(RedirectToPage("/Cart"));
            }

            return(Page());
        }
Exemplo n.º 26
0
        public async Task <IActionResult> OnPostAsync(
            string paymentId,
            [FromServices] CreateOrder createOrder,
            [FromServices] GetCart getCart,
            [FromServices] PaymentIntentService paymentIntentService)
        {
            var payment = await paymentIntentService.GetAsync(paymentId);

            if (payment == null)
            {
                //todo do some kinda notification that this went wrong.
                return(RedirectToPage());
            }

            var order = new Domain.Models.Order
            {
                StripeReference = paymentId,
                CartId          = await getCart.Id(User.GetUserId()),
            };
            await createOrder.Do(order);

            return(RedirectToPage("/Checkout/Success", new { orderId = order.Id }));
        }
        public Client.Query.OrderItem.Models.Cart Handle(GetCart query)
        {
            var ordersItens = from oi in _architectureContext.Orders
                              .Include(x => x.Customer)
                              .Include(x => x.OrderItems)
                              from o in oi.OrderItems
                              //where oi.Customer.Id == _user.UserId()
                              select o;

            var result = ordersItens.Include(x => x.Product)
                         .Select(x => new OrderItemIndex
            {
                Id      = x.Id,
                Product = $"{x.Product.Name}, Price:{x.Product.Price}",
                Qtd     = x.Qtd
            }).ToList();

            return(new Client.Query.OrderItem.Models.Cart
            {
                OrderItens = result,
                TotalPrice = ordersItens.Sum(x => x.Product.Price * x.Qtd)
            });
        }
Exemplo n.º 28
0
 public async Task <ActionResult <CartDto> > Get([FromRoute] GetCart query)
 => Single(await QueryAsync(query));
Exemplo n.º 29
0
 public CartViewComponent(GetCart getCart)
 {
     _getCart = getCart;
 }
Exemplo n.º 30
0
 public IActionResult GetCart([FromServices] GetCart getCart) => Ok(getCart.Do());