public async Task <ICustomerDto> AddCustomerAsync(ICustomerDto customerDto) { if (customerDto == null) { throw new ArgumentNullException(nameof(customerDto)); } if (customerDto.Id > 0) { throw new ArgumentException("Customer has already an id.", nameof(customerDto)); } var customerPoco = this.mapper.Map <CustomerPoco>(customerDto); var savedCustomerPoco = await this.customerDataAccess.InsertCustomerAsync(customerPoco); this.logger.LogInformation(LoggingEvents.InsertItem, $"{nameof(this.AddCustomerAsync)}: successful [Id: {savedCustomerPoco.Id}]"); var savedCustomerDto = this.mapper.Map <CustomerDto>(savedCustomerPoco); return(savedCustomerDto); }
public async Task <ICustomerDto> ModifyCustomerAsync(ICustomerDto customerDto) { if (customerDto == null) { throw new ArgumentNullException(nameof(customerDto)); } var customerPoco = this.mapper.Map <CustomerPoco>(customerDto); if (!await this.customerDataAccess.ExistsCustomerAsync(customerPoco.Id)) { throw new ArgumentException("Customer doesn't exist.", nameof(customerDto)); } var savedCustomerPoco = await this.customerDataAccess.UpdateCustomerAsync(customerPoco); this.logger.LogInformation(LoggingEvents.UpdateItem, $"{nameof(this.ModifyCustomerAsync)}: successful [Id: {savedCustomerPoco.Id}]"); var savedCustomerDto = this.mapper.Map <CustomerDto>(savedCustomerPoco); return(savedCustomerDto); }
public async Task <bool> DeleteCustomerAsync(ICustomerDto customerDto) { if (customerDto == null) { throw new ArgumentNullException(nameof(customerDto)); } var customerPoco = this.mapper.Map <CustomerPoco>(customerDto); if (!await this.customerDataAccess.ExistsCustomerAsync(customerPoco.Id)) { return(false); } // TODO: Remove products var successful = await this.customerDataAccess.RemoveCustomerAsync(customerPoco.Id); if (successful) { this.logger.LogInformation(LoggingEvents.DeleteItem, $"{nameof(this.DeleteCustomerAsync)}: successful [Id: {customerPoco.Id}]"); } return(successful); }
public CustomerResponse(ICustomerDto customerDto) { Uid = customerDto.Uid; Name = customerDto.Name; }