public async Task <object> Create(FamilyProfileViewModel familyProfileVM)
        {
            if (ModelState.IsValid)
            {
                //By default family profile set to active
                familyProfileVM.FamilyProfile.Active = true;

                if (familyProfileVM.FamilyProfile.Person.SSN != null)
                {
                    familyProfileVM.FamilyProfile.Person.SSN = Function.Encryptdata(familyProfileVM.FamilyProfile.Person.SSN);
                }

                // Create Person
                personRepository.Create(familyProfileVM.FamilyProfile.Person);
                var retVal = await personRepository.Save();

                if (familyProfileVM.FamilyProfile.Person.ID != 0)
                {
                    //Create New Person Supplemental Record
                    familyProfileVM.PersonSupplemental.PersonID = familyProfileVM.FamilyProfile.Person.ID;

                    // Create FamilyProfile Record
                    familyProfileVM.FamilyProfile.FamilyMemberID = familyProfileVM.FamilyProfile.Person.ID;

                    FamilyProfile newFamilyProfile = familyProfileVM.FamilyProfile;

                    newFamilyProfile.Person = null;

                    // Save to the database
                    personSupplementalRepository.Create(familyProfileVM.PersonSupplemental);

                    await personSupplementalRepository.Save();


                    familyProfileRepository.Create(newFamilyProfile);

                    await familyProfileRepository.Save();
                }

                return(familyProfileVM);
            }

            return(null);
        }
Esempio n. 2
0
        public async Task <object> Create(Person person)
        {
            int systemID = _authRepository.GetSystemIDByLoggedInUserRole();

            Person jtsResult;

            ClientProfile clientProfile = new ClientProfile
            {
                SystemID    = systemID,
                Active      = true,
                UpdatedBy   = User.Identity.Name,
                CreatedBy   = User.Identity.Name,
                CreatedDate = DateTime.Now,
                UpdatedDate = DateTime.Now
            };

            if (ModelState.IsValid)
            {
                if (person.SSN != null)
                {
                    person.SSN = Function.Encryptdata(person.SSN);
                }


                jtsResult = context.Person.Where(x => x.JTS == person.JTS && x.JTS != "" && x.JTS != null).FirstOrDefault();

                if (systemID == Convert.ToInt32(EmpowerSystem.Juvenile) && jtsResult != null)
                {
                    return("JTS");
                }

                var ssnresult = context.Person.Where(x => x.SSN == person.SSN && x.SSN != null && x.SSN != "").FirstOrDefault();

                if (ssnresult != null)
                {
                    return("SSN");
                }


                person.CreatedBy = User.Identity.Name;

                //Create Person
                _personRepository.Create(person);
                var retVal = await _personRepository.Save();

                if (person.ID != 0)
                {
                    // Create New ClientProfile
                    clientProfile.PersonID    = person.ID;
                    clientProfile.CreatedDate = DateTime.Now;
                    clientProfile.UpdatedDate = DateTime.Now;
                    clientProfile.UpdatedBy   = User.Identity.Name;
                    clientProfile.CreatedBy   = User.Identity.Name;
                    _clientProfileRepository.Create(clientProfile);
                    var cpVal = await _clientProfileRepository.Save();

                    // Create New PersonSupplemental
                    PersonSupplemental personSupplemental = new PersonSupplemental
                    {
                        PersonID    = person.ID,
                        Active      = true,
                        UpdatedBy   = User.Identity.Name,
                        CreatedBy   = User.Identity.Name,
                        CreatedDate = DateTime.Now,
                        UpdatedDate = DateTime.Now
                    };
                    _personSupplementalRepository.Create(personSupplemental);
                    var psVal = await _personSupplementalRepository.Save();
                }

                //decrypt it again for display
                clientProfile.Person.SSN = Function.Decryptdata(clientProfile.Person.SSN);

                return(clientProfile);
            }

            return(null);
        }