Example #1
0
        public async Task <PersonDTO> CreatePerson(PersonDTO personModel)
        {
            Person person = PersonMapper.ConvertModelToEntity(personModel);

            if (await _personRepo.CreatePerson(person))
            {
                return(PersonMapper.ConvertEntityToModel(person));
            }

            return(null);
        }
Example #2
0
        public async Task <PersonDTO> GetPerson(int personId)
        {
            var person = await _personRepo.GetPersonById(personId);


            if (person != null)
            {
                return(PersonMapper.ConvertEntityToModel(person));
            }

            return(null);
        }
Example #3
0
        public async Task <PersonDTO> PartialUpdatePerson(int personId, JsonPatchDocument <PersonDTO> patchDoc)
        {
            var person = await _personRepo.GetPersonById(personId);

            if (person == null)
            {
                return(null);
            }

            PersonDTO updatedPerson = PersonMapper.ConvertEntityToModel(person);

            patchDoc.ApplyTo(updatedPerson);

            person = PersonMapper.UpdateEntityFromModel(person, updatedPerson);

            if (person != null && await _personRepo.UpdatePerson(person))
            {
                return(PersonMapper.ConvertEntityToModel(person));
            }

            return(null);
        }
Example #4
0
        public async Task <PersonDTO> UpdatePerson(int personId, PersonDTO personModel)
        {
            var person = await _personRepo.GetPersonById(personId);

            //upsert
            if (person == null)
            {
                person = new Person()
                {
                    Id = personId
                };
            }

            person = PersonMapper.UpdateEntityFromModel(person, personModel);

            if (person != null && await _personRepo.UpdatePerson(person))
            {
                return(PersonMapper.ConvertEntityToModel(person));
            }

            return(null);
        }