Esempio n. 1
0
        public UserViewModel()
        {
            this.user = new User("bob", "123");
            LoginCommand = new LoginUserCommand(this);
            NewUserCommand = new CreateUserCommand(new UserCreationViewModel());

        }
        public async Task<IHttpActionResult> PostUser(CreateUserCommand command)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = await _mediator.SendAsync(command);
            return CreatedAtRoute("DefaultApi", new { id = user.Id }, user);
        }
Esempio n. 3
0
 public async Task<IActionResult> Post([FromBody]UserCreationDto dto)
 {
     var cmd = new CreateUserCommand { UserName = dto.UserName, Password = dto.Password };
     var result = await _sagaBus.InvokeAsync<CreateUserCommand, UserCreationResult>(cmd);
     if (result.Succeed)
     {
         return Created(Url.Action(nameof(GetById), new { id = result.UserId }), null);
     }
     // currently, the only reason for failure is that a user of the same username exists.
     return StatusCode(412, result.Message);
 }
Esempio n. 4
0
 public async Task Creation_Fail_When_User_Exists()
 {
     var mockRepo = new Mock<IUserRepository>();
     var saga = new CreateUserSaga(mockRepo.Object);
     var userName = Guid.NewGuid().ToString();
     var password = Guid.NewGuid().ToString();
     mockRepo.Setup(r => r.FindByUserNameAsync(It.Is<string>(n => n == userName)))
         .Returns(Task.FromResult<User>(User.Create(Guid.NewGuid(), userName)));
     var command = new CreateUserCommand
     {
         UserName = userName,
         Password = password
     };
     var result = await saga.StartAsync(command);
     Assert.False(result.Succeed);
     Assert.True(saga.IsCompleted);
 }
Esempio n. 5
0
 public async Task Invoke_Test()
 {
     var mockRepo = new Mock<IUserRepository>();
     var saga = new CreateUserSaga(mockRepo.Object);
     var userName = Guid.NewGuid().ToString();
     var password = Guid.NewGuid().ToString();
     mockRepo.Setup(r => r.FindByUserNameAsync(It.Is<string>(n => n == userName)))
         .Returns(Task.FromResult<User>(null));
     var command = new CreateUserCommand
     {
         UserName = userName,
         Password = password
     };
     var result = await saga.StartAsync(command);
     mockRepo.Verify(repo => repo.AddAsync(It.Is<User>(u => u.UserName == userName && u.VaildatePassword(password))));
     Assert.True(result.Succeed);
     Assert.True(saga.IsCompleted);
 }
        public async Task <IActionResult> Post(CreateUserCommand data)
        {
            var result = await _mediatr.Send(data);

            return(Ok(result));
        }
        public async Task <ActionResult <string> > Register([FromForm] CreateUserCommand command)
        {
            var result = await Mediator.Send(command);

            return(RedirectToAction("Index", "Home", false));
        }
Esempio n. 8
0
 public UserViewService(IDbContext dbContext, IMapper mapper, UserRepository userRepository, CreateUserCommand createUserCommand)
 {
     this._dbContext         = dbContext;
     this._mapper            = mapper;
     this._userRepository    = userRepository;
     this._createUserCommand = createUserCommand;
 }
Esempio n. 9
0
 public Task<OperationResponse<int>> PostAsync(CreateUserCommand command)
 {
     return _userService.CreateUserAsync(command);
 }
Esempio n. 10
0
 public async void Post([FromBody] CreateUserRequestModel model)
 {
     var command = new CreateUserCommand(model.Email, model.Password);
     await _mediator.Send(command);
 }
Esempio n. 11
0
        public async Task <ActionResult <int> > CreateUser(CreateUserCommand createUserCommand)
        {
            var userId = await _mediator.Send(createUserCommand);

            return(CreatedAtAction(nameof(CreateUser), userId));
        }
Esempio n. 12
0
        public async Task <IActionResult> CreateUser(CreateUserCommand command)
        {
            var userId = await _mediator.Send(command);

            return(CreatedAtRoute("GetUserById", new { userId }, userId));
        }
Esempio n. 13
0
        public async Task <ActionResult> CreateUser([FromBody] CreateUserCommand command)
        {
            await busClient.PublishAsync(command);

            return(Accepted());
        }
Esempio n. 14
0
        public async Task <IActionResult> Post([FromBody] CreateUserCommand input)
        {
            await _mediator.Publish(input);

            return(Ok());
        }
Esempio n. 15
0
        public async Task <IActionResult> Create([FromBody] CreateUserCommand command)
        {
            var result = await Mediator.Send(command);

            return(Ok(result));
        }
