public ActionResult Index(Cart cart,string returnUrl) { var model = new CartViewModel() { Cart = cart, ReturnUrl = returnUrl }; return View(model); }
public ActionResult RemoveFromCart(Cart cart,int productID,string returnUrl) { var product = _productRepository.Products .FirstOrDefault(x => x.ProductID == productID); if (product != null) { cart.Remove(product); } return RedirectToAction("Index", new {returnUrl}); }
//controlador actual public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var cart = controllerContext.HttpContext.Session["cart"] as Cart; if (cart==null) { cart = new Cart(); controllerContext.HttpContext.Session["cart"] = cart; } return cart; }
public void Carrito_se_limpia_al_llamar_clear() { //Arrange var carrito = new Cart(); var producto = new Product() { ProductID = 1 }; carrito.Add(producto, 3); const int items = 0; //Act Llama la función carrito.Clear(); //Assert comparar Assert.AreEqual(carrito.Lines.Count(), items); }
public void Remove_quita_producto_existente() { //Arrange var cart = new Cart(); var ptest = new Product() {ProductID = 13}; //Act cart.Add(ptest,1); cart.Remove(ptest); //Assert Assert.AreEqual(cart.Lines.Count(),0); }
public ActionResult Checkout(Cart cart,ShippingDetails detalles) { if (!cart.Lines.Any()) ModelState.AddModelError("", "Tu carrito esta vacío."); if (ModelState.IsValid) { //Process _orderProcessor.Process(cart, detalles); cart.Clear(); return View("Completed"); } return View(detalles); }
public void Agrega_producto_existente() { //Arrange var cart = new Cart(); var ptest = new Product() { ProductID = 99 }; //Act cart.Add(ptest,1); cart.Add(ptest,4); //Assert Assert.AreEqual(cart.Lines.Count(), 1); Assert.AreEqual(cart.Lines.First().Product.ProductID, 99); Assert.AreEqual(cart.Lines.First().Quantity,5); }
public void Agrega_producto_nuevo() { //Arrange var cart = new Cart(); var ptest = new Product() {ProductID = 99}; var qtest = 3; //Act cart.Add(ptest,qtest); //Assert Assert.AreEqual(cart.Lines.Count(),1); Assert.AreEqual(cart.Lines.First().Product.ProductID,99); Assert.AreEqual(cart.Lines.First().Quantity,qtest); }
//Metodo que devuelve una acción //Debe de recibir los mismos nombres que están en la vista de ProductSummary public ActionResult AddToCart(Cart cart, int productID, string returnUrl) { //Para buscar, traer cualquier producto usamos el objeto repository //FirstOrDefault si no lo encuentra devuelve nullo var product = _productRepository.Products.FirstOrDefault(x => x.ProductID == productID); if (product!=null) { //Obtiene un carrito y lo agrega cart.Add(product, 1); } //le pasas la vista index y el tipo de dato URL //el index no esta creado, por defecto tomaría el index de la carpeta Cart //return View("Index", new { returnUrl }); return RedirectToAction("Index", new { returnUrl }); }
public void Calcula_precio_productos() { //Arrange var cart = new Cart(); var ptest = new Product() { ProductID = 1,Price = 99 }; var pse = new Product() { ProductID = 2,Price = 50 }; //Act cart.Add(ptest,1); cart.Add(pse,2); //Assert Assert.AreEqual(cart.TotalPrice,199); }
public void Process(Cart cart, ShippingDetails shipping) { using(var client = new SmtpClient()) { ConfigureSMTP(client); var body = BuildMessage(cart, shipping); var message = new MailMessage( _settings.MailFrom, //From _settings.MailTo,//To "Nueva orden enviada", //Subject body);//Contenido if (_settings.WriteAsFile) { message.BodyEncoding = Encoding.UTF8; } client.Send(message); } }
private string BuildMessage(Cart cart, ShippingDetails shipping) { var sb = new StringBuilder(); sb.AppendLine("Nueva orden enviada.") .AppendLine("--------------------") .AppendLine("Items:") .AppendLine("--------------------"); foreach (var line in cart.Lines) { sb.AppendFormat("{0} x {1} (subtotal: {2:c}", line.Product.Name, line.Quantity, line.SubTotal); sb.AppendLine(""); } sb.AppendLine(""); sb.AppendFormat("Total de la Orden: {0:c}", cart.TotalPrice); sb.AppendLine("--------------------") .AppendLine("Enviar a:") .AppendLine("--------------------") .AppendLine(shipping.Name) .AppendLine(shipping.Line1) .AppendLine(shipping.Line2 ?? "") .AppendLine(shipping.Line3 ?? "") .AppendLine(shipping.City) .AppendLine(shipping.State) .AppendLine(shipping.ZIP) .AppendLine(shipping.Country) .AppendLine("--------------------") .AppendFormat("Envoltura de regalo:{0}", shipping.GiftWrap ? "Si" : "No"); return sb.ToString(); }
public ActionResult Summary(Cart cart) { return PartialView(cart); }