Exemplo n.º 1
0
        public Task CreateEnterpiseAsync(ApplicationUser applicationUser, RegisterEnterpriseViewModel model)
        {
            Enterprise enterprise = new Enterprise
            {
                Id          = ObjectId.GenerateNewId(),
                Name        = model.Name,
                Description = model.Description,
                Address     = model.Address,
                Photo       = model.Photo,
                Jobs        = new List <ObjectId>(),
            };

            UpdateDefinition <ApplicationUser> updateDefinition = Builders <ApplicationUser> .Update.Set("ActorId", enterprise.Id);

            this.mongoContext.ApplicationUsers.FindOneAndUpdateAsync(u => u.NormalizedEmail.Equals(applicationUser.NormalizedEmail), updateDefinition);

            this.mongoContext.Enterprises.InsertOne(enterprise);

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> RegisterEnterprise(RegisterEnterpriseViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Folders = _actorCreator.CreateFolders()
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                var role = new MongoIdentityRole
                {
                    Name = "ENTERPRISE"
                };
                await _roleManager.CreateAsync(role);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");
                    await _userManager.AddToRoleAsync(user, "ENTERPRISE");

                    //await _folderCreator.CreateFolderAsync(user);
                    await _actorCreator.CreateEnterpiseAsync(user, model);


                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id.ToString(), code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToAction("Index", "Enterprise"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }