Ejemplo n.º 1
0
        public IHttpActionResult PostPhieuThaoTac(PhieuThaoTac phieuThaoTac)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PhieuThaoTacs.Add(phieuThaoTac);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (PhieuThaoTacExists(phieuThaoTac.MaPhieuThaoTac))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = phieuThaoTac.MaPhieuThaoTac }, phieuThaoTac));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutPhieuThaoTac(string id, PhieuThaoTac phieuThaoTac)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != phieuThaoTac.MaPhieuThaoTac)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetPhieuThaoTac(string id)
        {
            PhieuThaoTac phieuThaoTac = db.PhieuThaoTacs.Find(id);

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

            return(Ok(phieuThaoTac));
        }
Ejemplo n.º 4
0
        public IHttpActionResult DeletePhieuThaoTac(string id)
        {
            PhieuThaoTac phieuThaoTac = db.PhieuThaoTacs.Find(id);

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

            db.PhieuThaoTacs.Remove(phieuThaoTac);
            db.SaveChanges();

            return(Ok(phieuThaoTac));
        }