public async Task <bool> AddUserRoles(UserRoles Role)
        {
            var existingRoles = await _roleManager.FindByNameAsync(Role.ToString()).ConfigureAwait(false);

            if (existingRoles != null)
            {
                var exception = new VSException("Role Already Existing");
                exception.Value = "Role Already Existing:" + Role.ToString();
                throw exception;
            }

            var results = await _roleManager.CreateAsync(new IdentityRole
            {
                Name = Role.ToString(),
            }).ConfigureAwait(false);

            if (results?.Errors.Any() == true)
            {
                var exception = new VSException("error occured");
                exception.Value = string.Join(';', results.Errors);
                throw exception;
            }

            return(results.Succeeded);
        }
        public async Task <bool> DeleteUser(UserViewModel user)
        {
            var IsUserExist = await _userManager.FindByEmailAsync(user.Email).ConfigureAwait(false);

            if (IsUserExist == null)
            {
                throw new VSException("User Not Exists to Delete");
            }

            IdentityResult results = null;

            try
            {
                results = await _userManager.DeleteAsync(IsUserExist).ConfigureAwait(false);

                if (results.Succeeded == false)
                {
                    if (results?.Errors.Any() == true)
                    {
                        var exception = new VSException("error occured");
                        exception.Value = string.Join(';', results.Errors);
                        throw exception;
                    }
                }
                return(results.Succeeded);
            }
            catch (Exception)
            {
                throw new VSException("Unable to Delete the User with following errors", results?.Errors);
            }
        }
        public async Task <bool> LogOut()
        {
            try
            {
                await _signInManager.SignOutAsync().ConfigureAwait(false);

                return(true);
            }
            catch (Exception)
            {
                var exception = new VSException("error occured");
                exception.Value = "Unable To Logout";
                throw exception;
            }
        }
        public async Task <UserViewModel> Login(LoginViewModel login)
        {
            var userexists = _identityContext.Users.SingleOrDefault(u => u.Email.Equals(login.Email, StringComparison.OrdinalIgnoreCase));

            if (userexists == null)
            {
                var exception = new VSException("Looks like Email is not registered");
                exception.Value = "Looks like Email is not registered";
                throw exception;
            }

            var results = await _signInManager.PasswordSignInAsync(userexists.UserName, login.Password, login.RememberMe, false).ConfigureAwait(false);

            if (results.Succeeded)
            {
                var user = _map.Map <UserViewModel>(userexists);
                user.Token = authenticateToken(userexists);
                return(user);
            }

            if (results.IsLockedOut)
            {
                var exception = new VSException("Your Account is Locked");
                exception.Value = "Your Account is Locked";
                throw exception;
            }
            else if (results.IsNotAllowed)
            {
                var exception = new VSException("Invalid Attempt to Login");
                exception.Value = "Invalid Attempt to Login";
                throw exception;
            }
            else
            {
                var exception = new VSException("Invalid Attempt to Login");
                exception.Value = "Invalid Attempt to Login";
                throw exception;
            }
        }