Esempio n. 1
0
        public ReservationEntity(UserEntity user, RoomEntity room, DateTime from, DateTime to, IEnumerable <ServiceEntity>?services = null)
        {
            ReservationException.AssertDatesValid(from, to);

            Id           = Guid.NewGuid();
            User         = user;
            Room         = room;
            ReservedFrom = from;
            ReservedTo   = to;
            Services     = services ?? new List <ServiceEntity>();
        }
        public async Task ExecuteAsync(Guid reservationId)
        {
            var reservation = await ReservationRepository.GetAsync(reservationId);

            if (reservation.User != CurrentUser)
            {
                throw ReservationException.DoesNotBelongToYou();
            }

            if (DateTime.Now > reservation.ReservedTo)
            {
                throw ReservationException.AlreadyExpired();
            }

            await ReservationRepository.DeleteAndFlushAsync(reservation);
        }