Exemplo n.º 1
0
 public IActionResult Register
     (UsersRegisterViewModel usersRegisterViewModel)
 {
     //perform validation
     //store user in Db
     //redirect to ...
     if (ModelState.IsValid)
     {
         return(RedirectToAction("RegistrationSuccess"));
     }
     return(View(usersRegisterViewModel));
 }
Exemplo n.º 2
0
        public ActionResult Register(UsersRegisterViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(Content("Coś poszło nie tak.."));
            }

            var userRegisterRequestModel = _mapper.Map <UsersRegisterViewModel, UserRegisterRequestModel>(vm);

            _userService.Register(userRegisterRequestModel);

            return(View("VerificationEmailSent"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create(UsersRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName       = model.Email,
                    Email          = model.Email,
                    FirstName      = model.FirstName,
                    LastName       = model.LastName,
                    OrganizationId = model.OrganizationId,
                    CreatedBy      = User.Identity.Name,
                    CreatedDate    = DateTime.Now
                };

                var createUser = await _userManager.CreateAsync(user, model.Password);

                if (createUser.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    ApplicationRole role = await _roleManager.FindByIdAsync(model.RoleId.ToString());

                    if (role != null)
                    {
                        var addRoles = await _userManager.AddToRoleAsync(user, role.Name);

                        if (!addRoles.Succeeded)
                        {
                            AddErrors(addRoles);

                            ViewData["RoleId"] = new SelectList(_roleManager.Roles
                                                                //.Where(x => x.Name != "Administrator")
                                                                .Select(x => new
                            {
                                x.Id,
                                Name = x.Name + " - " + x.Description
                            }), "Id", "Name");

                            ViewData["OrganizationId"] = new SelectList(_context.Organizations, "OrganizationId", "OrganizationName");

                            return(RedirectToAction(nameof(Index)));
                        }
                    }

                    TempData["messageType"]  = "success";
                    TempData["messageTitle"] = "RECORD CREATED";
                    TempData["message"]      = "New record created successfully";

                    return(RedirectToAction(nameof(Index)));
                }

                AddErrors(createUser);
            }

            ViewData["RoleId"] = new SelectList(_roleManager.Roles
                                                .Where(x => x.Name != "Administrador")
                                                .Select(x => new
            {
                x.Id,
                Name = x.Name + " - " + x.Description
            }), "Id", "Name");

            ViewData["OrganizationId"] = new SelectList(_context.Organizations, "OrganizationId", "OrganizationName");

            return(View(model));
        }