Пример #1
0
        public async Task <ActionResult> Checkout()
        {
            Cart cart = await shoppingCartService.GetCartAsync();

            ApplicationUser user = userManager.FindById(User.Identity.GetUserId());

            Order order = new Order()
            {
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Title     = user.Title.Value.ToString(),
                Address   = user.Address,
                House     = user.House,
                Zip       = user.Zip,
                City      = user.City,
                Email     = user.Email,
                Tax       = financeService.Tax,
                Date      = DateTime.Now
            };

            foreach (CartItem cartItem in cart.Items)
            {
                Product product = await catalogService.FindAsync(cartItem.ProductId);

                order.Items.Add(new OrderItem()
                {
                    ProductId = product.Id,
                    Price     = product.Price,
                    Quantity  = cartItem.Quantity
                });
            }
            await erpService.SaveAsync(order);

            await shoppingCartService.EmptyCartAsync(cart);

            return(RedirectToAction("Thanks", new { order.Id }));
        }
Пример #2
0
        public async Task <ActionResult> AcceptPayment()
        {
            var  order = Session["CurrentOrder"] as Order;
            Cart cart  = await shoppingCartService.GetCartAsync();

            ///<summary>     This puts the subtotal of the entire order into a decimal
            ///                 variable I pass into the Run method to process credit
            ///                 cards. </summary>
            decimal subTotal = Convert.ToDecimal(Session["CartTotal"]);

            ///<summary>     The bellow strings passed into run are the values that I have
            ///                 Been given by authorize.net to test values passeed to the
            ///                 api. </summary>
            if (Request.Form["codButton"] == "on")
            {
                await Run("47hFF4Udk9", "6WP4DWnD2b45yQ6m", subTotal, order, cart);
            }

            CreateNewShipStationOrder(cart, order);

            /// <summary>     This saves the values to the order, and also removes all items
            ///                 from the cart service. </summary>
            await erpService.SaveAsync(order);

            await shoppingCartService.EmptyCartAsync(cart);

            #region SMTP mail server
            /// <summary>    This gets current user information and sends an email to them confirming that thier horder
            ///                 has been properly placed and will be sending an invoice soon. It seends the email from
            ////                 our contact source [email protected] </summary>
            //ClaimsIdentity claimsIdentity = User.Identity as ClaimsIdentity;
            //Claim   emailClaim = claimsIdentity != null ? claimsIdentity.Claims.Where(x => x.Type == ClaimTypes.Email).FirstOrDefault() : null;
            //Claim   nameClaim  = claimsIdentity != null ? claimsIdentity.Claims.Where(x => x.Type == ClaimTypes.Name).FirstOrDefault()  : null;
            //string userEmail   = emailClaim     != null ? emailClaim.Value : User.Identity.GetUserName();
            //string userName    = nameClaim      != null ? nameClaim.Value  : User.Identity.GetUserName();


            /// Currently not working smptserver email

            //var          fromAddress  = new MailAddress("*****@*****.**", "Pinnacle Purchase"); /// [email protected]
            //const string fromPassword = "******"; ///@thebestCBD1 P1nnacle@CBD


            //var toAddress  = new MailAddress(userEmail, userName);
            //string       subject    = "Your purchase with id :" + order.Id.ToString();
            //const string body       = "Your purchase order " +
            //    "for Pinnacle WholeSale has gone through and is being processed now! \n We will email you an invoice once the order has been placed.";

            //var smtp = new SmtpClient
            //{
            //    Credentials           = new NetworkCredential(fromAddress.Address, fromPassword),
            //    DeliveryMethod        = SmtpDeliveryMethod.Network,
            //    Host                  = "smtp.gmail.com",
            //    UseDefaultCredentials = false,
            //    EnableSsl             = true,
            //    Port                  = 587,
            //};
            //using (var message = new MailMessage(fromAddress, toAddress)
            //{
            //    Subject = subject,
            //    Body    = body
            //})
            //{
            //    smtp.Send(message);
            //}

            #endregion

            /// <summary>  Redirects user to the thank you for your purchase page.  </summary>
            return(RedirectToAction("Thanks", new { order.Id }));
        }