Esempio n. 16
0
        public async Task <IActionResult> Post([FromBody] CreateUserCommand command)
        {
            var result = await CommandAsync(command);

            return(Ok(result));
        }
 partial void OnCreatedUser(IServiceRequestWithData <Cqrs.Authentication.ISingleSignOnToken, Entities.UserEntity> serviceRequest, CreateUserCommand command);
Esempio n. 18
0
        public async Task <IActionResult> Post([FromBody] CreateUserCommand command)
        {
            await CommandDispatcher.DispatchAsync(command);

            return(Ok());
        }
        public async Task <ActionResult <UserModel> > UserCreate([FromBody] CreateUserCommand model)
        {
            var response = new BaseResponseModel <UserModel>(await _mediator.Send(model));

            return(Created(string.Empty, CreateLinksForUser(response)));
        }
Esempio n. 20
0
 public async Task <User> Register(CreateUserCommand input)
 {
     return(await _mediator.Value.Send(input));
 }
Esempio n. 21
0
        public async Task <ActionResult <string> > Post([FromBody] CreateUserCommand command)
        {
            string result = await _Mediator.Send(command);

            return(Ok(result));
        }
Esempio n. 22
0
        public async Task <IActionResult> CreateUserAsync(CreateUserCommand command)
        {
            await _commandProcessor.SendAsync(command);

            return(Ok(SuccessCodes.UserCreated));
        }
 public async Task <ActionResult <string> > MyAccount([FromForm] CreateUserCommand command)
 {
     return(await Mediator.Send(command));
 }
Esempio n. 24
0
 public CreateCommandResult <string> Create([FromBody] CreateUserCommand command) => Execute <CreateUserCommand, CreateCommandResult <string> >(command ?? new CreateUserCommand());
Esempio n. 25
0
 public ICommandResult Post([FromBody] CreateUserCommand command)
 {
     return(_handler.Handle(command));
 }
Esempio n. 26
0
        public int CreateUser(CreateUserCommand command)
        {
            _userService.Create(command.Name, command.Surname, command.Email, command.Age, command.Nickname);

            return(1);
        }
Esempio n. 27
0
        public async Task <IActionResult> Post([FromBody] CreateUserCommand command)
        {
            var id = await _mediator.Send(command);

            return(CreatedAtAction(nameof(GetById), new { id }, command));
        }
Esempio n. 28
0
 public IHttpActionResult Post(CreateUserCommand command)
 {
     return(HandleCommand(command));
 }
Esempio n. 29
0
 internal void OnCreatUserCommandReceivedOnHandler(CreateUserCommand createUserCommand)
 {
     CreateUserCommandReceivedOnHandler = createUserCommand;
 }
Esempio n. 30
0
 public async Task <int> CreateAsync(CreateUserCommand command)
 {
     return(await Mediator.Send(command));
 }
        public async Task <IActionResult> Register([FromBody] CreateUserCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
Esempio n. 32
0
 public async Task <ActionResult <string> > Create(CreateUserCommand command)
 {
     return(await Mediator.Send(command));
 }
Esempio n. 33
0
        public void Send_ShouldCallRegisteredCommands()
        {
            bus = new InternalBus();
            bus.ResetRoutes();
            bus.RegisterCommandHandler<CreateUserCommand, CreateUserCommandHandler>();

            var command = new CreateUserCommand() {UserName = "******"};
            CreateUserCommandHandler.Called = false;
            bus.Send(command);
            Assert.IsTrue(CreateUserCommandHandler.Called);
        }
Esempio n. 34
0
        //  [Authorize]
        public int Post([FromBody] CreateUserCommand userCommand)
        {
            var userClaims = HttpContext.User.Claims;

            return(_commandBus.Dispatch <CreateUserCommand, CreateUserCommandResult>(userCommand).UserId);
        }
Esempio n. 35
0
        public async Task <ActionResult <string> > PostUserAsync([FromBody] CreateUserCommand request)
        {
            string userId = await Mediator.Send(request);

            return(Ok(userId));
        }
Esempio n. 36
0
        public async Task <IActionResult> CreateUser(CreateUserCommand request)
        {
            await _mediator.Send(request);

            return(Ok());
        }
 private static void CompareCreateUserCommand(CreateUserCommand c, CreateUserCommand dc)
 {
     Assert.AreEqual(c.Username, dc.Username);
     Assert.AreEqual(c.Password, dc.Password);
     Assert.AreEqual(c.Email, dc.Email);
     Assert.AreEqual(c.DisplayName, dc.DisplayName);
 }
Esempio n. 38
0
        public ActionResult Create(CreateUserCommand command)
        {
            _commandService.Execute(command);

            return(RedirectToAction("Index"));
        }