Exemple #1
0
        public List <BaseUser> GetUsers()
        {
            List <BaseUser> users            = new List <BaseUser>();
            var             connectionString = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;

            using (var connection = new SqlConnection(connectionString))
            {
                var command = new SqlCommand
                {
                    Connection  = connection,
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "usp_GetUsers"
                };

                connection.Open();
                var reader = command.ExecuteReader(CommandBehavior.CloseConnection);

                while (reader.Read())
                {
                    Int64 roleInt           = reader.GetInt64(4);
                    UserTypeDataAccess   ut = new UserTypeDataAccess();
                    MenuVoicesDataAccess mt = new MenuVoicesDataAccess();

                    Role role = ut.GetRoleById(roleInt);
                    List <MenuBarVoices> menu = mt.GetMenuVoicesByMenuId(reader.GetInt64(6));
                    role.Menu = menu;

                    Store store = new Store();
                    store.Id   = reader.GetInt64(9);
                    store.Name = reader.GetString(10);

                    Department department = new Department();
                    department.Id   = reader.GetInt64(11);
                    department.Name = reader.GetString(12);

                    ClientUser user = new ClientUser();
                    user.Id         = reader.GetInt64(0);
                    user.Firstname  = reader.GetString(1);
                    user.Surname    = reader.GetString(2);
                    user.Email      = reader.GetString(3);
                    user.Username   = reader.GetString(8);
                    user.IsActive   = reader.GetBoolean(7);
                    user.Role       = role;
                    user.Store      = store;
                    user.Department = department;

                    users.Add(user);
                }
            }

            return(users);
        }
Exemple #2
0
        public BaseUser GetUser(string username, string password)
        {
            BaseUser user             = null;
            var      connectionString = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;

            using (var connection = new SqlConnection(connectionString))
            {
                var command = new SqlCommand
                {
                    Connection  = connection,
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "usp_GetUser"
                };

                var parameterUsername = new SqlParameter("@username", SqlDbType.VarChar)
                {
                    Value = username
                };
                var parameterPassword = new SqlParameter("@password", SqlDbType.VarChar)
                {
                    Value = password
                };
                command.Parameters.Add(parameterUsername);
                command.Parameters.Add(parameterPassword);

                connection.Open();
                var reader = command.ExecuteReader(CommandBehavior.CloseConnection);

                if (reader.Read())
                {
                    Int64 roleInt           = reader.GetInt64(4);
                    UserTypeDataAccess   ut = new UserTypeDataAccess();
                    MenuVoicesDataAccess mt = new MenuVoicesDataAccess();

                    Role role = ut.GetRoleById(roleInt);

                    Store store = new Store();
                    store.Id   = reader.GetInt64(7);
                    store.Name = reader.GetString(8);

                    Department department = new Department();
                    department.Id   = reader.GetInt64(9);
                    department.Name = reader.GetString(10);

                    List <MenuBarVoices> menu = mt.GetMenuVoicesByMenuId(reader.GetInt64(6));
                    role.Menu                = menu;
                    user                     = UserFactory.getUser(role);
                    user.Id                  = reader.GetInt64(0);
                    user.Firstname           = reader.GetString(1);
                    user.Surname             = reader.GetString(2);
                    user.Email               = reader.GetString(3);
                    user.Username            = username;
                    user.Password            = password;
                    user.Role                = role;
                    user.Store               = store;
                    user.Department          = department;
                    user.IsPasswordRecovered = reader.GetBoolean(11);
                }
            }

            return(user);
        }