Example #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));
        }
Example #2
0
        public async Task <List <CompanyVm> > GetAll()
        {
            var result = await _query.Get();

            return(CompanyVm.Map(result));
        }