Esempio n. 1
0
        public async Task <NewConsumerDto> Create(NewConsumerDto newConsumerDto)
        {
            if (newConsumerDto == null)
            {
                throw new ArgumentNullException(nameof(newConsumerDto));
            }

            var password = newConsumerDto.Password;

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("Password is required");
            }

            if (_repository.FindByEmail(newConsumerDto.Email).Result != null)
            {
                throw new Exception("Email \"" + newConsumerDto.Email + "\" is already taken");
            }

            var newConsumer = _mapper.Map <Consumer>(newConsumerDto);

            await _repository.Create(newConsumer);

            await _userService.Create(newConsumer, newConsumerDto);

            var consumerDto = _mapper.Map <NewConsumerDto>(newConsumer);

            return(consumerDto);
        }
Esempio n. 2
0
 public bool Create(Consumer entity)
 {
     return(_consumerRepository.Create(entity));
 }