protected void Page_Load(object sender, EventArgs e) { myCart = Session["MyCart"] as MyCart; if (myCart == null) { myCart = new MyCart(); Session["MyCart"] = myCart; } if (Request.QueryString["prodId"] != null) productId = Request.QueryString["prodId"].ToString(); else productId = "Chai"; if (!Page.IsPostBack) LoadProduct(productId); }
public ActionResult AddToCart(int Id, int quantity, string size) { size = size.Replace("\r\n", "").Trim(); Item item; using (InternetStoreContext db = new InternetStoreContext()) { item = db.Items.FirstOrDefault(x => x.Id == Id); } if (item != null) { item.Quantity = quantity; item.SizeName = size; } MyCart.GetInstance().Cart.Add(item); return(RedirectToAction("Index")); }
public string AddCart(string pName, decimal pPrice) { string messageAddCart = ""; MyCart mc = new MyCart(); mc.ProductName = pName; mc.Price = pPrice; if (Session["CurrentCart"] != null) { cartList = (List <MyCart>)Session["CurrentCart"]; } if (!cartList.Contains(mc) && (mc.ProductName != null)) { cartList.Add(mc); Session["CurrentCart"] = cartList; } messageAddCart = "Ürün sepete eklendi"; return(messageAddCart); }
public ActionResult UserCart() { string pName = Request.QueryString["name"]; decimal pPrice = Convert.ToDecimal(Request.QueryString["price"]); MyCart mc = new MyCart(); mc.ProductName = pName; mc.Price = pPrice; if (Session["CurrentCart"] != null) { cartList = (List <MyCart>)Session["CurrentCart"]; } if (!cartList.Contains(mc) && (mc.ProductName != null)) { cartList.Add(mc); Session["CurrentCart"] = cartList; } return(View(cartList)); }
public ActionResult AddToMyCart(int id) { // MyCart mycart = new MyCart(); bu kullanım her sepete ekle için yeni sepet oluşturur yani her ürün farklı sepette olur MyCart cart = Session["cart"] as MyCart; CartItemDTO cartItem = new CartItemDTO(); var eklenenAlbum = albumService.Get(id); cartItem.ID = eklenenAlbum.ID; cartItem.Name = eklenenAlbum.Title; //cartItem.Price = eklenenAlbum.Price; //price eklerken indirim olsun,%10 indirim olsun cartItem.Price = eklenenAlbum.Discounted ? eklenenAlbum.Price * 0.9m : eklenenAlbum.Price; cartItem.Amount = 1; cart.Add(cartItem); Session["cart"] = cart; return(PartialView("_CartButton")); }
//DeleteCart public ActionResult DeleteCart(int id) { MVCTestEntities _entity = new MVCTestEntities(); var crt = _entity.Carts.Where(x => x.CartID == id).First(); _entity.Carts.Remove(crt); _entity.SaveChanges(); int userid = Convert.ToInt32(Session["UserID"]); var lst1 = (from mc in _entity.Carts join pr in _entity.Products on mc.ProductID equals pr.ProductID join ur in _entity.Users on mc.UserID equals ur.UserID where mc.UserID == userid select new { ProductName = pr.Name, ProductImage = pr.ImagePath, ProductQnt = mc.ProductQnt, TotalPrice = mc.TotalPrice, CartID = mc.CartID }).ToList(); List <MyCart> mcrt = new List <MyCart>(); for (int j = 0; j < lst1.Count; j++) { MyCart mct = new MyCart(); mct.ProductName = lst1[j].ProductName; mct.ProductQnt = lst1[j].ProductQnt; mct.TotalPrice = lst1[j].TotalPrice; mct.CartID = lst1[j].CartID; mct.ProductImage = lst1[j].ProductImage; mcrt.Add(mct); } Session["Result"] = mcrt; ViewBag.Myorder = mcrt; return(View("MyCart", mcrt)); }
protected void QuantityTextBox_TextChanged(object sender, EventArgs e) { GridViewRow row = ((Control)(sender)).NamingContainer as GridViewRow; GridView grid = row.NamingContainer as GridView; string productId = grid.DataKeys[row.RowIndex].Value.ToString(); MyCart myCart = Session["MyCart"] as MyCart; if (myCart != null) { List <ShoppingCartItem> list = myCart.MyCartList; int index = list.IndexOf(new ShoppingCartItem { ProductId = productId }); list[index].Quantity = int.Parse((row.FindControl("QuantityTextBox") as TextBox).Text); list[index].Total = list[index].UnitPrice * list[index].Quantity; Session["MyCart"] = myCart; LoadData(); } }
protected void button_checkout_Click(object sender, EventArgs e) { try { MyCart objCart = this.Session["MyCart"] as MyCart; if (objCart.ListProducts.Count > 0) { MembershipUser objUser = Membership.GetUser(); MailMessage email = new MailMessage(); email.To.Add(new MailAddress(objUser.Email)); email.From = new MailAddress("*****@*****.**"); email.Subject = "Buy product in my shop ( " + DateTime.Now.ToString("dd/MMM/yyyy hh:mm:ss") + " ) "; email.Body = TemplateEmail(objCart); email.IsBodyHtml = true; email.Priority = MailPriority.Normal; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.Credentials = new NetworkCredential("*****@*****.**", "3177094218"); smtp.Send(email); email.Dispose(); this.Session["MyCart"] = new MyCart(); Response.Redirect("MyProducts.aspx"); ((Site)this.Page.Master).ShowAlert("success", "Send email with detail of sale. Done"); } else { ((Site)this.Page.Master).ShowAlert("warnning", "You must at least add a product to the shopping cart"); } } catch (Exception ex) { ((Site)this.Page.Master).ShowAlert("danger", "Error in send email: " + ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { myCart = Session["MyCart"] as MyCart; if (myCart == null) { myCart = new MyCart(); Session["MyCart"] = myCart; } if (Request.QueryString["catId"] != null) { categoryId = Request.QueryString["catId"].ToString(); } else categoryId = "1"; if (!Page.IsPostBack) { LoadProducts(categoryId); } }
// // GET: /HelloWorld/Welcome/ public async Task <IActionResult> MyCart() { MyCart mycart = new MyCart(); //List<Item> items = new List<Item>(); //var item1 = new Item(); //item1.ItemDescription = "notebook"; //item1.Qty = 3; //item1.UnitPrice = 4; //var item2 = new Item(); //item2.ItemDescription = "computers"; //item2.Qty = 1; //item2.UnitPrice = 10; //items.Add(item1); //items.Add(item2); //mycart.items = items; mycart.items = await myClientBus.GetCartList(); return(View(mycart)); }
public ActionResult AddCart(int id) { MyCart myCart; if (Session["cart"] == null) { myCart = new MyCart(); } else { myCart = Session["cart"] as MyCart; } Product product = _productManager.GetProduct(id); CartItem cartItem = new CartItem(); cartItem.ID = product.ProductID; cartItem.Name = product.ProductName; cartItem.Price = (decimal)product.UnitPrice; myCart.Add(cartItem); Session["cart"] = myCart; return(RedirectToAction("ListProductsForOrder")); }
public ActionResult Create(OrderViewModel orderViewModel) { if (ModelState.IsValid) { int customerId = ConnectToDb.GetLastGeneratedValue(orderViewModel.FirstName, orderViewModel.LastName); if (customerId != 0) { bookDbContext.CustomerAdresses.Add(new CustomerAdress { Country = orderViewModel.Country, CityOrVillage = orderViewModel.CityOrVillage, Street = orderViewModel.Street, House = orderViewModel.House, Appartment = orderViewModel.Appartment, CustomerId = customerId }); MyCart cart = MyCart.GetCart(); for (int i = 0; i < cart.bookCartCount; i++) { bookDbContext.CustomerOrders.Add(new CustomerOrder { CustomerId = customerId, BookId = cart[i].book.BookId, Price = cart[i].book.Price, Quantity = cart[i].amount, OrderDateTime = DateTime.Now, OrderStatus = OrderStatus.Open.ToString() }); } bookDbContext.SaveChanges(); return(View("Success", cart)); } } return(View("Fall")); }
protected void UpdateMyCart_Click(object sender, EventArgs e) { MyCart myCart = Session["MyCart"] as MyCart; if (myCart != null) { List <ShoppingCartItem> list = myCart.MyCartList; for (int i = 0; i < MyCartGridView.Rows.Count; i++) { CheckBox checkBox = MyCartGridView.Rows[i].FindControl("DeleteCheckBox") as CheckBox; string productId = MyCartGridView.DataKeys[i].Value.ToString(); if (checkBox.Checked == true) { list.Remove(new ShoppingCartItem { ProductId = productId }); } } Session["MyCart"] = myCart; LoadData(); } }
public ActionResult AddToCart(int id) { if (Session["kullanici"] != null) { MyCart cart = Session["cart"] as MyCart; CartItemDTO cartItem = new CartItemDTO(); var eklenenAlbum = albumService.Get(id); cartItem.ID = eklenenAlbum.ID; cartItem.Name = eklenenAlbum.Title; cartItem.Price = eklenenAlbum.Discontinued ? eklenenAlbum.Price * 0.9m : eklenenAlbum.Price; //indirim varsa indirimli fiyat, yoksa normal fiyatı verir (????) cartItem.Amount = 1; cart.Add(cartItem); Session["cart"] = cart; } else { throw new Exception(); } return(PartialView("_CartButton")); }
protected void Page_Load(object sender, EventArgs e) { myCart = Session["MyCart"] as MyCart; if (myCart == null) { myCart = new MyCart(); Session["MyCart"] = myCart; } if (Request.QueryString["catId"] != null) { categoryId = Request.QueryString["catId"].ToString(); } else { categoryId = "1"; } if (!Page.IsPostBack) { LoadProducts(categoryId); } }
// Update Cart Command // public MyCart UpdateMyCart(MyCart myCartToUpdate) { using (var db = new SqlConnection(ConnectionString)) { var updateQuery = @"Update MyCarts Set UserId = @userId, CartsId = @cartsId, ImageUrl = @imageUrl, Name = @name, Genre = @genre, ReleaseDate = @releaseDate, Where Id = @id"; var rowsAffected = db.Execute(updateQuery, myCartToUpdate); if (rowsAffected == 1) { return(myCartToUpdate); } throw new Exception("There Was An Error. Your NESVault Cart Wasn't Updated"); } }
// // GET: /Basket/ public ActionResult Index() { MyCart cart = MyCart.GetCart(); return(View(cart)); }
protected void Page_Load(object sender, EventArgs e) { myCart = Session["MyCart"] as MyCart; if (myCart == null) { myCart = new MyCart(); Session["MyCart"] = myCart; } if (!Page.IsPostBack) RetreiveWishList(); }
public ActionResult _CartItems() { MyCart myCart = Session["cart"] as MyCart; return(PartialView(myCart.CartItems)); }
protected void Session_Start(object sender, EventArgs e) { Session["cart"] = new MyCart(); }
protected void Session_Start() { //kişi siteye girdiği anda tetiklenen metod Session["cart"] = new MyCart(); }
public ActionResult ShowCart() { return(View(MyCart.GetInstance().Cart)); }
protected void Session_Start() { Session["cart"] = new MyCart(); Session["lang"] = "tr-TR"; }
public IActionResult GetCartButton() { MyCart myCart = HttpContext.Session.Get <MyCart>("cart"); return(PartialView("_cartButton", myCart.TotalAmount)); }
//get my cart list public List <MyCart> GetMyCartDAL(string username) { //define cartlist List <MyCart> MyCartList = new List <MyCart>(); try { //Connection to database SqlConnection objCon = new SqlConnection(Database.ConnectionString); //get sql stored procedure to execute SqlCommand objCom = new SqlCommand(Database.VIEWMYCARTS, objCon); //setting command type to stored procedure objCom.CommandType = CommandType.StoredProcedure; //Defining parameters for StoredProcedure SqlParameter objSP_username = new SqlParameter("@username", username); //Add parameter objCom.Parameters.Add(objSP_username); //open connection objCon.Open(); SqlDataReader sqlDataReader = objCom.ExecuteReader(); //fetch data while (sqlDataReader.Read()) { //mycart entity object MyCart mycart = new MyCart(); mycart.CartId = sqlDataReader.GetInt32(0); mycart.Name = sqlDataReader.GetString(1); mycart.IngredientQuantity = sqlDataReader.GetDecimal(2); mycart.Price = sqlDataReader.GetDecimal(3); mycart.Amount = sqlDataReader.GetDecimal(4); MyCartList.Add(mycart); } //clsoe connection objCon.Close(); } catch (Exception ex) { throw new RecipeIngredientSystemExceptions(ex.Message); } return(MyCartList); /*SqlDataAdapter da = new SqlDataAdapter(objCom); * DataSet ds = new DataSet(); * DataTable dt = new DataTable(); * da.Fill(ds); * * dt = ds.Tables[0]; * * for (int i = 0; i < dt.Rows.Count; i++) * { * MyCart objMyCart = new MyCart(); * objMyCart.CartId = Convert.ToInt32(dt.Rows[i]["CartId"]); * objMyCart.IngredientName = Convert.ToString(dt.Rows[i]["IngredientName"]); * objMyCart.IngredientQuantity = Convert.ToDecimal(dt.Rows[i]["IngredientQuantity"]); * objMyCart.Price = Convert.ToDecimal(dt.Rows[i]["Price"]); * objMyCart.Amount = Convert.ToDecimal(dt.Rows[i]["Amount"]); * MyCartList.Add(objMyCart); * } * return MyCartList;*/ }