public async Task <IActionResult> PutCongThucNuoc([FromRoute] int id, [FromBody] CongThucNuoc congthucnuoc)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != congthucnuoc.CongThucNuocId)
            {
                return(BadRequest());
            }
            var user   = this.User.Identity.Name;
            var userId = Utilities.GetUserId(this.User);

            congthucnuoc.NgaySua  = DateTime.Now;
            congthucnuoc.NguoiSua = user;
            var checkten = await _context.CongThucNuocs.SingleOrDefaultAsync(r => r.TenCongThucNuoc == congthucnuoc.TenCongThucNuoc && r.CongThucNuocId != id);

            if (checkten == null)
            {
                _context.Entry(congthucnuoc).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            else
            {
                var warn = "";
                if (checkten != null)
                {
                    warn = "Exist";
                }
                return(Ok(warn));
            }
        }
        public async Task <IActionResult> PostCongThucNuoc([FromBody] CongThucNuoc congthucnuoc)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var user   = this.User.Identity.Name;
            var userId = Utilities.GetUserId(this.User);

            congthucnuoc.NgayNhap  = DateTime.Now;
            congthucnuoc.NguoiNhap = user;
            var checkten = await _context.CongThucNuocs.SingleOrDefaultAsync(r => r.TenCongThucNuoc == congthucnuoc.TenCongThucNuoc);

            if (checkten == null)
            {
                _context.CongThucNuocs.Add(congthucnuoc);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetCongThucNuoc", new { id = congthucnuoc.CongThucNuocId }, congthucnuoc));
            }
            else
            {
                var warn = new CongThucNuoc();
                if (checkten != null)
                {
                    warn.TenCongThucNuoc = "Exist";
                }
                return(Ok(warn));
            }
        }
        public async Task <IActionResult> updateTable(int id)
        {
            CongThucNuoc ctn   = new CongThucNuoc();
            var          check = _context.CongThucNuocs.Where(r => r.CongThucNuocId != id && r.Status == true);

            if (check.Count() != 0)
            {
                foreach (var item in check)
                {
                    item.Status = false;
                }
            }
            await _context.SaveChangesAsync();

            return(NoContent());
        }