コード例 #1
0
        public async Task <string> CancelReservation(Guid id)
        {
            try
            {
                var filter = Builders <Reservation> .Filter.Eq("Id", id);

                var reservation = _reservation.Find(filter).FirstOrDefault();
                if (reservation == null)
                {
                    throw new Exception("Book doesn't existst");
                }

                var newTransferReservation = new CancelReservation()
                {
                    RoomId = reservation.RoomId
                };

                await _publicher.CancelPublish(newTransferReservation);


                _reservation.DeleteOne(Builders <Reservation> .Filter.Eq("Id", id));

                return("Reservation was canceled successfully");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public async Task CheckReservation()
        {
            var allReservation = _reservation.Find(_ => true).ToList();

            foreach (var finishDates in allReservation)
            {
                if (DateTime.Now > finishDates.FinishDateOfBooking)
                {
                    var newTransferReservation = new CancelReservation()
                    {
                        RoomId = finishDates.RoomId
                    };
                    await _publicher.CancelPublish(newTransferReservation);

                    var id = finishDates.Id;
                    _reservation.DeleteOne(Builders <Reservation> .Filter.Eq("Id", id));
                }
            }
        }