Exemplo n.º 1
0
        public async Task <IActionResult> Register([FromBody] RegisterModel registerModel)
        {
            if (ModelState.IsValid)
            {
                var companyId = await _companyCommand.Create(new CreateCompanyVm { Name = registerModel.CompanyName });

                var company = await _companyQuery.Get(companyId);

                if (company is null)
                {
                    throw new Exception("Unable to create company.");
                }
                var user = new Core.Model.User(company, registerModel.Email, registerModel.Username);

                var identityResult = await this.userManager.CreateAsync(user, registerModel.Password);

                if (identityResult.Succeeded)
                {
                    await signInManager.SignInAsync(user, isPersistent : false);

                    return(Ok(GetToken(user)));
                }
                else
                {
                    return(BadRequest(identityResult.Errors));
                }
            }
            return(BadRequest(ModelState));
        }
Exemplo n.º 2
0
        public void Add_Business(string name)
        {
            // Arrange

            var model = new CreateCompanyVm
            {
                Name = name,
            };

            // Act
            var id = _commandService.Create(model).Result;

            var result = _context.Company.First(x => x.Id == id);

            // Assert
            result.Should().NotBeNull();
            result.Name.Should().Be(model.Name);
        }
 public async Task <string> Add([Service] ICompanyCommandService service, CreateCompanyVm model)
 {
     return(Ok(await service.Create(model)));
 }
Exemplo n.º 4
0
 public async Task <string> Create(CreateCompanyVm vm)
 {
     return(await _command.Create(vm));
 }