예제 #1
0
        public ActionResult CreateDieuChinhPHNC([Bind(Include = "Id,ThongTinBaoId,DieuChinhKHXBDetailId,DiemTiepNhanId")] BDieuChinhPhanHuongUnitModel BDieuChinhPhanHuongUnit, string listId, string typeid)
        {
            if (ModelState.IsValid)
            {
                //check session unitmodel
                string DieuChinhKHXBDetailId = BDieuChinhPhanHuongUnit.DieuChinhKHXBDetailId;
                UnitModelDieuChinh objUnitNew = BuildSessionDieuChinhPHNC(BDieuChinhPhanHuongUnit.ThongTinBaoId, DieuChinhKHXBDetailId);
                List<v_Unit> lstUnits = new List<v_Unit>();
                List<QuanHuyen> lstQuanHuyen = new List<QuanHuyen>();
                //lstids typeid: 1: list province, 2: list district, 3: list unit
                string[] lstids = listId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                if (lstids.Count() == 0)
                {
                    return this.Json(new { MSG = "Bạn chưa chọn quận huyện hay bưu cục nào !" });
                }
                if (!string.IsNullOrWhiteSpace(typeid) && typeid == "3")
                {
                    if (DieuChinhKHXBDetailId != null)
                    {
                        lstUnits = objUnitNew.getUnitNotMap(lstids, typeid);
                        //bind data
                        BDieuChinhPhanHuongUnit.CreateBy = userInfo.Id;
                        BDieuChinhPhanHuongUnit.CreateDate = DateTime.Now;
                        BDieuChinhPhanHuongUnit.ModifyBy = userInfo.Id;
                        BDieuChinhPhanHuongUnit.ModifyDate = DateTime.Now;
                        BDieuChinhPhanHuongUnit.DieuChinhKHXBDetailId = DieuChinhKHXBDetailId;
                        //add action
                        dbDieuChinhPHNC.Add(BDieuChinhPhanHuongUnit.toBDieuChinhPhanHuongUnit(), lstUnits);
                        //map lai list vua tao cho object
                        objUnitNew.setListUnitMapNew(lstUnits, BDieuChinhPhanHuongUnit.DiemTiepNhanId);
                        Session[Application.Session.UnitModelDieuChinh] = objUnitNew;
                    }
                    else
                    {
                        BDieuChinhPhanHuongUnitModel bDieuChinhPhanHuongUnitModel = new BDieuChinhPhanHuongUnitModel();
                        lstUnits = objUnitNew.getUnitNotMap(lstids, typeid);
                        //bind data for district
                        bDieuChinhPhanHuongUnitModel.DiemTiepNhanId = BDieuChinhPhanHuongUnit.DiemTiepNhanId;
                        bDieuChinhPhanHuongUnitModel.ThongTinBaoId = BDieuChinhPhanHuongUnit.ThongTinBaoId;
                        bDieuChinhPhanHuongUnitModel.DieuChinhKHXBDetailId = DieuChinhKHXBDetailId;
                        bDieuChinhPhanHuongUnitModel.CreateBy = userInfo.Id;
                        bDieuChinhPhanHuongUnitModel.CreateDate = DateTime.Now;
                        bDieuChinhPhanHuongUnitModel.ModifyBy = userInfo.Id;
                        bDieuChinhPhanHuongUnitModel.ModifyDate = DateTime.Now;
                        //add action
                        dbDieuChinhPHNC.Add(bDieuChinhPhanHuongUnitModel.toBDieuChinhPhanHuongUnit(), lstUnits);
                    }
                }
                else if(!string.IsNullOrWhiteSpace(typeid))
                {
                    lstQuanHuyen = objUnitNew.getDistrictNotMap(lstids, typeid);
                    if(DieuChinhKHXBDetailId != null)
                    {
                        BDieuChinhPhanHuongDistrictModel bDieuChinhPhanHuongDistrict = new BDieuChinhPhanHuongDistrictModel();
                        //bind data for district
                        bDieuChinhPhanHuongDistrict.DiemTiepNhanId = BDieuChinhPhanHuongUnit.DiemTiepNhanId;
                        bDieuChinhPhanHuongDistrict.ThongTinBaoId = BDieuChinhPhanHuongUnit.ThongTinBaoId;
                        bDieuChinhPhanHuongDistrict.DieuChinhKHXBDetailId = DieuChinhKHXBDetailId;
                        bDieuChinhPhanHuongDistrict.CreateBy = userInfo.Id;
                        bDieuChinhPhanHuongDistrict.CreateDate = DateTime.Now;
                        bDieuChinhPhanHuongDistrict.ModifyBy = userInfo.Id;
                        bDieuChinhPhanHuongDistrict.ModifyDate = DateTime.Now;
                        //add action
                        dbDieuChinhPHNC.AddDistrict(bDieuChinhPhanHuongDistrict.toBDieuChinhPhanHuongDistrict(), lstQuanHuyen);
                    }
                    else
                    {
                        BPhanHuongNhuCauDistrictModel bPhanHuongNhuCauDistrictModel = new BPhanHuongNhuCauDistrictModel();
                        //bind data for district
                        bPhanHuongNhuCauDistrictModel.DiemTiepNhanId = BDieuChinhPhanHuongUnit.DiemTiepNhanId;
                        bPhanHuongNhuCauDistrictModel.ThongTinBaoId = BDieuChinhPhanHuongUnit.ThongTinBaoId;
                        bPhanHuongNhuCauDistrictModel.CreateBy = userInfo.Id;
                        bPhanHuongNhuCauDistrictModel.CreateDate = DateTime.Now;
                        bPhanHuongNhuCauDistrictModel.ModifyBy = userInfo.Id;
                        bPhanHuongNhuCauDistrictModel.ModifyDate = DateTime.Now;
                        //add action
                        dbDieuChinhPHNC.AddDistrict(bPhanHuongNhuCauDistrictModel.toBPhanHuongNhuCauDistrict(), lstQuanHuyen);
                    }
                }

                if (Session["ProvinceCode"] != null)
                {
                    return Json(new { MSG = "Bạn đã thiết lập thông tin phân hướng thành công !" });
                }
                else
                {
                    return Json(new { MSG = "Bạn đã thiết lập thông tin phân hướng thành công !" });
                }
            }

            return this.Json(new { MSG = "Có lỗi xảy ra, dữ liệu không hợp lệ !" });
        }
