public ActionResult HDAddDoAn(hoa_don_chi_tiet _hdct)
        {
            if (!AuthCheck("nhanvien"))
            {
                return(RedirectToAction("Index", "QLDoAn"));
            }
            try
            {
                Random random     = new Random();
                string chars      = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789qwertyuiopasdfghjklzxcvbnm";
                string randomChar = new string(Enumerable.Repeat(chars, 5).Select(s => s[random.Next(s.Length)]).ToArray());

                var _dact = db.do_an_chi_tiet.Where(s => s.id == _hdct.do_an_chi_tiet_id).FirstOrDefault();

                _hdct.id        = _hdct.hoa_don_id + "-" + randomChar;
                _hdct.tong_tien = _dact.don_gia * _hdct.so_luong;
                db.hoa_don_chi_tiet.Add(_hdct);
                db.SaveChanges();
                ViewBag.ID = _hdct.hoa_don_id;
                return(RedirectToAction("AddHoaDon", "QLDoAn", new { id = _hdct.hoa_don_id }));
            }
            catch (Exception e)
            {
                ViewBag.Error = e.ToString();
                return(View("~/Views/QLHome/Error.cshtml"));
            }
        }
        public ActionResult DeleteHDCT(string id)
        {
            if (!AuthCheck("nhanvien"))
            {
                return(RedirectToAction("Index", "QLDoAn"));
            }
            hoa_don_chi_tiet _hdct = db.hoa_don_chi_tiet.Where(item => item.id == id).FirstOrDefault();
            string           hdid  = _hdct.hoa_don_id;

            ViewBag.ID            = hdid;
            db.Entry(_hdct).State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
            return(RedirectToAction("AddHoaDon", "QLDoAn", new { id = hdid }));
        }
        public ActionResult UpdateHDCT(FormCollection form)
        {
            if (!AuthCheck("nhanvien"))
            {
                return(RedirectToAction("Index", "QLDoAn"));
            }
            string           id    = form["idHDCT"].ToString();
            hoa_don_chi_tiet _hdct = db.hoa_don_chi_tiet.Where(item => item.id == id).FirstOrDefault();

            if (String.IsNullOrEmpty(form["SoLuong"]) || int.Parse(form["SoLuong"]) < 1)
            {
                _hdct.so_luong = 1;
            }
            else
            {
                _hdct.so_luong = int.Parse(form["SoLuong"]);
            }
            _hdct.tong_tien = _hdct.so_luong * _hdct.do_an_chi_tiet.don_gia;
            db.SaveChanges();
            return(RedirectToAction("AddHoaDon", "QLDoAn", new { id = _hdct.hoa_don_id }));
        }