Example #1
0
        public async Task <IActionResult> Create([FromBody] CreateUserModel userModel,
                                                 [FromServices] IValidatorFactory validatorFactory,
                                                 [FromServices] ICreateUserCommand createUserCommand)
        {
            try
            {
                if (userModel == null)
                {
                    return(BadRequest(new Message("Something bad happened. Try again.")));
                }

                IValidator validator = validatorFactory.Create();
                string     accountId = await createUserCommand.Execute(userModel.AccountId, userModel, validator);

                if (validator.HasErrors)
                {
                    return(BadRequest(validator.Errors));
                }
                else
                {
                    return(Created("", accountId));
                }
            }
            catch (Exception ex)
            {
                //Log error
                _logger.LogError("UserController.Create", "Exception was thrown", new
                {
                    UserModel = userModel,
                    Exception = ex
                });

                return(BadRequest(new Message("Something bad happened. Try again")));
            }
        }
Example #2
0
        private void SetDomainValues(ICreateUserCommand command)
        {
            if (!string.IsNullOrEmpty(command.Name))
            {
                this.Name = command.Name;
            }

            //if (!string.IsNullOrEmpty(command.Email))
            //    this.Email = command.Email;

            if (!string.IsNullOrEmpty(command.Password))
            {
                this.PasswordHash = command.Password;
            }

            if (!string.IsNullOrEmpty(command.Country))
            {
                this.Country = command.Country;
            }

            if (!string.IsNullOrEmpty(command.Phone))
            {
                this.Phone = command.Phone;
            }

            if (command.Characters != null && command.Characters.Count() > 0)
            {
                this.Characters = command.Characters;
            }
        }
Example #3
0
        public UserModule(IUserRepository userRepo, ICreateUserCommand createUserCommand, IUpdateUserPasswordCommand updateUserPasswordCommand, IDeleteUserCommand deleteUserCommand) : base()
        {
            _userRepo                  = userRepo;
            _createUserCommand         = createUserCommand;
            _updateUserPasswordCommand = updateUserPasswordCommand;
            _deleteUserCommand         = deleteUserCommand;

            Get[Actions.User.Default] = (x) =>
            {
                AddScript(Scripts.UserView);
                return(Default());
            };
            Post[Actions.User.Delete] = (x) =>
            {
                this.RequiresClaims(new[] { Claims.UserDelete });
                return(DeleteUser());
            };
            Get[Actions.User.List] = (x) =>
            {
                this.RequiresClaims(new[] { Claims.UserList });
                return(List());
            };
            Post[Actions.User.ChangePassword] = (x) =>
            {
                return(ChangePassword());
            };
            Post[Actions.User.Save] = (x) =>
            {
                this.RequiresClaims(new[] { Claims.UserAdd });
                return(Save());
            };
        }
Example #4
0
 public UserController(IGetUsersCommand getCommand, IGetUserCommand getOneCommand, ICreateUserCommand createUserCommand, IEditUserCommand editUserCommand, IDeleteUserCommand deleteUserCommand)
 {
     _getCommand        = getCommand;
     _getOneCommand     = getOneCommand;
     _createUserCommand = createUserCommand;
     _editUserCommand   = editUserCommand;
     _deleteUserCommand = deleteUserCommand;
 }
 public UsersController(ICreateUserCommand userCreate, IEditUserCommand userEdit, IGetUserCommand userGet, IGetUsersPaginatedCommand usersGet, IDeleteUserCommand deleteUser)
 {
     _userCreate = userCreate;
     _userEdit   = userEdit;
     _userGet    = userGet;
     _usersGet   = usersGet;
     _deleteUser = deleteUser;
 }
Example #6
0
 public UsersController(ICreateUserCommand createUser, IGetUsersCommand getUsers, IEditUserCommand editUser, IDeleteUserCommand deleteUser, Context baza)
 {
     this.createUser = createUser;
     this.getUsers   = getUsers;
     this.editUser   = editUser;
     this.deleteUser = deleteUser;
     this.baza       = baza;
 }
Example #7
0
 public UserController(IGetOneUserCommand getOneUser, ICreateUserCommand createUser, IGetUserCommand getUser, IDeleteUserCommand deleteUser, IUpdateUserCommand updateUser)
 {
     _getOneUser = getOneUser;
     _createUser = createUser;
     _getUser    = getUser;
     _deleteUser = deleteUser;
     _updateUser = updateUser;
 }
