public ActionResult ChiTiet(int id)
 {
     HoSoGiayPhep gphd = _gphdRepository.GetHoSoGiayPhepByID(id);
     if (gphd == null)
     {
         return RedirectToAction("ThongBao", new {iMsg = 2});
     }
     BaoCaoHoatDong bc = new BaoCaoHoatDong();
     bc = gphd.ThongTinChung.BaoCaoHoatDongs.SingleOrDefault(m=>m.MaThongTinChung == gphd.MaThongTinChung);
     int k = 0;
     if (bc != null)
     {
         k = bc.MaBaoCao;
     }
     var dangkyMoi = _dkhdRespository.GetDangKyHDMoi(id);
     var dangkyDuocCap = _dkhdRespository.GetDKHDDaCap(id);
     var dangkyBS = _dkhdRespository.GetDKHDBoSung(id);
     var model = new GiayPhepDetailModel
     {
         DangKy = dangkyMoi,
         DangKyDaCap = dangkyDuocCap,
         DangKyBoSung = dangkyBS,
         giayphep = gphd,
         MaBaoCao = k
         //hoatdong = hoatdongList
        // nangluc = nanglucList
     };
     return View(model);
 }
 public void Update(BaoCaoHoatDong BaoCaoHoatDong)
 {
     BaoCaoHoatDong temp = new BaoCaoHoatDong();
     temp.MaToChuc = BaoCaoHoatDong.MaToChuc;
     temp.MaThongTinChung = BaoCaoHoatDong.MaThongTinChung;
     temp.TuNam = BaoCaoHoatDong.TuNam;
     temp.DenNam = BaoCaoHoatDong.DenNam;
     temp.DoanhThu = BaoCaoHoatDong.DoanhThu;
     temp.NopNganSach = BaoCaoHoatDong.NopNganSach;
     db.SubmitChanges();
 }
 public BaoCaoHoatDong GetBaoCaoHoatDongByTTC(int ttcid)
 {
     var list = (from nn in db.BaoCaoHoatDongs
                 where nn.MaThongTinChung == ttcid
                 select nn).ToList();
     BaoCaoHoatDong baocao = new BaoCaoHoatDong();
     if (list != null && list.Count > 0)
     {
         baocao = list[0];
     }
     return baocao;
 }
 public ActionResult Create(int gpid)
 {
     HoSoGiayPhep hs = _gphdRepository.GetHoSoGiayPhepByID(gpid);
     BaoCaoHoatDong bc = new BaoCaoHoatDong();
     bc = hs.ThongTinChung.BaoCaoHoatDongs.SingleOrDefault(m => m.MaThongTinChung == hs.MaThongTinChung);
     int k = 0;
     if (bc != null)
     {
         k = bc.MaBaoCao;
     }
     var dangky = _dkhdRespository.GetDangKyHDs(gpid);
     var hdDaCap = _dkhdRespository.GetDKHDDaCap(gpid);
     var hdBoSung = _dkhdRespository.GetDKHDBoSung(gpid);
     var maHDList = _dkhdRespository.getSelectedHD(dangky.ToList<DangKyHoatDong>());
     var hoatdongList = new List<HoatDong>();
     foreach (int i in maHDList)
     {
         hoatdongList.Add(_hoatdongRespository.GetHoatDongByID(i));
     }
     var gpchitiet = new GiayPhepDetailModel
     {
         DangKy = dangky,
         giayphep = hs,
         hoatdong = hoatdongList,
         DangKyDaCap = hdDaCap,
         DangKyBoSung = hdBoSung,
         MaBaoCao = k
         // nangluc = nanglucList
     };
     var td = _thamdinhRepository.GetThamDinhByGPID(gpid);
     if (td == null)
     {
         td = new ThamDinh();
     }
     ThamDinhEditViewModel model = new ThamDinhEditViewModel();
     model.giayphep = _gphdRepository.GetHoSoGiayPhepByID(gpid);
        // model.SoGiayPhep = model.giayphep.SoGiayPhep;
     model.thongtinchung = gpchitiet;
     model.ThamDinh = td;
     //model.m = gpid;
     return View(model);
 }
