public async Task <bool> DoesEmailExist(string email) { await using (var context = new DimselabDbContext()) { return(context.Users.Any(u => u.Email.ToLower() == email.ToLower())); } }
public async Task <User> GetUserByEmail(string email) { await using (var context = new DimselabDbContext()) { return(context.Users.SingleOrDefault(u => u.Email.ToLower() == email.ToLower())); } }
/// <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)); } }
/// <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()); } }
/// <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(); } }
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; }
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); }
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); }
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); }
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); }