Пример #1
0
        public async Task RemoveAllReservations(string userId)
        {
            await using var dbCtx = new BookingsDbContext(_dbContextOptions);
            var allReservations = _db.UserReservations.Where(e => e.UserId == userId);

            dbCtx.UserReservations.RemoveRange(allReservations);
            await dbCtx.SaveChangesAsync();
        }
Пример #2
0
        public async Task RemoveReservation(string userId, UserReservation reservation)
        {
            await using var dbCtx = new BookingsDbContext(_dbContextOptions);
            var itemToRemove = await dbCtx.UserReservations.FirstOrDefaultAsync(res =>
                                                                                res.UserId == userId && res.TeamId == reservation.TeamId && res.StartTime == reservation.StartTime);

            if (itemToRemove == null)
            {
                return;
            }
            dbCtx.UserReservations.Remove(itemToRemove);
            await dbCtx.SaveChangesAsync();
        }
Пример #3
0
        public async Task AddReservation(string userId, UserReservation reservation)
        {
            await using var dbCtx = new BookingsDbContext(_dbContextOptions);
            var reservationEntity = new UserReservationEntity
            {
                StartTime = reservation.StartTime,
                TeamId    = reservation.TeamId,
                UserId    = userId,
                EndTime   = reservation.StartTime + _teamService.GetTeam(reservation.TeamId).Duration
            };

            dbCtx.UserReservations.Add(reservationEntity);
            await dbCtx.SaveChangesAsync();
        }
Пример #4
0
 public EfBookingStorage(TeamService teamService, BookingsDbContext dbContext, DbContextOptions <BookingsDbContext> dbContextOptions)
 {
     _teamService      = teamService;
     _db               = dbContext;
     _dbContextOptions = dbContextOptions;
 }