public Response ResetPasswordUser(IUserRestartPasswordViewModel userModel)
        {
            var result = new Response();

            using (var context = ContextFactory())
            {
                try
                {
                    var newPassword = SafeManager.CreatePassword(10);
                    SafeManager.HashString(newPassword, out var hash, out var salt);
                    var user = context.Set <TEntity>().FirstOrDefault(w => w.Id == userModel.Id && !w.IsDeleted);
                    if (user != null)
                    {
                        user.Password             = hash;
                        user.Salt                 = salt;
                        user.PasswordFailureCount = 0;
                        context.SaveChanges();
                        result.AddSucces($"Hasło zostało zresetowane. Nowe to: {newPassword}");
                    }
                    else
                    {
                        result.AddError("Brak użytkownika");
                    }
                }
                catch (Exception e)
                {
                    //LoggerManager.Log(e);
                    //transaction.Rollback();
                    result.AddError("Bład zapisu");
                }
            }

            return(result);
        }
        public Response ChangePasswordUser(IUserRestartPasswordViewModel userModel)
        {
            var result = new Response();

            using (var context = ContextFactory())
            {
                try
                {
                    SafeManager.HashString(userModel.Password, out var hash, out var salt);
                    var user = context.Set <TEntity>().FirstOrDefault(w => w.Id == userModel.Id && !w.IsDeleted);
                    if (user != null)
                    {
                        var hashPassword = SafeManager.GetHashString(userModel.OldPassword, user.Salt);
                        if (user.Password.Equals(hashPassword))
                        {
                            if (userModel.OldPassword.Equals(userModel.Password))
                            {
                                result.AddError("Hasło jest takie samo jak poprzednie");
                            }
                            else
                            {
                                user.Password             = hash;
                                user.Salt                 = salt;
                                user.PasswordFailureCount = 0;
                                context.SaveChanges();
                                result.AddSucces("Hasło zostało zmienione.");
                            }
                        }
                        else
                        {
                            result.AddError("Złe hasło użytkownika");
                        }
                    }
                    else
                    {
                        result.AddError("Brak użytkownika");
                    }
                }
                catch (Exception e)
                {
                    //LoggerManager.Log(e);
                    //transaction.Rollback();
                    result.AddError("Bład zapisu");
                }
            }

            return(result);
        }
        public Response EditUser(IUserViewModel userModel)
        {
            var result = new Response();

            using (var context = ContextFactory())
            {
                try
                {
                    if (
                        context.Set <TEntity>()
                        .Any(w => w.Login == userModel.Login && w.Id != userModel.Id && !w.IsDeleted))
                    {
                        result.AddError("Login nie jest unikalny");
                        return(result);
                    }


                    var user = context.Set <TEntity>().FirstOrDefault(w => w.Id == userModel.Id && !w.IsDeleted);
                    if (user == null)
                    {
                        SafeManager.HashString(userModel.Password, out var hash, out var salt);

                        user = new TEntity
                        {
                            Nazwisko = userModel.Nazwisko,
                            Imie     = userModel.Imie,
                            IsBlock  = !userModel.IsActive,
                            Rola     = userModel.Rola,
                            EditDate = DateTime.Now,
                            AddDate  = DateTime.Now,
                            Email    = userModel.Email,
                            Login    = userModel.Login,
                            Password = hash,
                            Salt     = salt
                        };
                        context.Set <TEntity>().Add(user);
                        result.AddSucces($"Użytkownik {userModel.Login} został dodany.");
                    }
                    else
                    {
                        user.Nazwisko = userModel.Nazwisko;
                        user.Imie     = userModel.Imie;
                        user.IsBlock  = !userModel.IsActive;
                        user.Rola     = userModel.Rola;
                        user.EditDate = DateTime.Now;
                        user.Email    = userModel.Email;
                        user.Login    = userModel.Login;
                        result.AddSucces($"Użytkownik {userModel.Login} został zedytowany.");
                    }

                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    //LoggerManager.Log(e);
                    //transaction.Rollback();
                    result.AddError("Bład zapisu");
                }
            }

            return(result);
        }