public async Task <BookBorrow> GetByBookIdAndStatus(long bookId, int status) { using (var context = new BMDbContext()) { return(await context.BookBorrow.FirstOrDefaultAsync(x => x.BookId == bookId && x.Status == status)); } }
public async Task <List <BookCategory> > GetAll() { using (var context = new BMDbContext()) { return(await context.BookCategory.ToListAsync()); } }
public async Task <BookBorrow> GetbyBookIdAndUserId(long bookId, long userId) { using (var context = new BMDbContext()) { return(await context.BookBorrow.FirstOrDefaultAsync(x => x.BookId == bookId && x.BorrowUserId == userId)); } }
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 <List <BookBorrow> > GetListByUserId(int userId) { using (var context = new BMDbContext()) { return(await context.BookBorrow.Where(x => x.BorrowUserId == userId).ToListAsync()); } }
public async Task <SysUser> GetByUserName(string userName) { using (var context = new BMDbContext()) { return(await context.SysUser.FirstOrDefaultAsync(x => x.UserName.ToLower() == userName.ToLower())); } }
public async Task <List <UserComments> > GetAll() { using (var context = new BMDbContext()) { return(await context.UserComments.OrderByDescending(x => x.UpdateDate).ToListAsync()); } }
public async Task <SysUser> GetByUserNameAndId(string userName, long id) { using (var context = new BMDbContext()) { return(await context.SysUser .FirstOrDefaultAsync(x => x.UserName.ToLower() == userName.ToLower() && (id == 0 || x.Id != id))); } }
public async Task <BookInfo> GetIncludeById(long id) { using (var context = new BMDbContext()) { return(await context.BookInfo.Include(x => x.BookCategory) .FirstOrDefaultAsync(x => x.Id == id)); } }
public async Task <List <BookInfo> > QueryByParameter(string key) { using (var context = new BMDbContext()) { return(await context.BookInfo.Include(x => x.BookCategory).Where(x => x.Title.Contains(key) || x.Description.Contains(key) || x.BookCategory.CategoryName.Contains(key)).ToListAsync()); } }
public async Task <BookCategory> ExistSameName(long id, string categoryName) { using (var context = new BMDbContext()) { return(await context.BookCategory .Where(x => (x.Id != id || id == 0) && x.CategoryName == categoryName) .FirstOrDefaultAsync()); } }
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 <List <BookBorrow> > QueryByParameter(string key, int userId) { using (var context = new BMDbContext()) { var dataList = await context.BookBorrow.Include(x => x.BookInfo.BookCategory).Where(x => x.BorrowUserId == userId).ToListAsync(); return(dataList.Where(x => x.BookInfo.Title.Contains(key) || x.BookInfo.Description.Contains(key) || x.BookInfo.BookCategory.CategoryName.Contains(key)).ToList()); } }
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 <int> QueryCount(string keyword) { using (var context = new BMDbContext()) { var dataList = context.SysUser.AsQueryable(); if (!string.IsNullOrEmpty(keyword)) { dataList = dataList.Where(x => x.UserName.Contains(keyword)); } return(await dataList .CountAsync()); } }
public async Task <List <SysUser> > Query(string keyword, int pageSize, int pageIndex) { using (var context = new BMDbContext()) { var dataList = context.SysUser.AsQueryable(); if (!string.IsNullOrEmpty(keyword)) { dataList = dataList.Where(x => x.UserName.Contains(keyword)); } return(await dataList .OrderByDescending(x => x.UpdateDate) .Skip((pageIndex - 1) * pageSize) .Take(pageSize) .ToListAsync()); } }
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); } }