private void updatequality(int id) { List<GiohangModel> ls = (List<GiohangModel>)Session["giohang"]; GiohangModel gm = new GiohangModel(); gm = ls.Where(g => g.Productid == id).FirstOrDefault(); GiohangModel gm1 = new GiohangModel(); gm1.Productid = id; gm1.ProductName = gm.ProductName; gm1.Quality = gm.Quality; gm1.Soluong = gm.Soluong + 1; ls.RemoveAll(x => x.Productid == id); //ls.Add(gm1); ls.Insert(0,gm1); Session["giohang"] = ls; }
public ActionResult Capnhapsoluong(string a , string a1) { List<GiohangModel> lg = (List<GiohangModel>)Session["giohang"]; GiohangModel obj = new GiohangModel(); if(!TestSo(a)) { } else { obj = lg.Where(e => e.Productid == Convert.ToInt32(a1)).FirstOrDefault(); GiohangModel g = new GiohangModel(); g.Productid = Convert.ToInt32(a1); g.ProductName = obj.ProductName; g.Quality = obj.Quality; g.Descript = obj.Descript; g.Soluong = Convert.ToInt32(a); lg.RemoveAll(x=>x.Productid==Convert.ToInt32(a1)); lg.Insert(0, g); Session["giohang"] = lg; Response.Write("ok"); } return null; }
public ActionResult giohang(int id) { string a = ""; StationeryModelcs sc = new StationeryModelcs(); if (Session["giohang"] == null) { List<GiohangModel> lg1 = new List<GiohangModel>(); GiohangModel gl = new GiohangModel(); gl.ProductName = sc.stati(id).ProductName; gl.Productid = sc.stati(id).ProductId; gl.Quality = Convert.ToInt32(sc.stati(id).Quantity); gl.Descript = sc.stati(id).Description; gl.Soluong = 1; lg1.Add(gl); Session["giohang"] = lg1; a += "<tr class='remove' >"; a += String.Format("<td class='id'>{0}</td>", gl.Productid); a += String.Format("<td>{0}</td>", gl.ProductName); a += String.Format("<td>{0}</td>", gl.Quality); a += String.Format("<td>{0}</td>", gl.Descript); a += String.Format("<td><input type='type' name='sl' class='sl' value='{0}' /></td>", gl.Soluong); a += String.Format("<td><button class='remove1'>Remove</button><input type='hidden' class='giatri1' value='{0}'></td></td>", gl.Productid); a += "</tr>"; Response.Write(a); } else { if (TestProduct(id)) { string a1 = ""; updatequality(id); List<GiohangModel> gh = (List<GiohangModel>)Session["giohang"]; foreach (GiohangModel g in gh) { a1 += "<tr class='remove'>"; a1 += String.Format("<td class='id'>{0}</td>", g.Productid); a1 += String.Format("<td>{0}</td>", g.ProductName); a1 += String.Format("<td>{0}</td>", g.Quality); a1 += String.Format("<td>{0}</td>", g.Descript); a1 += String.Format("<td><input type='type' name='sl' class='sl' value='{0}' /></td>", g.Soluong); a1 += String.Format("<td><button class='remove1'>Remove</button><input type='hidden' class='giatri1' value='{0}'></td></td>", g.Productid); a1 += "</tr>"; } Response.Write(a1); } else { List<GiohangModel> lg1 = (List<GiohangModel>)Session["giohang"]; Stationery s1 = sc.stati(id); GiohangModel gm1 = new GiohangModel(); gm1.Productid = s1.ProductId; gm1.ProductName = s1.ProductName; gm1.Quality = Convert.ToInt32(s1.Quantity); gm1.Soluong = 1; lg1.Insert(0, gm1); Session["giohang"] = lg1; string a2 = ""; foreach (GiohangModel g in (List<GiohangModel>)Session["giohang"]) { a2 += "<tr class='remove'>"; a2 += String.Format("<td class='id'>{0}</td>", g.Productid); a2 += String.Format("<td>{0}</td>", g.ProductName); a2 += String.Format("<td>{0}</td>", g.Quality); a2 += String.Format("<td>{0}</td>", g.Descript); a2 += String.Format("<td><input type='type' name='sl' class='sl' value='{0}' /></td>", g.Soluong); a2 += String.Format("<td><button class='remove1'>Remove</button><input type='hidden' class='giatri1' value='{0}'></td></td>", g.Productid); a2 += "</tr>"; } Response.Write(a2); } } return null; }