Exemplo n.º 1
0
        public async Task <SSG_Person> SavePerson(PersonEntity person, CancellationToken cancellationToken)
        {
            //ssg_duplicatedetectionhash is set to be Unique in DB, so we can use this to detect duplicates.
            person.DuplicateDetectHash = await _duplicateDetectService.GetDuplicateDetectHashData(person);

            try
            {
                return(await this._oDataClient.For <SSG_Person>().Set(person).InsertEntryAsync(cancellationToken));
            }
            catch (WebRequestException e) when(e.IsDuplicateHashError())
            {
                string hashData      = person.DuplicateDetectHash;
                var    existedPerson = await this._oDataClient.For <SSG_Person>()
                                       .Filter(x => x.DuplicateDetectHash == hashData)
                                       .Expand(x => x.SSG_Addresses)
                                       .Expand(x => x.SSG_Identifiers)
                                       .Expand(x => x.SSG_Aliases)
                                       .Expand(x => x.SSG_Asset_BankingInformations)
                                       .Expand(x => x.SSG_Asset_ICBCClaims)
                                       .Expand(x => x.SSG_Asset_Others)
                                       .Expand(x => x.SSG_Asset_Vehicles)
                                       .Expand(x => x.SSG_Asset_WorkSafeBcClaims)
                                       .Expand(x => x.SSG_Employments)
                                       .Expand(x => x.SSG_Identities)
                                       .Expand(x => x.SSG_PhoneNumbers)
                                       .Expand(x => x.SSG_SafetyConcernDetails)
                                       .Expand(x => x.SSG_Emails)
                                       .Expand(x => x.SearchRequest)
                                       .FindEntryAsync(CancellationToken.None);

                existedPerson.IsDuplicated = true;
                return(existedPerson);
            }
        }
Exemplo n.º 2
0
        public async Task <SSG_Person> SavePerson(PersonEntity person, CancellationToken cancellationToken)
        {
            person.DuplicateDetectHash = await _duplicateDetectService.GetDuplicateDetectHashData(person);

            string hashData = person.DuplicateDetectHash;
            var    p        = await this._oDataClient.For <SSG_Person>()
                              .Filter(x => x.DuplicateDetectHash == hashData)
                              .FindEntryAsync(cancellationToken);

            if (p == null)
            {
                return(await this._oDataClient.For <SSG_Person>().Set(person).InsertEntryAsync(cancellationToken));
            }
            else
            {
                var duplicatedPerson = await _oDataClient.For <SSG_Person>()
                                       .Key(p.PersonId)
                                       .Expand(x => x.SSG_Addresses)
                                       .Expand(x => x.SSG_Identifiers)
                                       .Expand(x => x.SSG_Aliases)
                                       .Expand(x => x.SSG_Asset_BankingInformations)
                                       .Expand(x => x.SSG_Asset_ICBCClaims)
                                       .Expand(x => x.SSG_Asset_Others)
                                       .Expand(x => x.SSG_Asset_Vehicles)
                                       .Expand(x => x.SSG_Asset_WorkSafeBcClaims)
                                       .Expand(x => x.SSG_Employments)
                                       .Expand(x => x.SSG_Identities)
                                       .Expand(x => x.SSG_PhoneNumbers)
                                       .Expand(x => x.SSG_SafetyConcernDetails)
                                       .Expand(x => x.SearchRequest)
                                       .FindEntryAsync(cancellationToken);

                duplicatedPerson.IsDuplicated = true;
                return(duplicatedPerson);
            }
        }