public async Task <ActionResult> Create(ClientCreateModel model)
        {
            if (ModelState.IsValid)
            {
                CreateClientCommand createClientCommand = model.ToCreateClientCommand();
                createClientCommand.CreatedBy = User.Identity.Name;
                createClientCommand.CreatedOn = DateTime.Now;

                int result = await Mediator.Send(createClientCommand);

                if (result > 0)
                {
                    return(View("List"));
                }
                else
                {
                    ModelState.AddModelError("", "Thêm Client thất bại");
                }
            }

            model.AvailableClaims = await GetClaims();

            model.AvailableScopes = await GetScopes();

            model.InitData();

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ICommandResult> Post([FromBody] PostClientDto clientDto)
        {
            CreateClientCommand cmd = clientDto;
            var commandResult       = await _commandBus.Submit(cmd);

            return(commandResult);
        }
Exemplo n.º 3
0
        public void Create_Client_With_All_Required_Information()
        {
            const string name         = "test";
            var          initialCount = Session.QueryOver <Client>().Where(c => c.Name == name).RowCount();

            double latitude  = 3.2342;
            double longitude = 23.4545;

            var createCommand = new CreateClientCommand(name, "*****@*****.**", "123456", "brag", latitude, longitude, 1);

            ExecuteCommand(createCommand);

            var client = Session.QueryOver <Client>().Fetch(c => c.ClientSettings).Eager
                         .Where(c => c.Name == name).SingleOrDefault();

            Assert.NotNull(client);
            Assert.AreEqual(name, client.Name);
            Assert.AreEqual(0, initialCount);

            Assert.AreEqual(latitude, client.Location.Y);
            Assert.AreEqual(longitude, client.Location.X);

            Assert.NotNull(client.ClientSettings);
            Assert.AreEqual(0, client.ClientSettings.AdCount);
        }
Exemplo n.º 4
0
        public async Task ShouldCreate_A_Client()
        {
            string name     = "Vader";
            Guid   clientId = Guid.NewGuid();

            var request = new CreateClientCommand {
                Name = name
            };
            var expected = new CreateClientResponse {
                Name = name, Id = clientId
            };

            var mapper         = PetShopMappingConfiguration.GetPetShopMappings();
            var mockRepository = new Mock <IClientRepository>();

            mockRepository.Setup(p => p.Add(It.Is <Client>(c => c.Name == name)))
            .Returns((Client client) => Task.Run(() =>
            {
                client.Id = clientId;
            }));

            var handler = new CreateClientCommandHandler(mapper, mockRepository.Object);

            var result = await handler.Handle(request, CancellationToken.None);

            result.Data.Should().BeEquivalentTo(expected);
            result.Message.Should().BeEquivalentTo("Client Created");
            mockRepository.Verify(m => m.Add(It.IsAny <Client>()), Times.Once());
        }
Exemplo n.º 5
0
        void PupulateEntities(out int clientId, out int serviceId)
        {
            var createCategory = new AddCategoryCommand(null, "test");

            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);

            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver <Category>().FutureValue();
            var client   = Session.QueryOver <Client>().FutureValue();

            var categoryId = category.Value.Id;

            clientId = client.Value.Id;

            var createServiceCommand = new CreateServiceCommand(true, "title", "body", categoryId, clientId, 23.234, 5.343, null, null, null);

            ExecuteCommand(createServiceCommand);

            var service = Session.QueryOver <Service>().SingleOrDefault();

            serviceId = service.Id;
        }
        public async Task <GenericCommandResult <ClientEntity> > Create([FromServices] IClientHandler handler,
                                                                        [FromBody] CreateClientCommand command)
        {
            var result = (GenericCommandResult <ClientEntity>) await handler.HandleAsync(command);

            return(result);
        }
        public ActionResult <ClientModel> Post([FromBody] CreateClientModel createClientModel)
        {
            var command = new CreateClientCommand()
            {
                FirstName     = createClientModel.FirstName,
                LastName      = createClientModel.LastName,
                StreetAddress = createClientModel.StreetAddress,
                City          = createClientModel.City,
                StateCode     = createClientModel.StateCode,
                ZipCode       = createClientModel.ZipCode,
                DateOfBirth   = createClientModel.DateOfBirth,
                EmailAddress  = createClientModel.EmailAddress,
                Phone         = createClientModel.Phone
            };

            var result = _clientService.CreateClient(command);

            if (result.IsSuccess)
            {
                var model = _mapper.Map <Client, ClientModel>(result.Value);
                return(CreatedAtRoute("GetClientById", new { clientId = model.ClientId }, model));
            }
            else
            {
                return(MapErrorResult <Client, ClientModel>(result));
            }
        }
