Example #1
0
        public void UpdateRelationShips(string relationshipTypeId, Guid clientId, Guid otherClientId)
        {
            var exisitngRelationship = _clientRelationshipRepository.Find(relationshipTypeId, clientId, otherClientId);

            if (null == exisitngRelationship)
            {
                var newRelation = ClientRelationship.Create(relationshipTypeId, otherClientId, true, clientId, false);
                _clientRelationshipRepository.Save(newRelation);
                var state = RelationshipType.IsPartner(relationshipTypeId)
                    ? LiveState.HtsPatlisted
                    : LiveState.HtsFamlisted;
                _clientStateRepository.SaveOrUpdate(new ClientState(clientId, state));
            }

            var exisitngRelationshipReverse = _clientRelationshipRepository.Find(relationshipTypeId, otherClientId, clientId);

            if (null == exisitngRelationshipReverse)
            {
                //otherClientId  clientId
                var newRelationReverse = ClientRelationship.Create(relationshipTypeId, clientId, true, otherClientId, true);
                _clientRelationshipRepository.Save(newRelationReverse);
                var state = RelationshipType.IsPartner(relationshipTypeId)
                    ? LiveState.PartnerListed
                    : LiveState.FamilyListed;
                _clientStateRepository.SaveOrUpdate(new ClientState(otherClientId, state, clientId));
            }
        }
Example #2
0
        public void SmartSync(ClientInfo client)
        {
            // IDS
            var clientIdentifiers = ClientIdentifier.Create(client.Identifiers);

            client.Identifiers = new List <IdentifierInfo>();

            // RELATIONSHIPS
            var clientRelationships = ClientRelationship.Create(client.Relationships);

            client.Relationships = new List <RelationshipInfo>();

            //STATES
            var states = client.ClientStates;

            client.ClientStates = new List <ClientStateInfo>();

            // PERSON
            var personInfo     = client.Person;
            var exisitngPerson = _personRepository.GetDemographics(personInfo.Id);

            try
            {
                if (null == exisitngPerson)
                {
                    var person = Person.CreateClient(personInfo);
                    _personRepository.Insert(person);
                    _personRepository.Save();

                    //client
                    var cient = Client.Create(client, client.PracticeId.Value, person.Id);


                    _clientRepository.Insert(cient);
                    _clientRepository.Save();
                }
                else
                {
                    exisitngPerson.UpdateClient(personInfo);
                    _personRepository.Update(exisitngPerson);
                    _personRepository.Save();

                    var existingClient = _clientRepository.GetClient(client.Id, false);

                    if (null != existingClient)
                    {
                        existingClient.Update(client);
                        _clientRepository.Update(existingClient);
                        _clientRepository.Save();
                    }
                    else
                    {
                        var cient = Client.Create(client, client.PracticeId.Value, exisitngPerson.Id);

                        _clientRepository.Insert(cient);
                        _clientRepository.Save();
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error saving Client");
                Preserve(client);
                return;
            }


            //STATES
            var allstates = Mapper.Map <List <ClientState> >(states);

            _clientRepository.UpdateClientState(client.Id, allstates);

            //IDS
            if (clientIdentifiers.Any())
            {
                _clientRepository.UpdateIds(clientIdentifiers);
                // _clientRepository.Save();
            }

            // RELATIONSHIPS
            if (clientRelationships.Any())
            {
                _clientRepository.UpdateTempRelations(clientRelationships);
                _clientRepository.UpdateRelationships();
            }
        }