コード例 #1
0
ファイル: DbOrderProcessor.cs プロジェクト: andr74r/Store
 public void ProcessOrder(Cart cart, Order order)
 {
     order.OrderLines = cart.Lines
         .Select(l => new OrderLine() { Item = l.Item, Quantity = l.Quantity, Order = order })
         .ToList();
     repository.SaveOrder(order);
 }
コード例 #2
0
ファイル: CartController.cs プロジェクト: duda92/StoreMVC
 public RedirectToRouteResult RemoveFromCart(Cart cart, int productId)
 {
     Product product = repository.Products.FirstOrDefault(p => p.ProductID == productId);
     if (product != null)
         cart.RemoveLine(product);
     return RedirectToAction("Index", new { app_culture = ControllerContext.RequestContext.RouteData.Values["app_culture"] });
 }
コード例 #3
0
ファイル: CartController.cs プロジェクト: andr74r/Store
 public ViewResult Index(Cart cart, string returnUrl)
 {
     return View(new CartIndexViewModel
     {
         Cart = cart,
         ReturnUrl = returnUrl
     });
 }
コード例 #4
0
ファイル: CartModelBinder.cs プロジェクト: duda92/StoreMVC
 public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     Cart cart = (Cart)controllerContext.HttpContext.Session["Cart"];
     if (cart == null)
     {
         cart = new Cart();
         controllerContext.HttpContext.Session["Cart"] = cart;
     }
     return cart;
 }
コード例 #5
0
        public RedirectToRouteResult RemoveFromCart(Cart cart,int productId, string returnUrl)
        {
            Product product = repository.Products.FirstOrDefault(p => p.ProductID == productId);

            if (product != null)
            {
                cart.RemoveLine(product);
            }
            return RedirectToAction("Index", new { returnUrl });
        }
コード例 #6
0
        public async Task<RedirectToRouteResult> AddToCart(Cart cart, string IdString, string returnUrl)
        {
            Product product = await repository.GetProductById(IdString);

            if (product != null)
            {
                cart.AddItem(product, 1);
            }
            return RedirectToAction("Index", new { returnUrl });
        }
コード例 #7
0
        public void ProcessorOrder(Cart cart, ShippingDetails shippingInfo)
        {
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl = emaileSettings.UseSsl;
                smtpClient.Host = emaileSettings.ServerName;
                smtpClient.Port = emaileSettings.ServerPort;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new NetworkCredential(emaileSettings.ServerName, emaileSettings.Password);

                if (emaileSettings.WriteAsFile)
                {
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = emaileSettings.Filelocation;
                    smtpClient.EnableSsl = false;

                }

                StringBuilder body = new StringBuilder()
                    .AppendLine("New order is processed")
                    .AppendLine("---")
                    .AppendLine("Products:");

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

                body.AppendFormat("General price: {0:c}",cart.ComputerTotalValue())
                    .AppendLine("---")
                    .AppendLine("Delivery")
                    .AppendLine(shippingInfo.Name)
                    .AppendLine(shippingInfo.Line1)
                    .AppendLine(shippingInfo.Line2 ?? "")
                    .AppendLine(shippingInfo.Line3 ?? "")
                    .AppendLine(shippingInfo.City)
                    .AppendLine(shippingInfo.Country)
                    .AppendLine("---")
                    .AppendFormat("Gift wrap: {0}",shippingInfo.GiftWrap ? "Yes" : "No");

                MailMessage mailMassage = new MailMessage(
                    emaileSettings.MailFromAddress,
                    emaileSettings.MailToAddress,
                    "New order send",
                    body.ToString());

                if (emaileSettings.WriteAsFile)
                {
                    mailMassage.BodyEncoding = Encoding.UTF8;
                }

                smtpClient.Send(mailMassage);
            }
        }
コード例 #8
0
ファイル: CartController.cs プロジェクト: andr74r/Store
        public RedirectToRouteResult AddToCart(Cart cart, int itemId, string returnUrl)
        {
            Item item = repository.Items
                .FirstOrDefault(it => it.ItemId == itemId);

            if (item != null)
            {
                cart.AddItem(item, 1);
            }
            return RedirectToAction("Index", new { returnUrl });
        }
コード例 #9
0
ファイル: CartController.cs プロジェクト: andr74r/Store
        public RedirectToRouteResult RemoveFromCart(Cart cart, int itemId, string returnUrl)
        {
            Item item = repository.Items
                .FirstOrDefault(it => it.ItemId == itemId);

            if (item != null)
            {
                cart.RemoveLine(item);
            }
            return RedirectToAction("Index", new { returnUrl });
        }
