Пример #1
0
 public async Task <bool> DoesEmailExist(string email)
 {
     await using (var context = new DimselabDbContext())
     {
         return(context.Users.Any(u => u.Email.ToLower() == email.ToLower()));
     }
 }
Пример #2
0
 public async Task <User> GetUserByEmail(string email)
 {
     await using (var context = new DimselabDbContext())
     {
         return(context.Users.SingleOrDefault(u => u.Email.ToLower() == email.ToLower()));
     }
 }
Пример #3
0
 /// <summary>
 /// Finds object with the specified key in the database and returns it
 /// </summary>
 /// <param name="key">Key of the object you wish to find</param>
 /// <returns>Object with the matching key</returns>
 public virtual async Task <T> GetObjectByKeyAsync(int key)
 {
     await using (var context = new DimselabDbContext())
     {
         return(await context.Set <T>().FindAsync(key));
     }
 }
Пример #4
0
 /// <summary>
 /// Gets all objects of the type from the database
 /// </summary>
 /// <returns>Returns all objects in the Set of the given type as List</returns>
 public virtual async Task <IEnumerable <T> > GetObjectsAsync()
 {
     await using (var context = new DimselabDbContext())
     {
         return(await context.Set <T>().AsNoTracking().ToListAsync());
     }
 }
Пример #5
0
 /// <summary>
 /// Updates the given object in the database
 /// </summary>
 /// <param name="obj">The updated object</param>
 /// <returns>async Task</returns>
 public virtual async Task UpdateObjectAsync(T obj)
 {
     await using (var context = new DimselabDbContext())
     {
         context.Set <T>().Update(obj);
         await context.SaveChangesAsync();
     }
 }
Пример #6
0
            public MockData()
            {
                var options = new DbContextOptionsBuilder <DimselabDbContext>()
                              .UseInMemoryDatabase(Guid.NewGuid().ToString())
                              .Options;

                dbContext = new DimselabDbContext(options);
                LoadDatabase();
            }
            public UserMockData()
            {
                passwordHasher = new PasswordHasher <string>();
                var options = new DbContextOptionsBuilder <DimselabDbContext>()
                              .UseInMemoryDatabase(Guid.NewGuid().ToString()).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                              .Options;

                dbContext = new DimselabDbContext(options);
                LoadDatabase();

                //dbContext.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
            }
Пример #8
0
        public override async Task <IEnumerable <Booking> > GetObjectsAsync()
        {
            List <Booking> bookings;

            using (var context = new DimselabDbContext())
            {
                bookings = await context.Bookings
                           .Include(u => u.User)
                           .Include(i => i.BookingItems)
                           .ThenInclude(bi => bi.Item).ToListAsync();
            }
            return(bookings);
        }
Пример #9
0
            public async Task <List <Item> > GetAllItemsWithCategoriesAsync()
            {
                List <Item> items;

                using (var context = new DimselabDbContext())
                {
                    items = await context.Items
                            .Include(i => i.Category)
                            .ToListAsync();
                }

                return(items);
            }
Пример #10
0
        public override async Task <Booking> GetObjectByKeyAsync(int id)
        {
            Booking booking = new Booking();

            using (var context = new DimselabDbContext())
            {
                booking = await context.Bookings
                          .Include(u => u.User)
                          .Include(i => i.BookingItems)
                          .Where(b => b.Id == id).FirstOrDefaultAsync();
            }

            return(booking);
        }
Пример #11
0
            public async Task <Item> GetItemWithCategoriesAsync(int id)
            {
                Item item;

                using (var context = new DimselabDbContext())
                {
                    item = await context.Items
                           .Include(i => i.Category)
                           .Where(i => i.Id == id)
                           .FirstOrDefaultAsync();
                }

                return(item);
            }