Exemplo n.º 8
0
        public void Create(CreateClientCommand model)
        {
            MySqlCommand command = _context.CreateCommand();

            command.CommandText = GetCreateClientCommandText();
            CreateClientPopulateParameters(model, command);
            command.ExecuteNonQuery();
        }
Exemplo n.º 9
0
        public void Teste()
        {
            var command = new CreateClientCommand();

            command.FirstName = "";
            command.Validate();

            Assert.AreEqual(false, command.Valid);
        }
Exemplo n.º 10
0
        public void ShouldReturnComnandExist()
        {
            var command = new CreateClientCommand("", "Pereira", "84028092788", "RJ", "*****@*****.**");

            //command.FirstName = "";
            command.Validate();
            Assert.True(command.Valid);
            // Assert.Equals(true, command.Valid);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create([FromBody] ClientRequest clientRequest)
        {
            var clientViewModel = mapper.Map <ClientViewModel>(clientRequest);

            var command = new CreateClientCommand(clientViewModel);
            var result  = await mediator.Send(command);

            return(CreatedAtAction("CreateClient", result));
        }
        public CreateClientHandlerTests()
        {
            _repository = Substitute.For<IClientRepository>();
            _handler = new ClientHandler(_repository);

            _commandWithoutName = _fixture
                                    .Build<CreateClientCommand>()
                                    .Without(x => x.Name)
                                    .Create();
        }
Exemplo n.º 13
0
        public async Task <CommandExecutionResult> HandleAsync(CreateClientCommand command)
        {
            command.ClientId = Guid.NewGuid();

            var clientEntity = command.Adapt <ClientEntity>();

            await _repository.InsertAsync(clientEntity);

            return(CommandExecutionResult.Success);
        }
Exemplo n.º 14
0
 public async Task<IActionResult> Post([FromBody] ClientCreationDto dto)
 {
     var cmd = new CreateClientCommand { DisplayName = dto.DisplayName, RedirectUri = dto.RedirectUri };
     var result = await _sagaBus.InvokeAsync<CreateClientCommand, ClientCreationResult>(cmd);
     if (result.Succeed)
     {
         return Created(Url.Action(nameof(GetById), new { id = result.Id }), null);
     }
     return StatusCode(412, result.Message);
 }
Exemplo n.º 15
0
        public void Shoud_have_error_when_name_is_empty()
        {
            var validator = new CreateClientCommandValidator();

            var model = new CreateClientCommand {
                Name = string.Empty
            };

            validator.Validate(model).IsValid.Should().BeFalse();
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Post([FromBody] CreateClientCommand command)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var response = await this._mediator.Send(command);

            return(this.Created(Url.RouteUrl("GetClientById", new { id = response.Id }), new { }));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Post(int id, [FromBody] CreateClientDto client, CancellationToken cancellationToken)
        {
            var command = new CreateClientCommand {
                Client = client, ServerId = id
            };
            var clientId = await Mediator.Send(command, cancellationToken);

            return(new JsonResult(new { id = clientId })
            {
                StatusCode = 201
            });
        }
Exemplo n.º 18
0
        public void LoginUser_With_Correct_Password_And_Unverified()
        {
            const string email = "*****@*****.**";

            var createCommand = new CreateClientCommand("test", email, "123456", "brag", 3.2342, 23.4545, 1);
            ExecuteCommand(createCommand);

            var loginUserCommand = new LoginUserCommand(email, "123456");
            ExecuteCommand(loginUserCommand);

            Assert.IsNull(loginUserCommand.Result);
        }
Exemplo n.º 19
0
        public void Change_Password_With_Incorrect_Existing_Password()
        {
            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);
            ExecuteCommand(createClientCommand);

            var client = Session.QueryOver<Client>().FutureValue();

            var changePasswordCommand = new ChangePasswordCommand(client.Value.Id, "987654", "456789");
            ExecuteCommand(changePasswordCommand);

            Assert.IsFalse(changePasswordCommand.Result);
        }
Exemplo n.º 20
0
 public IActionResult RegisterClient([FromBody] CreateClientCommand createClientCommand)
 {
     try
     {
         var client = _clientAggregateFactory.Create(createClientCommand);
         _clientsWriteRepository.Save(client);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Exemplo n.º 21
0
        public async Task <IActionResult> Add(CreateClientQuery query, CreateClientCommand command)
        {
            if (ModelState.IsValid == false)
            {
                var vm = BuildAddForm(command.Adapt <ClientEntity>());

                return(View("FormView", vm));
            }

            await _clientService.HandleAsync(command);

            return(Redirect(Url.AppUri(nameof(Edit), nameof(ClientController), new UpdateClientQuery(command.ClientId))));
        }
        public void Handle(CreateClientCommand command)
        {
            Client client = _clientRepository.GetEntity(command.ClientId);

            if (client != null)
            {
                throw new InvalidOperationException($"Client already exists with this Id {command.ClientId}");
            }

            client = Client.Create(command.ClientId, command.FirstName, command.LastName, command.adresse);

            _clientRepository.SaveAggregateEvents(client);
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Post([FromBody] ClientCreationDto dto)
        {
            var cmd = new CreateClientCommand {
                DisplayName = dto.DisplayName, RedirectUri = dto.RedirectUri
            };
            var result = await _sagaBus.InvokeAsync <CreateClientCommand, ClientCreationResult>(cmd);

            if (result.Succeed)
            {
                var url = Url.Action(nameof(GetById), new { id = result.Id });
                return(Created(url, null));
            }
            return(StatusCode(412, result.Message));
        }
Exemplo n.º 24
0
        public void LoginUser_With_Correct_Password_And_Unverified()
        {
            const string email = "*****@*****.**";

            var createCommand = new CreateClientCommand("test", email, "123456", "brag", 3.2342, 23.4545, 1);

            ExecuteCommand(createCommand);

            var loginUserCommand = new LoginUserCommand(email, "123456");

            ExecuteCommand(loginUserCommand);

            Assert.IsNull(loginUserCommand.Result);
        }
Exemplo n.º 25
0
        public async Task <ICommandResult> HandleAsync(CreateClientCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult <ClientEntity>(false, command.Notifications));
            }

            var client = new ClientEntity(command.Name, command.BirthDate, command.TypeDocument, command.NumberDocument);

            await _repository.CreateAsync(client);

            return(new GenericCommandResult <ClientEntity>(true, client));
        }
Exemplo n.º 26
0
        public void Change_Password_With_Incorrect_Existing_Password()
        {
            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);

            ExecuteCommand(createClientCommand);

            var client = Session.QueryOver <Client>().FutureValue();

            var changePasswordCommand = new ChangePasswordCommand(client.Value.Id, "987654", "456789");

            ExecuteCommand(changePasswordCommand);

            Assert.IsFalse(changePasswordCommand.Result);
        }
Exemplo n.º 27
0
        void PupulateEntities(out int categoryId, out int clientId)
        {
            var createCategory = new AddCategoryCommand(null, "test");
            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);
            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver<Category>().FutureValue();

            var client = Session.QueryOver<Client>().FutureValue();

            categoryId = category.Value.Id;
            clientId = client.Value.Id;
        }
