コード例 #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());
        }
コード例 #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());
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        public async Task <IActionResult> XoaLoai([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var loai = await ketnoidatabase.LoaiSanPham.SingleOrDefaultAsync(m => m.Id == id);

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

            ketnoidatabase.LoaiSanPham.Remove(loai);
            await ketnoidatabase.SaveChangesAsync();

            return(Ok(loai));
        }
コード例 #5
0
        public async Task <IActionResult> DangKy([FromBody] ModelDangKyMau taikhoandungdedangky)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var khachhang = new KhachHang()
            {
                Id    = Guid.NewGuid().ToString(),
                HoTen = taikhoandungdedangky.Ho + " " + taikhoandungdedangky.Ten,
            };

            await ketnoidatabase.KhachHang.AddAsync(khachhang);

            await ketnoidatabase.SaveChangesAsync();

            var kqTaoKhachHang = ketnoidatabase.KhachHang.Where(p => p.Id == khachhang.Id).SingleOrDefault();

            var taikhoan = new NguoiDungEntity()
            {
                UserName    = taikhoandungdedangky.Email,
                Email       = taikhoandungdedangky.Email,
                Ho          = taikhoandungdedangky.Ho,
                Ten         = taikhoandungdedangky.Ten,
                IdKhachHang = kqTaoKhachHang.Id
            };
            //Tao tai khoan user bang CreateAsync
            var kq = await _quanlyTaiKhoan.CreateAsync(taikhoan, taikhoandungdedangky.MatKhau);

            if (kq.Succeeded)
            {
                return(Ok(kq));
            }

            foreach (var err in kq.Errors)
            {
                ModelState.AddModelError("error", err.Description);
            }

            return(BadRequest(kq.Errors));
        }