Esempio n. 5
0
		private void detach_BaoCaoHoatDongs(BaoCaoHoatDong entity)
		{
			this.SendPropertyChanging();
			entity.ThongTinChung = null;
		}
Esempio n. 6
0
 partial void DeleteBaoCaoHoatDong(BaoCaoHoatDong instance);
Esempio n. 7
0
 partial void UpdateBaoCaoHoatDong(BaoCaoHoatDong instance);
Esempio n. 8
0
 partial void InsertBaoCaoHoatDong(BaoCaoHoatDong instance);
Esempio n. 9
0
		private void attach_BaoCaoHoatDongs(BaoCaoHoatDong entity)
		{
			this.SendPropertyChanging();
			entity.ToChuc = this;
		}
 public void Delete(BaoCaoHoatDong baocao)
 {
     db.BaoCaoHoatDongs.DeleteOnSubmit(baocao);
     db.SubmitChanges();
 }
 public void Add(BaoCaoHoatDong baocao)
 {
     db.BaoCaoHoatDongs.InsertOnSubmit(baocao);
     db.SubmitChanges();
 }
Esempio n. 12
0
        public ActionResult Edit(int gpid)
        {
            HoSoGiayPhep hs = _gphdRepository.GetHoSoGiayPhepByID(gpid);
            ThamDinh td = _thamdinhRepository.GetThamDinhByGPID(hs.MaHoSo);
            if (td != null && td.TinhTrangThamDinh == true)
            {
                return RedirectToAction("thongbao", new { iMsg = true});
            }
            BaoCaoHoatDong bc = new BaoCaoHoatDong();
            bc = hs.ThongTinChung.BaoCaoHoatDongs.SingleOrDefault(m => m.MaThongTinChung == hs.MaThongTinChung);

            var dangky = _dkhdRespository.GetDangKyHDs(gpid);
            var hdDaCap = _dkhdRespository.GetDKHDDaCap(gpid);
            var hdBoSung = _dkhdRespository.GetDKHDBoSung(gpid);
            var maHDList = _dkhdRespository.getSelectedHD(dangky.ToList<DangKyHoatDong>());
            var hoatdongList = new List<HoatDong>();
            foreach (int i in maHDList)
            {
                hoatdongList.Add(_hoatdongRespository.GetHoatDongByID(i));
            }
            var gpchitiet = new GiayPhepDetailModel
            {
                DangKy = dangky,
                giayphep = hs,
                hoatdong = hoatdongList,
                DangKyDaCap = hdDaCap,
                DangKyBoSung = hdBoSung,
                MaBaoCao = bc == null ? 0 : bc.MaBaoCao
                // nangluc = nanglucList
            };
            //            var td = _thamdinhRepository.GetThamDinhByGPID(gpid);
            ThamDinhEditViewModel model = new ThamDinhEditViewModel();
            model.giayphep = _gphdRepository.GetHoSoGiayPhepByID(gpid);
            model.thongtinchung = gpchitiet;
            model.ThamDinh = td;
            model.ThamDinh.NguoiThamDinh = model.ThamDinh.NguoiThamDinh.Replace(";", System.Environment.NewLine);
            model.ThamDinh.NguoiPhiaToChuc = model.ThamDinh.NguoiPhiaToChuc.Replace(";", System.Environment.NewLine);
            //model.m = gpid;
            return View(model);
        }