Exemplo n.º 28
0
        public void LoginUser_With_Incorrect_Password_But_Verified()
        {
            const string email = "*****@*****.**";

            var createCommand = new CreateClientCommand("test", email, "123456", "brag", 3.2342, 23.4545, 1);
            ExecuteCommand(createCommand);

            var client = Session.QueryOver<Client>().Where(c => c.Email == email).SingleOrDefault();
            client.IsVerified = true;
            Session.Update(client);

            var loginUserCommand = new LoginUserCommand(email, "12345678");
            ExecuteCommand(loginUserCommand);

            Assert.AreEqual(1, loginUserCommand.Result.RetryCount);
        }
Exemplo n.º 29
0
        public ActionResult SignUp(SignUpViewModel signUp)
        {
            if (ModelState.IsValid)
            {
                var createClient = new CreateClientCommand(signUp.Name, signUp.Email, signUp.Password, signUp.Brag,
                                                           signUp.Latitude, signUp.Longitude, signUp.Source.Value);

                ExecuteCommand(createClient);

                _userMailer.Welcome(signUp.Name, createClient.EmailVerificationCode, signUp.Email).Send();

                return(RedirectToAction("SignUpSuccess"));
            }

            return(View());
        }
Exemplo n.º 30
0
        public async Task <ClientDTO> CreateClientAsync(CreateClientCommand command, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var client = new Client
            {
                Name   = command.Name,
                Age    = command.Age,
                Gender = command.Gender
            };

            _context.Clients.Add(client);
            await _context.SaveChangesAsync(cancellationToken);

            return(client.ToDTO());
        }
Exemplo n.º 31
0
        void PupulateEntities(out int categoryId, out int clientId)
        {
            var createCategory = new AddCategoryCommand(null, "test");

            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);

            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver <Category>().FutureValue();

            var client = Session.QueryOver <Client>().FutureValue();

            categoryId = category.Value.Id;
            clientId   = client.Value.Id;
        }