コード例 #10
0
        public RedirectToRouteResult AddToCart(Cart cart,int productId, string returnUrl)
        {
            Product product = repository.Products.FirstOrDefault(p => p.ProductID == productId);

            if (product != null)
            {
                cart.AddItem(product, 1);
            }

            return RedirectToAction("Index", new { returnUrl });
        }
コード例 #11
0
        public async Task<RedirectToRouteResult> RemoveFromCart(Cart cart, string productId, string returnUrl)
        {
            Product product = await repository.GetProductById(productId);

            if (product != null)
            {
                cart.RemoveLine(product);
            }

            return RedirectToAction("Index", new { returnUrl });
        }
コード例 #12
0
ファイル: CartController.cs プロジェクト: duda92/StoreMVC
 public ViewResult Checkout(Cart cart, Order order)
 {
     if (cart.Lines.Count() == 0)
         ModelState.AddModelError("", CartStrings.Your_cart_is_empty);
     if (ModelState.IsValid)
     {
         orderProcessor.ProcessOrder(cart, order);
         cart.Clear();
         return View("Completed");
     }
     else
     {
         ViewBag.Shippers = repository.Shippers;
         return View(order);
     }
 }
コード例 #13
0
        public ActionResult ShippingDetails(Cart cart, ShippingDetails shippingDetails)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Sorry, your cart is empty!");
            }

            if (ModelState.IsValid)
            {
                TempData["shipping_details"] = shippingDetails;
                return RedirectToAction("PaymentWithPaypal", "PaymentProcessor");
            }
            else
            {
                return View(shippingDetails);
            }
        }
コード例 #14
0
 public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
 {
     if (cart.Lines.Count() == 0)
     {
         ModelState.AddModelError("", "Sorry your cat is empty");
     }
     if (ModelState.IsValid)
     {
         orderProcessor.ProcessorOrder(cart, shippingDetails);
         cart.Clear();
         return View("Completed");
     }
     else
     {
         return View(shippingDetails);
     }
 }
コード例 #15
0
ファイル: CartController.cs プロジェクト: andr74r/Store
        public ViewResult Checkout(Cart cart, Order order)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Извините, ваша корзина пуста!");
            }

            if (ModelState.IsValid)
            {
                orderProcessor.ProcessOrder(cart, order);
                cart.Clear();
                return View("Completed");
            }
            else
            {
                return View(order);
            }
        }
コード例 #16
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            Cart cart = null;
            if (controllerContext.HttpContext.Session != null)
            {
              cart = (Cart)controllerContext.HttpContext.Session[sessionKey];
            }

            if (cart == null)
            {
                cart = new Cart();
                if (controllerContext.HttpContext.Session != null)
                {
                    controllerContext.HttpContext.Session[sessionKey] = cart;
                }
            }

            return cart;
        }
コード例 #17
0
 public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     // get the Cart from the session
     Cart cart = null;
     if (controllerContext.HttpContext.Session != null)
     {
         cart = (Cart)controllerContext.HttpContext.Session[sessionKey];
     }
     // create the Cart if there wasn't one in the session data
     if (cart == null)
     {
         cart = new Cart();
         if (controllerContext.HttpContext.Session != null)
         {
             controllerContext.HttpContext.Session[sessionKey] = cart;
         }
     }
     // return the cart
     return cart;
 }
コード例 #18
0
ファイル: CartModelBinder.cs プロジェクト: andr74r/Store
        public object BindModel(ControllerContext controllerContext,
            ModelBindingContext bindingContext)
        {
            // Получить объект Cart из сеанса
            Cart cart = null;
            if (controllerContext.HttpContext.Session != null)
            {
                cart = (Cart)controllerContext.HttpContext.Session[sessionKey];
            }

            // Создать объект Cart если он не обнаружен в сеансе
            if (cart == null)
            {
                cart = new Cart();
                if (controllerContext.HttpContext.Session != null)
                {
                    controllerContext.HttpContext.Session[sessionKey] = cart;
                }
            }

            // Возвратить объект Cart
            return cart;
        }