Esempio n. 13
0
 // GET: /ThamDinh/Details/5
 public ActionResult Detail(int gpid)
 {
     //ThamDinh thamdinh = new ThamDinh();
     HoSoGiayPhep hs = _gphdRepository.GetHoSoGiayPhepByID(gpid);
     BaoCaoHoatDong bc = new BaoCaoHoatDong();
     bc = hs.ThongTinChung.BaoCaoHoatDongs.SingleOrDefault(m => m.MaThongTinChung == hs.MaThongTinChung);
     var dangky = _dkhdRespository.GetDangKyHDs(gpid);
     var hdDaCap = _dkhdRespository.GetDKHDDaCap(gpid);
     var hdBoSung = _dkhdRespository.GetDKHDBoSung(gpid);
     var maHDList = _dkhdRespository.getSelectedHD(dangky.ToList<DangKyHoatDong>());
     var hoatdongList = new List<HoatDong>();
     foreach (int i in maHDList)
     {
         hoatdongList.Add(_hoatdongRespository.GetHoatDongByID(i));
     }
     var gpchitiet = new GiayPhepDetailModel
     {
         DangKy = dangky,
         giayphep = hs,
         hoatdong = hoatdongList,
         DangKyDaCap = hdDaCap,
         DangKyBoSung = hdBoSung,
         MaBaoCao = (bc == null? 0 : bc.MaBaoCao)
         // nangluc = nanglucList
     };
     ThamDinh thamdinh = _thamdinhRepository.GetThamDinhByGPID(gpid);
     var viewmodel = new ThamDinhEditViewModel { ThamDinh = thamdinh, giayphep =hs, thongtinchung = gpchitiet };
     return View(viewmodel);
 }
        public ActionResult GiaHanGiayPhep(ToChucBoSungViewModel model, int save)
        {
            TaiKhoan tk = ((EnhancedPrincipal)HttpContext.User).Data;
            int msg = 0;

            if (save == 1)
            {
               // using (TransactionScope scope = new TransactionScope())
                //{
                    try
                    {
                        ThongTinChung ttc = new ThongTinChung();
                        //using (TransactionScope s1 = new TransactionScope())
                        //{
                            ttc.TenToChuc = model.TenToChuc;
                            ttc.GiayPhepKinhDoanh = model.GiayPhepKinhDoanh;
                            ttc.HangDoanhNghiep = model.HangDoanhNghiep;
                            ttc.VonLuuDong = model.VonLuuDong;
                            ttc.VonPhapDinh = model.VonPhapDinh;
                            ttc.SoTaiKhoan = model.SoTaiKhoan;
                            ttc.TongSoCanBo = model.TongSoCanBo;
                            ttc.MaLoaiHinhToChuc = model.MaLoaiHinhToChuc;
                            ttc.TruSoChinh = model.TruSoChinh;
                            ttc.NguoiDaiDien = model.NguoiDaiDien;
                            ttc.DienThoai = model.DienThoai;
                            ttc.Email = model.Email;
                            ttc.Fax = model.Fax;
                            _ttcRespository.Add(ttc);

                            // Luu vao to chuc neu chua co hoac update
                            //ToChuc t = _tochucRespository.GetToChucByID(model.MaToChuc);
                            List<ToChuc> tcs = tk.ToChucs.ToList();
                            if (tcs.Count == 0)
                            {
                                ToChuc tc1 = new ToChuc();
                                tc1.TenToChuc = model.TenToChuc;
                                tc1.GiayPhepKinhDoanh = model.GiayPhepKinhDoanh;
                                tc1.HangDoanhNghiep = model.HangDoanhNghiep;
                                tc1.VonLuuDong = model.VonLuuDong;
                                tc1.VonPhapDinh = model.VonPhapDinh;
                                tc1.SoTaiKhoan = model.SoTaiKhoan;
                                tc1.TongSoCanBo = model.TongSoCanBo;
                                tc1.MaLoaiHinhToChuc = model.MaLoaiHinhToChuc;
                                tc1.TruSoChinh = model.TruSoChinh;
                                tc1.NguoiDaiDien = model.NguoiDaiDien;
                                tc1.DienThoai = model.DienThoai;
                                tc1.Email = model.Email;
                                tc1.Fax = model.Fax;
                                tc1.MaTaiKhoan = tk.MaTaiKhoan;
                                _tochucRespository.Add(tc1);
                            }
                            else
                            {
                                ToChuc t = tcs[0];
                                t.TenToChuc = model.TenToChuc;
                                t.GiayPhepKinhDoanh = model.GiayPhepKinhDoanh;
                                t.HangDoanhNghiep = model.HangDoanhNghiep;
                                t.VonLuuDong = model.VonLuuDong;
                                t.VonPhapDinh = model.VonPhapDinh;
                                t.SoTaiKhoan = model.SoTaiKhoan;
                                t.TongSoCanBo = model.TongSoCanBo;
                                t.MaLoaiHinhToChuc = model.MaLoaiHinhToChuc;
                                t.TruSoChinh = model.TruSoChinh;
                                t.NguoiDaiDien = model.NguoiDaiDien;
                                t.DienThoai = model.DienThoai;
                                t.Email = model.Email;
                                t.Fax = model.Fax;
                                _tochucRespository.Update(t);
                            }
                          //  s1.Complete();
                        //}
                        // xoa nhung nangluckekhai co MaToChuc va them vao nangluckekhai co MaToChuc moi
                        // them những nangluckekhai co MaThongTinChung

                        ToChuc tochuc = _tochucRespository.GetToChucByTaiKhoan(tk.MaTaiKhoan);
                        List<NangLucKeKhai> listNangLucCu = _nanglucRespository.GetNangLucByTCID(tochuc.MaToChuc);
                        foreach (var nlCu in listNangLucCu)
                        {
                            _nanglucRespository.Delete(nlCu);
                        }
                        IEnumerable<NangLucVM> listNangLuc = model.NangLucRow;
                        if (listNangLuc != null)
                        {
                            foreach (var i in listNangLuc)
                            {
                                if (i.NganhNghe != "" && i.NganhNghe != null)
                                {
                                    NangLucKeKhai nl = new NangLucKeKhai();
                                    nl.MaToChuc = tochuc.MaToChuc;
                                    nl.NganhNghe = i.NganhNghe;
                                    nl.SoTrenDaiHoc = i.Daihoc.GetValueOrDefault(0);
                                    nl.SoTrungCap = i.TrungCap.GetValueOrDefault(0);
                                    nl.SoCongNhanKyThuat = i.CongNhan.GetValueOrDefault(0);
                                    nl.LoaiKhac = i.LoaiKhac.GetValueOrDefault(0);
                                    _nanglucRespository.Add(nl);
                                    NangLucKeKhai nl1 = new NangLucKeKhai();
                                    nl1.MaThongTinChung = ttc.MaThongTinChung;
                                    nl1.NganhNghe = i.NganhNghe;
                                    nl1.SoTrenDaiHoc = i.Daihoc.GetValueOrDefault(0);
                                    nl1.SoTrungCap = i.TrungCap.GetValueOrDefault(0);
                                    nl1.SoCongNhanKyThuat = i.CongNhan.GetValueOrDefault(0);
                                    nl1.LoaiKhac = i.LoaiKhac.GetValueOrDefault(0);
                                    _nanglucRespository.Add(nl1);
                                }
                            }
                        }
                        // xoa nhung ThietBi co MaToChuc va them vao ThietBi co MaToChuc moi
                        // them những ThietBi co MaThongTinChung
                        List<ThietBi> listThietBiCu = _thietbiRespository.GetThietBiByTCID(tochuc.MaToChuc);
                        foreach (var tbCu in listThietBiCu)
                        {
                            _thietbiRespository.Delete(tbCu);
                        }
                        IEnumerable<ThietBiVM> listThietBi = model.ThietBiRow;
                        if (listThietBi != null)
                        {
                            foreach (var i in listThietBi)
                            {
                                if (i.TenThietBi_CongNghe != "" && i.TenThietBi_CongNghe != null)
                                {
                                    ThietBi tb = new ThietBi();
                                    tb.MaToChuc = tochuc.MaToChuc;
                                    tb.TenThietBi_CongNghe = i.TenThietBi_CongNghe;
                                    tb.SoLuong = i.SoLuong.GetValueOrDefault(0);
                                    tb.TinhTrang = i.TinhTrang;
                                    tb.GhiChu = i.GhiChu;
                                    _thietbiRespository.Add(tb);
                                    ThietBi tb1 = new ThietBi();
                                    tb1.MaThongTinChung = ttc.MaThongTinChung;
                                    tb1.TenThietBi_CongNghe = i.TenThietBi_CongNghe;
                                    tb1.SoLuong = i.SoLuong.GetValueOrDefault(0);
                                    tb1.TinhTrang = i.TinhTrang;
                                    tb1.GhiChu = i.GhiChu;
                                    _thietbiRespository.Add(tb1);
                                }
                            }
                        }

                        // xoa nhung ThietBi co MaToChuc va them vao ThietBi co MaToChuc moi
                        // them những ThietBi co MaThongTinChung

                        List<NhanLuc> listNhanLucCu = _nhanlucRespository.GetNhanLucByTCID(tochuc.MaToChuc);
                        foreach (var nlCu in listNhanLucCu)
                        {
                            _nhanlucRespository.Delete(nlCu);
                        }
                        IEnumerable<NhanLucVM> listNhanLuc = model.NhanLucRow;
                        if (listNhanLuc != null)
                        {
                            foreach (var i in listNhanLuc)
                            {
                                if (i.HoTen != "" && i.HoTen != null)
                                {
                                    NhanLuc nl = new NhanLuc();
                                    nl.MaToChuc = tochuc.MaToChuc;
                                    nl.HoTen = i.HoTen;
                                    nl.ChucVu = i.ChucVu;
                                    nl.TrinhDoHocVan = i.TrinhDoHocVan;
                                    nl.ThamNien = i.ThamNien;
                                    _nhanlucRespository.Add(nl);
                                    NhanLuc nl1 = new NhanLuc();
                                    nl1.MaThongTinChung = ttc.MaThongTinChung;
                                    nl1.HoTen = i.HoTen;
                                    nl1.ChucVu = i.ChucVu;
                                    nl1.TrinhDoHocVan = i.TrinhDoHocVan;
                                    nl1.ThamNien = i.ThamNien;
                                    _nhanlucRespository.Add(nl1);
                                }
                            }
                        }
                        ///xóa báo cáo hoạt động có mã tổ chức
                        ///xóa báo cáo hoạt động có mã báo cáo
                        //thêm báo cáo hoạt động mới(1 cho tổ chức + 1 cho thông tin chung)
                        //thêm những row báo cáo công trình mới

                        BaoCaoHoatDong bchd1 = _bchdRespository.GetBaoCaoHoatDongByTC(tochuc.MaToChuc);
                        if (bchd1 != null && bchd1.MaBaoCao != 0)
                        {
                            // bchd1.MaToChuc = tochuc.MaToChuc;
                            bchd1.TuNam = model.TuNam;
                            bchd1.DenNam = model.DenNam;
                            bchd1.DoanhThu = model.DoanhThuNam.GetValueOrDefault(0);
                            bchd1.NopNganSach = model.NopNganSach.GetValueOrDefault(0);
                            _bchdRespository.Update(bchd1);
                        }
                        else
                        {
                            BaoCaoHoatDong b = new BaoCaoHoatDong();
                            b.MaToChuc = tochuc.MaToChuc;
                            b.TuNam = model.TuNam;
                            b.DenNam = model.DenNam;
                            b.DoanhThu = model.DoanhThuNam.GetValueOrDefault(0);
                            b.NopNganSach = model.NopNganSach.GetValueOrDefault(0);
                            _bchdRespository.Add(b);
                        }
                        bchd1 = _bchdRespository.GetBaoCaoHoatDongByTC(tochuc.MaToChuc);
                        BaoCaoHoatDong bchd2 = new BaoCaoHoatDong();
                        bchd2.MaThongTinChung = ttc.MaThongTinChung;
                        bchd2.TuNam = model.TuNam;
                        bchd2.DenNam = model.DenNam;
                        bchd2.DoanhThu = model.DoanhThuNam.GetValueOrDefault(0);
                        bchd2.NopNganSach = model.NopNganSach.GetValueOrDefault(0);
                        _bchdRespository.Add(bchd2);
                        List<BaoCaoCongTrinh> congtrinhListCu = _bcctRespository.GetBCCTByBCHD(bchd1.MaBaoCao);
                        foreach (var bc in congtrinhListCu)
                        {
                            _bcctRespository.Delete(bc);
                        }

                        IEnumerable<CongTrinhVM> congtrinhList = model.CongTrinhRow;
                        if (congtrinhList != null)
                        {
                            foreach (var i in congtrinhList)
                            {
                                if (i.TenCongTrinh != "" && i.TenCongTrinh != null)
                                {
                                    BaoCaoCongTrinh bc = new BaoCaoCongTrinh();
                                    bc.MaBaoCao = bchd1.MaBaoCao;
                                    bc.TenCongTrinh = i.TenCongTrinh;
                                    bc.ChuDauTu = i.ChuDauTu;
                                    bc.ThoiGianThucHien = i.ThoiGianThucHien;
                                    bc.GiaTriDaThucHien = i.GiaTriThucHien;
                                    bc.GhiChu = i.GhiChu;
                                    _bcctRespository.Add(bc);
                                    BaoCaoCongTrinh bc1 = new BaoCaoCongTrinh();
                                    bc1.MaBaoCao = bchd2.MaBaoCao;
                                    bc1.TenCongTrinh = i.TenCongTrinh;
                                    bc1.ChuDauTu = i.ChuDauTu;
                                    bc1.ThoiGianThucHien = i.ThoiGianThucHien;
                                    bc1.GiaTriDaThucHien = i.GiaTriThucHien;
                                    bc1.GhiChu = i.GhiChu;
                                    _bcctRespository.Add(bc1);
                                }
                            }
                        }

                        HoSoGiayPhep hs = new HoSoGiayPhep();
                        hs.MaToChuc = tochuc.MaToChuc;
                        hs.SoGiayPhep = model.SoGiayPhep;
                        hs.MaThongTinChung = ttc.MaThongTinChung;
                        hs.NgayXinPhep = DateTime.Today;
                        hs.TinhTrang = 9;
                        hs.LoaiGiayPhep = 3;
                        hs.CamKet = model.Camket;
                        hs.LyDo = model.LyDo;
                        if (Request.Files["tepdinhkem"] != null) // If uploaded synchronously
                        {
                            var tep_guid = _fileStore.SaveUploadedFile(Request.Files["tepdinhkem"]);
                            var tep_filename = Request.Files["tepdinhkem"].FileName;
                            hs.TepDinhKem = tep_guid.ToString();
                        }
                        else
                        {
                            hs.TepDinhKem = Request["tepdinhkem_guid"].ToString();
                        }
                        _hsgpRepository.Add(hs);

                        //scope.Complete();
                        msg = 20;
                    }
                    catch
                    {
                        //MessageHelper.CreateMessage(MessageType.Error, "", new List<string> { "Gửi hồ sơ không thành công" }, HttpContext.Response);
                        msg = 21;
                    }
               // }
            }
            else
            {
                try
                {
                    //using (TransactionScope s2 = new TransactionScope())
                   // {
                        List<ToChuc> tcs = tk.ToChucs.ToList();
                        if (tcs.Count == 0)
                        {
                            ToChuc tc = new ToChuc();
                            tc.TenToChuc = model.TenToChuc;
                            tc.GiayPhepKinhDoanh = model.GiayPhepKinhDoanh;
                            tc.HangDoanhNghiep = model.HangDoanhNghiep;
                            tc.VonLuuDong = model.VonLuuDong;
                            tc.VonPhapDinh = model.VonPhapDinh;
                            tc.SoTaiKhoan = model.SoTaiKhoan;
                            tc.TongSoCanBo = model.TongSoCanBo;
                            tc.MaLoaiHinhToChuc = model.MaLoaiHinhToChuc;
                            tc.TruSoChinh = model.TruSoChinh;
                            tc.NguoiDaiDien = model.NguoiDaiDien;
                            tc.DienThoai = model.DienThoai;
                            tc.Email = model.Email;
                            tc.Fax = model.Fax;
                            tc.MaTaiKhoan = tk.MaTaiKhoan;
                            _tochucRespository.Add(tc);
                        }
                        else
                        {
                            ToChuc tc = tcs[0];
                            tc.TenToChuc = model.TenToChuc;
                            tc.GiayPhepKinhDoanh = model.GiayPhepKinhDoanh;
                            tc.HangDoanhNghiep = model.HangDoanhNghiep;
                            tc.VonLuuDong = model.VonLuuDong;
                            tc.VonPhapDinh = model.VonPhapDinh;
                            tc.SoTaiKhoan = model.SoTaiKhoan;
                            tc.TongSoCanBo = model.TongSoCanBo;
                            tc.MaLoaiHinhToChuc = model.MaLoaiHinhToChuc;
                            tc.TruSoChinh = model.TruSoChinh;
                            tc.NguoiDaiDien = model.NguoiDaiDien;
                            tc.DienThoai = model.DienThoai;
                            tc.Email = model.Email;
                            tc.Fax = model.Fax;
                            _tochucRespository.Update(tc);
                        }

                        ToChuc tochuc = _tochucRespository.GetToChucByTaiKhoan(tk.MaTaiKhoan);
                        List<NhanLuc> listNhanLucCu = _nhanlucRespository.GetNhanLucByTCID(tochuc.MaToChuc);
                        foreach (var nlCu in listNhanLucCu)
                        {
                            _nhanlucRespository.Delete(nlCu);
                        }
                        IEnumerable<NhanLucVM> listNhanLuc = model.NhanLucRow;
                        if (listNhanLuc != null)
                        {
                            foreach (var i in listNhanLuc)
                            {
                                NhanLuc nl = new NhanLuc();
                                nl.MaToChuc = tochuc.MaToChuc;
                                nl.HoTen = i.HoTen;
                                nl.ChucVu = i.ChucVu;
                                nl.ThamNien = i.ThamNien;
                                _nhanlucRespository.Add(nl);
                            }
                        }

                        List<NangLucKeKhai> listNangLucCu = _nanglucRespository.GetNangLucByTCID(tochuc.MaToChuc);
                        foreach (var nlCu in listNangLucCu)
                        {
                            _nanglucRespository.Delete(nlCu);
                        }
                        IEnumerable<NangLucVM> listNangLuc = model.NangLucRow;
                        if (listNangLuc != null)
                        {
                            foreach (var i in listNangLuc)
                            {
                                NangLucKeKhai nl = new NangLucKeKhai();
                                nl.MaToChuc = tochuc.MaToChuc;
                                nl.NganhNghe = i.NganhNghe;
                                nl.SoTrenDaiHoc = i.Daihoc.GetValueOrDefault(0);
                                nl.SoTrungCap = i.TrungCap.GetValueOrDefault(0);
                                nl.SoCongNhanKyThuat = i.CongNhan.GetValueOrDefault(0);
                                nl.LoaiKhac = i.LoaiKhac.GetValueOrDefault(0);
                                _nanglucRespository.Add(nl);
                            }
                        }

                        List<ThietBi> listThietBiCu = _thietbiRespository.GetThietBiByTCID(tochuc.MaToChuc);
                        foreach (var tbCu in listThietBiCu)
                        {
                            _thietbiRespository.Delete(tbCu);
                        }
                        IEnumerable<ThietBiVM> listThietBi = model.ThietBiRow;
                        if (listThietBi != null)
                        {
                            foreach (var i in listThietBi)
                            {
                                ThietBi tb = new ThietBi();
                                tb.MaToChuc = tochuc.MaToChuc;
                                tb.TenThietBi_CongNghe = i.TenThietBi_CongNghe;
                                tb.SoLuong = i.SoLuong.GetValueOrDefault(0);
                                tb.TinhTrang = i.TinhTrang;
                                tb.GhiChu = i.GhiChu;
                                _thietbiRespository.Add(tb);
                            }
                        }

                        /// cập nhật báo cáo hoạt động có mã tổ chức, xóa hết báo cáo công trình có mã báo cáo vừa update
                        /// thêm bc công trình với mã báo cáo cũ
                        BaoCaoHoatDong bchd1 = _bchdRespository.GetBaoCaoHoatDongByTC(tochuc.MaToChuc);

                        if (bchd1 != null && bchd1.MaBaoCao != 0)
                        {
                           // bchd1.MaToChuc = tochuc.MaToChuc;
                            bchd1.TuNam = model.TuNam;
                            bchd1.DenNam = model.DenNam;
                            bchd1.DoanhThu = model.DoanhThuNam.GetValueOrDefault(0);
                            bchd1.NopNganSach = model.NopNganSach.GetValueOrDefault(0);
                            _bchdRespository.Update(bchd1);
                        }
                        else
                        {
                            BaoCaoHoatDong b = new BaoCaoHoatDong();
                            b.MaToChuc = tochuc.MaToChuc;
                            b.TuNam = model.TuNam;
                            b.DenNam = model.DenNam;
                            b.DoanhThu = model.DoanhThuNam.GetValueOrDefault(0);
                            b.NopNganSach = model.NopNganSach.GetValueOrDefault(0);
                            _bchdRespository.Add(b);
                            bchd1 = _bchdRespository.GetBaoCaoHoatDongByTC(tochuc.MaToChuc);
                        }

                        List<BaoCaoCongTrinh> congtrinhListCu = _bcctRespository.GetBCCTByBCHD(bchd1.MaBaoCao);
                        foreach (var bc in congtrinhListCu)
                        {
                            _bcctRespository.Delete(bc);
                        }

                        IEnumerable<CongTrinhVM> congtrinhList = model.CongTrinhRow;
                        if (congtrinhList != null)
                        {
                            foreach (var i in congtrinhList)
                            {
                                BaoCaoCongTrinh bc = new BaoCaoCongTrinh();
                                bc.MaBaoCao = bchd1.MaBaoCao;
                                bc.TenCongTrinh = i.TenCongTrinh;
                                bc.ChuDauTu = i.ChuDauTu;
                                bc.ThoiGianThucHien = i.ThoiGianThucHien;
                                bc.GiaTriDaThucHien = i.GiaTriThucHien;
                                bc.GhiChu = i.GhiChu;
                                _bcctRespository.Add(bc);
                            }
                        }
                        //s2.Complete();
                        msg = 22;
                   // }
                }
                catch
                {
                    msg = 23;
                }
            }
            return RedirectToAction("ThongBao", new { iMsg = msg });

            //HoSoGiayPhep hsgp = new HoSoGiayPhep();
        }
 public ActionResult ChiTiet()
 {
     TaiKhoan tk = ((EnhancedPrincipal)HttpContext.User).Data;
     int id = tk.MaTaiKhoan;
     List<ToChuc> tcs = tk.ToChucs.ToList();
     if (tcs.Count == 0)
     {
         return RedirectToAction("ThongBao", new { iMsg = 14 });
     }
     ToChuc tc = tcs[0];
     HoSoGiayPhep gphd = _hsgpRepository.GetHSGPByToChucId(tc.MaToChuc);
     BaoCaoHoatDong bc = new BaoCaoHoatDong();
     bc = gphd.ThongTinChung.BaoCaoHoatDongs.SingleOrDefault(m=>m.MaThongTinChung == gphd.MaThongTinChung);
     int k = 0;
     if (bc != null)
     {
         k = bc.MaBaoCao;
     }
     var dangkyMoi = _dkhdRespository.GetDangKyHDMoi(id);
     var dangkyDuocCap = _dkhdRespository.GetDKHDDaCap(id);
     var dangkyBS = _dkhdRespository.GetDKHDBoSung(id);
     var model = new GiayPhepDetailModel
     {
         DangKy = dangkyMoi,
         DangKyDaCap = dangkyDuocCap,
         DangKyBoSung = dangkyBS,
         giayphep = gphd,
         MaBaoCao = k
         //hoatdong = hoatdongList
        // nangluc = nanglucList
     };
     return View(model);
 }