Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <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));
        }
Ejemplo n.º 6
0
 public static DataPerson ToData(this BusinessPerson person, IMapper mapper)
 {
     return(mapper.Map <DataPerson>(person));
 }