public IActionResult Register(RegisterInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Users/Register"));
            }

            if (model.Password != model.ConfirmPassword)
            {
                ModelState.Add(string.Empty, "The passwords must match");
                return(Redirect("/Users/Register"));
            }

            if (usersService.UserExists(model.Username))
            {
                ModelState.Add(string.Empty, "User with the same username already exists!");
                return(Redirect("/Users/Register"));
            }

            User   user   = model.MapTo <User>();
            string userId = usersService.CreateUser(user);

            usersService.AddToRole(Constants.RoleUserName, userId);
            var roles = usersService.GetUserRoles(userId);

            SignIn(userId, model.Username, model.Email, roles);

            return(Redirect("/"));
        }