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);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <FamilyProfile> > Get(string name)
        {
            GenderizeResult result = null;
            FamilyProfile   profile;

            try
            {
                string baseUrl = genderizeOptions.Value.BaseUrl;
                string key     = genderizeOptions.Value.DeveloperApiKey;

                logger.LogInformation("Acquiring name details for {FamilyName}.", name);

                result = await genderizeClient.GetGenderForName(name, key);

                Gender gender;
                profile = new FamilyProfile()
                {
                    Name   = name,
                    Gender = Enum.TryParse <Gender>(result.Gender, true, out gender)
                        ? gender : Gender.Unknown
                };
            }
            catch (HttpRequestException ex)
            {
                logger.LogWarning(ex, "Http request failed.");
                return(StatusCode(StatusCodes.Status502BadGateway, "Failed request to external resource."));
            }
            catch (TimeoutRejectedException ex)
            {
                logger.LogWarning(ex, "Timeout occurred when retrieving details for {FamilyName}.", name);
                return(StatusCode(StatusCodes.Status504GatewayTimeout, "Timeout on external web request."));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Unknown exception occurred while retrieving gender details.");

                // Exception shielding for all other exceptions
                return(StatusCode(StatusCodes.Status500InternalServerError, "Request could not be processed."));
            }
            return(Ok(profile));
        }