Beispiel #1
0
        public async Task <IActionResult> CapNhatDonHang([FromRoute] int id, [FromBody] DonHang donhang)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != donhang.Id)
            {
                return(BadRequest());
            }

            ketnoidatabase.Entry(donhang).State = EntityState.Modified;

            try
            {
                await ketnoidatabase.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Kiemtrasutontaicuadonhang(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> CapNhatKhachHang([FromRoute] string id, [FromBody] KhachHang khachhang)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != khachhang.Id)
            {
                return(BadRequest());
            }

            ketnoidatabase.Entry(khachhang).State = EntityState.Modified;

            try
            {
                await ketnoidatabase.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KtKhachHangTonTai(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> CapNhatSanPham([FromRoute] int id, [FromBody] SanPham product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.Id)
            {
                return(BadRequest());
            }

            ketnoidatabase.Entry(product).State = EntityState.Modified;

            try
            {
                await ketnoidatabase.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KiemTraSanPhamTonTai(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public JsonResult CapNhatLoaiSanPham([FromBody] LoaiSanPham loai)
        {
            var cate = ketnoidatabase.LoaiSanPham.Find(loai.Id);

            if (cate == null)
            {
                throw new Exception("Khong the cap nhat");
            }
            else
            {
                cate.Ten  = loai.Ten;
                cate.MoTa = loai.MoTa;
                ketnoidatabase.Entry(cate).State = EntityState.Modified;
                ketnoidatabase.SaveChanges();
            }
            return(Json(true));
        }