Exemplo n.º 1
0
        public async Task ProcessOrder(Carts.Cart cart, ShippingDetails shippingDetails)
        {
            // return await Task.Run(ProcessOrderMock(cart, shippingDetails));
            await Work(cart, shippingDetails);

            //return new Task();
        }
Exemplo n.º 2
0
        public ViewResult Checkout(Carts.Cart cart)
        {
            var model = new ShippingDetailsInput();

            model.Cart = JsonConvert.SerializeObject(cart);
            return(View(model));
        }
Exemplo n.º 3
0
        public async Task RemoveProductFromCart(Carts.Cart cart1, int productId)
        {
            var cart    = GetCart();
            var product = await _productRepository.GetAsync(productId);

            if (product != null)
            {
                cart1.RemoveLine(product);
            }
            //return null;
        }
Exemplo n.º 4
0
        public async Task AddProductToCart(Carts.Cart cart1, int productId)
        {
            var cart    = GetCart();
            var product = await _productRepository.GetAsync(productId);

            if (product != null)
            {
                cart1.AddItem(product, 1);
            }
            // return null;
        }
Exemplo n.º 5
0
 public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     //get the cart from the session
     Carts.Cart cart = (Carts.Cart)controllerContext.HttpContext.Session[SessionKey];
     //create the Cart if there wasnt one in the session data
     if (cart == null)
     {
         cart = new Carts.Cart();
         controllerContext.HttpContext.Session[SessionKey] = cart;
     }
     //return the cart
     return(cart);
 }
Exemplo n.º 6
0
        public ViewResult Index(Carts.Cart cart, string returnUrl)
        {
            //throw new Exception("A sample exception message...");
            //throw new UserFriendlyException("Ooppps! There is a problem!", "You are trying to see a product that is deleted...");

            var model = new CartIndexViewModel
            {
                Cart = cart,

                ReturnUrl = returnUrl
            };

            return(View(model));
        }
Exemplo n.º 7
0
        private Carts.Cart GetCart()
        {
            /*We use ASp.NET session state feature to store and retrieve Cart objects. ASP.NET has a nice session feature that uses cookies or URL rewriting to assocciate requests from a user together, to form a single browsing session.
             * A related feature is session state, which allows us to associate data with a session. This is an ideal fit for our cart class. We want each user to have their own cart, and we want the cart to be persistent between requests.
             * Data associated with a session is deleted when a session expires (typically when a user has not made a request for a while). No storage or lifecycle management of the cart objects nessacary*/

            /*In order to avoid using ASP>NET Session, use claims to add new property to session */
            //https://gist.github.com/hikalkan/67469e05475c2d18cb88#gistcomment-2029767
            var cart = (Carts.Cart)HttpContext.Current.Session[CartSessionKey];

            if (cart == null)
            {
                cart = new Carts.Cart();
                HttpContext.Current.Session[CartSessionKey] = cart;
            }
            return(cart);
        }
Exemplo n.º 8
0
        public async Task <RedirectToRouteResult> RemoveFromCart(Carts.Cart cart, int productId, string returnUrl)
        {
            await _cartService.RemoveProductFromCart(cart, productId);

            return(RedirectToAction("Index", new { returnUrl }));
        }
Exemplo n.º 9
0
        [DisableAbpAntiForgeryTokenValidation] //https://forum.aspnetboilerplate.com/viewtopic.php?t=3270&p=7596
        public async Task <RedirectToRouteResult> AddToCart(Carts.Cart cart, int id, string returnUrl)
        {
            await _cartService.AddProductToCart(cart, id);

            return(RedirectToAction("Index", new { returnUrl }));
        }
Exemplo n.º 10
0
 public PartialViewResult Summary(Carts.Cart cart)
 {
     return(PartialView(cart));
 }
Exemplo n.º 11
0
 public ViewResult Completed(Carts.Cart cart)
 {
     cart.Clear();
     return(View());
 }
Exemplo n.º 12
0
        private Task Work(Carts.Cart cart, ShippingDetails shippingDetails)
        {
            //http://www.hexacta.com/2016/06/01/task-run-vs-async-await/
            return(Task.Run(() =>
            {
                using (var smtpClient = new SmtpClient())
                {
                    smtpClient.EnableSsl = _emailsSettings.UseSsl;
                    smtpClient.Host = _emailsSettings.ServerName;
                    smtpClient.Port = _emailsSettings.ServerPort;
                    smtpClient.UseDefaultCredentials = false;
                    smtpClient.Credentials
                        = new NetworkCredential(_emailsSettings.Username,
                                                _emailsSettings.Password);
                    if (_emailsSettings.WriteAsFile)
                    {
                        smtpClient.DeliveryMethod
                            = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                        smtpClient.PickupDirectoryLocation = _emailsSettings.FileLocation;
                        smtpClient.EnableSsl = false;
                    }

                    StringBuilder body = new StringBuilder()
                                         .AppendLine("A new order has been submitted")
                                         .AppendLine("---")
                                         .AppendLine("Items:");

                    foreach (var line in cart.Lines)
                    {
                        var subtotal = line.Product.Price * line.Quantity;
                        body.AppendFormat("{0} x {1} (subtotal: {2:c}", line.Quantity,
                                          line.Product.Name,
                                          subtotal);
                    }

                    body.AppendFormat("Total order value: {0:c}", cart.CalcTotalValue())
                    .AppendLine("---")
                    .AppendLine("Ship to:")
                    .AppendLine(shippingDetails.Name)
                    .AppendLine(shippingDetails.Line1)
                    .AppendLine(shippingDetails.Line2 ?? "")
                    .AppendLine(shippingDetails.Line3 ?? "")
                    .AppendLine(shippingDetails.City)
                    .AppendLine(shippingDetails.State ?? "")
                    .AppendLine(shippingDetails.Country)
                    .AppendLine(shippingDetails.Zip)
                    .AppendLine("---")
                    .AppendFormat("Gift wrap: {0}",
                                  shippingDetails.GiftWrap ? "Yes" : "No");


                    MailMessage mailMessage = new MailMessage(
                        _emailsSettings.MailFromAddress, // From
                        _emailsSettings.MailToAddress,   // To
                        "New order submitted!",          // Subject
                        body.ToString());                // Body

                    if (_emailsSettings.WriteAsFile)
                    {
                        mailMessage.BodyEncoding = Encoding.ASCII;
                    }

                    smtpClient.Send(mailMessage);
                }
            }));
        }
Exemplo n.º 13
0
 public void SetCart(Carts.Cart cart)
 {
     //_cart = cart;
 }