コード例 #19
0
        public ActionResult PaymentWithPaypal(Cart cart)
        {
            ShippingDetails shippingDetails = (ShippingDetails)TempData["shipping_details"];

            //getting the apiContext as earlier
            APIContext apiContext = PaypalConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];

                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist
                    //it is returned by the create function call of the payment class

                    // Creating a payment
                    // baseURL is the url on which paypal sendsback the data.
                    // So we have provided URL of this controller only
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority +
                                "/Paypal/PaymentWithPayPal?";

                    //guid we are generating for storing the paymentID received in session
                    //after calling the create function and it is used in the payment execution

                    var guid = Convert.ToString((new Random()).Next(100000));

                    var payer = new Payer() { payment_method = "paypal" };

                    var redirUrls = new RedirectUrls()
                    {
                        cancel_url = baseURI + "guid=" + guid,
                        return_url = baseURI + "guid=" + guid
                    };

                    List<Transaction> transactions = GenerateteTransactions(cart);

                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    payment = new Payment()
                    {
                        intent = "sale",
                        payer = payer,
                        transactions = transactions,
                        redirect_urls = redirUrls
                    };

                    var createdPayment = payment.Create(apiContext);
                    //get links returned from paypal in response to Create function call

                    var links = createdPayment.links.GetEnumerator();

                    string paypalRedirectUrl = null;

                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;

                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }

                    // saving the paymentID in the key guid
                    Session.Add(guid, createdPayment.id);

                    return Redirect(paypalRedirectUrl);
                }
                else
                {
                    // This section is executed when we have received all the payments parameters

                    // from the previous call to the function Create

                    // Executing a payment

                    var guid = Request.Params["guid"];

                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);

                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return View("Failure");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return View("Failure");
            }

            orderProcessor.ProcessOrder(cart, shippingDetails);
            cart.Clear();

            return View("Success");
        }
コード例 #20
0
        private List<Transaction> GenerateteTransactions(Cart cart)
        {
            var itemList = new ItemList() { items = new List<Item>() };

            foreach(CartLine cartLine in cart.Lines)
            {
                itemList.items.Add(new Item()
                {
                    name = cartLine.Product.Name,
                    currency = "USD",
                    price = cartLine.Product.Price.ToString(),
                    quantity = cartLine.Quantity.ToString(),
                    //sku = "sku"
                });
            }

            var payer = new Payer() { payment_method = "paypal" };

            // similar as we did for credit card, do here and create details object
            var details = new Details()
            {
                tax = "0",
                shipping = "0",
                subtotal = "0"
            };

            // similar as we did for credit card, do here and create amount object
            var amount = new Amount()
            {
                currency = "USD",
                total = cart.ComputeTotalValue().ToString(), // Total must be equal to sum of shipping, tax and subtotal.
                details = details
            };

            var transactionList = new List<Transaction>();

            transactionList.Add(new Transaction()
            {
                description = "Transaction description.",
                invoice_number = "your invoice number",
                amount = amount,
                item_list = itemList
            });

            return transactionList;
        }
コード例 #21
0
ファイル: CartController.cs プロジェクト: andr74r/Store
 public PartialViewResult _Summary(Cart cart)
 {
     return PartialView(cart);
 }
コード例 #22
0
ファイル: CartController.cs プロジェクト: duda92/StoreMVC
 public ViewResult Summary(Cart cart)
 {
     return View(cart);
 }
コード例 #23
0
ファイル: CartController.cs プロジェクト: duda92/StoreMVC
 public ViewResult Index(Cart cart)
 {
     return View(new CartIndexViewModel { Cart = cart });
 }
コード例 #24
0
        public void ProcessOrder(Cart cart, ShippingDetails shippingInfo)
        {
            using (var smtpClient = new SmtpClient())
            {
                smtpClient.EnableSsl = emailSettings.UseSsl;
                smtpClient.Host = emailSettings.ServerName;
                smtpClient.Port = emailSettings.ServerPort;
                smtpClient.UseDefaultCredentials = false;
                smtpClient.Credentials = new NetworkCredential(emailSettings.Username, emailSettings.Password);

                if (emailSettings.WriteAsFile)
                {
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = emailSettings.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.ComputeTotalValue())
                .AppendLine("---")
                .AppendLine("Ship to:")
                .AppendLine(shippingInfo.Name)
                .AppendLine(shippingInfo.Line1)
                .AppendLine(shippingInfo.Line2 ?? "")
                .AppendLine(shippingInfo.Line3 ?? "")
                .AppendLine(shippingInfo.City)
                .AppendLine(shippingInfo.State ?? "")
                .AppendLine(shippingInfo.Country)
                .AppendLine(shippingInfo.Zip)
                .AppendLine("---")
                .AppendFormat("Gift wrap: {0}",
                shippingInfo.GiftWrap ? "Yes" : "No");

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

                // Body

                if (emailSettings.WriteAsFile)
                {
                    mailMessage.BodyEncoding = Encoding.ASCII;
                }
                smtpClient.Send(mailMessage);
            }
        }