Exemple #1
0
        public bool Insert(User user)
        {
            bool res = false;

            try
            {
                ICrypt crypto = new SimpleCrypt();

                this.query.Parameters.Clear();

                this.query.Parameters.Add(new SqlParameter("@UserName", crypto.Encrypt(user.Name)));
                this.query.Parameters.Add(new SqlParameter("@UserPass", crypto.Encrypt(user.Password)));
                this.query.Parameters.Add(new SqlParameter("@UserLocale", user.Culture.CultureName));
                this.query.Parameters.Add(new SqlParameter("@IsEnabled", user.IsEnabled));
                this.query.Parameters.Add(new SqlParameter("@RoleId", user.Role.Id));
                this.query.Parameters.Add(new SqlParameter("@IsEmployee", user.IsEmployee));

                int id;
                res     = this.query.ExecuteInsertProc("UsersAdd", out id);
                user.Id = id;
            }
            catch (Exception ex)
            {
                try
                {
                    DomainModel.Application.Status.Update(
                        StatusController.Abstract.StatusTypes.Error,
                        "",
                        ex.Message);
                }
                catch { }
            }

            return(res);
        }
Exemple #2
0
        public Entities.UserCollection GetAll()
        {
            Entities.UserCollection users = new Entities.UserCollection();

            using (SqlConnection cnn = new SqlConnection(ConnectionString))
            {
                string query = "SELECT * FROM Users";

                using (SqlCommand cmd = new SqlCommand(query, cnn))
                {
                    cmd.CommandType = CommandType.Text;

                    cnn.Open();

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader != null && reader.HasRows)
                        {
                            ICrypt crypto = new SimpleCrypt();

                            while (reader.Read())
                            {
                                Entities.User user = new Entities.User();

                                user.Id         = Utils.GetSafeInt32(reader, "UserId");
                                user.Name       = crypto.Decrypt(Utils.GetSafeString(reader, "UserName"));
                                user.Password   = crypto.Decrypt(Utils.GetSafeString(reader, "UserPass"));
                                user.Culture    = cultures[Utils.GetSafeString(reader, "UserLocale")];
                                user.IsEnabled  = Utils.GetSafeBoolean(reader, "IsEnabled");
                                user.Role       = Membership.Roles.GetById(Utils.GetSafeInt32(reader, "RoleId"));
                                user.IsEmployee = Utils.GetSafeBoolean(reader, "IsEmployee");
                                Membership.UserSettings.LoadById(user);

                                users.Add(user);
                            }
                        }
                    }
                }
            }

            return(users);
        }
        public static bool CreateUser(string Email, string culture)
        {
            // Validate input
            if (string.IsNullOrEmpty(Email))
            {
                throw new ArgumentException("Argument cannot be null or empty", "Email");
            }
            Email = Email.Trim();


            // Generate a password
            IPasswordGenerator passwordGenerator = new SimplePasswordGenerator();
            string             password          = passwordGenerator.Generate(7);

            // Encrypt information
            ICrypt crypt = new SimpleCrypt();

            Email    = crypt.Encrypt(Email);
            password = crypt.Encrypt(password);

            return(DomainModel.Repository.Sql.Users.Create(Email, password, culture));
        }