Exemple #1
0
        public IHttpActionResult PostNhapHoaDon(NhapHoaDon nhapHoaDon)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.nhapHoaDons.Add(nhapHoaDon);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (NhapHoaDonExists(nhapHoaDon.IDNHD))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = nhapHoaDon.IDNHD }, nhapHoaDon));
        }
Exemple #2
0
        public IHttpActionResult PutNhapHoaDon(string id, NhapHoaDon nhapHoaDon)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != nhapHoaDon.IDNHD)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #3
0
        public IHttpActionResult GetNhapHoaDon(string id)
        {
            NhapHoaDon nhapHoaDon = db.nhapHoaDons.Find(id);

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

            return(Ok(nhapHoaDon));
        }
Exemple #4
0
        public IHttpActionResult PostNhapHoaDonGetIdentity(NhapHoaDon nhapHoaDon)
        {
            using (var entity = new BanHangDBContext())
            {
                nhapHoaDon.IDNHD = GetIdentity();
                entity.nhapHoaDons.Add(nhapHoaDon);

                entity.SaveChanges();
            }

            return(Ok(nhapHoaDon));
        }
Exemple #5
0
        public IHttpActionResult DeleteNhapHoaDon(string id)
        {
            NhapHoaDon nhapHoaDon = db.nhapHoaDons.Find(id);

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

            db.nhapHoaDons.Remove(nhapHoaDon);
            db.SaveChanges();

            return(Ok(nhapHoaDon));
        }