Ejemplo n.º 1
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();
     }
 }
Ejemplo n.º 2
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();
     }
 }
Ejemplo n.º 3
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);
            }
        }