Exemplo n.º 32
0
        public async Task Handle(ClientCreatedEvent message, IMessageHandlerContext context)
        {
            using (LogContext.PushProperty("IntegrationEventContext", $"{message.Id}-{Program.AppName}"))
            {
                _logger.LogInformation("----- Handling ClientCreatedEvent: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", message.Id, Program.AppName, message);

                // create client
                var command = new CreateClientCommand
                {
                    ClientId   = message.ClientId,
                    ClientName = message.Name,
                    Secret     = message.Secret
                };

                await _mediator.Send(command);
            }
        }
        public async Task <IActionResult> Post([FromBody] CreateClientCommand command)
        {
            try
            {
                var client = await _mediator.Send(command);

                return(Ok(client));
            }
            catch (KeyNotFoundException ex)
            {
                return(NotFound());
            }
            catch (ArgumentException argumentException)
            {
                return(BadRequest(argumentException.Message));
            }
        }
Exemplo n.º 34
0
        public async Task <Client> Post([FromBody] CreateClientCommand body)
        {
            // var command = new  CreateClientCommand(
            //   firstName:  (string)body.first,
            //   lastName:  (string)body.last,
            //   documento:  (string)body.document,
            //   sigla:  (string)body.estado,
            //   address:  (string)body.email

            //);

            var cliente = _service.Create(body);

            await  SalvarMongo(cliente);

            return(cliente);
        }
Exemplo n.º 35
0
        public void LoginUser_With_Incorrect_Password_But_Verified()
        {
            const string email = "*****@*****.**";

            var createCommand = new CreateClientCommand("test", email, "123456", "brag", 3.2342, 23.4545, 1);

            ExecuteCommand(createCommand);

            var client = Session.QueryOver <Client>().Where(c => c.Email == email).SingleOrDefault();

            client.IsVerified = true;
            Session.Update(client);

            var loginUserCommand = new LoginUserCommand(email, "12345678");

            ExecuteCommand(loginUserCommand);

            Assert.AreEqual(1, loginUserCommand.Result.RetryCount);
        }
Exemplo n.º 36
0
        void PupulateEntities(out int clientId, out int serviceId)
        {
            var createCategory = new AddCategoryCommand(null, "test");
            ExecuteCommand(createCategory);

            var createClientCommand = new CreateClientCommand("test", "*****@*****.**", "123456", "brag", 23.565, 12.34, 1);
            ExecuteCommand(createClientCommand);

            var category = Session.QueryOver<Category>().FutureValue();
            var client = Session.QueryOver<Client>().FutureValue();

            var categoryId = category.Value.Id;
            clientId = client.Value.Id;

            var createServiceCommand = new CreateServiceCommand(true, "title", "body", categoryId, clientId, 23.234, 5.343, null, null, null);
            ExecuteCommand(createServiceCommand);

            var service =  Session.QueryOver<Service>().SingleOrDefault();

            serviceId = service.Id;
        }
Exemplo n.º 37
0
        public void Create_Client_With_All_Required_Information()
        {
            const string name = "test";
            var initialCount = Session.QueryOver<Client>().Where(c => c.Name == name).RowCount();

            double latitude = 3.2342;
            double longitude = 23.4545;

            var createCommand = new CreateClientCommand(name, "*****@*****.**", "123456", "brag", latitude, longitude, 1);
            ExecuteCommand(createCommand);

            var client = Session.QueryOver<Client>().Fetch(c => c.ClientSettings).Eager
                .Where(c => c.Name == name).SingleOrDefault();

            Assert.NotNull(client);
            Assert.AreEqual(name, client.Name);
            Assert.AreEqual(0, initialCount);

            Assert.AreEqual(latitude, client.Location.Y);
            Assert.AreEqual(longitude, client.Location.X);

            Assert.NotNull(client.ClientSettings);
            Assert.AreEqual(0, client.ClientSettings.AdCount);
        }
Exemplo n.º 38
0
        public ActionResult SignUp(SignUpViewModel signUp)
        {
            if (ModelState.IsValid)
            {
                var createClient = new CreateClientCommand(signUp.Name, signUp.Email, signUp.Password, signUp.Brag,
                    signUp.Latitude, signUp.Longitude, signUp.Source.Value);

                ExecuteCommand(createClient);

                _userMailer.Welcome(signUp.Name, createClient.EmailVerificationCode, signUp.Email).Send();

                return RedirectToAction("SignUpSuccess");
            }

            return View();
        }