Exemple #1
0
        private ExerciseModel ParseExerciseFromReader(SqlDataReader reader)
        {
            ExerciseModel exercise = new ExerciseModel();

            exercise.Summary          = (String)reader["EX_SUMMARY"];
            exercise.Name             = (String)reader["EX_NAME"];
            exercise.Description      = (String)reader["EX_DESCRIPTION"];
            exercise.ExerciseId       = (int)reader["EX_ID"];
            exercise.DataSourceId     = (int)reader["DS_ID"];
            exercise.Published        = DAHelpers.BooleanFromReader(reader, "EX_PUBLISHED");
            exercise.PublishedDate    = DAHelpers.DateTimeFromReader(reader, "EX_PUBLISHED_DATE");
            exercise.SectionName      = (String)reader["EX_SECTION_NAME"];
            exercise.Order            = (int)reader["EX_ORDER"];
            exercise.ShowQueryBuilder = DAHelpers.BooleanFromReader(reader, "EX_SHOW_QUERY_BUILDER");
            exercise.ExerciseIdGuid   = (Guid)reader["EX_ID_GUID"];
            exercise.CreatedDate      = DAHelpers.DateTimeFromReader(reader, "EX_CREATED_DATE");
            exercise.CreatedBy        = DAHelpers.StringFromReader(reader, "EX_CREATED_BY");
            exercise.UpdatedDate      = DAHelpers.NullableDateTimeFromReader(reader, "EX_UPDATED_DATE");
            exercise.UpdatedBy        = DAHelpers.NullableStringFromReader(reader, "EX_UPDATED_BY");

            return(exercise);
        }
Exemple #2
0
        public UserModel GetUser(UserModel user, Boolean checkPassword = true)
        {
            // Check that the user model has been populated
            if (String.IsNullOrEmpty(user.Email) || (String.IsNullOrEmpty(user.HashedPassword) && checkPassword))
            {
                throw new Exception("Email or Hashed Password not provided to DA.GetUser");
            }

            String query = "select * from users where us_email_address = @EmailAddress";

            if (checkPassword)
            {
                query += " and us_password = @Password";
            }

            try
            {
                using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.DatabaseConnectionString))
                {
                    conn.Open();
                    using (SqlCommand command = new SqlCommand(query, conn))
                    {
                        command.Parameters.AddWithValue("EmailAddress", user.Email);
                        command.Parameters.AddWithValue("Password", user.HashedPassword);
                        SqlDataReader reader = command.ExecuteReader();
                        reader.Read();
                        user.UserId    = (int)reader["US_ID"];
                        user.FirstName = (String)reader["US_FIRST_NAME"];
                        user.LastName  = (String)reader["US_LAST_NAME"];
                        user.IsAdmin   = DAHelpers.BooleanFromReader(reader, "US_ADMIN_ACCESS");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Error getting user {0} - {1}", user.Email, ex.Message));
            }
            return(user);
        }