Пример #1
0
 public async Task DeleteById(long id)
 {
     using (var context = new BMDbContext())
     {
         var item = context.Set <T>().FirstOrDefault(x => x.Id == id);
         if (item != null)
         {
             context.Set <T>().Remove(item);
         }
         await context.SaveChangesAsync();
     }
 }
Пример #2
0
 public async Task <T> GetById(long id)
 {
     using (var context = new BMDbContext())
     {
         return(await context.Set <T>().FirstOrDefaultAsync(x => x.Id == id));
     }
 }
Пример #3
0
 public async Task AddOrUpdate(T entity)
 {
     using (var context = new BMDbContext())
     {
         entity.UpdateBy   = GlobalVariance.UserName ?? "";
         entity.UpdateDate = DateTime.Now;
         context.Set <T>().AddOrUpdate(entity);
         await context.SaveChangesAsync();
     }
 }
Пример #4
0
        public async Task <int> ImportByExcel(BookInfo entity)
        {
            using (var context = new BMDbContext())
            {
                entity.UpdateBy   = GlobalVariance.UserName ?? "";
                entity.UpdateDate = DateTime.Now;
                var count    = 0;
                var hasExist = await context.BookInfo.FirstOrDefaultAsync(x => x.Title == entity.Title);

                if (hasExist == null)
                {
                    count += 1;
                    context.Set <BookInfo>().AddOrUpdate(entity);
                    await context.SaveChangesAsync();
                }

                return(count);
            }
        }