public IHttpActionResult PostCTGIOHANG(CTGIOHANG cTGIOHANG)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CTGIOHANGs.Add(cTGIOHANG);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CTGIOHANGExists(cTGIOHANG.MaDienThoai))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = cTGIOHANG.MaDienThoai }, cTGIOHANG));
        }
        public IHttpActionResult PutCTGIOHANG(string id, CTGIOHANG cTGIOHANG)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cTGIOHANG.MaDienThoai)
            {
                return(BadRequest());
            }

            db.Entry(cTGIOHANG).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CTGIOHANGExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult GetCTGIOHANG(string id)
        {
            CTGIOHANG cTGIOHANG = db.CTGIOHANGs.Find(id);

            if (cTGIOHANG == null)
            {
                return(NotFound());
            }

            return(Ok(cTGIOHANG));
        }
        public IHttpActionResult DeleteCTGIOHANG(string id)
        {
            CTGIOHANG cTGIOHANG = db.CTGIOHANGs.Find(id);

            if (cTGIOHANG == null)
            {
                return(NotFound());
            }

            db.CTGIOHANGs.Remove(cTGIOHANG);
            db.SaveChanges();

            return(Ok(cTGIOHANG));
        }
Beispiel #5
0
        public ActionResult ConfirmBuy([Bind(Include = "MAGH,MATP,MAPTTT,TRANGTHAI,NGAYXUAT,TONGTIEN,HOTENKH,SDTKH,GIOITINHKH,LOINHAN,DIACHI")] GIOHANG gIOHANG, string tp, string qh)
        {
            if (Session["giohang"] == null)
            {
                return(RedirectToAction("CheckOutResult", "User", new { success = false }));
            }

            if (ModelState.IsValid)
            {
                if (gIOHANG.LOINHAN == null || gIOHANG.LOINHAN.Replace(" ", "").Length <= 0)
                {
                    gIOHANG.LOINHAN = "Không có";
                }
                List <CTMH> ctghs = Session["giohang"] as List <CTMH>;
                var         id    = GetNewCartId();
                gIOHANG.MAGH = id;
                db.GIOHANGs.Add(gIOHANG);
                db.SaveChanges();
                foreach (var item in ctghs)
                {
                    var gh = new CTGIOHANG();
                    gh.MAGH      = gIOHANG.MAGH;
                    gh.MAMH      = item.MAMH;
                    gh.MATHANG   = db.MATHANGs.Find(item.MAMH);
                    gh.SOLUONG   = item.SOLUONG;
                    gh.THANHTIEN = item.THANHTIEN;
                    gh.GIOHANG   = gIOHANG;
                    db.CTGIOHANGs.Add(gh);
                    db.SaveChanges();
                }
                Session["giohang"] = null;
                return(RedirectToAction("CheckOutResult", "User", new { success = true, id = id }));
            }

            ViewBag.MAPTTT = new SelectList(db.PHUONGTHUCTHANHTOANs, "MAPTTT", "TENPTTT", gIOHANG.MAPTTT);
            ViewBag.MATP   = new SelectList(db.PHUONGXAs, "MAPX", "TENPX", gIOHANG.MATP);
            ViewBag.TENTP  = tp;
            ViewBag.TENQH  = qh;
            return(View(gIOHANG));
        }