public async Task <GenericResult <PersonDto> > AddPerson(PersonDto personDto) { try { if (personDto.FKPopulationInformationID.HasValue) { var isPopulationExists = (await _populationService.IsPopulationExists(personDto.FKPopulationInformationID.Value)); if (!isPopulationExists.IsSucceed) { return(GenericResult <PersonDto> .UserSafeError("An error occurred when requesting population.Errors: " + isPopulationExists.GetAllMessage())); } else if (!isPopulationExists.Data) { return(GenericResult <PersonDto> .UserSafeError("There is no population info with given id")); } } var newPerson = await _personRepo.InsertAsync(_mapper.Map <Person>(personDto)); return(GenericResult <PersonDto> .Success(_mapper.Map <PersonDto>(newPerson))); } catch (Exception e) { return(GenericResult <PersonDto> .Error(e)); } }
public async Task <GenericResult <bool> > Exists(int id) { var result = await _populationService.IsPopulationExists(id); return(result.GetUserSafeResult()); }