/// <inheritdoc/> public async Task <BusinessPerson> UpdateAsync(BusinessPerson person) { if (person == null) { throw new ArgumentNullOrEmptyException(nameof(person), ExceptionResources.ArgumentNullOrEmptyException_RequiredPersonData); } DataPerson foundPerson = await this.FindWithGuardsAsync(person.Identifier).ConfigureAwait(false); if (foundPerson == null) { return(null); } DataPerson editedDataPerson = this._mapper.Map(person, foundPerson); DataPerson updatedDataPerson = await this._personRepository.UpdateAsync(editedDataPerson).ConfigureAwait(false); if (updatedDataPerson == null) { throw new FailedActionException(ExceptionResources.FailedActionException_EditActionName, ExceptionResources.FailedActionException_EditPersonExceptionMessage); } BusinessPerson updatedPerson = updatedDataPerson.ToBusiness(this._mapper); return(updatedPerson); }
/// <inheritdoc/> public async Task <PersonViewModel> ReadAsync(Guid identifier) { if (identifier == Guid.Empty) { return(null); } BusinessPerson foundPerson = await this._personManager.ReadAsync(identifier).ConfigureAwait(false); return(foundPerson.ToviewModel(this._mapper)); }
/// <inheritdoc/> public async Task <PersonViewModel> DeteleAsync(Guid identifier) { if (identifier == Guid.Empty) { return(null); } BusinessPerson deletedBusinessPerson = await this._personManager.DeteleAsync(identifier).ConfigureAwait(false); PersonViewModel deletedPersonModel = deletedBusinessPerson.ToviewModel(this._mapper); return(deletedPersonModel); }
private async Task <PersonViewModel> EditPersonWithGuardsAsync(PersonViewModel personModel, Func <BusinessPerson, Task <BusinessPerson> > editionFunctionAsync) { if (personModel == null) { return(null); } BusinessPerson personToEdit = personModel.ToBusiness(this._mapper); BusinessPerson editedBusinessPerson = await editionFunctionAsync(personToEdit).ConfigureAwait(false); PersonViewModel editedPersonModel = editedBusinessPerson.ToviewModel(this._mapper); return(editedPersonModel); }
/// <inheritdoc/> public async Task <BusinessPerson> CreateAsync(BusinessPerson person) { if (person == null) { throw new ArgumentNullOrEmptyException(nameof(person), ExceptionResources.ArgumentNullOrEmptyException_RequiredPersonData); } DataPerson newPerson = person.ToData(this._mapper); newPerson.Identifier = Guid.NewGuid(); DataPerson editedDataPerson = await this._personRepository.CreateAsync(newPerson).ConfigureAwait(false); if (editedDataPerson == null) { throw new FailedActionException(ExceptionResources.FailedActionException_EditActionName, ExceptionResources.FailedActionException_EditPersonExceptionMessage); } return(editedDataPerson.ToBusiness(this._mapper)); }
public static DataPerson ToData(this BusinessPerson person, IMapper mapper) { return(mapper.Map <DataPerson>(person)); }