public static User FillUserRoles(User user) { SqlParameter parameter = null; SqlParameter[] parameters = new SqlParameter[1]; MSSQLHandler.CurrentConnectionType = GetConnectionType(); //add parameters parameter = new SqlParameter("@UserId", System.Data.SqlDbType.Int); parameter.Value = user.Id; parameters[0] = parameter; var dataTable = MSSQLHandler.ExecuteReader("GetUserRolesByUserId", parameters); foreach (DataRow row in dataTable.Rows) { user.roles.Add(new Role() { Id = Convert.ToInt32(row["Id"]), Name = Convert.ToString(row["Name"]) }); } return user; }
public static User GetUserByUsername(string username) { User user = null; SqlParameter parameter = null; SqlParameter[] parameters = new SqlParameter[1]; MSSQLHandler.CurrentConnectionType = GetConnectionType(); //add parameters parameter = new SqlParameter("@Username", System.Data.SqlDbType.VarChar, 150); parameter.Value = username; parameters[0] = parameter; var dataTable = MSSQLHandler.ExecuteReader("GetUserByUsername", parameters); foreach (DataRow row in dataTable.Rows) { user = new User() { Id = Convert.ToInt32(row["Id"]), Username = Convert.ToString(row["Username"]), Password = Convert.ToString(row["Password"]), Firstname = Convert.ToString(row["Firstname"]), Lastname = Convert.ToString(row["Lastname"]), Email = Convert.ToString(row["Email"]) }; } return user; }