static void test1() { using (var db = new WdDbContext()) { var s = new Student() { LoginName = "20081101", Name = "yh", Pwd = "123456", Major = "cs", IsTeacher = false }; var t = new Teacher() { LoginName = "JC200803040", Name = "tr", Pwd = "123456", IsTeacher = true }; var d = new Direction() { Name = "dotNET", Director = t }; db.Students.Add(s); db.Teachers.Add(t); db.Directions.Add(d); db.SaveChanges(); } }
static void test2() { using (var db = new WdDbContext()) { List <User> ts = db.Users.ToList <User>(); foreach (var t in ts) { if (t.IsTeacher) { var tech = db.Teachers.Include("Directions").FirstOrDefault(tt => tt.Id == t.Id); Console.WriteLine($"UserName:{tech.Name}, Password:{tech.Pwd}, Direction:{tech.Direction.Name}"); } else { var stu = t as Student; Console.WriteLine($"UserName:{stu.Name}, Password:{stu.Pwd}, Marjor:{stu.Major}"); } } //DirectionManage dba = new DirectionManage(); //var dir= dba.GetAllDirection(); //foreach(Direction x in dir) //{ // Console.WriteLine("ID:" + x.Id + "Name:" + x.Name); //} } }
public ActionResult AddCourse(Course course) { using (WdDbContext dbContext = new WdDbContext()) { dbContext.Courses.Add(course); return(Content("<script>alert('添加成功');window.location.href='../Course/Index';</script>")); } }
public static Teacher GetUser() { using (WdDbContext db = new WdDbContext()) { var user = new Teacher(); user = db.Teachers.Where(x => x.LoginName == userName).FirstOrDefault(); return(user); } }
public static Student GetUser() { using (WdDbContext db = new WdDbContext()) { var user = new Student(); user = db.Students.Where(x => x.LoginName == userName).FirstOrDefault(); return(user); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WdDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); dbContext.Database.Migrate(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
/// <summary> /// 是否已经截止 /// </summary> /// <param name="cutoffTime">截止时间</param> /// <returns>是否截止</returns> public static bool IsOverTime(DateTime cutoffTime) { bool b = false; using (var db = new WdDbContext()) { var config = db.ServerConfigurations.FirstOrDefault(); if (config != null) { DateTime deadline = config.Deadline; if (cutoffTime <= deadline) { b = true; } } } return(b); }
/// <summary> /// 设置截止时间 /// </summary> /// <param name="theTime">截止时间</param> /// <returns>是否设置成功</returns> public static bool SetDeadline(DateTime theTime) { bool b = false; using (var db = new WdDbContext()) { var config = db.ServerConfigurations.FirstOrDefault(); if (config != null) { config.Deadline = theTime; int i = db.SaveChanges(); if (i > 0) { b = true; } } } return(b); }
public UserRepository(WdDbContext dbcontext, DapperContext db) : base(dbcontext, db) { }
public ExerciseController(WdDbContext dbContext) { _dbContext = dbContext; }
/// <summary> /// 通过构造函数注入得到数据上下文对象实例 /// </summary> /// <param name="dbContext"></param> /// <param name="dapper"></param> public Repository(WdDbContext dbContext, DapperContext dapper) { _dbContext = dbContext; _dapper = dapper; }
public DepartmentRepository(WdDbContext dbcontext, DapperContext db) : base(dbcontext, db) { }
public TrainingController(WdDbContext dbContext) { _dbContext = dbContext; }