Ejemplo n.º 1
0
        // GET: CYCAAdmission
        public ActionResult Index(int id)
        {
            //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;
                }
            }

            //instanciate viewmodel
            CYCAAdmissionViewModel personVM = new CYCAAdmissionViewModel();

            //get person id by assessment id
            int personId = admissionModel.GetPCMPersonIdByintAssId(id);

            //get person record
            personVM = admissionModel.GetPCMPerson(personId);

            int ClientRefid = admissionModel.GetClientRefIdssId(id);
            //Get Module Reference number ....................
            string ClientRef = admissionModel.GetClientRef(ClientRefid);

            Session["ClientRef"] = ClientRef;
            var personIdUpdate = personId;

            if (ClientRef == null || ClientRef == "")
            {
                #region CreateReferenceNumber

                var dbContext = new SDIIS_DatabaseEntities();
                #region ObtainProvinceOfLoggedInUser
                //var currentUser = (User)Session["CurrentUser"];
                var userName = string.Empty;
                //var currentUserProvinceId = -1;
                //if (currentUser != null)
                //{
                //    userName = currentUser.User_Name;
                //}
                //if (currentUser.Employees.Any())
                //    userProvince = currentUser.apl_Social_Worker.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id;
                #endregion
                ClientModel clientModel = new ClientModel();
                int         client_ID   = dbContext.Intake_Assessments.Find(id).Client_Id;
                int         module_ID   = Convert.ToInt32(dbContext.Problem_Sub_Categories.Find(dbContext.Intake_Assessments.Find(id).Problem_Sub_Category_Id).Module_Id);
                var         CheckExist  = (from a in dbContext.int_Client_Module_Registration
                                           where a.Client_Id == client_ID && a.Module_Id == module_ID
                                           select a).ToList();
                if (CheckExist.Count() == 0)
                {
                    int ProblemCatId = dbContext.Problem_Sub_Categories.Find(dbContext.Intake_Assessments.Find(id).Problem_Sub_Category_Id).Problem_Category_Id;
                    int_Client_Module_Registration Adopt_int_Client = new int_Client_Module_Registration
                    {
                        //string ProvinceAbbr = dbContext.Provinces.Find(currentUserProvinceId).Abbreviation;
                        Client_Module_Ref_No = clientModel.CreatePCMReferenceNumber(DateTime.Now.Year.ToString(), ProblemCatId, client_ID),
                        Client_Id            = client_ID,
                        Module_Id            = module_ID
                    };
                    dbContext.int_Client_Module_Registration.Add(Adopt_int_Client);
                    dbContext.SaveChanges();

                    ClientRefid = admissionModel.GetClientRefIdssId(id);
                    //Get Module Reference number ....................
                    ClientRef = admissionModel.GetClientRef(ClientRefid);
                }
                #endregion
            }

            Session["ClientRef"] = ClientRef;
            ViewBag.ModuleRef    = ClientRef;

            Session["PersonId"]     = personIdUpdate;
            Session["Idassessment"] = id;

            return(PartialView(personVM));
        }