public ActionResult DeleteConfirmed(int id)
        {
            tdKiemTraH         tdkiemtrah         = db.tdKiemTraH.Where(kt => kt.UngVien_id == id).First();
            tdNoiSinh          tdnoisinh          = db.tdNoiSinh.Where(ns => ns.UngVien_id == id).First();
            tdTheDinhDanh      tdthedinhdanh      = db.tdTheDinhDanh.Where(dd => dd.UngVien_id == id).First();
            tdThongTinUngTuyen tdthongtinungtuyen = db.tdThongTinUngTuyen.Where(ut => ut.UngVien_id == id).First();
            tdThongTinLienHe   tdthongtinlienhe   = db.tdThongTinLienHe.Where(lh => lh.UngVien_id == id).First();
            tdHoKhauThuongTru  tdhokhauthuongtru  = db.tdHoKhauThuongTru.Where(tt => tt.TTLienHe_id == tdthongtinlienhe.id).First();
            tdDiaChiLienLac    tddiachilienlac    = db.tdDiaChiLienLac.Where(ll => ll.TTLienHe_id == tdthongtinlienhe.id).First();
            tdTTUngCuVien      tdttungcuvien      = db.tdTTUngCuVien.Find(id);


            db.tdKiemTraH.Remove(tdkiemtrah);
            db.tdNoiSinh.Remove(tdnoisinh);
            db.tdTheDinhDanh.Remove(tdthedinhdanh);
            db.tdThongTinUngTuyen.Remove(tdthongtinungtuyen);
            db.tdHoKhauThuongTru.Remove(tdhokhauthuongtru);
            db.tdDiaChiLienLac.Remove(tddiachilienlac);
            db.tdThongTinLienHe.Remove(tdthongtinlienhe);
            try
            {
                tdXemVaXepLichHen tdquanlylh = db.tdXemVaXepLichHen.Where(qllh => qllh.UngCuVien_id == id).First();
                db.tdXemVaXepLichHen.Remove(tdquanlylh);
            }
            catch
            {
            }
            try
            {
                var lisqttd = new List <tdQuaTrinhTuyenDung>();
                lisqttd = db.tdQuaTrinhTuyenDung.Where(qttd => qttd.UngVien_id == id).ToList();
                foreach (var item in lisqttd)
                {
                    db.tdQuaTrinhTuyenDung.Remove(item);
                }
            }
            catch
            {
            }
            try
            {
                var listdbc = new List <tdBangCap>();
                listdbc = db.tdBangCap.Where(qttd => qttd.UngVien_id == id).ToList();
                foreach (var item in listdbc)
                {
                    db.tdBangCap.Remove(item);
                }
            }
            catch
            {
            }
            db.tdTTUngCuVien.Remove(tdttungcuvien);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #2
0
 public ActionResult Create(tdThongTinLienHe tdthongtinlienhe, tdHoKhauThuongTru tdhokhauthuongtru, tdDiaChiLienLac tddiachilienlac)
 {
     if (ModelState.IsValid)
     {
         // edit thong tin lien he
         db.Entry(tdthongtinlienhe).State = EntityState.Modified;
         db.SaveChanges();
         // edit ho khau thuong
         var ttold = db.tdHoKhauThuongTru.Where(tt => tt.TTLienHe_id == tdthongtinlienhe.id).First();
         tdhokhauthuongtru.id          = ttold.id;
         tdhokhauthuongtru.TTLienHe_id = tdthongtinlienhe.id;
         db.Entry(ttold).CurrentValues.SetValues(tdhokhauthuongtru);
         db.SaveChanges();
         // edit dia chi lien lac
         var llold = db.tdDiaChiLienLac.Where(ll => ll.TTLienHe_id == tdthongtinlienhe.id).First();
         tddiachilienlac.id          = llold.id;
         tddiachilienlac.TTLienHe_id = tdthongtinlienhe.id;
         db.Entry(llold).CurrentValues.SetValues(tddiachilienlac);
         db.SaveChanges();
         return(RedirectToAction("Create", "TuyenDung", new { tab = "ThongTinUngTuyen", UV_id = tdthongtinlienhe.UngVien_id }));
     }
     return(View(tdthongtinlienhe));
 }
Exemple #3
0
        public ActionResult Create(tdTTUngCuVien tdttungcuvien, tdTheDinhDanh tdthedinhdanh, tdNoiSinh tdnoisinh, tdThongTinLienHe tdthongtinlienhe)
        {
            if (ModelState.IsValid)
            {
                db.tdTTUngCuVien.Add(tdttungcuvien);
                db.SaveChanges();
                // create the dinh danh
                var ddmodel = new tdTheDinhDanh()
                {
                    UngVien_id = tdttungcuvien.id, LoaiThe_id = tdthedinhdanh.LoaiThe_id, SoThe = tdthedinhdanh.SoThe, NgayCap = tdthedinhdanh.NgayCap, NoiCap_id = tdthedinhdanh.NoiCap_id, NgayHetHan = tdthedinhdanh.NgayHetHan
                };
                db.tdTheDinhDanh.Add(ddmodel);
                db.SaveChanges();
                // create noi sinh
                //var nsmodel = new tdNoiSinh() { UngVien_id = tdttungcuvien.id, QuocGia_id = tdnoisinh.QuocGia_id, TinhThanh_id = tdnoisinh.TinhThanh_id};
                tdnoisinh.UngVien_id = tdttungcuvien.id;
                db.tdNoiSinh.Add(tdnoisinh);
                db.SaveChanges();
                // create kiem tra hs
                var hsmodel = new tdKiemTraH()
                {
                    UngVien_id = tdttungcuvien.id, DonXinViec = false, SoYeuLyLich = false, TheDinhDanh = false, SoHoKhau = false, GiayKhamSucKhoe = false, BangCapBangDiem = false, Hinh = false, GiayToKhac = false
                };
                db.tdKiemTraH.Add(hsmodel);
                db.SaveChanges();

                //// create bang cap
                //var bcmodel = new tdBangCap() { UngVien_id = tdttungcuvien.id};
                //db.tdBangCap.Add(bcmodel);
                //db.SaveChanges();

                // create thong tin lien he
                //var lhmodel = new tdThongTinLienHe() { UngVien_id = tdttungcuvien.id};
                tdthongtinlienhe.UngVien_id = tdttungcuvien.id;
                db.tdThongTinLienHe.Add(tdthongtinlienhe);
                db.SaveChanges();
                // create dia chi thuong tru
                var lhttmodel = new tdHoKhauThuongTru()
                {
                    TTLienHe_id = tdthongtinlienhe.id
                };
                db.tdHoKhauThuongTru.Add(lhttmodel);
                // create dia chi lien lac
                var lhllmodel = new tdDiaChiLienLac()
                {
                    TTLienHe_id = tdthongtinlienhe.id
                };
                db.tdDiaChiLienLac.Add(lhllmodel);
                db.SaveChanges();

                // create thong tin ung tuyen
                var utmodel = new tdThongTinUngTuyen()
                {
                    UngVien_id = tdttungcuvien.id
                };
                db.tdThongTinUngTuyen.Add(utmodel);
                db.SaveChanges();


                //var qttdmodel = new tdQuaTrinhTuyenDung() { UngVien_id = tdttungcuvien.id };
                //db.tdQuaTrinhTuyenDung.Add(qttdmodel);
                //db.SaveChanges();
                //var qllhmodel = new tdXemVaXepLichHen() { UngCuVien_id = tdttungcuvien.id, DaBaoChoUngCuVien = false};
                //db.tdXemVaXepLichHen.Add(qllhmodel);
                //db.SaveChanges();
                //return RedirectToAction("Create","TuyenDung", new { tab = "ThongTinBangCap", UV_id = tdttungcuvien.id });
                return(RedirectToAction("Details", "TuyenDung", new { tab = "ThongTinBangCap", nat = "Edit", id = tdttungcuvien.id }));
            }
            return(View(tdttungcuvien));
        }
        public ActionResult ImportToExcel()
        {
            if (Request.Form["import"] != null)
            {
                var listview = new List <tdImportExcel>();
                listview = (List <tdImportExcel>)TempData["listImport"];
                int countSuccess = 0;
                int countFail    = 0;
                try
                {
                    foreach (var dReader in listview)
                    {
                        countFail++;
                        var HoVaTen      = dReader.HoVaTen;
                        var gttempt      = dReader.GioiTinh;
                        var GioiTinh     = db0.dmGioiTinh.Where(gt => gt.tenGioiTinh.ToLower() == gttempt.ToLower()).First().id;
                        var NgaySinh     = DateTime.Parse(dReader.NgaySinh);
                        var nstempt      = dReader.NoiSinh;
                        var NoiSinh      = db0.dmTinhThanh.Where(tt => tt.tenTinhThanh.ToLower().Contains(nstempt.ToLower())).First().id;
                        var loaithetempt = dReader.LoaiTheDinhDanh;
                        var LoaiTheDD    = db.tdLoaiTheDinhDanh.Where(dd => dd.LoaiTheDinhDanh.ToLower() == loaithetempt.ToLower()).First().id;
                        var SoTheDD      = dReader.SoThe;
                        var noicaptempt  = dReader.NoiCap;
                        var NoiCap       = db0.dmTinhThanh.Where(tt => tt.tenTinhThanh.ToLower().Contains(noicaptempt.ToLower())).First().id;
                        var NgayCap      = DateTime.Parse(dReader.NgayCap);
                        var NgayHetHan   = new DateTime();
                        try
                        {
                            NgayHetHan = DateTime.Parse(dReader.NgayHetHan);
                        }
                        catch
                        {
                        }
                        var DTDiDong     = dReader.DTDiDong;
                        var DTNha        = dReader.DTNha;
                        var Email        = dReader.Email;
                        var DiaChiLienHe = dReader.DiaChiLienHe;


                        var ViTriUngTuyen   = dReader.ViTriUngTuyen;
                        var dvtempt         = dReader.DonViUngTuyen;
                        var DonViUngTuyen   = db0.dmDonVi.Where(dv => dv.tenDonVi.ToLower() == dvtempt.ToLower()).First().id;
                        var NgayNhanHoSo    = DateTime.Parse(dReader.NgayNhanHoSo);
                        var KetQuaTuyenDung = dReader.KetQuaTuyenDung;
                        var GhiChu          = dReader.GhiChu;
                        var QuocGia         = db0.dmQuocGia.Where(qg => qg.tenQuocGia.ToLower() == "Việt Nam".ToLower()).First().id;
                        //save thong tin ung vien
                        var tdttungcuvien = new tdTTUngCuVien {
                            HoVaTen = HoVaTen, GioiTinh_id = GioiTinh, NgaySinh = NgaySinh, QuocTich_id = QuocGia, KetQuaTuyenDung = KetQuaTuyenDung
                        };
                        db.tdTTUngCuVien.Add(tdttungcuvien);
                        db.SaveChanges();

                        // get ung vien id
                        var UngVien_id = db.tdTTUngCuVien.ToList().Last().id;

                        //save bang cap
                        foreach (var im in dReader.BangCap)
                        {
                            try
                            {
                                string[] ttdbangcap  = im.Split(",".ToArray());
                                string   trinhdo     = ttdbangcap[0];
                                string   chuyennganh = ttdbangcap[1];
                                string   noihoc      = ttdbangcap[2];
                                int?     namtn;
                                try
                                {
                                    namtn = int.Parse(ttdbangcap[3]);
                                }
                                catch
                                {
                                    namtn = null;
                                }
                                string xeploai = ttdbangcap[4];

                                var TrinhDo_id     = db0.dmHocVi.Where(hv => hv.tenHocVi.ToLower() == trinhdo.ToLower()).First().id;
                                var ChuyenNganh_id = db0.dmChuyenNganh.Where(cn => cn.tenChuyenNganh.ToLower() == chuyennganh.ToLower()).First().id;
                                var XepLoai_id     = db0.dmXepLoaiTotNghiep.Where(tn => tn.tenXepLoaiTotNghiep.ToLower() == xeploai.ToLower()).First().id;

                                var tdbangcapCrete = new tdBangCap {
                                    UngVien_id = UngVien_id, TrinhDo_id = TrinhDo_id, ChuyenNganh_id = ChuyenNganh_id, NoiDaoTao = noihoc, NamTotNghiep = namtn, XepLoai_id = XepLoai_id, SetDefault = false
                                };
                                db.tdBangCap.Add(tdbangcapCrete);
                                db.SaveChanges();
                            }
                            catch
                            {
                            }
                        }
                        //save noi sinh, the dinh danh, kiem tra du thieu hs, qua trinh tuyendung, quan ly lich hen
                        var tdnoisinh = new tdNoiSinh {
                            UngVien_id = UngVien_id, QuocGia_id = QuocGia, TinhThanh_id = NoiSinh
                        };
                        db.tdNoiSinh.Add(tdnoisinh);
                        var tdthedinhdanh = new tdTheDinhDanh {
                            UngVien_id = UngVien_id, LoaiThe_id = LoaiTheDD, SoThe = SoTheDD, NoiCap_id = NoiCap, NgayCap = NgayCap, NgayHetHan = NgayHetHan
                        };
                        db.tdTheDinhDanh.Add(tdthedinhdanh);
                        var hsmodel = new tdKiemTraH()
                        {
                            UngVien_id = UngVien_id, DonXinViec = false, SoYeuLyLich = false, TheDinhDanh = false, SoHoKhau = false, GiayKhamSucKhoe = false, BangCapBangDiem = false, Hinh = false, GiayToKhac = false
                        };
                        db.tdKiemTraH.Add(hsmodel);
                        //var tdqttuyendung = new tdQuaTrinhTuyenDung { UngVien_id = UngVien_id };
                        //db.tdQuaTrinhTuyenDung.Add(tdqttuyendung);
                        //var tdqllichhen = new tdXemVaXepLichHen { UngCuVien_id = UngVien_id, DaBaoChoUngCuVien = false };
                        //db.tdXemVaXepLichHen.Add(tdqllichhen);
                        db.SaveChanges();

                        // save tt lien he
                        var tdttlienhe = new tdThongTinLienHe {
                            UngVien_id = UngVien_id, DTDiDong1 = DTDiDong, DTNha = DTNha, Email = Email
                        };
                        db.tdThongTinLienHe.Add(tdttlienhe);
                        db.SaveChanges();

                        // get TT lien he id
                        var TTLienHe_id = db.tdThongTinLienHe.ToList().Last().id;

                        //save dia chi lien lac & ho khau thuong tru
                        string[] ttlienhe = DiaChiLienHe.Split(",".ToArray());
                        string   tend     = ttlienhe[0];
                        string   pxa      = ttlienhe[1];
                        string   qhu      = ttlienhe[2];
                        string   tth      = ttlienhe[3];
                        try
                        {
                            var PhuongXa        = db0.dmPhuongXa.Where(px => px.tenPhuongXa.ToLower().Contains(pxa.ToLower())).First().id;
                            var QuanHuyen       = db0.dmQuanHuyen.Where(qh => qh.tenQuanHuyen.ToLower().Contains(qhu.ToLower())).First().id;
                            var TinhThanh       = db0.dmTinhThanh.Where(tt => tt.tenTinhThanh.ToLower().Contains(tth.ToLower())).First().id;
                            var tddiachilienlac = new tdDiaChiLienLac {
                                TTLienHe_id = TTLienHe_id, llQuocGia_id = QuocGia, llTinhThanh_id = TinhThanh, llQuanHuyen_id = QuanHuyen, llPhuongXa_id = PhuongXa, llTenDuong = tend
                            };
                            db.tdDiaChiLienLac.Add(tddiachilienlac);
                        }
                        catch
                        {
                            var tddiachilienlac = new tdDiaChiLienLac {
                                TTLienHe_id = TTLienHe_id
                            };
                            db.tdDiaChiLienLac.Add(tddiachilienlac);
                        }
                        var tdhokhauthuongtru = new tdHoKhauThuongTru {
                            TTLienHe_id = TTLienHe_id
                        };
                        db.tdHoKhauThuongTru.Add(tdhokhauthuongtru);
                        db.SaveChanges();

                        //save thong tin ung tuyen
                        var ViTriUngTuyen_id = db0.dmChucDanhChuyenMon.Where(cm => cm.tenChucDanhChuyenMon.ToLower() == ViTriUngTuyen.ToLower()).First().id;
                        var tdttungtuyen     = new tdThongTinUngTuyen {
                            UngVien_id = UngVien_id, ViTriUngTuyen_id = ViTriUngTuyen_id, DonViUngTuyen_id = DonViUngTuyen, NgayNhanHS = NgayNhanHoSo, GhiChu = GhiChu
                        };
                        db.tdThongTinUngTuyen.Add(tdttungtuyen);
                        db.SaveChanges();
                        countSuccess++;
                    }
                    countFail           = countFail;
                    TempData["Message"] = "Bạn đã import thành công thông tin " + countSuccess + "/" + countFail + " ứng viên";
                }
                catch
                {
                    if (Request.Files["FileUpload1"].ContentLength > 0)
                    {
                        string extension = System.IO.Path.GetExtension(Request.Files["FileUpload1"].FileName);
                        string path1     = string.Format("{0}/{1}", Server.MapPath("~/Areas/TuyenDung/Contents/UploadedFolder"), Request.Files["FileUpload1"].FileName);
                        if (System.IO.File.Exists(path1))
                        {
                            System.IO.File.Delete(path1);
                        }
                        Request.Files["FileUpload1"].SaveAs(path1);


                        //Create connection string to Excel work book
                        string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path1 + ";Extended Properties=Excel 12.0;Persist Security Info=False";
                        //Create Connection to Excel work book
                        OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
                        //Create OleDbCommand to fetch data from Excel
                        OleDbCommand cmd = new OleDbCommand("Select * from [Sheet1$]", excelConnection);

                        excelConnection.Open();
                        OleDbDataReader dReader;
                        dReader = cmd.ExecuteReader();

                        while (dReader.Read())
                        {
                            try
                            {
                                countFail++;
                                var HoVaTen = dReader.GetValue(0).ToString();
                                if (HoVaTen == "")
                                {
                                    dReader.NextResult();
                                }
                                else
                                {
                                    var      gttempt      = dReader.GetValue(1).ToString();
                                    var      GioiTinh     = db0.dmGioiTinh.Where(gt => gt.tenGioiTinh.ToLower() == gttempt.ToLower()).First().id;
                                    var      NgaySinh     = DateTime.Parse(dReader.GetValue(2).ToString());
                                    var      nstempt      = dReader.GetValue(3).ToString();
                                    var      NoiSinh      = db0.dmTinhThanh.Where(tt => tt.tenTinhThanh.ToLower().Contains(nstempt.ToLower())).First().id;
                                    var      loaithetempt = dReader.GetValue(4).ToString();
                                    var      LoaiTheDD    = db.tdLoaiTheDinhDanh.Where(dd => dd.LoaiTheDinhDanh.ToLower() == loaithetempt.ToLower()).First().id;
                                    var      SoTheDD      = dReader.GetValue(5).ToString();
                                    var      noicaptempt  = dReader.GetValue(6).ToString();
                                    var      NoiCap       = db0.dmTinhThanh.Where(tt => tt.tenTinhThanh.ToLower().Contains(noicaptempt.ToLower())).First().id;
                                    var      NgayCap      = DateTime.Parse(dReader.GetValue(7).ToString());
                                    DateTime?NgayHetHan   = new DateTime();
                                    try
                                    {
                                        NgayHetHan = DateTime.Parse(dReader.GetValue(8).ToString());
                                    }
                                    catch
                                    {
                                        NgayHetHan = null;
                                    }
                                    var DTDiDong     = dReader.GetValue(9).ToString();
                                    var DTNha        = dReader.GetValue(10).ToString();
                                    var Email        = dReader.GetValue(11).ToString();
                                    var DiaChiLienHe = dReader.GetValue(12).ToString();
                                    var BangCapList  = new List <string>();
                                    int co           = dReader.FieldCount - 18;
                                    int i            = 0;
                                    var list         = new List <string>();
                                    for (i = 0; i < co; i++)
                                    {
                                        list.Add(dReader.GetValue(13 + i).ToString());
                                    }
                                    BangCapList = list;
                                    var ViTriUngTuyen   = dReader.GetValue(13 + i).ToString();
                                    var dvtempt         = dReader.GetValue(13 + i + 1).ToString();
                                    var DonViUngTuyen   = db0.dmDonVi.Where(dv => dv.tenDonVi.ToLower() == dvtempt.ToLower()).First().id;
                                    var NgayNhanHoSo    = DateTime.Parse(dReader.GetValue(13 + i + 2).ToString());
                                    var KetQuaTuyenDung = dReader.GetValue(13 + i + 3).ToString();
                                    var GhiChu          = dReader.GetValue(13 + i + 4).ToString();
                                    var QuocGia         = db0.dmQuocGia.Where(qg => qg.tenQuocGia.ToLower() == "Việt Nam".ToLower()).First().id;

                                    //save thong tin ung vien
                                    var kqtd = new Nullable <bool>();
                                    if (KetQuaTuyenDung == "Trúng tuyển")
                                    {
                                        kqtd = true;
                                    }
                                    if (KetQuaTuyenDung == "Không trúng tuyển")
                                    {
                                        kqtd = false;
                                    }
                                    if (KetQuaTuyenDung == "Chưa có kết quả")
                                    {
                                        kqtd = null;
                                    }
                                    var tdttungcuvien = new tdTTUngCuVien {
                                        HoVaTen = HoVaTen, GioiTinh_id = GioiTinh, NgaySinh = NgaySinh, QuocTich_id = QuocGia, KetQuaTuyenDung = kqtd
                                    };
                                    db.tdTTUngCuVien.Add(tdttungcuvien);
                                    db.SaveChanges();

                                    // get ung vien id
                                    var UngVien_id = db.tdTTUngCuVien.ToList().Last().id;

                                    // save bang cap
                                    foreach (var im in BangCapList)
                                    {
                                        try
                                        {
                                            string[] ttdbangcap  = im.Split(",".ToArray());
                                            string   trinhdo     = ttdbangcap[0];
                                            string   chuyennganh = ttdbangcap[1];
                                            string   noihoc      = ttdbangcap[2];
                                            int?     namtn;
                                            try
                                            {
                                                namtn = int.Parse(ttdbangcap[3]);
                                            }
                                            catch
                                            {
                                                namtn = null;
                                            }
                                            string xeploai = ttdbangcap[4];

                                            var TrinhDo_id     = db0.dmHocVi.Where(td => td.tenHocVi.ToLower() == trinhdo.ToLower()).First().id;
                                            var ChuyenNganh_id = db0.dmChuyenNganh.Where(td => td.tenChuyenNganh.ToLower() == chuyennganh.ToLower()).First().id;
                                            var XepLoai_id     = db0.dmXepLoaiTotNghiep.Where(td => td.tenXepLoaiTotNghiep.ToLower() == xeploai.ToLower()).First().id;

                                            var tdbangcapCrete = new tdBangCap {
                                                UngVien_id = UngVien_id, TrinhDo_id = TrinhDo_id, ChuyenNganh_id = ChuyenNganh_id, NoiDaoTao = noihoc, NamTotNghiep = namtn, XepLoai_id = XepLoai_id, SetDefault = false
                                            };
                                            db.tdBangCap.Add(tdbangcapCrete);
                                            db.SaveChanges();
                                        }
                                        catch
                                        {
                                        }
                                    }


                                    //save noi sinh, the dinh danh, kiem tra du thieu hs, qua trinh tuyendung, quan ly lich hen
                                    var tdnoisinh = new tdNoiSinh {
                                        UngVien_id = UngVien_id, QuocGia_id = QuocGia, TinhThanh_id = NoiSinh
                                    };
                                    db.tdNoiSinh.Add(tdnoisinh);
                                    var tdthedinhdanh = new tdTheDinhDanh {
                                        UngVien_id = UngVien_id, LoaiThe_id = LoaiTheDD, SoThe = SoTheDD, NoiCap_id = NoiCap, NgayCap = NgayCap, NgayHetHan = NgayHetHan
                                    };
                                    db.tdTheDinhDanh.Add(tdthedinhdanh);
                                    var hsmodel = new tdKiemTraH()
                                    {
                                        UngVien_id = UngVien_id, DonXinViec = false, SoYeuLyLich = false, TheDinhDanh = false, SoHoKhau = false, GiayKhamSucKhoe = false, BangCapBangDiem = false, Hinh = false, GiayToKhac = false
                                    };
                                    db.tdKiemTraH.Add(hsmodel);
                                    //var tdqttuyendung = new tdQuaTrinhTuyenDung { UngVien_id = UngVien_id };
                                    //db.tdQuaTrinhTuyenDung.Add(tdqttuyendung);
                                    //var tdqllichhen = new tdXemVaXepLichHen { UngCuVien_id = UngVien_id, DaBaoChoUngCuVien = false };
                                    //db.tdXemVaXepLichHen.Add(tdqllichhen);
                                    db.SaveChanges();

                                    // save tt lien he
                                    var tdttlienhe = new tdThongTinLienHe {
                                        UngVien_id = UngVien_id, DTDiDong1 = DTDiDong, DTNha = DTNha, Email = Email
                                    };
                                    db.tdThongTinLienHe.Add(tdttlienhe);
                                    db.SaveChanges();

                                    // get TT lien he id
                                    var TTLienHe_id = db.tdThongTinLienHe.ToList().Last().id;

                                    //save dia chi lien lac & ho khau thuong tru
                                    string[] ttlienhe = DiaChiLienHe.Split(",".ToArray());
                                    string   tend     = ttlienhe[0];
                                    string   pxa      = ttlienhe[1];
                                    string   qhu      = ttlienhe[2];
                                    string   tth      = ttlienhe[3];
                                    try
                                    {
                                        var PhuongXa        = db0.dmPhuongXa.Where(px => px.tenPhuongXa.ToLower() == pxa.ToString().ToLower()).First().id;
                                        var QuanHuyen       = db0.dmQuanHuyen.Where(qh => qh.tenQuanHuyen.ToLower().Contains(qhu.ToLower())).First().id;
                                        var TinhThanh       = db0.dmTinhThanh.Where(tt => tt.tenTinhThanh.ToLower().Contains(tth.ToLower())).First().id;
                                        var tddiachilienlac = new tdDiaChiLienLac {
                                            TTLienHe_id = TTLienHe_id, llQuocGia_id = QuocGia, llTinhThanh_id = TinhThanh, llQuanHuyen_id = QuanHuyen, llPhuongXa_id = PhuongXa, llTenDuong = tend
                                        };
                                        db.tdDiaChiLienLac.Add(tddiachilienlac);
                                    }
                                    catch
                                    {
                                        var tddiachilienlac = new tdDiaChiLienLac {
                                            TTLienHe_id = TTLienHe_id
                                        };
                                        db.tdDiaChiLienLac.Add(tddiachilienlac);
                                    }
                                    var tdhokhauthuongtru = new tdHoKhauThuongTru {
                                        TTLienHe_id = TTLienHe_id
                                    };
                                    db.tdHoKhauThuongTru.Add(tdhokhauthuongtru);
                                    db.SaveChanges();

                                    //save thong tin ung tuyen
                                    var ViTriUngTuyen_id = db0.dmChucDanhChuyenMon.Where(cm => cm.tenChucDanhChuyenMon.ToLower() == ViTriUngTuyen.ToLower()).First().id;
                                    var tdttungtuyen     = new tdThongTinUngTuyen {
                                        UngVien_id = UngVien_id, ViTriUngTuyen_id = ViTriUngTuyen_id, DonViUngTuyen_id = DonViUngTuyen, NgayNhanHS = NgayNhanHoSo, GhiChu = GhiChu
                                    };
                                    db.tdThongTinUngTuyen.Add(tdttungtuyen);
                                    db.SaveChanges();
                                    countSuccess++;
                                }
                            }
                            catch
                            {
                            }
                        }
                        excelConnection.Close();
                        countFail           = countFail - 1;
                        TempData["Message"] = "Bạn đã import thành công thông tin " + countSuccess + "/" + countFail + " ứng viên";
                    }
                }

                return(RedirectToAction("Index", "TuyenDung"));
            }
            else
            {
                if (Request.Files["FileUpload1"].ContentLength > 0)
                {
                    string extension = System.IO.Path.GetExtension(Request.Files["FileUpload1"].FileName);
                    string path1     = string.Format("{0}/{1}", Server.MapPath("~/Areas/TuyenDung/Contents/UploadedFolder"), Request.Files["FileUpload1"].FileName);
                    if (System.IO.File.Exists(path1))
                    {
                        System.IO.File.Delete(path1);
                    }
                    Request.Files["FileUpload1"].SaveAs(path1);


                    //Create connection string to Excel work book
                    string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path1 + ";Extended Properties=Excel 12.0;Persist Security Info=False";
                    //Create Connection to Excel work book
                    OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
                    //Create OleDbCommand to fetch data from Excel
                    OleDbCommand cmd = new OleDbCommand("Select * from [Sheet1$]", excelConnection);

                    excelConnection.Open();
                    OleDbDataReader dReader;
                    dReader = cmd.ExecuteReader();

                    var listview = new List <tdImportExcel>();

                    while (dReader.Read())
                    {
                        var tduv    = new tdImportExcel();
                        var HoVaTen = dReader.GetValue(0).ToString();
                        if (HoVaTen == "")
                        {
                            dReader.NextResult();
                        }
                        else
                        {
                            tduv.HoVaTen = HoVaTen;
                            var gttempt       = dReader.GetValue(1).ToString();
                            var gioitinhtempt = db0.dmGioiTinh.Where(gt => gt.tenGioiTinh.ToLower() == gttempt.ToLower()).First().tenGioiTinh;
                            tduv.GioiTinh = gioitinhtempt;
                            tduv.NgaySinh = DateTime.Parse(dReader.GetValue(2).ToString()).ToShortDateString();
                            var nstempt = dReader.GetValue(3).ToString();
                            tduv.NoiSinh = db0.dmTinhThanh.Where(tt => tt.tenTinhThanh.ToLower().Contains(nstempt.ToLower())).First().tenTinhThanh;
                            var loaithetempt = dReader.GetValue(4).ToString();
                            tduv.LoaiTheDinhDanh = db.tdLoaiTheDinhDanh.Where(dd => dd.LoaiTheDinhDanh.ToLower() == loaithetempt.ToLower()).First().LoaiTheDinhDanh;
                            tduv.SoThe           = dReader.GetValue(5).ToString();
                            var noicaptempt = dReader.GetValue(6).ToString();
                            tduv.NoiCap  = db0.dmTinhThanh.Where(tt => tt.tenTinhThanh.ToLower().Contains(noicaptempt.ToLower())).First().tenTinhThanh;
                            tduv.NgayCap = DateTime.Parse(dReader.GetValue(7).ToString()).ToShortDateString();
                            DateTime?NgayHetHan = new DateTime();
                            try
                            {
                                NgayHetHan      = DateTime.Parse(dReader.GetValue(8).ToString());
                                tduv.NgayHetHan = NgayHetHan.Value.ToShortDateString();
                            }
                            catch
                            {
                                NgayHetHan = null;
                            }

                            tduv.DTDiDong     = dReader.GetValue(9).ToString();
                            tduv.DTNha        = dReader.GetValue(10).ToString();
                            tduv.Email        = dReader.GetValue(11).ToString();
                            tduv.DiaChiLienHe = dReader.GetValue(12).ToString();
                            int co   = dReader.FieldCount - 18;
                            int i    = 0;
                            var list = new List <string>();
                            for (i = 0; i < co; i++)
                            {
                                list.Add(dReader.GetValue(13 + i).ToString());
                            }
                            tduv.BangCap       = list;
                            tduv.ViTriUngTuyen = dReader.GetValue(13 + i).ToString();
                            var dvtempt = dReader.GetValue(13 + i + 1).ToString();
                            tduv.DonViUngTuyen = db0.dmDonVi.Where(dv => dv.tenDonVi.ToLower() == dvtempt.ToLower()).First().tenDonVi;
                            tduv.NgayNhanHoSo  = DateTime.Parse(dReader.GetValue(13 + i + 2).ToString()).ToShortDateString();
                            var KetQuaTuyenDung = dReader.GetValue(13 + i + 3).ToString();
                            if (KetQuaTuyenDung == "Trúng tuyển")
                            {
                                tduv.KetQuaTuyenDung = true;
                            }
                            if (KetQuaTuyenDung == "Không trúng tuyển")
                            {
                                tduv.KetQuaTuyenDung = false;
                            }
                            if (KetQuaTuyenDung == "Chưa có kết quả")
                            {
                                tduv.KetQuaTuyenDung = null;
                            }
                            //tduv.KetQuaTuyenDung = dReader.GetValue(13+i+3).ToString();
                            tduv.GhiChu = dReader.GetValue(13 + i + 4).ToString();
                            listview.Add(tduv);
                        }
                    }
                    excelConnection.Close();
                    TempData["tdttungvien"] = listview;
                    TempData["filepath"]    = Request.Files["FileUpload1"].FileName;
                }

                return(RedirectToAction("Index"));
            }
        }