Example #1
0
        public async Task <T> Create(T entity)
        {
            using SchoolDBContext context = _contextFactory.CreateDbContext();
            EntityEntry <T> createdResult = await context.Set <T>().AddAsync(entity);

            await context.SaveChangesAsync();

            return(createdResult.Entity);
        }
Example #2
0
        public async Task <SchoolItem> GetSchoolAsync(int id)
        {
            using SchoolDBContext context = _contextFactory.CreateDbContext();
            SchoolModel entity = await context.SchoolModels
                                 .FirstOrDefaultAsync((e) => e.Id == id);

            SchoolItem school = MakeSchoolFromModel(entity);

            return(school);
        }