Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
 public CustomerResponse(ICustomerDto customerDto)
 {
     Uid  = customerDto.Uid;
     Name = customerDto.Name;
 }