public ViewResult Index(Cart cart, string returnUrl)
 {
     return View(new CartView
     {
         Cart = cart,
         ReturnUrl = returnUrl
     });
 }
        public RedirectToRouteResult RemoveFromCart(Cart cart, int gameId, string returnUrl)
        {
            var game = _repository.Games.FirstOrDefault(g => g.GameId == gameId);

            if(game != null)
                cart.RemoveLine(game);

            return RedirectToAction("Index", new {returnUrl});
        }
        public RedirectToRouteResult AddToCart(Cart cart, int gameId, string returnUrl)
        {
            var game = _repository.Games.FirstOrDefault(g => g.GameId == gameId);

            if (game != null)
                cart.AddItem(game, 1);

            return RedirectToAction("Index", new {returnUrl});
        }
        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;
            //    }

            //    var body = new StringBuilder()
            //        .AppendLine("Новый заказ обработан")
            //        .AppendLine("---")
            //        .AppendLine("Товары:");

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

            //    body.AppendFormat("Общая стоимость: {0:c}", cart.ComputeTotalValue())
            //        .AppendLine("---")
            //        .AppendLine("Доставка:")
            //        .AppendLine(shippingInfo.Name)
            //        .AppendLine(shippingInfo.Line)
            //        .AppendLine(shippingInfo.City)
            //        .AppendLine(shippingInfo.Country)
            //        .AppendLine("---")
            //        .AppendFormat("Подарочная упаковка: {0}",
            //            shippingInfo.GiftWrap ? "Да" : "Нет");

            //    var mailMessage = new MailMessage(
            //        _emailSettings.MailFromAddress,
            //        _emailSettings.MailToAddress,
            //        "Новый заказ отправлен!",
            //        body.ToString());

            //    if (_emailSettings.WriteAsFile)
            //    {
            //        mailMessage.BodyEncoding = Encoding.UTF8;
            //    }

            //    smtpClient.Send(mailMessage);
            //}
        }
        public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
        {
            if (!cart.Lines.Any())
                ModelState.AddModelError("", "Извините, ваша корзина пуста!");

            if (ModelState.IsValid)
            {
                _orderProcessor.ProcessOrder(cart, shippingDetails);
                cart.Clear();

                return View("Completed");
            }

            return View(shippingDetails);
        }
示例#6
0
        public void Can_Add_New_Lines()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1"};
            var game2 = new Game {GameId = 2, Name = "Игра2"};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 1);
            var results = cart.Lines.ToList();

            Assert.AreEqual(results.Count(), 2);
            Assert.AreEqual(results[0].Game, game1);
            Assert.AreEqual(results[1].Game, game2);
        }
示例#7
0
        public void Calculate_Cart_Total()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1", Price = 100};
            var game2 = new Game {GameId = 2, Name = "Игра2", Price = 50};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 1);
            cart.AddItem(game1, 5);

            var result = cart.ComputeTotalValue();

            Assert.AreEqual(result, 650);
        }
示例#8
0
        public void Can_Add_Quantity_For_Existing_Lines()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1"};
            var game2 = new Game {GameId = 2, Name = "Игра2"};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 1);
            cart.AddItem(game1, 5);
            var results = cart.Lines.OrderBy(c => c.Game.GameId).ToList();

            Assert.AreEqual(results.Count(), 2);
            Assert.AreEqual(results[0].Quantity, 6);
            Assert.AreEqual(results[1].Quantity, 1);
        }
示例#9
0
        public void Cannot_Checkout_Empty_Cart()
        {
            var mock = new Mock<IOrderProcessor>();

            var cart = new Cart();
            var shippingDetails = new ShippingDetails();

            var cartController = new CartController(null, mock.Object);
            var viewResult = cartController.Checkout(cart, shippingDetails);

            mock.Verify(m => m.ProcessOrder(It.IsAny<Cart>(), It.IsAny<ShippingDetails>()),
                Times.Never());

            Assert.AreEqual("", viewResult.ViewName);
            Assert.AreEqual(false, viewResult.ViewData.ModelState.IsValid);
        }
示例#10
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;
        }
示例#11
0
 public PartialViewResult Summary(Cart cart)
 {
     return PartialView(cart);
 }
示例#12
0
        public void Can_Clear_Cart()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1", Price = 100};
            var game2 = new Game {GameId = 2, Name = "Игра2", Price = 55};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 1);
            cart.AddItem(game1, 5);
            cart.Clear();

            Assert.AreEqual(cart.Lines.Count(), 0);
        }
示例#13
0
        public void Can_Remove_Line()
        {
            var game1 = new Game {GameId = 1, Name = "Игра1"};
            var game2 = new Game {GameId = 2, Name = "Игра2"};
            var game3 = new Game {GameId = 3, Name = "Игра3"};

            var cart = new Cart();

            cart.AddItem(game1, 1);
            cart.AddItem(game2, 4);
            cart.AddItem(game3, 2);
            cart.AddItem(game2, 1);

            cart.RemoveLine(game2);

            Assert.AreEqual(cart.Lines.Count(c => c.Game == game2), 0);
            Assert.AreEqual(cart.Lines.Count(), 2);
        }