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(); } }
public async Task <T> GetById(long id) { using (var context = new BMDbContext()) { return(await context.Set <T>().FirstOrDefaultAsync(x => x.Id == id)); } }
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(); } }
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); } }