Example #1
0
        public async Task <IActionResult> Create(CreateVm createVm, CancellationToken token)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = createVm.Email,
                    Email    = createVm.Email,
                    //extended properties
                    FirstName      = createVm.FirstName,
                    LastName       = createVm.LastName,
                    AvatarURL      = "/images/user.png",
                    DateRegistered = DateTime.UtcNow.ToString(),
                    Position       = "",
                    NickName       = "",
                };

                var result = await _userManager.CreateAsync(user, createVm.Password);

                if (result.Succeeded)
                {
                    var companyMember = new CompanyMember
                    {
                        Company = await GetCompany(token),
                        UserId  = user.Id,
                        Role    = MemberRole.Administrator
                    };

                    await _companyMemberRepository.AddAsync(companyMember, CancellationToken.None);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }

            return(View(createVm));
        }
Example #2
0
        private async Task CreateCompany(string name)
        {
            var company = new Company
            {
                Name              = name,
                AccentColorFirst  = "#ff55a5",
                AccentColorSecond = "#ff5860"
            };

            company = await _companyRepository.AddAsync(company, CancellationToken.None);

            var user = await _userManager.FindByIdAsync(_userManager.GetUserId(User)) as IdentityUser;

            var companyMember = new CompanyMember
            {
                Company = company,
                UserId  = user.Id,
                Role    = MemberRole.Administrator
            };

            await _companyMemberRepository.AddAsync(companyMember, CancellationToken.None);
        }