public async Task <object> Update(FamilyProfileViewModel familyProfileVM)
        {
            if (ModelState.IsValid)
            {
                familyProfileVM.FamilyProfile.Person.SSN = Function.Encryptdata(familyProfileVM.FamilyProfile.Person.SSN);
                // Create Person
                personRepository.Update(familyProfileVM.FamilyProfile.Person);
                var retVal = await personRepository.Save();

                familyProfileVM.FamilyProfile.Person = null;

                // Update database
                personSupplementalRepository.Update(familyProfileVM.PersonSupplemental);

                await personSupplementalRepository.Save();

                familyProfileRepository.Update(familyProfileVM.FamilyProfile);

                await familyProfileRepository.Save();

                return(familyProfileVM);
            }

            return(null);
        }
Beispiel #2
0
        public async Task <IActionResult> UpdateFamilyProfile([FromBody] FamilyProfileViewModel profile)
        {
            var context = GetUserContext();
            var family  = new Family
            {
                FamilyId = context.FamilyId,
                ChurchId = context.ChurchId
            };

            family.Address          = profile.Address;
            family.PhotoUrl         = profile.PhotoUrl;
            family.HomeParish       = profile.HomeParish;
            family.RevealAddress    = profile.RevealAddress;
            family.RevealHomeParish = profile.RevealHomeParish;

            if (!string.IsNullOrEmpty(profile.PhotoUrl))
            {
                var origFamily = await DataRepository.GetFamily(context.ChurchId, context.FamilyId);

                if (!string.IsNullOrEmpty(origFamily.PhotoUrl))
                {
                    await _imageService.DeletObject(origFamily.PhotoUrl);
                }
            }

            var result = await DataRepository.UpdateFamily(family);

            return(result ? Ok() : StatusCode((int)HttpStatusCode.InternalServerError));
        }
        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);
        }