Example #1
0
        public static List <User> GetUsersByInstitution(int institution_fk)
        {
            List <User> list = new List <User>();

            try
            {
                using (SqlConnection connection = new SqlConnection(Config.ConnectionString))
                {
                    string     query   = @"select * from users where active = 1 and fk_institution = @fk";
                    SqlCommand command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@fk", institution_fk);

                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        User usr = new User();

                        usr.Id          = reader.GetInt32(reader.GetOrdinal("id"));
                        usr.Name        = reader.GetString(reader.GetOrdinal("nombre"));
                        usr.Appat       = reader.GetString(reader.GetOrdinal("appat"));
                        usr.Apmat       = reader.GetString(reader.GetOrdinal("apmat"));
                        usr.Email       = reader.GetString(reader.GetOrdinal("email"));
                        usr.Username    = reader.GetString(reader.GetOrdinal("username"));
                        usr.Password    = reader.GetString(reader.GetOrdinal("password"));
                        usr.Type        = reader.GetString(reader.GetOrdinal("usertype"));
                        usr.Institution = InstitutionDAO.GetInstitution(reader.GetInt32(reader.GetOrdinal("fk_institution")));
                        usr.Schedule    = ScheduleDAO.GetSchedule(reader.GetInt32(reader.GetOrdinal("fk_schedule")));

                        list.Add(usr);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
                Debug.WriteLine(ex.Message);
            }

            return(list);
        }
Example #2
0
        public static User Login(string username, string password)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(Config.ConnectionString))
                {
                    string query = @"select * from users where active = 1 and username = @username and password = @password";

                    SqlCommand command = new SqlCommand(query, connection);
                    command.Parameters.AddWithValue("@username", username);
                    command.Parameters.AddWithValue("@password", Crypto.SHA512(password));

                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        User usr = new User();

                        usr.Id          = reader.GetInt32(reader.GetOrdinal("id"));
                        usr.Name        = reader.GetString(reader.GetOrdinal("nombre"));
                        usr.Appat       = reader.GetString(reader.GetOrdinal("appat"));
                        usr.Apmat       = reader.GetString(reader.GetOrdinal("apmat"));
                        usr.Email       = reader.GetString(reader.GetOrdinal("email"));
                        usr.Username    = reader.GetString(reader.GetOrdinal("username"));
                        usr.Password    = reader.GetString(reader.GetOrdinal("password"));
                        usr.Type        = reader.GetString(reader.GetOrdinal("usertype"));
                        usr.Institution = InstitutionDAO.GetInstitution(reader.GetInt32(reader.GetOrdinal("fk_institution")));
                        usr.Schedule    = ScheduleDAO.GetSchedule(reader.GetInt32(reader.GetOrdinal("fk_schedule")));

                        return(usr);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.StackTrace);
                Debug.WriteLine(ex.Message);
            }

            return(null);
        }