private async Task <Person> MergePerson(dto.Person person)
        {
            var personId = person.PersonID > 0 ? person.PersonID : await _sessionBag.PersonId();

            var nskPerson = await GetPerson(personId);

            var changedPerson = Mapper.Map <Person>(person);

            nskPerson.State           = MessageState.Modified;
            nskPerson.DOB             = changedPerson.DOB;
            nskPerson.CultureCode     = changedPerson.CultureCode;
            nskPerson.Gender          = changedPerson.Gender;
            nskPerson.Nationality     = changedPerson.Nationality;
            nskPerson.ResidentCountry = changedPerson.ResidentCountry;
            if (changedPerson.TravelDocs != null && changedPerson.TravelDocs.Length > 0)
            {
                var newTravelDocs = changedPerson.TravelDocs.ToList();
                newTravelDocs[0].Default = true;
                newTravelDocs.ForEach(p => { p.PersonID = personId; p.State = MessageState.New; });
                var updatedNskDocs = nskPerson.TravelDocs != null?nskPerson.TravelDocs.ToList() : new List <TravelDoc>();

                updatedNskDocs.ForEach(p => { p.State = MessageState.Deleted; });
                updatedNskDocs.AddRange(newTravelDocs);
                nskPerson.TravelDocs = updatedNskDocs.ToArray();
            }
            if (changedPerson.PersonNameList != null)
            {
                var newPersonNames = changedPerson.PersonNameList.ToList();
                newPersonNames[0].NameType = NameType.True;
                newPersonNames.ForEach(p => { p.PersonID = personId; p.State = MessageState.New; });
                var updatedPersonNames = nskPerson.PersonNameList != null?nskPerson.PersonNameList.ToList() : new List <PersonName>();

                updatedPersonNames.ForEach(p => { p.State = MessageState.Deleted; });
                updatedPersonNames.AddRange(newPersonNames);
                nskPerson.PersonNameList = updatedPersonNames.ToArray();
            }
            if (changedPerson.PersonPhoneList != null)
            {
                var newPersonPhones = changedPerson.PersonPhoneList.ToList();
                newPersonPhones[0].Default = true;
                newPersonPhones.ForEach(p => { p.PersonID = personId; p.State = MessageState.New; });
                var updatedPersonPhones = nskPerson.PersonPhoneList != null?nskPerson.PersonPhoneList.ToList() : new List <PersonPhone>();

                updatedPersonPhones.ForEach(p => { p.State = MessageState.Deleted; });
                updatedPersonPhones.AddRange(newPersonPhones);
                nskPerson.PersonPhoneList = updatedPersonPhones.ToArray();
            }
            if (changedPerson.PersonAddressList != null)
            {
                var newPersonAddresses = changedPerson.PersonAddressList.ToList();
                newPersonAddresses[0].Default = true;
                newPersonAddresses.ForEach(p => { p.PersonID = personId; p.State = MessageState.New; });
                var updatedPersonAddresses = nskPerson.PersonAddressList != null?nskPerson.PersonAddressList.ToList() : new List <PersonAddress>();

                updatedPersonAddresses.ForEach(p => { p.State = MessageState.Deleted; });
                updatedPersonAddresses.AddRange(newPersonAddresses);
                nskPerson.PersonAddressList = updatedPersonAddresses.ToArray();
            }
            return(nskPerson);
        }
        public async Task <dto.Person> UpdatePerson(dto.Person person)
        {
            var nskPerson = await MergePerson(person);

            var request = new CommitPersonRequest
            {
                ContractVersion        = _navApiContractVer,
                MessageContractVersion = _navMsgContractVer,
                Signature = await _sessionBag.Signature(),
                EnableExceptionStackTrace = false,
                personReqData             = nskPerson
            };
            var commitResponse = await _personClient.CommitAsync(request);

            return(Mapper.Map <dto.Person>(commitResponse.Person));
        }