Beispiel #1
0
 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();
     }
 }
Beispiel #2
0
 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>"));
     }
 }
Beispiel #4
0
 public static Teacher GetUser()
 {
     using (WdDbContext db = new WdDbContext())
     {
         var user = new Teacher();
         user = db.Teachers.Where(x => x.LoginName == userName).FirstOrDefault();
         return(user);
     }
 }
Beispiel #5
0
 public static Student GetUser()
 {
     using (WdDbContext db = new WdDbContext())
     {
         var user = new Student();
         user = db.Students.Where(x => x.LoginName == userName).FirstOrDefault();
         return(user);
     }
 }
Beispiel #6
0
        // 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(); });
        }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
        /// <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);
        }
Beispiel #9
0
 public UserRepository(WdDbContext dbcontext, DapperContext db) : base(dbcontext, db)
 {
 }
 public ExerciseController(WdDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Beispiel #11
0
 /// <summary>
 /// 通过构造函数注入得到数据上下文对象实例
 /// </summary>
 /// <param name="dbContext"></param>
 /// <param name="dapper"></param>
 public Repository(WdDbContext dbContext, DapperContext dapper)
 {
     _dbContext = dbContext;
     _dapper    = dapper;
 }
Beispiel #12
0
 public DepartmentRepository(WdDbContext dbcontext, DapperContext db) : base(dbcontext, db)
 {
 }
Beispiel #13
0
 public TrainingController(WdDbContext dbContext)
 {
     _dbContext = dbContext;
 }