Example #8
0
 public UsersController(IGetUserCommand getUser, IGetUsersCommand getUsers, ICreateUserCommand createUser, IEditUserCommand editUser, IDeleteUserCommand deleteUser)
 {
     _getUser    = getUser;
     _getUsers   = getUsers;
     _createUser = createUser;
     _editUser   = editUser;
     _deleteUser = deleteUser;
 }
        public void CreateUserCommandTest_SetUp()
        {
            _dbContext        = Substitute.For <IDbContext>();
            _userValidator    = Substitute.For <IUserValidator>();
            _passwordProvider = Substitute.For <IPasswordProvider>();

            _createUserCommand = new CreateUserCommand(_dbContext, _userValidator, _passwordProvider);
        }
Example #10
0
 public UsersController(IGetUsersCommand searchUsersCommand, IGetUserCommand getOneUserCommand, ICreateUserCommand createUserCommand, IEditUserCommand editUserCommand, IDeleteUserCommand deleteUserCommand, WebNewsContext context)
 {
     _searchUsersCommand = searchUsersCommand;
     _getOneUserCommand  = getOneUserCommand;
     _createUserCommand  = createUserCommand;
     _editUserCommand    = editUserCommand;
     _deleteUserCommand  = deleteUserCommand;
     _context            = context;
 }
 public UsersController(
     IOptions <AppSettings> appSettings,
     ICreateUserCommand createUserCommand,
     IAuthenticateUserQuery authenticateUserQuery)
 {
     _appSettings           = appSettings.Value;
     _createUserCommand     = createUserCommand;
     _authenticateUserQuery = authenticateUserQuery;
 }
Example #12
0
 public UsersController(ICreateUserCommand createUser, IActivateUserCommand activateUser, IGetUsersCommand getUsers, IDeleteUserCommand deleteUser, IEditUserEmailCommand editUserEmail, IEditUserPasswordCommand editUserPassword, IAuthenticateUserCommand authUser)
 {
     _createUser       = createUser;
     _activateUser     = activateUser;
     _getUsers         = getUsers;
     _deleteUser       = deleteUser;
     _editUserEmail    = editUserEmail;
     _editUserPassword = editUserPassword;
     _authUser         = authUser;
 }
 public CreateUserApplicationKernalService(
     ITransactionManager transactionManager,
     ICommandRepository <User> commandRepository,
     IQueryRepository <Identity> queryRepository,
     ICreateUserCommand createUserCommand)
 {
     _transactionManager = transactionManager;
     _commandRepository  = commandRepository;
     _queryRepository    = queryRepository;
     _createUserCommand  = createUserCommand;
 }
 public IActionResult Register([FromBody] CreateUserModel user, [FromServices] ICreateUserCommand createUserCommand)
 {
     if (ModelState.IsValid)
     {
         var storedUser = createUserCommand.Execute(user);
         return(Created(Request.Path.Value + "/" + storedUser.Id, storedUser));
     }
     else
     {
         return(BadRequest("User data error"));
     }
 }
 public IActionResult Post([FromBody] AddUser dto, [FromServices] ICreateUserCommand command)
 {
     try
     {
         executor.ExecuteCommand(command, dto);
         return(StatusCode(202, "User added"));
     }
     catch (EntityAllreadyExists)
     {
         return(StatusCode(422, "Fail"));
     }
 }
Example #16
0
 public AccountUseCase(
     Lazy <IDbTransactionManager> dbTransationManagerLazy,
     IMapper mapper,
     ICreateUserCommand createUserCommand,
     ICreateTokenCommand createTokenCommand,
     IUserQuery userQuery)
 {
     this.dbTransationManagerLazy = dbTransationManagerLazy;
     this.mapper             = mapper;
     this.createUserCommand  = createUserCommand;
     this.createTokenCommand = createTokenCommand;
     this.userQuery          = userQuery;
 }
Example #17
0
        public void UserModuleTest_SetUp()
        {
            _userRepo                  = Substitute.For <IUserRepository>();
            _userValidator             = Substitute.For <IUserValidator>();
            _passwordProvider          = Substitute.For <IPasswordProvider>();
            _createUserCommand         = Substitute.For <ICreateUserCommand>();
            _updateUserPasswordCommand = Substitute.For <IUpdateUserPasswordCommand>();
            _deleteUserCommand         = Substitute.For <IDeleteUserCommand>();

            Mapper.Initialize((cfg) =>
            {
                cfg.CreateMap <UserViewModel, UserModel>();
            });
        }
