Beispiel #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));
     }
 }
Beispiel #2
0
 public async Task <List <BookCategory> > GetAll()
 {
     using (var context = new BMDbContext())
     {
         return(await context.BookCategory.ToListAsync());
     }
 }
Beispiel #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));
     }
 }
Beispiel #4
0
 public async Task <T> GetById(long id)
 {
     using (var context = new BMDbContext())
     {
         return(await context.Set <T>().FirstOrDefaultAsync(x => x.Id == id));
     }
 }
Beispiel #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());
     }
 }
Beispiel #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()));
     }
 }
Beispiel #7
0
 public async Task <List <UserComments> > GetAll()
 {
     using (var context = new BMDbContext())
     {
         return(await context.UserComments.OrderByDescending(x => x.UpdateDate).ToListAsync());
     }
 }
Beispiel #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)));
     }
 }
Beispiel #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));
     }
 }
Beispiel #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());
     }
 }
Beispiel #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());
     }
 }
Beispiel #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();
     }
 }
Beispiel #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());
            }
        }
Beispiel #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();
     }
 }
Beispiel #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());
     }
 }
Beispiel #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());
     }
 }
Beispiel #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);
            }
        }