Team58LMSContext MakeMockDB() { var optionsBuilder = new DbContextOptionsBuilder <Team58LMSContext>(); optionsBuilder.UseInMemoryDatabase("mock_db").UseApplicationServiceProvider(NewServiceProvider()); Team58LMSContext db = new Team58LMSContext(optionsBuilder.Options); Departments d = new Departments(); d.Name = "School of Computing"; d.Subject = "CS"; Departments d2 = new Departments(); d.Name = "School of Music"; d.Subject = "MUSC"; Departments d3 = new Departments(); d.Name = "School of Mathematics"; d.Subject = "MATH"; db.Departments.Add(d); db.Departments.Add(d2); db.Departments.Add(d3); db.SaveChanges(); return(db); }
/*******Begin code to modify********/ private string GenerateUId() { using (Team58LMSContext db = new Team58LMSContext()) { var maxUId = (from s in db.Students select s.UId) .Union(from p in db.Professors select p.UId) .Union(from a in db.Administrators select a.UId) .DefaultIfEmpty("u0000000") .Max(); int i = 0; if (int.TryParse(maxUId.Substring(1), out i)) { i++; return("u" + i.ToString().PadLeft(7, '0')); } return(null); } }
/* * WARNING: This is the quick and easy way to make the controller * use a different LibraryContext - good enough for our purposes. * The "right" way is through Dependency Injection via the constructor * (look this up if interested). */ // (Done)TODO: Uncomment and change 'X' after you have scaffoled public void UseLMSContext(Team58LMSContext ctx) { db = ctx; }
public CommonController() { db = new Team58LMSContext(); }