public ActionResult ChinhSuaLoiDanToc(int id)
        {
            ModelQuyenNguoiDung quyenNguoiDung = Session["QuyenNguoiDung"] as ModelQuyenNguoiDung;

            if (quyenNguoiDung != null && (quyenNguoiDung.Quyen.Ten == "QuanLyThongTinHocSinh" || quyenNguoiDung.Quyen.Ten == "Admin"))
            {
                LoiModel  chitietLoi = new LoiModel();
                TABLE_LOI tableLoi   = db.TABLE_LOI.Find(id);
                string    typeLoi    = tableLoi.TypeLOI;
                ViewBag.typeLoi = typeLoi;
                ViewBag.idLoi   = id;
                Xuly xuly = new Xuly();
                ViewBag.HocSinhLoi = xuly.ReturnHoten(id);
                int id_GKS = tableLoi.id_GKS ?? 0;
                int id_BTN = tableLoi.id_BTN ?? 0;
                int id_HB  = tableLoi.id_HB ?? 0;
                if (check(id_GKS))
                {
                    chitietLoi.Giaykhaisinh = db.GIAYKHAISINHs.Find(id_GKS);
                }
                if (check(id_BTN))
                {
                    chitietLoi.Bangtotnghiep = db.BANGTOTNGHIEPs.Find(id_BTN);
                }
                if (check(id_HB))
                {
                    chitietLoi.Hocba = db.HOCBAs.Find(id_HB);
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public JsonResult ChinhSuaLoiDanToc(List <string> listKey)
        {
            LoiModel  chitietLoi = new LoiModel();
            int       idLoi      = Int32.Parse(listKey[0]);
            string    DanTocGKS  = listKey[1];
            string    DanTocBTN  = listKey[2];
            string    DanTocHB   = listKey[3];
            TABLE_LOI tableLoi   = db.TABLE_LOI.Find(idLoi);
            string    typeLoi    = tableLoi.TypeLOI;

            if (DanTocGKS != null)
            {
                GIAYKHAISINH gks = db.GIAYKHAISINHs.Find(tableLoi.id_GKS);
                gks.DanToc          = DanTocGKS;
                db.Entry(gks).State = System.Data.Entity.EntityState.Modified;
            }
            if (DanTocBTN != null)
            {
                BANGTOTNGHIEP btn = db.BANGTOTNGHIEPs.Find(tableLoi.id_BTN);
                btn.DanToc          = DanTocBTN;
                db.Entry(btn).State = System.Data.Entity.EntityState.Modified;
            }
            if (DanTocHB != null)
            {
                HOCBA hocba = db.HOCBAs.Find(tableLoi.id_HB);
                hocba.DanToc          = DanTocHB;
                db.Entry(hocba).State = System.Data.Entity.EntityState.Modified;
            }
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
        public ActionResult ChinhSuaLoiQueQuan(int id)
        {
            ModelQuyenNguoiDung quyenNguoiDung = Session["QuyenNguoiDung"] as ModelQuyenNguoiDung;

            if (quyenNguoiDung != null && (quyenNguoiDung.Quyen.Ten == "QuanLyThongTinHocSinh" || quyenNguoiDung.Quyen.Ten == "Admin"))
            {
                LoiModel  chitietLoi = new LoiModel();
                TABLE_LOI tableLoi   = db.TABLE_LOI.Find(id);
                string    typeLoi    = tableLoi.TypeLOI;
                ViewBag.idLoi   = id;
                ViewBag.typeLoi = typeLoi;
                Xuly xuly = new Xuly();
                ViewBag.HocSinhLoi = xuly.ReturnHoten(id);
                int    id_GKS = tableLoi.id_GKS ?? 0;
                string so_CMT = tableLoi.So_CMT ?? null;
                if (check(id_GKS))
                {
                    chitietLoi.Giaykhaisinh = db.GIAYKHAISINHs.Find(id_GKS);
                }
                if (so_CMT != null)
                {
                    chitietLoi.Cmt = db.CMTs.Find(so_CMT);
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public JsonResult ChinhSuaLoiNgaySinh(List <string> listKey)
        {
            try
            {
                LoiModel  chitietLoi = new LoiModel();
                int       idLoi      = Int32.Parse(listKey[0]);
                TABLE_LOI tableLoi   = db.TABLE_LOI.Find(idLoi);
                string    typeLoi    = tableLoi.TypeLOI;
                if (listKey[1] != null)
                {
                    DateTime NgaySinhCMT = DateTime.Parse(listKey[1]);
                    CMT      cmt         = db.CMTs.Find(tableLoi.So_CMT);
                    cmt.NgaySinh        = NgaySinhCMT;
                    db.Entry(cmt).State = EntityState.Modified;
                }

                if (listKey[2] != null)
                {
                    DateTime     NgaySinhGKS = DateTime.Parse(listKey[2]);
                    GIAYKHAISINH gks         = db.GIAYKHAISINHs.Find(tableLoi.id_GKS);
                    gks.NgaySinh        = NgaySinhGKS;
                    db.Entry(gks).State = EntityState.Modified;
                }

                if (listKey[3] != null)
                {
                    DateTime      NgaySinhBTN = DateTime.Parse(listKey[3]);
                    BANGTOTNGHIEP btn         = db.BANGTOTNGHIEPs.Find(tableLoi.id_BTN);
                    btn.NgaySinh        = NgaySinhBTN;
                    db.Entry(btn).State = EntityState.Modified;
                }

                if (listKey[4] != null)
                {
                    DateTime NgaySinhHB = DateTime.Parse(listKey[4]);
                    HOCBA    hocba      = db.HOCBAs.Find(tableLoi.id_HB);
                    hocba.NgaySinh        = NgaySinhHB;
                    db.Entry(hocba).State = EntityState.Modified;
                }
                db.SaveChanges();
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(e, JsonRequestBehavior.AllowGet));
            }
        }
        public JsonResult ChinhSuaLoiHoTen(List <string> listKey)
        {
            LoiModel  chitietLoi = new LoiModel();
            int       idLoi      = Int32.Parse(listKey[0]);
            string    TenHS      = listKey[1];
            string    TenCMT     = listKey[2];
            string    TenGKS     = listKey[3];
            string    TenBTN     = listKey[4];
            string    TenHB      = listKey[5];
            TABLE_LOI tableLoi   = db.TABLE_LOI.Find(idLoi);
            string    typeLoi    = tableLoi.TypeLOI;

            if (TenHS != null)
            {
                HOCSINH hocsinh = db.HOCSINHs.Find(tableLoi.id_HS);
                hocsinh.TenHS           = TenHS;
                db.Entry(hocsinh).State = System.Data.Entity.EntityState.Modified;
            }
            if (TenCMT != null)
            {
                CMT cmt = db.CMTs.Find(tableLoi.So_CMT);
                cmt.HoTen           = TenCMT;
                db.Entry(cmt).State = System.Data.Entity.EntityState.Modified;
            }
            if (TenGKS != null)
            {
                GIAYKHAISINH gks = db.GIAYKHAISINHs.Find(tableLoi.id_GKS);
                gks.HoTen           = TenGKS;
                db.Entry(gks).State = System.Data.Entity.EntityState.Modified;
            }
            if (TenBTN != null)
            {
                BANGTOTNGHIEP btn = db.BANGTOTNGHIEPs.Find(tableLoi.id_BTN);
                btn.HoTen           = TenBTN;
                db.Entry(btn).State = System.Data.Entity.EntityState.Modified;
            }
            if (TenHB != null)
            {
                HOCBA hocba = db.HOCBAs.Find(tableLoi.id_HB);
                hocba.HoTen           = TenHB;
                db.Entry(hocba).State = System.Data.Entity.EntityState.Modified;
            }
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }
        public ActionResult ChinhSua(int id)  //id -- mã bên lỗi
        {
            ModelQuyenNguoiDung quyenNguoiDung = Session["QuyenNguoiDung"] as ModelQuyenNguoiDung;

            if (quyenNguoiDung != null && (quyenNguoiDung.Quyen.Ten == "QuanLyThongTinHocSinh" || quyenNguoiDung.Quyen.Ten == "Admin"))
            {
                CapNhatTb();

                LoiModel  chitietLoi = new LoiModel();
                TABLE_LOI tableLoi   = db.TABLE_LOI.Find(id);
                if (checkNguoiTao(tableLoi, quyenNguoiDung.Nhanvien.id) == false)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                string typeLoi = tableLoi.TypeLOI;
                ViewBag.typeLoi = typeLoi;

                if (typeLoi == "HoTen")
                {
                    return(RedirectToAction("ChinhSuaLoiHoTen", new { id = id }));
                }
                if (typeLoi == "NgaySinh")
                {
                    return(RedirectToAction("ChinhSuaLoiNgaySinh", new { id = id }));
                }
                if (typeLoi == "NoiSinh")
                {
                    return(RedirectToAction("ChinhSuaLoiNoiSinh", new { id = id }));
                }
                if (typeLoi == "QueQuan")
                {
                    return(RedirectToAction("ChinhSuaLoiQueQuan", new { id = id }));
                }
                if (typeLoi == "GioiTinh")
                {
                    return(RedirectToAction("ChinhSuaLoiGioiTinh", new { id = id }));
                }
                if (typeLoi == "DanToc")
                {
                    return(RedirectToAction("ChinhSuaLoiDanToc", new { id = id }));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public JsonResult ChinhSuaLoiQueQuan(List <string> listKey)
        {
            LoiModel  chitietLoi = new LoiModel();
            int       idLoi      = Int32.Parse(listKey[0]);
            string    QueQuanCMT = listKey[1];
            string    QueQuanGKS = listKey[2];
            TABLE_LOI tableLoi   = db.TABLE_LOI.Find(idLoi);
            string    typeLoi    = tableLoi.TypeLOI;

            if (QueQuanCMT != null)
            {
                CMT cmt = db.CMTs.Find(tableLoi.So_CMT);
                cmt.QueQuan         = QueQuanCMT;
                db.Entry(cmt).State = System.Data.Entity.EntityState.Modified;
            }
            if (QueQuanGKS != null)
            {
                GIAYKHAISINH gks = db.GIAYKHAISINHs.Find(tableLoi.id_GKS);
                gks.QueQuan         = QueQuanGKS;
                db.Entry(gks).State = System.Data.Entity.EntityState.Modified;
            }
            db.SaveChanges();
            return(Json(true, JsonRequestBehavior.AllowGet));
        }