static void Main(string[] args) { using (var db = new SchoolContext()) { var std = new Standard() { StandardName = "國小" }; std.Students.Add(new Student() { StudentName = "Will", Weight = 30, Height = 170, DateOfBirth = DateTime.Now }); std.Students.Add(new Student() { StudentName = "Will 2", Weight = 50, Height = 170, DateOfBirth = DateTime.Now }); db.Standards.Add(std); db.SaveChanges(); foreach (var item in db.Students) { Console.WriteLine(item.StudentName + "\t" + item.Standard.StandardName); } } }
public ActionResult Student() { var db=new SchoolContext(); var StudentList = (from student in db.Students select student).ToList(); return View(StudentList); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SchoolContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitializer.Initialize(context); }
public UnitOfWork(SchoolContext ctx) { this.context = ctx; CoursesFromGenericRepo = new CourseRepository(context); CourseRepo = new CourseRepository(context); StudentGenericRepo = new StudentRepository(context); StudentRepo = new StudentRepository(context); }
public void TestMethod1() { using (var context = new SchoolContext()) { foreach (var p in context.People) { Console.WriteLine($"{p.FirstName} {p.LastName}"); } } }
static void Main(string[] args) { using (var ctx = new SchoolContext()) { Student stud = new Student() { StudentName = "New Student" }; ctx.Students.Add(stud); ctx.SaveChanges(); } }
public ActionResult Detail(int? id) { var db = new SchoolContext(); if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Student student = db.Students.Find(id); if (student == null) { return HttpNotFound(); } return View(student); }
static void Main(string[] args) { //using (var ctx = new SchoolContext()) //{ // var osmaci = ctx.Classes.FirstOrDefault(c => c.ClassName.Contains("8.A")); // var stud = new Student() { StudentName = "Marek", Class = osmaci }; // if (osmaci == null) // { // osmaci = new Class() { ClassName = "8.A" }; // ctx.Classes.Add(osmaci); // } // ctx.Students.Add(stud); // ctx.SaveChanges(); // var students = ctx.Students.ToList(); // var studentMarek = ctx.Students.FirstOrDefault(s => s.StudentName.Contains("Marek")); // studentMarek.StudentName = "Marek Skotnica"; // ctx.SaveChanges(); //} using (var ctx = new SchoolContext()) { var marek = ctx.Students.FirstOrDefault(s => s.StudentName.Contains("Marek")); ctx.Students.Remove(marek); ctx.SaveChanges(); } //if (marek != null) //{ // marek.StudentName = "Marek Skotnica"; //} //using (var ctx = new SchoolContext()) //{ // ctx.Entry(marek).State = System.Data.Entity.EntityState.Modified; // ctx.SaveChanges(); //} }
public ActionResult CreateStudent(Student model) { try { if (ModelState.IsValid) { var db = new SchoolContext(); db.Students.Add(model); db.SaveChanges(); TempData["success"] = "true"; TempData["message"] = "The Student has been added successfully"; return RedirectToAction("Student"); } } catch (RetryLimitExceededException ex) { TempData["error"] = "true"; TempData["message"] = "An error has ocurred while added the Student"; return RedirectToAction("Student"); } return View(); }
void OnInsertCommand(string param) { using (var ctx = new SchoolContext()) { if (param == "Student") { ctx.Student.Add(new Student() { Name = "Jerry" }); ctx.SaveChanges(); } else if (param == "Teacher") { ctx.Teacher.Add(new Teacher() { Name = "Kim" }); ctx.SaveChanges(); } else if (param == "Course") { ctx.Course.Add(new Course() { Name = "Biology" }); ctx.SaveChanges(); } else { ; } } }
public QueryHandler(SchoolContext db, MapperConfiguration config) { _db = db; _config = config; }
public InstructorsController(SchoolContext context) { _context = context; }
public EFUnitOfWork(string connectionString) { _context = new SchoolContext(connectionString); }
public EconomicPermissionsController(SchoolContext context) { _context = context; }
public InstructorRepository(SchoolContext schoolContext) { this.context = schoolContext; }
public StudentsController(SchoolContext context, IEmailSender emailSender) { _context = context; _emailSender = emailSender; }
public Handler(SchoolContext db) => _db = db;
public CreateModel(SchoolContext context) { _context = context; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, SchoolContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DbInitializer.Initialize(context); }
public EnrollmentsController(SchoolContext context) { _context = context; }
public GenericRepository(SchoolContext context) { _context = context; }
public static void Initialize(SchoolContext context) { //context.Database.EnsureCreated(); // Look for any students. if (context.Students.Any()) { return; // DB has been seeded } var students = new Student[] { new Student { FirstMidName = "Carson", LastName = "Alexander", EnrollmentDate = DateTime.Parse("2010-09-01") }, new Student { FirstMidName = "Meredith", LastName = "Alonso", EnrollmentDate = DateTime.Parse("2012-09-01") }, new Student { FirstMidName = "Arturo", LastName = "Anand", EnrollmentDate = DateTime.Parse("2013-09-01") }, new Student { FirstMidName = "Gytis", LastName = "Barzdukas", EnrollmentDate = DateTime.Parse("2012-09-01") }, new Student { FirstMidName = "Yan", LastName = "Li", EnrollmentDate = DateTime.Parse("2012-09-01") }, new Student { FirstMidName = "Peggy", LastName = "Justice", EnrollmentDate = DateTime.Parse("2011-09-01") }, new Student { FirstMidName = "Laura", LastName = "Norman", EnrollmentDate = DateTime.Parse("2013-09-01") }, new Student { FirstMidName = "Nino", LastName = "Olivetto", EnrollmentDate = DateTime.Parse("2005-09-01") } }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var instructors = new Instructor[] { new Instructor { FirstMidName = "Kim", LastName = "Abercrombie", HireDate = DateTime.Parse("1995-03-11") }, new Instructor { FirstMidName = "Fadi", LastName = "Fakhouri", HireDate = DateTime.Parse("2002-07-06") }, new Instructor { FirstMidName = "Roger", LastName = "Harui", HireDate = DateTime.Parse("1998-07-01") }, new Instructor { FirstMidName = "Candace", LastName = "Kapoor", HireDate = DateTime.Parse("2001-01-15") }, new Instructor { FirstMidName = "Roger", LastName = "Zheng", HireDate = DateTime.Parse("2004-02-12") } }; foreach (Instructor i in instructors) { context.Instructors.Add(i); } context.SaveChanges(); var departments = new Department[] { new Department { Name = "English", Budget = 350000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = instructors.Single( i => i.LastName == "Abercrombie").ID }, new Department { Name = "Mathematics", Budget = 100000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = instructors.Single( i => i.LastName == "Fakhouri").ID }, new Department { Name = "Engineering", Budget = 350000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = instructors.Single( i => i.LastName == "Harui").ID }, new Department { Name = "Economics", Budget = 100000, StartDate = DateTime.Parse("2007-09-01"), InstructorID = instructors.Single( i => i.LastName == "Kapoor").ID } }; foreach (Department d in departments) { context.Departments.Add(d); } context.SaveChanges(); var courses = new Course[] { new Course {CourseID = 1050, Title = "Chemistry", Credits = 3, DepartmentID = departments.Single( s => s.Name == "Engineering").DepartmentID }, new Course {CourseID = 4022, Title = "Microeconomics", Credits = 3, DepartmentID = departments.Single( s => s.Name == "Economics").DepartmentID }, new Course {CourseID = 4041, Title = "Macroeconomics", Credits = 3, DepartmentID = departments.Single( s => s.Name == "Economics").DepartmentID }, new Course {CourseID = 1045, Title = "Calculus", Credits = 4, DepartmentID = departments.Single( s => s.Name == "Mathematics").DepartmentID }, new Course {CourseID = 3141, Title = "Trigonometry", Credits = 4, DepartmentID = departments.Single( s => s.Name == "Mathematics").DepartmentID }, new Course {CourseID = 2021, Title = "Composition", Credits = 3, DepartmentID = departments.Single( s => s.Name == "English").DepartmentID }, new Course {CourseID = 2042, Title = "Literature", Credits = 4, DepartmentID = departments.Single( s => s.Name == "English").DepartmentID }, }; foreach (Course c in courses) { context.Courses.Add(c); } context.SaveChanges(); var officeAssignments = new OfficeAssignment[] { new OfficeAssignment { InstructorID = instructors.Single( i => i.LastName == "Fakhouri").ID, Location = "Smith 17" }, new OfficeAssignment { InstructorID = instructors.Single( i => i.LastName == "Harui").ID, Location = "Gowan 27" }, new OfficeAssignment { InstructorID = instructors.Single( i => i.LastName == "Kapoor").ID, Location = "Thompson 304" }, }; foreach (OfficeAssignment o in officeAssignments) { context.OfficeAssignments.Add(o); } context.SaveChanges(); var courseInstructors = new CourseAssignment[] { new CourseAssignment { CourseID = courses.Single(c => c.Title == "Chemistry" ).CourseID, InstructorID = instructors.Single(i => i.LastName == "Kapoor").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Chemistry" ).CourseID, InstructorID = instructors.Single(i => i.LastName == "Harui").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Microeconomics" ).CourseID, InstructorID = instructors.Single(i => i.LastName == "Zheng").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Macroeconomics" ).CourseID, InstructorID = instructors.Single(i => i.LastName == "Zheng").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Calculus" ).CourseID, InstructorID = instructors.Single(i => i.LastName == "Fakhouri").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Trigonometry" ).CourseID, InstructorID = instructors.Single(i => i.LastName == "Harui").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Composition" ).CourseID, InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID }, new CourseAssignment { CourseID = courses.Single(c => c.Title == "Literature" ).CourseID, InstructorID = instructors.Single(i => i.LastName == "Abercrombie").ID }, }; foreach (CourseAssignment ci in courseInstructors) { context.CourseAssignments.Add(ci); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment { StudentID = students.Single(s => s.LastName == "Alexander").ID, CourseID = courses.Single(c => c.Title == "Chemistry" ).CourseID, Grade = Grade.A }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alexander").ID, CourseID = courses.Single(c => c.Title == "Microeconomics" ).CourseID, Grade = Grade.C }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alexander").ID, CourseID = courses.Single(c => c.Title == "Macroeconomics" ).CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alonso").ID, CourseID = courses.Single(c => c.Title == "Calculus" ).CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alonso").ID, CourseID = courses.Single(c => c.Title == "Trigonometry" ).CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Alonso").ID, CourseID = courses.Single(c => c.Title == "Composition" ).CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Anand").ID, CourseID = courses.Single(c => c.Title == "Chemistry" ).CourseID }, new Enrollment { StudentID = students.Single(s => s.LastName == "Anand").ID, CourseID = courses.Single(c => c.Title == "Microeconomics").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Barzdukas").ID, CourseID = courses.Single(c => c.Title == "Chemistry").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Li").ID, CourseID = courses.Single(c => c.Title == "Composition").CourseID, Grade = Grade.B }, new Enrollment { StudentID = students.Single(s => s.LastName == "Justice").ID, CourseID = courses.Single(c => c.Title == "Literature").CourseID, Grade = Grade.B } }; foreach (Enrollment e in enrollments) { var enrollmentInDataBase = context.Enrollments.Where( s => s.Student.ID == e.StudentID && s.Course.CourseID == e.CourseID).SingleOrDefault(); if (enrollmentInDataBase == null) { context.Enrollments.Add(e); } } context.SaveChanges(); }
// constructor will set the value of the contex base on the passing parameter public StudentRepository(SchoolContext context) { this.context = context; // using "this" key word to access to the private data }
public Handler(SchoolContext db, IMapper mapper) { _db = db; this.mapper = mapper; }
public SubjectsController(SchoolContext db) : base(db) { this.repository = new SubjectRepository(db); }
public ProjectMemberOrchestrator() { _schoolContext = new SchoolContext(); }
public OfficeAssigmentRepository(SchoolContext schoolContext) { this.context = schoolContext; }
public SqlServer(SchoolContext schoolContext) { _context = schoolContext; }
public AccountController(SchoolContext context, UserManager <ApplicationUser> userManager) { _context = context; _userManager = userManager; }
public IndexModel(SchoolContext context) { _context = context; }
public QueryHandler(SchoolContext db) { _db = db; }
public TableController(SchoolContext context) { db = context; }
public DepartmentsController(SchoolContext context) { _context = context; }
void OnDeleteCommand(string param) { using (var ctx = new SchoolContext()) { if (param == "Student") { Student student = ctx.Student.FirstOrDefault(s => s.Name == "Lisa"); if (student != null) ctx.Student.Remove(student); student = ctx.Student.FirstOrDefault(s => s.Name == "Jerry"); if (student != null) ctx.Student.Remove(student); ctx.SaveChanges(); } else if (param == "Teacher") { Teacher teacher = ctx.Teacher.FirstOrDefault(t => t.Name == "Clause"); ctx.Teacher.Remove(teacher); ctx.SaveChanges(); } else if (param == "Course") { Course course = ctx.Course.FirstOrDefault(c => c.Name == "Arts"); ctx.Course.Remove(course); ctx.SaveChanges(); } else { ; } } }
public CoursesController(SchoolContext context) { _context = context; }
public static void Initialize(SchoolContext context) { context.Database.EnsureCreated(); // Look for any students. if (context.Students.Any()) { return; // DB has been seeded } var students = new Student[] { new Student{FirstMidName="Carson",LastName="Alexander",EnrollmentDate=DateTime.Parse("2005-09-01")}, new Student{FirstMidName="Meredith",LastName="Alonso",EnrollmentDate=DateTime.Parse("2002-09-01")}, new Student{FirstMidName="Arturo",LastName="Anand",EnrollmentDate=DateTime.Parse("2003-09-01")}, new Student{FirstMidName="Gytis",LastName="Barzdukas",EnrollmentDate=DateTime.Parse("2002-09-01")}, new Student{FirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2002-09-01")}, new Student{FirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2001-09-01")}, new Student{FirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2003-09-01")}, new Student{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2005-09-01")} }; foreach (Student s in students) { context.Students.Add(s); } context.SaveChanges(); var courses = new Course[] { new Course{CourseID=1050,Title="Chemistry",Credits=3,}, new Course{CourseID=4022,Title="Microeconomics",Credits=3,}, new Course{CourseID=4041,Title="Macroeconomics",Credits=3,}, new Course{CourseID=1045,Title="Calculus",Credits=4,}, new Course{CourseID=3141,Title="Trigonometry",Credits=4,}, new Course{CourseID=2021,Title="Composition",Credits=3,}, new Course{CourseID=2042,Title="Literature",Credits=4,} }; foreach (Course c in courses) { context.Courses.Add(c); } context.SaveChanges(); var enrollments = new Enrollment[] { new Enrollment{StudentID=1,CourseID=1050,Grade=Grade.A}, new Enrollment{StudentID=1,CourseID=4022,Grade=Grade.C}, new Enrollment{StudentID=1,CourseID=4041,Grade=Grade.B}, new Enrollment{StudentID=2,CourseID=1045,Grade=Grade.B}, new Enrollment{StudentID=2,CourseID=3141,Grade=Grade.F}, new Enrollment{StudentID=2,CourseID=2021,Grade=Grade.F}, new Enrollment{StudentID=3,CourseID=1050}, new Enrollment{StudentID=4,CourseID=1050,}, new Enrollment{StudentID=4,CourseID=4022,Grade=Grade.F}, new Enrollment{StudentID=5,CourseID=4041,Grade=Grade.C}, new Enrollment{StudentID=6,CourseID=1045}, new Enrollment{StudentID=7,CourseID=3141,Grade=Grade.A}, }; foreach (Enrollment e in enrollments) { context.Enrollments.Add(e); } context.SaveChanges(); }
public InstructorController(SchoolContext db) { this.db = db; }
public ActionResult EditStudent(Student student) { try { var db = new SchoolContext(); db.Entry(student).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); TempData["success"] = "true"; TempData["message"] = "The student has been updated"; return RedirectToAction("Student"); } catch (Exception ex) { TempData["error"] = "true"; TempData["message"] = "An error has ocurred while update the student"; return RedirectToAction("Student"); } }
public DeleteModel(SchoolContext context) { _context = context; }
public LecturesController(SchoolContext context) { _context = context; }
public JsonResult DeleteStudent(int? id) { try { var db = new SchoolContext(); Student student = db.Students.Find(id); db.Students.Remove(student); db.SaveChanges(); return Json(new { result = "ok", message = "The Student has been deleted" }); } catch (Exception ex) { return Json(new { result = "error", message = "An error has ocurred while delete student" }); } }
public SchoolContext Init() { return dbContext ?? (dbContext = new SchoolContext()); }
public HomeController(SchoolContext context, IStringLocalizer<HomeController> localizer) { _context = context; _localizer = localizer; }
public StudentRepository(SchoolContext SchoolContext) : base(SchoolContext) { _schoolContext = SchoolContext; }
public ActionResult EditStudent(int? id) { var db=new SchoolContext(); Student student = db.Students.Find(id); return View(student); }
public SotrudnikDetailsController(SchoolContext context) { _context = context; }
public StudentProfile() { context = new SchoolContext(); }
public DatAssignment(SchoolContext schoolContext) { _schoolContext = schoolContext; }
public DepartmentRepository(SchoolContext schoolContext) { this.context = schoolContext; }
public StudentsController(SchoolContext context) { _context = context; }
public HomeController(SchoolContext context) { _context = context; }
public Handler(SchoolContext db, IConfigurationProvider configuration) { _db = db; _configuration = configuration; }
public DepartmentController(SchoolContext schoolContext) { db = schoolContext; }
public StudentRepository(SchoolContext context) { this.context = context; }
public StoredProcedure(SchoolContext db) { _db = db; }