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)); }
public async Task <ICommandResult> Post([FromBody] PostClientDto clientDto) { CreateClientCommand cmd = clientDto; var commandResult = await _commandBus.Submit(cmd); return(commandResult); }
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); }
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()); }
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)); } }
public void Create(CreateClientCommand model) { MySqlCommand command = _context.CreateCommand(); command.CommandText = GetCreateClientCommandText(); CreateClientPopulateParameters(model, command); command.ExecuteNonQuery(); }
public void Teste() { var command = new CreateClientCommand(); command.FirstName = ""; command.Validate(); Assert.AreEqual(false, command.Valid); }
public void ShouldReturnComnandExist() { var command = new CreateClientCommand("", "Pereira", "84028092788", "RJ", "*****@*****.**"); //command.FirstName = ""; command.Validate(); Assert.True(command.Valid); // Assert.Equals(true, command.Valid); }
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(); }
public async Task <CommandExecutionResult> HandleAsync(CreateClientCommand command) { command.ClientId = Guid.NewGuid(); var clientEntity = command.Adapt <ClientEntity>(); await _repository.InsertAsync(clientEntity); return(CommandExecutionResult.Success); }
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); }
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(); }
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 { })); }
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 }); }
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); }
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); }
public IActionResult RegisterClient([FromBody] CreateClientCommand createClientCommand) { try { var client = _clientAggregateFactory.Create(createClientCommand); _clientsWriteRepository.Save(client); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
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); }
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)); }
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)); }
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); }
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; }
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); }
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()); }
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()); }
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; }
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)); } }
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); }
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); }
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 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); }
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(); }