Beispiel #1
0
        public async Task <OperationResult> UpdateAsync(Guid id, Customer customer)
        {
            var customerToUpdate = await _customersRepository.FindAsync(id);

            customerToUpdate.Update(customer);

            var validationResult = _validator.Validate(customerToUpdate);

            if (!validationResult.IsValid)
            {
                var errors = validationResult.Errors.Select(e => e.ErrorMessage).ToList();
                return(new OperationResult(false, customer, errors));
            }

            await _customersRepository.UpdateAsync(customerToUpdate);

            await _unitOfWork.CommitAsync();

            return(new OperationResult(true, customerToUpdate, null));
        }