Example #18
0
 public UserService(IDeleteUserCommand deleteUserCommand,
                    IUpdateUserCommand updateUserCommand,
                    ICreateUserCommand createUserCommand,
                    IGetUserByIdQuery getUserByIdQuery,
                    IGetAllNonDeletedUsersQuery getAllNonDeletedUsersQuery,
                    IGetUserByUsernameQuery getUserByUsernameQuery, 
                    IGetUserByEmailQuery getUserByEmailQuery)
 {
     _deleteUserCommand = deleteUserCommand;
     _updateUserCommand = updateUserCommand;
     _createUserCommand = createUserCommand;
     _getUserByIdQuery = getUserByIdQuery;
     _getAllNonDeletedUsersQuery = getAllNonDeletedUsersQuery;
     _getUserByUsernameQuery = getUserByUsernameQuery;
     _getUserByEmailQuery = getUserByEmailQuery;
 }
 public UsersController(
     ILogger <UsersController> logger,
     ICreateUserCommand createUserCommand,
     IUpdateUserCommand updateUserCommand,
     IDeleteUserCommand deleteUserCommand,
     IGetUserQuery getUserQuery,
     IGetAllUsersQuery getAllUsersQuery
     )
 {
     this.logger            = logger;
     this.createUserCommand = createUserCommand;
     this.updateUserCommand = updateUserCommand;
     this.deleteUserCommand = deleteUserCommand;
     this.getUserQuery      = getUserQuery;
     this.getAllUsersQuery  = getAllUsersQuery;
 }
Example #20
0
        public async Task <IActionResult> Register(CreateUserRequest user, [FromServices] ICreateUserCommand command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                UserResponse response = await command.ExecuteAsync(user);

                return(CreatedAtRoute("GetSingleUser", new { userId = response.Id }, response));
            }
            catch (CannotCreateUserExeption exception)
            {
                foreach (var error in exception.Errors)
                {
                    ModelState.AddModelError(exception.Message, error.Description);
                }
                return(BadRequest(ModelState));
            }
        }
 public UserController(ICreateUserCommand createUserCommand, IUserExistsQuery userExistsQuery)
 {
     _createUserCommand = createUserCommand;
     _userExistsQuery   = userExistsQuery;
 }
Example #22
0
 public CreateUser(ICreateUserCommand createUserCommand)
 {
     _createUserCommand = createUserCommand;
 }
 public void UserServiceTest_SetUp()
 {
     _userRepo          = Substitute.For <IUserRepository>();
     _createUserCommand = Substitute.For <ICreateUserCommand>();
     _userService       = new UserService(_userRepo, _createUserCommand);
 }
Example #24
0
 public IActionResult Post([FromBody] UserCreateDto dto, [FromServices] ICreateUserCommand command)
 {
     _executor.ExecuteCommand(command, dto);
     return(Ok("uneto"));
 }
        public void Setup()
        {
            _fixture = new Fixture();
            _fixture.Customize(new AutoNSubstituteCustomization());

            _userByEmailQuery = _fixture.Freeze<IUserByEmailQuery>();
            _createUserCommand = _fixture.Freeze<ICreateUserCommand>();
        }
Example #26
0
 public void Post([FromBody] UserDto dto,
                  [FromServices] ICreateUserCommand command)
 {
     _executor.ExecuteCommand(command, dto);
 }
Example #27
0
 public void Create(ICreateUserCommand command, IEnumerable <Role> roles)
 {
     this.SetDomainValues(command);
     this.AddRoles(roles);
 }
Example #28
0
 public IActionResult Post([FromBody] UserDto dto, [FromServices] ICreateUserCommand command)
 {
     executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status201Created));
 }
Example #29
0
 public IActionResult Post([FromBody] UserDto dto,
                           [FromServices] ICreateUserCommand createUserCommand)
 {
     _dispatcher.DispatchCommand(createUserCommand, dto);
     return(StatusCode(StatusCodes.Status201Created));
 }
Example #30
0
 public ActionResult Post([FromBody] UserDto dto,
                          [FromServices] ICreateUserCommand command)
 {
     executor.ExecuteCommand(command, dto);
     return(NoContent());
 }
 public void Setup()
 {
     _userByEmailQuery = Substitute.For<IUserByEmailQuery>();
     _createUserCommand = Substitute.For<ICreateUserCommand>();
     _deleteUserCommand = Substitute.For<IDeleteUserCommand>();
 }
Example #32
0
 public UserService(IUserRepository userRepo, ICreateUserCommand createUserCommand)
 {
     _userRepo          = userRepo;
     _createUserCommand = createUserCommand;
 }
 public RegistrationCompletedHandler(ICreateUserCommand createUserCommand)
 {
     this.createUserCommand = createUserCommand;
 }