public int Delete() { try { using (ProgDecEntities dc = new ProgDecEntities()) { if (Id >= 0) { tblProgram program = dc.tblPrograms.Where(s => s.Id == Id).FirstOrDefault(); if (program != null) { dc.tblPrograms.Remove(program); return(dc.SaveChanges()); } else { throw new Exception("Row was not found"); } } else { throw new Exception("ID is not set"); } } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (ProgDecEntities dc = new ProgDecEntities()) { if (Id >= 0) { tblProgram program = dc.tblPrograms.Where(s => s.Id == Id).FirstOrDefault(); if (program != null) { program.Description = this.Description; program.DegreeTypeId = this.DegreeTypeId; program.ImagePath = this.ImagePath; return(dc.SaveChanges()); } else { throw new Exception("Row was not found"); } } else { throw new Exception("ID is not set"); } } } catch (Exception ex) { throw ex; } }
public void DeleteTest() { using (ProgDecEntities dc = new ProgDecEntities()) { tblProgram row = (from dt in dc.tblPrograms where dt.Id == -99 select dt).FirstOrDefault(); if (row != null) { dc.tblPrograms.Remove(row); int actual = dc.SaveChanges(); Assert.AreNotEqual(0, actual); } } }
public void UpdateTest() { ProgDecEntities dc = new ProgDecEntities(); tblProgram program = (from p in dc.tblPrograms where p.Id == -99 select p).FirstOrDefault(); program.Description = "Updated program"; program.DegreeTypeId = 3; dc.SaveChanges(); tblProgram updatedprogram = (from p in dc.tblPrograms where p.Id == -99 select p).FirstOrDefault(); Assert.AreEqual(program.Description, updatedprogram.Description); }
public static int Delete(int id) { try { using (ProgDecEntities dc = new ProgDecEntities()) { tblProgram deleterow = (from dt in dc.tblPrograms where dt.Id == id select dt).FirstOrDefault(); dc.tblPrograms.Remove(deleterow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public void UpdateTest() { using (ProgDecEntities dc = new ProgDecEntities()) { // Get the record that I want to update // SELECT * FROM tblProgram WHERE Id = -99 tblProgram row = (from dt in dc.tblPrograms where dt.Id == -99 select dt).FirstOrDefault(); if (row != null) { // Change values row.Description = "New Description"; row.DegreeTypeId = 2; int actual = dc.SaveChanges(); Assert.AreNotEqual(0, actual); } } }
public void DeleteTest() { ProgDecEntities dc = new ProgDecEntities(); tblProgram program = (from p in dc.tblPrograms where p.Id == -99 select p).FirstOrDefault(); if (program != null) { dc.tblPrograms.Remove(program); dc.SaveChanges(); } tblProgram deletedprogram = (from p in dc.tblPrograms where p.Id == -99 select p).FirstOrDefault(); Assert.IsNull(deletedprogram); // confirms the delete worked }
public void InsertTest() { using (ProgDecEntities dc = new ProgDecEntities()) { // Make a new Program tblProgram newrow = new tblProgram(); // Set the column values newrow.Id = -99; newrow.Description = "My new shiny program"; newrow.DegreeTypeId = 3; // Add the row dc.tblPrograms.Add(newrow); // Save the Changes int results = dc.SaveChanges(); Assert.IsTrue(results > 0); } }
public static int Update(int id, string description, int degreeTypeId, string imagePath) { try { using (ProgDecEntities dc = new ProgDecEntities()) { tblProgram updaterow = (from dt in dc.tblPrograms where dt.Id == id select dt).FirstOrDefault(); updaterow.ImagePath = imagePath; updaterow.Description = description; updaterow.DegreeTypeId = degreeTypeId; return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Insert(out int id, string description, int programId, string imagePath) { try { using (ProgDecEntities dc = new ProgDecEntities()) { tblProgram newrow = new tblProgram(); newrow.Id = dc.tblPrograms.Any() ? dc.tblPrograms.Max(dt => dt.Id) + 1 : 1; newrow.Description = description; newrow.DegreeTypeId = programId; newrow.ImagePath = imagePath; id = newrow.Id; dc.tblPrograms.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
} // public int Insert() { try { using (ProgDecEntities dc = new ProgDecEntities()) { tblProgram program = new tblProgram(); program.Id = dc.tblPrograms.Any() ? dc.tblPrograms.Max(s => s.Id) + 1 : 1; // (if condition) ? thenthis : else program.Description = this.Description; program.DegreeTypeId = this.DegreeTypeId; program.ImagePath = this.ImagePath; this.Id = program.Id; dc.tblPrograms.Add(program); return(dc.SaveChanges()); // returns rows affected } } catch (Exception ex) { throw ex; } }
public void InsertTest() { ProgDecEntities dc = new ProgDecEntities(); // Dimension and instatiate new row tblProgram newrow = new tblProgram(); // set properties for the new record newrow.Id = -99; newrow.Description = "New Program"; newrow.DegreeTypeId = 2; // Insert the row into the database dc.tblPrograms.Add(newrow); // Commit the changes dc.SaveChanges(); tblProgram program = (from p in dc.tblPrograms where p.Id == -99 select p).FirstOrDefault(); Assert.AreSame(newrow, program); // one way to test if a new row was successfully added }
static void runCleanup() { try { oeg_reportsEntities db = new oeg_reportsEntities(); oeg_lookupsEntities db2 = new oeg_lookupsEntities(); System.Diagnostics.Debug.WriteLine("Starting Remove unmatched"); db.Database.ExecuteSqlCommand("UpdatePreGroupID"); System.Diagnostics.Debug.WriteLine("Finished Remove unmatched"); System.Diagnostics.Debug.WriteLine("Starting Remove unmatched"); db.Database.ExecuteSqlCommand("RemoveIncompletes"); System.Diagnostics.Debug.WriteLine("Finished Remove unmatched"); System.Diagnostics.Debug.WriteLine("Starting EmployeeNumber Update"); db.Database.ExecuteSqlCommand("UpdateEmployeeNumber"); System.Diagnostics.Debug.WriteLine("Finished EmployeeNumber Update"); ////update lookup table from Gaia db.Database.ExecuteSqlCommand("CleanoutLookups"); var source = from f in db.ReportDatas select f; var employees = (from f in source where f.EmployeeName != null select new { EmployeeNumber = f.EmployeeNumber }).Distinct(); string emp = ""; foreach (string s in employees.Select(o => o.EmployeeNumber)) { emp += s + ","; } emp = emp.Remove(emp.Length - 1); var lkEmployess = db2.GetEmployees(emp).ToList(); foreach (GetEmployees_Result r in lkEmployess) { tblHR_Entities hr = new tblHR_Entities(); hr.EntityID = r.EntityID; hr.FullName = r.FullName; db.tblHR_Entities.Add(hr); } db.SaveChanges(); //get jobcodes for every user var users = (from f in db.Users where f.EmployeeNumber != null select new { EmployeeNumber = f.EmployeeNumber }).Distinct(); string u = ""; foreach (string s in users.Select(o => o.EmployeeNumber)) { int n; bool isNumeric = int.TryParse(s, out n); if (isNumeric) { u += s + ","; } } u = u.Remove(u.Length - 1); var lkUsers = db2.GetRosteredJobcodesCSVByEmployeeNumbers(u, null, null).ToList(); foreach (GetRosteredJobcodesCSVByEmployeeNumbers_Result r in lkUsers) { User us = db.Users.Where(x => x.EmployeeNumber == r.EmployeeID.ToString()).FirstOrDefault(); if (us != null && r.Jobcodes_CSV != null) { us.JobCodes = r.Jobcodes_CSV.Replace(" ", ""); db.Entry(us).State = EntityState.Modified; } } db.SaveChanges(); var jobcodes = (from f in source select new { JobCode = f.JobCode }).Distinct(); string jc = ""; foreach (string s in jobcodes.Select(o => o.JobCode)) { jc += s + ","; } jc = jc.Remove(jc.Length - 1); var lkjobcodes = db2.GetPrograms(jc).ToList(); foreach (GetPrograms_Result r in lkjobcodes) { tblProgram j = new tblProgram(); j.Duration = r.Duration; j.JobCode = r.JobCode; j.JobFrom = r.JobFrom; j.SchoolCode = r.Client; j.Venue = r.Venue; j.Year = r.Year.ToString(); j.YearLvl = r.YearLvl; db.tblPrograms.Add(j); } db.SaveChanges(); System.Diagnostics.Debug.WriteLine("Starting ATLAS Data Update"); db.Database.ExecuteSqlCommand("UpdateATLASData"); System.Diagnostics.Debug.WriteLine("Finished ATLAS Data Update"); System.Diagnostics.Debug.WriteLine("Starting EmployeeName Update"); db.Database.ExecuteSqlCommand("UpdateEmployeeName"); System.Diagnostics.Debug.WriteLine("Finished EmployeeName Update"); System.Diagnostics.Debug.WriteLine("Starting Question Text Update"); db.Database.ExecuteSqlCommand("UpdateQuestionText"); System.Diagnostics.Debug.WriteLine("Finished Question Text Update"); System.Diagnostics.Debug.WriteLine("Starting Factor Text Update"); db.Database.ExecuteSqlCommand("UpdateFactorText"); System.Diagnostics.Debug.WriteLine("Finished Factor Text Update"); System.Diagnostics.Debug.WriteLine("Complete!"); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }