Skip to content

Instantly share code, notes, and snippets.

@mikebosco
Created March 20, 2012 20:53
Show Gist options
  • Select an option

  • Save mikebosco/2141167 to your computer and use it in GitHub Desktop.

Select an option

Save mikebosco/2141167 to your computer and use it in GitHub Desktop.
Take this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubSonic;
using Dev.Data;
namespace UBoundTools.Database.ProgramData
{
class SchoolPrograms2
{
public List<ProgramStructure> getSchoolPrograms(string eduComplete, string schoolCode, string areaOfInterest)
{
int eduBasement = SubQuery.getEduIDBasement(eduComplete);
int edu = SubQuery.getEduID(eduComplete);
int schoolid = SubQuery.getSchoolID(schoolCode);
int areaOfInterestID = SubQuery.getAOIID(areaOfInterest);
List<Program> Programs = new DevDB().Select
.From<Program>()
.InnerJoin<Degree>()
.InnerJoin<DegreeCategory>()
.Where(ProgramsTable.ActiveColumn).IsEqualTo(true)
.And(ProgramsTable.SchoolIDColumn).IsEqualTo(schoolid)
.And(ProgramsTable.AreaOfInterestColumn).IsEqualTo(areaOfInterestID)
.And(DegreesTable.DegreeCategoryIDColumn).IsGreaterThan(eduBasement-1)
.And(DegreesTable.DegreeCategoryIDColumn).IsLessThan(edu+1)
.ExecuteTypedList<Program>();
if (Programs.Count() > 0)
{
List<ProgramStructure> returnList = new List<ProgramStructure>();
foreach (var x in Programs)
{
returnList.Add(new ProgramStructure { DegreeCategoryTile = DegreeCategoriesTable.CategoryTitleColumn, programCode = x.ProgramCode, programTitle = x.ProgramTitle });
}
return returnList;
}
return null;
}
}
/// <summary>
/// Contains all the supporting queries for grabbing EDU ID's, SchoolID's, AOI ID's
/// from their string counterparts.
/// </summary>
class SubQuery
{
/// <summary>
/// Returns the AOI ID
/// </summary>
/// <param name="areaOfInterest">String of AOI</param>
/// <returns>int - AOIID</returns>
public static int getAOIID(string areaOfInterest)
{
if (string.IsNullOrEmpty(areaOfInterest))
{
throw new ArgumentNullException();
}
var query = from c in AreaOfInterest.All()
where c.InterestTitle == areaOfInterest
select c.InterestID;
return (int)query.FirstOrDefault();
}
public static int getProductID(string programCode)
{
if (string.IsNullOrEmpty(programCode))
{
throw new ArgumentNullException();
}
var query = from c in Program.All()
where c.ProgramCode == programCode
select c.ProgramID;
return (int)query.FirstOrDefault();
}
public static int getCategoryID(string programCategory)
{
if (string.IsNullOrEmpty(programCategory))
{
throw new ArgumentNullException();
}
var query = from c in ProgramCategory.All()
where c.CategoryTitle == programCategory
select c.CategoryID;
return (int)query.FirstOrDefault();
}
/// <summary>
/// Returns education level ID dependant on which EDU
/// is passed into the method. This is the upper/limit
/// level
/// </summary>
/// <param name="edu">Short code for EDU</param>
/// <returns>INT representation of EDU level</returns>
public static int getEduID(string edu)
{
if ((string.IsNullOrEmpty(edu)))
{
throw new ArgumentNullException();
}
//inject a bit of logic here to remap the SUB Associates level degrees
if ((edu == "DDG" | edu == "MDG" | edu == "DOC"))
{
edu = "DDG";
}
else if ((edu == "BDG"))
{
edu = "MDG";
}
else if ((edu == "GED" | edu == "HS" | edu == "SCL"))
{
edu = "BDG";
}
else
{
edu = "BDG";
//ASSUMING UNDERGRAD! mmkay
}
var query = from c in DegreeCategory.All()
.Where(c => c.ShortCode == edu)
select (c.DegreeCategoryID);
return query.FirstOrDefault();
}
/// <summary>
/// Returns education level ID dependant on which EDU
/// is passed into the method. This is the bottom/base
/// level
/// </summary>
/// <param name="edu">Short code for EDU</param>
/// <returns>INT representation of EDU level</returns>
public static int getEduIDBasement(string edu)
{
if ((string.IsNullOrEmpty(edu)))
{
throw new ArgumentNullException();
}
//inject a bit of logic here to remap the SUB Associates level degrees
if ((edu == "DDG" | edu == "DOC"))
{
edu = "MDG";
}
else if ((edu == "MDG"))
{
edu = "BDG";
}
else if ((edu == "BDG"))
{
edu = "ADG";
}
else if ((edu == "GED" | edu == "HS" | edu == "SCL"))
{
edu = "ADG";
}
else
{
edu = "ADG";
//ASSUMING UNDERGRAD! mmkay
}
var query = from c in DegreeCategory.All()
.Where(c => c.ShortCode == edu)
select (c.DegreeCategoryID);
return query.FirstOrDefault();
}
/// <summary>
/// Returns the Numeric id of the School
/// </summary>
/// <param name="schoolCode">String - Short code for the school</param>
/// <returns>int - SchoolID</returns>
public static int getSchoolID(string schoolCode)
{
var query = from c in School.All()
.Where(c => c.SchoolCode == schoolCode)
select (c.SchoolID);
return query.FirstOrDefault();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment