Пример #1
0
        public async Task <CommandResponse> Handler(CreateUserRequest command)
        {
            var user = _mapper.Map <CreateUserRequest, User>(command);

            if (!user.IsValid())
            {
                _notificationContext.AddNotifications(user.Validation);
                return(BadRequest(null, Messages.INVALID_FIELDS));
            }

            if (await _userRepository.CheckAlreadyExist(user.Email))
            {
                _notificationContext.AddNotification("Email", Messages.EMAIL_ALREADY_EXISTS);
                return(BadRequest(null, Messages.INVALID_FIELDS));
            }

            return(Created(await _userRepository.Add(user), Messages.CREATED_SUCCESS));
        }