public RefreshTokenRepository(KitchenRpContext ctx)
 {
     _ctx = ctx;
 }
Exemple #2
0
 public ReservationStatusRepository(KitchenRpContext context)
 {
     _context = context;
 }
        internal IQueryable <Reservation> RunQuery(KitchenRpContext ctx)
        {
            var reservations = ctx.Reservations.Select(r => r);

            if (Statuses != null)
            {
                var reservations1 = reservations;
                var r             =
                    from innerst in ctx.StatusChanges
                    group innerst by innerst.Reservation.Id
                    into g
                    select new { change = g.Max(sc => sc.ChangedAt), id = g.Key }
                into min
                from res in reservations1
                join statuses in ctx.StatusChanges on res.Id equals statuses.Reservation.Id
                where statuses.ChangedAt == min.change && res.Id == min.id
                    select new TempResult {
                    R = res, S = statuses
                };

                var pred = PredicateBuilder.False <TempResult>();

                foreach (var status in Statuses)
                {
                    pred = pred.Or(sc => sc.S.CurrentStatus.Id == status.Id);
                }

                reservations = r.Where(pred).Select(t => t.R);
            }

            if (Owner != null)
            {
                reservations = reservations.Where(r => r.Owner.Id == Owner.Id);
            }

            if (Resource != null)
            {
                reservations = reservations
                               .Where(r => r.ReservedResource.IsActive)
                               .Where(r => r.ReservedResource.Id == Resource.Id);
            }

            if (From != null && To != null)
            {
                var bufferedFrom = Instant.Subtract(From.Value, Buffer);
                var bufferedTo   = Instant.Add(To.Value, Buffer);
                reservations = reservations
                               .Where(r => (bufferedFrom >= r.StartTime && bufferedFrom < r.EndTime) ||
                                      (bufferedTo > r.StartTime && bufferedTo <= r.EndTime) ||
                                      (bufferedFrom <= r.StartTime && bufferedTo >= r.EndTime)
                                      );
            }

            return(reservations
                   .Include(r => r.Owner)
                   .Include(r => r.ReservedResource)
                   .Include(r => r.StatusChanges)
                   .ThenInclude(r => r.CurrentStatus)
                   .Include(r => r.StatusChanges)
                   .ThenInclude(r => r.PreviousStatus));
        }
 public UserRepository(KitchenRpContext ctx, IRolesRepository roles)
 {
     _ctx   = ctx;
     _roles = roles;
 }
 public ReservationRepository(KitchenRpContext ctx)
 {
     _ctx = ctx;
 }
 public ResourceRepository(KitchenRpContext ctx)
 {
     _ctx = ctx;
 }
Exemple #7
0
 public RolesRepository(KitchenRpContext ctx)
 {
     _ctx = ctx;
 }