예제 #2
0
        public ActionResult Edit([Bind(Include = "Id,UnitCode,ThongTinBaoId,DiemTiepNhanId,CreateDate,CreateBy")] BPhanHuongNhuCauUnit BPhanHuongNhuCauUnit, string listId, string typeid)
        {
            string ThongTinBaoId = null;
            //check session unitmodel
            UnitModelDieuChinh objUnitNew = new UnitModelDieuChinh();
            List<v_Unit> lstUnits = new List<v_Unit>();
            List<QuanHuyen> lstQuanHuyen = new List<QuanHuyen>();
            string currentprv = "";
            if (ModelState.IsValid)
            {
                ThongTinBaoId = BPhanHuongNhuCauUnit.ThongTinBaoId;
                objUnitNew = BuildSessionDieuChinhPHNC(ThongTinBaoId);
                //lstids typeid: 1: list province, 2: list district, 3: list unit
                string[] lstids = listId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                if (lstids.Count() == 0)
                {
                    return this.Json(new { MSG = "Bạn chưa chọn quận huyện hay bưu cục nào !" });
                }
                if (!string.IsNullOrWhiteSpace(typeid) && typeid == "3")
                {
                    lstUnits = objUnitNew.getUnitMap(lstids, typeid);
                    //get current province to back
                    currentprv = lstUnits.Select(t => t.ProvinceCode).FirstOrDefault();
                    //bind data
                    BPhanHuongNhuCauUnit.CreateBy = userInfo.Id;
                    BPhanHuongNhuCauUnit.CreateDate = DateTime.Now;
                    BPhanHuongNhuCauUnit.ModifyBy = userInfo.Id;
                    BPhanHuongNhuCauUnit.ModifyDate = DateTime.Now;
                    BPhanHuongNhuCauUnit.ThongTinBaoId = ThongTinBaoId;
                    //add action
                    db.Add(BPhanHuongNhuCauUnit, lstUnits);
                }
                else if (!string.IsNullOrWhiteSpace(typeid))
                {
                    lstQuanHuyen = objUnitNew.getDistrictMap(lstids, typeid);
                    currentprv = lstQuanHuyen.FirstOrDefault().ProvinceCode;
                    BPhanHuongNhuCauDistrictModel bPhanHuongNhuCauDistrict = new BPhanHuongNhuCauDistrictModel();
                    //bind data for district
                    bPhanHuongNhuCauDistrict.DiemTiepNhanId = BPhanHuongNhuCauUnit.DiemTiepNhanId;
                    bPhanHuongNhuCauDistrict.ThongTinBaoId = BPhanHuongNhuCauUnit.ThongTinBaoId;
                    bPhanHuongNhuCauDistrict.ThongTinBaoId = ThongTinBaoId;
                    bPhanHuongNhuCauDistrict.CreateBy = userInfo.Id;
                    bPhanHuongNhuCauDistrict.CreateDate = DateTime.Now;
                    bPhanHuongNhuCauDistrict.ModifyBy = userInfo.Id;
                    bPhanHuongNhuCauDistrict.ModifyDate = DateTime.Now;
                    //add action
                    db.AddDistrict(bPhanHuongNhuCauDistrict.toBPhanHuongNhuCauDistrict(), lstQuanHuyen);
                }
                buildMessage("Bạn đã sửa thông tin phân hướng thành công .");
                return RedirectToAction("Edit", new { provincecode = currentprv, ThongTinBaoId = ThongTinBaoId });
            }

            buildMessage("Bạn đã sửa thông tin phân hướng thât bại !");
            return RedirectToAction("Edit", new { provincecode = currentprv, ThongTinBaoId = ThongTinBaoId });
        }