private UserProfileModel ToUserProfileModel(StaffBiography biography, StaffProfileModel profile)
        {
            var model = new UserProfileModel
            {
                Usi         = profile.Staff.StaffUsi,
                UniqueId    = profile.Staff.StaffUniqueId,
                FirstName   = profile.Profile.FirstName,
                MiddleName  = profile.Profile.MiddleName,
                LastSurname = profile.Profile.LastSurname,
                Nickname    = profile.Profile.NickName,
                PreferredMethodOfContactTypeId = profile.Profile.PreferredMethodOfContactTypeId,
                ReplyExpectations  = profile.Profile.ReplyExpectations,
                LanguageCode       = profile.Profile.LanguageCode,
                IdentificationCode = profile.Staff.StaffIdentificationCodes.FirstOrDefault(x => x.AssigningOrganizationIdentificationCode == "LASID")?.IdentificationCode,
                Addresses          = profile.Profile.StaffProfileAddresses.Select(x => new AddressModel
                {
                    AddressTypeId            = x.AddressTypeId,
                    StreetNumberName         = x.StreetNumberName,
                    ApartmentRoomSuiteNumber = x.ApartmentRoomSuiteNumber,
                    City = x.City,
                    StateAbbreviationTypeId = x.StateAbbreviationTypeId,
                    PostalCode = x.PostalCode
                }).ToList(),
                ElectronicMails = profile.Profile.StaffProfileElectronicMails.Select(x => new ElectronicMailModel
                {
                    ElectronicMailAddress        = x.ElectronicMailAddress,
                    ElectronicMailTypeId         = x.ElectronicMailTypeId,
                    PrimaryEmailAddressIndicator = x.PrimaryEmailAddressIndicator
                }).ToList(),
                TelephoneNumbers = profile.Profile.StaffProfileTelephones.Select(x => new TelephoneModel
                {
                    TelephoneNumber = x.TelephoneNumber,
                    TextMessageCapabilityIndicator = x.TextMessageCapabilityIndicator,
                    TelephoneNumberTypeId          = x.TelephoneNumberTypeId,
                    PrimaryMethodOfContact         = x.PrimaryMethodOfContact,
                    TelephoneCarrierTypeId         = x.TelephoneCarrierTypeId,
                }).ToList()
            };

            if (biography != null)
            {
                model.FunFact        = biography.FunFact;
                model.ShortBiography = biography.ShortBiography;
                model.Biography      = biography.Biography;
            }

            return(model);
        }
        private UserProfileModel ToUserProfileModel(Staff edfiPerson, StaffBiography staffBiography)
        {
            var model = new UserProfileModel
            {
                Usi            = edfiPerson.StaffUsi,
                UniqueId       = edfiPerson.StaffUniqueId,
                FirstName      = edfiPerson.FirstName,
                MiddleName     = edfiPerson.MiddleName,
                LastSurname    = edfiPerson.LastSurname,
                FunFact        = staffBiography?.FunFact,
                ShortBiography = staffBiography?.ShortBiography,
                Biography      = staffBiography?.Biography,

                Addresses = edfiPerson.StaffAddresses.Select(x => new AddressModel
                {
                    AddressTypeId            = x.AddressTypeId,
                    StreetNumberName         = x.StreetNumberName,
                    ApartmentRoomSuiteNumber = x.ApartmentRoomSuiteNumber,
                    City = x.City,
                    StateAbbreviationTypeId = x.StateAbbreviationTypeId,
                    PostalCode = x.PostalCode
                }).ToList(),
                ElectronicMails = edfiPerson.StaffElectronicMails.Select(x => new ElectronicMailModel
                {
                    ElectronicMailAddress        = x.ElectronicMailAddress,
                    ElectronicMailTypeId         = x.ElectronicMailTypeId,
                    PrimaryEmailAddressIndicator = x.PrimaryEmailAddressIndicator
                }).ToList(),
                TelephoneNumbers = edfiPerson.StaffTelephones.Select(x => new TelephoneModel
                {
                    TelephoneNumber = x.TelephoneNumber,
                    TextMessageCapabilityIndicator = x.TextMessageCapabilityIndicator,
                    TelephoneNumberTypeId          = x.TelephoneNumberTypeId
                }).ToList()
            };

            if (staffBiography != null)
            {
                model.FunFact        = staffBiography.FunFact;
                model.ShortBiography = staffBiography.ShortBiography;
                model.Biography      = staffBiography.Biography;
            }

            return(model);
        }
        private async Task <StaffBiography> SaveStaffBiographyAsync(int staffUsi, UserProfileModel model)
        {
            var staff = await _edFiDb.Staffs.SingleOrDefaultAsync(p => p.StaffUsi == staffUsi);

            // Check if model has values, if not, dont save biography
            if (model.Biography == null && model.ShortBiography == null && model.FunFact == null)
            {
                return(null);
            }

            // Fetch current biography if any.
            var biography = await _edFiDb.StaffBiographies.SingleOrDefaultAsync(x => x.StaffUniqueId == staff.StaffUniqueId);

            // If its a new one.
            if (biography == null)
            {
                biography = new StaffBiography
                {
                    StaffUniqueId  = staff.StaffUniqueId,
                    FunFact        = model.FunFact,
                    ShortBiography = model.ShortBiography,
                    Biography      = model.Biography
                };

                _edFiDb.StaffBiographies.Add(biography);
            }
            else
            { // We are updating
                biography.FunFact        = model.FunFact;
                biography.ShortBiography = model.ShortBiography;
                biography.Biography      = model.Biography;
            }

            // Persist changes to db.
            await _edFiDb.SaveChangesAsync();

            return(biography);
        }