Example #1
0
 public Task <M> ReadAsync <M>(Func <DbSet <T>, M> query)
 {
     using (var context = new SchoolDB())
     {
         return(Task.FromResult(query(DbSet(context))));
     }
 }
Example #2
0
 public Task <T> ReadAsync <TId>(TId id) where TId : IComparable
 {
     using (var context = new SchoolDB())
     {
         return(Task.FromResult(DbSet(context).SingleOrDefault(x => CompareId(id, x))));
     }
 }
Example #3
0
 public Task <ICollection <T> > ReadAsync()
 {
     using (var context = new SchoolDB())
     {
         return(Task.FromResult <ICollection <T> >(DbSet(context).ToList()));
     }
 }
Example #4
0
 public async Task UpdateAsync <TId>(TId id, T entity) where TId : IComparable
 {
     using (var context = new SchoolDB())
     {
         UpdateGraph(context, entity);
         await context.SaveChangesAsync();
     }
 }
Example #5
0
        public async Task <T> CreateAsync(T entity)
        {
            using (var context = new SchoolDB())
            {
                entity = DbSet(context).Add(entity);
                await context.SaveChangesAsync();

                return(entity);
            }
        }
Example #6
0
        protected void Application_Start()
        {
            SchoolDB.SetInitializer();

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            DependencyConfig.RegisterDependencies();
        }
Example #7
0
 public async Task DeleteAsync <TId>(TId id) where TId : IComparable
 {
     using (var context = new SchoolDB())
     {
         Guid userId = Guid.Parse(id.ToString());
         var  entity = DbSet(context).SingleOrDefault(x => CompareId(id, x));
         if (entity != null)
         {
             DbSet(context).Remove(entity);
             await context.SaveChangesAsync();
         }
     }
 }
        public async Task <User> GetUserAsync(string username, string password)
        {
            using (var context = new SchoolDB())
            {
                var user = await DbSet(context).Include(x => x.Student).Include(x => x.Teacher).SingleOrDefaultAsync(x => x.UserName == username);

                if (user != null)
                {
                    if (user.UserPassword == password)
                    {
                        return(user);
                    }
                }
                return(null);
            }
        }
 protected override void UpdateGraph(SchoolDB context, User entity)
 {
     context.UpdateGraph(entity);
 }
 protected override DbSet <User> DbSet(SchoolDB context)
 {
     return(context.Users);
 }
Example #11
0
 public TestDtos()
 {
     context = new SchoolDB();
 }
Example #12
0
 protected abstract void UpdateGraph(SchoolDB context, T entity);
Example #13
0
 protected abstract DbSet <T> DbSet(SchoolDB context);
Example #14
0
 protected override DbSet <Student> DbSet(SchoolDB context)
 {
     return(context.Students);
 }
Example #15
0
 public StudentController(SchoolDB context)
 {
     _db = context;
 }
 protected override DbSet <Grade> DbSet(SchoolDB context)
 {
     return(context.Grades);
 }
Example #17
0
 public GroupController(SchoolDB context)
 {
     _db = context;
 }
 protected override DbSet <Teacher> DbSet(SchoolDB context)
 {
     return(context.Teachers);
 }
Example #19
0
 protected override DbSet <Subject> DbSet(SchoolDB context)
 {
     return(context.Subjects);
 }