示例#1
0
        public ActionResult GetPCMPresentense()
        {
            int intassid = Convert.ToInt32(Session["IntakeassId"]);
            // get current username
            string loginName = User.Identity.Name;

            Session["LoginName"] = loginName;
            var currentUser  = (User)Session["CurrentUser"];
            var userProvince = -1;
            var userId       = 0;

            if (currentUser != null)
            {
                userId = currentUser.User_Id;
                if (currentUser.Employees.Any())
                {
                    userProvince = currentUser.Employees.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id;
                }
                if (currentUser.apl_Social_Worker.Any())
                {
                    userProvince = currentUser.apl_Social_Worker.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id;
                }
            }
            PCMCaseModel caseModelC = new PCMCaseModel();

            string ClientRef = Convert.ToString(Session["ClientRef"]);

            ViewBag.ModuleRef = ClientRef;

            PCMPresentenceModel Model = new PCMPresentenceModel();
            //initialise view model
            PCMPresentenceDetailsViewModel VM = new PCMPresentenceDetailsViewModel();

            using (SDIIS_DatabaseEntities db = new SDIIS_DatabaseEntities())
            {
                int Presentenseid = Model.GetPCMPresentenseByassId(intassid);
                if (Presentenseid != 0)
                {
                    VM = Model.GetPresentenseList(Presentenseid);

                    //populate dropdown lists

                    VM.CommunityBasedOptions_List     = Model.GetCommunityBasedOption();
                    VM.SupendedPostponedSentence_List = Model.GetSupendedPostponedSentence();
                    VM.CaseStatus_List          = Model.GetCaseStatus();//..................?
                    VM.RestorectiveJustice_List = Model.GetRestorectiveJustice();
                    VM.ProgrammeType_List       = Model.GetProgrammeType();
                    VM.Programme_List           = Model.GetProgramme();
                    VM.Imprisoment_List         = Model.GetImprisoment();//..................?
                    VM.Department_List          = Model.GetDepartment();
                    VM.Court_List    = Model.GetAllCourt();
                    VM.Province_List = Model.GetAllProvinces();
                    VM.District_List = Model.GetAllDistrict();


                    if (Convert.ToInt32(Model.GetPresentenseList(Presentenseid).Court_id) != 0)
                    {
                        int Courtid = Convert.ToInt32(Model.GetPresentenseList(Presentenseid).Court_id);
                        ViewBag.Court = db.Courts.Find(Courtid).Description;

                        //Get District using the court..........................................
                        int DistrictId = (from k in db.Districts
                                          join k1 in db.Courts on k.District_Id equals k1.District_Id
                                          where k1.Court_Id == Courtid
                                          select k.District_Id).FirstOrDefault();

                        ViewData["district"] = new SelectList(db.Districts, "District_Id", "Description", DistrictId).ToList();

                        //Get Province using the District..........................................

                        int ProvinceId = (from a in db.Districts
                                          join b in db.Provinces on a.Province_Id equals b.Province_Id
                                          where a.District_Id.Equals(DistrictId)
                                          select b.Province_Id).FirstOrDefault();
                        ViewData["province"] = new SelectList(db.Provinces, "Province_Id", "Description", ProvinceId).ToList();
                    }

                    Session["presentdate"] = Presentenseid;

                    return(PartialView(VM));
                }
                else
                {
                    PCMPresentenceModel            Model1 = new PCMPresentenceModel();
                    PCMPresentenceDetailsViewModel VM1    = new PCMPresentenceDetailsViewModel();
                    //initialise view model

                    VM1.CommunityBasedOptions_List     = Model.GetCommunityBasedOption();
                    VM1.SupendedPostponedSentence_List = Model.GetSupendedPostponedSentence();
                    VM1.CaseStatus_List          = Model.GetCaseStatus();//..................?
                    VM1.RestorectiveJustice_List = Model.GetRestorectiveJustice();
                    VM1.ProgrammeType_List       = Model.GetProgrammeType();
                    VM1.Programme_List           = Model.GetProgramme();
                    VM1.Imprisoment_List         = Model.GetImprisoment();//..................?
                    VM1.Department_List          = Model.GetDepartment();
                    VM1.Court_List    = Model.GetAllCourt();
                    VM1.Province_List = Model.GetAllProvinces();
                    VM1.District_List = Model.GetAllDistrict();

                    //funtion that calls insert Socio Economy
                    Model1.InsertPresentence(VM1, intassid, userId);

                    PCMPresentenceDetailsViewModel VM2 = new PCMPresentenceDetailsViewModel();
                    int Presentenceidadd = Model.GetPCMPresentenseByassId(intassid);
                    VM2 = Model1.GetPresentenseList(Presentenceidadd);

                    VM2.CommunityBasedOptions_List     = Model.GetCommunityBasedOption();
                    VM2.SupendedPostponedSentence_List = Model.GetSupendedPostponedSentence();
                    VM2.CaseStatus_List          = Model.GetCaseStatus();//..................?
                    VM2.RestorectiveJustice_List = Model.GetRestorectiveJustice();
                    VM2.ProgrammeType_List       = Model.GetProgrammeType();
                    VM2.Programme_List           = Model.GetProgramme();
                    VM2.Imprisoment_List         = Model.GetImprisoment();//..................?
                    VM2.Department_List          = Model.GetDepartment();
                    VM2.Court_List        = Model.GetAllCourt();
                    VM2.Province_List     = Model.GetAllProvinces();
                    VM2.District_List     = Model.GetAllDistrict();
                    Session["presentadd"] = Presentenceidadd;
                    return(PartialView("GetPCMPresentense", VM2));
                }
            }
        }