Esempio n. 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ệ !" });
        }
Esempio n. 2
0
        public ActionResult EditDieuChinhPHNC([Bind(Include = "Id,UnitCode,DieuChinhKHXBDetailId,DiemTiepNhanId,CreateDate,CreateBy")] BDieuChinhPhanHuongUnit BDieuChinhPhanHuongUnit, string listId, string typeid)
        {
            string DieuChinhKHXBDetailId = 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)
            {
                DieuChinhKHXBDetailId = BDieuChinhPhanHuongUnit.DieuChinhKHXBDetailId;
                objUnitNew = BuildSessionDieuChinhPHNC(DieuChinhKHXBDetailId);
                //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
                    BDieuChinhPhanHuongUnit.CreateBy = userInfo.Id;
                    BDieuChinhPhanHuongUnit.CreateDate = DateTime.Now;
                    BDieuChinhPhanHuongUnit.ModifyBy = userInfo.Id;
                    BDieuChinhPhanHuongUnit.ModifyDate = DateTime.Now;
                    BDieuChinhPhanHuongUnit.DieuChinhKHXBDetailId = DieuChinhKHXBDetailId;
                    //add action
                    dbDieuChinhPHNC.Add(BDieuChinhPhanHuongUnit, lstUnits);
                    //remap unit lai cho object
                    objUnitNew.UpdateListUnitMap(lstUnits, BDieuChinhPhanHuongUnit.DiemTiepNhanId);
                    Session[Application.Session.UnitModelDieuChinh] = objUnitNew;
                }
                else if (!string.IsNullOrWhiteSpace(typeid))
                {
                    lstQuanHuyen = objUnitNew.getDistrictMap(lstids, typeid);
                    currentprv = lstQuanHuyen.FirstOrDefault().ProvinceCode;
                    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);
                    //map lai list vua tao cho object
                    objUnitNew.UpdateListDistrictMap(lstQuanHuyen, bDieuChinhPhanHuongDistrict.DiemTiepNhanId);
                    Session[Application.Session.UnitModelDieuChinh] = objUnitNew;
                }
                buildMessage("Bạn đã sửa thông tin phân hướng thành công .");
                return RedirectToAction("Edit" + subAction, new { provincecode = currentprv, DieuChinhKHXBDetailId = DieuChinhKHXBDetailId });
            }

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