예제 #1
0
 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));
     }
 }
예제 #2
0
 public async Task <List <BookCategory> > GetAll()
 {
     using (var context = new BMDbContext())
     {
         return(await context.BookCategory.ToListAsync());
     }
 }
예제 #3
0
 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));
     }
 }
예제 #4
0
 public async Task <T> GetById(long id)
 {
     using (var context = new BMDbContext())
     {
         return(await context.Set <T>().FirstOrDefaultAsync(x => x.Id == id));
     }
 }
예제 #5
0
 public async Task <List <BookBorrow> > GetListByUserId(int userId)
 {
     using (var context = new BMDbContext())
     {
         return(await context.BookBorrow.Where(x => x.BorrowUserId == userId).ToListAsync());
     }
 }
예제 #6
0
 public async Task <SysUser> GetByUserName(string userName)
 {
     using (var context = new BMDbContext())
     {
         return(await context.SysUser.FirstOrDefaultAsync(x => x.UserName.ToLower() == userName.ToLower()));
     }
 }
예제 #7
0
 public async Task <List <UserComments> > GetAll()
 {
     using (var context = new BMDbContext())
     {
         return(await context.UserComments.OrderByDescending(x => x.UpdateDate).ToListAsync());
     }
 }
예제 #8
0
 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)));
     }
 }
예제 #9
0
 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));
     }
 }
예제 #10
0
 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());
     }
 }
예제 #11
0
 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());
     }
 }
예제 #12
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();
     }
 }
예제 #13
0
        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());
            }
        }
예제 #14
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();
     }
 }
예제 #15
0
 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());
     }
 }
예제 #16
0
 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());
     }
 }
예제 #17
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);
            }
        }