public string GuardarCarro() { int id_producto; int existencia; int cantidad_comprada; decimal precio; MyShoppingCart shc = (MyShoppingCart)Session["shopping_cart"]; LinkButton lb; for (int i = 0; i < GVProductos.Rows.Count; i++) { lb = (LinkButton)GVProductos.Rows[i].FindControl("LBNombre"); id_producto = int.Parse(lb.CommandName); existencia = int.Parse(lb.CommandArgument); try { cantidad_comprada = int.Parse(((TextBox)GVProductos.Rows[i].FindControl("TBCantidad")).Text); } catch (Exception) { return("Debe cersiorarse de que la cantidad del producto" + lb.Text + " introducida tenga un formato numérico"); } if (existencia < cantidad_comprada)//Se controla que no se pidan mas productos que su existencia en el almacen { return("La cantidad de " + lb.Text + " comprada es mayor que la existencia del producto en el almacén"); } precio = decimal.Parse(((Label)GVProductos.Rows[i].FindControl("LPrecio")).Text); shc.Modifica_cant(id_producto, cantidad_comprada, precio); ((Label)GVProductos.Rows[i].FindControl("LSubtotal")).Text = UsefullProc.FormatoPrecio(cantidad_comprada * precio); } this.LabelTotal.Text = "Total a pagar: $ " + UsefullProc.FormatoPrecio(shc.Precio_total); this.LError.Text = ""; return(""); }
/// <summary> /// Update Cart Quantity and Remove Item /// </summary> /// <param name="str2"></param> /// <returns></returns> public ActionResult UpdateShoppingCart(string str2) { try { MyShoppingCart usersShoppingCart = new MyShoppingCart(); String cartId = GetShoppingCartId(); DataTable list1 = (DataTable)JsonConvert.DeserializeObject(str2, (typeof(DataTable))); for (int i = 0; i < list1.Rows.Count; i++) { if (Convert.ToString(list1.Rows[i]["ItemCode"]) != "") { usersShoppingCart.UpdateShoppingCartDatabase(cartId, Convert.ToString(list1.Rows[i]["ItemCode"]), Convert.ToString(list1.Rows[i]["Quantity"]), Convert.ToBoolean(list1.Rows[i]["Remove"])); } } ViewBag.lblTotal = String.Format("{0:c}", usersShoppingCart.GetTotal(cartId)); ViewBag.statusLabel = "Updated Shopping cart."; int numRows = 0; DataTable dt = new DataTable(); dt = objBALProductList.GetQuantity(Convert.ToString(Session["CartId"])); if (dt.Rows.Count > 0) { numRows = Convert.ToInt32(dt.Rows[0][0].ToString()); } return(Json(new { success = true, Message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { logger.Error(ex.ToString()); return(Json(new { success = true, Message = "Failed" }, JsonRequestBehavior.AllowGet)); } }
public void 一二三四集各買了一本() { //arrange var target = new List <Book>() { new Book { Name = "HarryPotter1", Price = 100 }, new Book { Name = "HarryPotter2", Price = 100 }, new Book { Name = "HarryPotter3", Price = 100 }, new Book { Name = "HarryPotter4", Price = 100 }, }; //act var actual = new MyShoppingCart().CheckOut(target); //assert var expected = 320; Assert.AreEqual(expected, actual); }
protected void add_onClick(object sender, ImageClickEventArgs e) { MyShoppingCart sc = (MyShoppingCart)Session["shopping_cart"]; int id_producto = int.Parse(this.IBProduct.CommandName); Producto p = new Producto(); p.LoadByPrimaryKey(id_producto); sc.Adiciona_prod(id_producto, p.Precio); Response.Redirect("ShoppingCart.aspx?ReturnUrl=Default.aspx"); }
protected void Page_Load(object sender, EventArgs e) { MostrarMenu(); MostrarInOut(); if (Session["shopping_cart"] == null) { MyShoppingCart sc = new MyShoppingCart(); Session["shopping_cart"] = sc; } }
protected void Annadir_Click(object sender, ImageClickEventArgs e) { MyShoppingCart sc = (MyShoppingCart)Session["shopping_cart"]; ImageButton addb = (ImageButton)sender; int id_producto = int.Parse(addb.CommandName); Producto p = new Producto(); p.LoadByPrimaryKey(id_producto); sc.Adiciona_prod(id_producto, p.Precio); Response.Redirect("ShoppingCart.aspx?ReturnUrl=Productos.aspx"); }
protected void LoginUser_LoggedIn(object sender, EventArgs e) { MyShoppingCart usersShoppingCart = new MyShoppingCart(); String cartId = usersShoppingCart.GetShoppingCartId(); usersShoppingCart.MigrateCart(cartId, LoginUser.UserName); if(Session["LoginReferrer"] != null) { Response.Redirect(Session["LoginReferrer"].ToString()); } Session["UserName"] = LoginUser.UserName; }
protected void LoginUser_LoggedIn(object sender, EventArgs e) { MyShoppingCart usersShoppingCart = new MyShoppingCart(); String cartId = usersShoppingCart.GetShoppingCartId(); usersShoppingCart.MigrateCart(cartId, LoginUser.UserName); if (Session["LoginReferrer"] != null) { Response.Redirect(Session["LoginReferrer"].ToString()); } Session["UserName"] = LoginUser.UserName; }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddDbContext <AppDBContext>(options => options.UseSqlServer(_configuration.GetConnectionString ("AppConnectionString"))); //services.AddScoped<ICategoryRepository, MockCategoryRepository>(); //services.AddScoped<ICourseRepository, MockCourseRepository>(); services.AddScoped <ICategoryRepository, EFCategoryRepository>(); services.AddScoped <ICourseRepository, EFCourseRepository>(); services.AddControllersWithViews(); services.AddScoped <MyShoppingCart>(s => MyShoppingCart.GetShoppingCart(s)); services.AddHttpContextAccessor(); services.AddSession(); }
protected void RegisterUser_CreatedUser(object sender, EventArgs e) { FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */); string continueUrl = RegisterUser.ContinueDestinationPageUrl; if (String.IsNullOrEmpty(continueUrl)) { continueUrl = "~/"; } MyShoppingCart usersShoppingCart = new MyShoppingCart(); String cartId = usersShoppingCart.GetShoppingCartId(); usersShoppingCart.MigrateCart(cartId, RegisterUser.UserName); Response.Redirect(continueUrl); }
/// <summary> /// showing Cart Product List /// </summary> /// <returns></returns> public ActionResult MyShoppingCart() { try { MyShoppingCart usersShoppingCart = new MyShoppingCart(); String cartId = GetShoppingCartId(); Session["PunchOut_CartID"] = cartId; decimal cartTotal = 0; cartTotal = usersShoppingCart.GetTotal(cartId); if (cartTotal > 0) { ViewBag.lblTotal = String.Format("{0:c}", usersShoppingCart.GetTotal(cartId)); ViewBag.ShoppingCartTitle = "Shopping Cart"; } else { ViewBag.ShoppingCartTitle = "Shopping Cart is Empty"; ViewBag.lblTotal = ""; ViewBag.LabelTotalText = ""; } if (Request.UrlReferrer != null && Request.QueryString["method"] != "noadd") { if (Request.UrlReferrer.ToString().Contains("ProductList") || Request.UrlReferrer.ToString().Contains("ProductDetails")) { ViewBag.statusLabel = "Successfully added item to shopping cart."; } } else { ViewBag.statusLabel = ""; } int numRows = 0; DataTable dt = new DataTable(); dt = objBALProductList.GetQuantity(Convert.ToString(Session["CartId"])); if (dt.Rows.Count > 0) { numRows = Convert.ToInt32(dt.Rows[0][0].ToString()); } var getCartitem = objBALProductList.GetMyShoopingCartList(Convert.ToString(Session["CartId"])); return(View("MyShoppingCart", getCartitem)); } catch (Exception ex) { logger.Error(ex.ToString()); return(View()); } }
protected void LBPagar_Click(object sender, EventArgs e) { MyShoppingCart shc = (MyShoppingCart)Session["shopping_cart"]; if (shc.Total_productos > 0) { //Aqui se efectua el pago con las credenciales de PayPal int id_usuario = 4; if (Session["id_usuario"] != null) { id_usuario = (int)Session["id_usuario"]; } int id_tipo_entrega = int.Parse(Request.QueryString["id_entrega"]); string direccion = Request.QueryString["direccion"]; string destinatario = Request.QueryString["destinatario"]; string comentario = Request.QueryString["comentario"]; string telefono = Request.QueryString["telefono"]; string email = Request.QueryString["email"]; decimal importe_total = 0; int no_orden = 0; Orden o = new Orden(); Producto p = new Producto(); Producto_Orden po = new Producto_Orden(); if (shc.IsValidCart()) { int id_orden = o.Insert(id_usuario, id_tipo_entrega, direccion, comentario, telefono, email, destinatario); no_orden = o.No_orden; foreach (MyCartItem item in shc.Items) { p.ActualizaVenta(item.id_producto, item.cantidad); p.RestaCantidad(item.id_producto, item.cantidad); po.Insert(id_orden, item.id_producto, item.cantidad); importe_total += item.cantidad * p.Precio; } shc.Reset(); GeneracionDeCorreos(no_orden, "Por procesar", destinatario, importe_total, email); Response.Redirect("Reporte_Orden.aspx?id=" + id_orden.ToString()); } else { Response.Redirect("../Error_Page.aspx?error_message=Durante el proceso de selección de productos alguno de los productos incluidos en su compra se agotó. Por favor, vaya a su carro de compras y verifique la existencia en el almacén de los productos seleccionados"); } } }
protected void Eiminar_onClick(object sender, EventArgs e) { int id_producto; decimal precio; CheckBox chb; MyShoppingCart shc = (MyShoppingCart)Session["shopping_cart"]; DataView dv = (DataView)GVProductos.DataSource; for (int i = 0; i < GVProductos.Rows.Count; i++) { chb = (CheckBox)GVProductos.Rows[i].FindControl("ChBEliminar"); if (chb.Checked) { id_producto = int.Parse(((LinkButton)GVProductos.Rows[i].FindControl("LBNombre")).CommandName); precio = decimal.Parse(((Label)GVProductos.Rows[i].FindControl("LPrecio")).Text); shc.Elimina_prod(id_producto, precio); } } this.LabelTotal.Text = "Total a pagar: $ " + UsefullProc.FormatoPrecio(shc.Precio_total); Response.Redirect("ShoppingCart.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["error_message"] != "") { this.LError.Text = Request.QueryString["error_message"]; } MyShoppingCart sc = (MyShoppingCart)Session["shopping_cart"]; bool m = (sc != null && sc.Total_productos > 0); this.LBEliminar.Visible = m; this.LBSeguir.Visible = m; this.LAnuncio.Visible = !m; this.IBComprar.Visible = m; this.IBSalvar.Visible = m; if (!IsPostBack) { if (m) { GVProductos.DataSource = sc.DefaultView; GVProductos.DataBind(); this.LabelTotal.Text = "Total a pagar: $ " + UsefullProc.FormatoPrecio(sc.Precio_total); } } }
/// <summary> /// Added Products To Cart /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult AddToCart(string id) { try { string productId; if (!String.IsNullOrEmpty(id)) { MyShoppingCart usersShoppingCart = new MyShoppingCart(); string cartId = GetShoppingCartId(); productId = id; usersShoppingCart.AddItem(cartId, productId, 1); return(RedirectToAction("MyShoppingCart")); } else { return(Content("<script language='javascript' type='text/javascript'>alert('We should never get to AddToCart without a ProductId.');</script>")); } } catch (Exception ex) { logger.Error(ex.ToString()); return(View()); } }
public ShoppingCartController(ICourseRepository courseRepository, MyShoppingCart shoppingCart) { _courseRepository = courseRepository; _shoppingCart = shoppingCart; }