Exemplo n.º 1
0
 public ActionResult GetToCart(int soLuong)
 {
     if (Session["userID"] != null)
     {
         using (var db = new Models.QLPhone())
         {
             Models.CTGIOHANG ct = new Models.CTGIOHANG();
             ct.MaDienThoai = Session["bookID"].ToString();
             ct.TenTaiKhoan = Session["userID"].ToString();
             Models.CTGIOHANG ct2 = db.CTGIOHANGs.Find(ct.MaDienThoai, ct.TenTaiKhoan);
             if (ct2 != null)
             {
                 ct2.SoLuongGioHang += short.Parse(soLuong.ToString());
                 db.Entry(ct2).State = EntityState.Modified;
             }
             else
             {
                 ct2                = new Models.CTGIOHANG();
                 ct2.MaDienThoai    = ct.MaDienThoai;
                 ct2.TenTaiKhoan    = ct.TenTaiKhoan;
                 ct2.SoLuongGioHang = short.Parse(soLuong.ToString());
                 db.CTGIOHANGs.Add(ct2);
             }
             db.SaveChanges();
         }
     }
     else
     {
         return(RedirectToAction("Login", "Login"));
     }
     return(RedirectToAction("Index", "Home"));
 }
Exemplo n.º 2
0
        public ActionResult Purchase(string idDT)
        {
            string idKhach = Session["userID"].ToString();

            using (var db = new Models.QLPhone())
            {
                Models.CTGIOHANG ct = new Models.CTGIOHANG();
                ct                 = db.CTGIOHANGs.Where(t => t.MaDienThoai == idDT && t.TenTaiKhoan == idKhach).FirstOrDefault();
                ViewBag.cccc       = idDT;
                db.Entry(ct).State = EntityState.Deleted;
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "Home"));
        }