コード例 #1
0
 public async Task <T> Get(int id)
 {
     using (var dbContext = new ArchaosDbContext())
     {
         return(await dbContext.Set <T>().FindAsync(id));
     }
 }
コード例 #2
0
 public async Task <IEnumerable <T> > Get()
 {
     using (var dbContext = new ArchaosDbContext())
     {
         return(await dbContext.Set <T>().ToListAsync());
     }
 }
コード例 #3
0
        public async Task <T> Add(T entity)
        {
            using (var dbContext = new ArchaosDbContext())
            {
                await dbContext.Set <T>().AddAsync(entity);

                await dbContext.SaveChangesAsync();

                return(entity);
            }
        }
コード例 #4
0
        public async Task <bool> Delete(int id)
        {
            using (var dbContext = new ArchaosDbContext())
            {
                var entity = await Get(id);

                dbContext.Set <T>().Remove(entity);
                await dbContext.SaveChangesAsync();

                return(true);
            }
        }
コード例 #5
0
        public async Task <T> Update(T entity)
        {
            using (var dbContext = new ArchaosDbContext())
            {
                var record = (BaseRecord)Convert.ChangeType(entity, typeof(T));
                if (await Get(record.Id) == null)
                {
                    return(null);
                }
                record.LastModDate = DateTime.Now;
                dbContext.Set <T>().Update(entity);
                await dbContext.SaveChangesAsync();

                return(entity);
            }
        }