public static void loadschdata(schdata schdata) { // receive schdata, load to database using (LexileTitlesEntities lr = new LexileTitlesEntities()) { List<Scholastic> existing = new List<Scholastic>(from s in lr.Scholastics where s.Isbn13 == schdata.isbn13 select s); if (existing.Count == 0) { // create new BarnesAndNoble Scholastic sch = new Scholastic(); sch.Isbn13 = schdata.isbn13; sch.InterestLowGrade = schdata.interestlowgrade; sch.InterestHighGrade = schdata.interesthighgrade; sch.GradeEquiv = schdata.gradeequiv; sch.DRA = schdata.dra; sch.GuidedReading = schdata.guidedreading; // genre TBD lr.Scholastics.Add(sch); lr.SaveChanges(); } else { // update fields on existing BarnesAndNoble existing[0].InterestLowGrade = schdata.interestlowgrade; existing[0].InterestHighGrade = schdata.interesthighgrade; existing[0].GradeEquiv = schdata.gradeequiv; existing[0].DRA = schdata.dra; existing[0].GuidedReading = schdata.guidedreading; lr.SaveChanges(); } } }
public static string loadschdata(ScholasticDto schdata) { string msg = "(Unable to load to local db)"; // receive schdata, load to database UTF8Encoding enc = new System.Text.UTF8Encoding(); byte[] bs = new byte[1]{(byte)schdata.ScholasticGradeHigher}; try { using (LexileTitlesEntities lr = new LexileTitlesEntities()) { List<Scholastic> existing = new List<Scholastic>(from s in lr.Scholastics where s.Isbn13 == schdata.Isbn13 select s); if (existing.Count == 0) { // create new BarnesAndNoble Scholastic sch = new Scholastic(); sch.Isbn13 = schdata.Isbn13; sch.InterestLowGrade = schdata.ScholasticGradeLower; sch.InterestHighGrade = enc.GetString(bs); sch.GradeEquiv = (decimal)schdata.ScholasticGrade; sch.DRA = schdata.Dra; sch.GuidedReading = schdata.GuidedReading; // genre TBD lr.Scholastics.Add(sch); lr.SaveChanges(); msg = "(Loaded new SCH to DB)"; } else { // update fields on existing BarnesAndNoble existing[0].InterestLowGrade = schdata.ScholasticGradeLower; existing[0].InterestHighGrade = enc.GetString(bs); existing[0].GradeEquiv = (decimal)schdata.ScholasticGrade; existing[0].DRA = schdata.Dra; existing[0].GuidedReading = schdata.GuidedReading; lr.SaveChanges(); msg = "(Updated existing SCH in DB)"; } } } catch { } return msg; }