Пример #1
0
        private bool AddNewRecurringReservation(ReservationCollection reservations, ReservationData data)
        {
            // [2013-05-16 jg] We need find any existing, unended and uncancelled reservations in the
            // same time slot. This can happen if there are overlapping recurring reservation patterns.
            // To determine if two reservations overlap I'm using this logic: (StartA < EndB) and(EndA > StartB)
            // [2019-06-10 jg] Can also overlap if the RecurrenceID and time slots are the same,
            // regardless of IsActive. This will prevent previously cancelled recurrences from being
            // created again.

            // Step 1. Get any overlapping by resource and date range.
            var overlapping = reservations.Where(x => x.ResourceID == data.ResourceID &&
                                                 (x.BeginDateTime <data.Duration.EndDateTime && x.EndDateTime> data.Duration.BeginDateTime)).ToList();

            // Step 2. Check for any active (uncancelled) or a reservation with the same RecurrenceID (cancelled or uncancelled).
            //      The idea here is a recurrence should be created if the time slot is unused or there is a cancelled reservation unless
            //      the cancelled reservation is the same recurrence, in which case we do not want to create the recurrence again.
            var isOverlapped = overlapping.Any(x => x.IsActive || x.RecurrenceID == data.RecurrenceID);

            //var overlapping = reservations.Any(x =>
            //    (x.IsActive || x.RecurrenceID == data.RecurrenceID)
            //    && x.ResourceID == data.ResourceID
            //    && (x.BeginDateTime < data.Duration.EndDateTime && x.EndDateTime > data.Duration.BeginDateTime)
            //    && x.ActualEndDateTime == null); <-- this was causing a problem when an existing cancelled recurrence was present because in this case ActualEndDateTime was not null so the recurrence was created again.

            if (!isOverlapped)
            {
                var util = Reservations.Create(Provider, DateTime.Now);
                var rsv  = util.CreateReservation(data);
                reservations.Add(rsv);
                return(true);
            }

            return(false);
        }
Пример #2
0
        public IReservationItem CreateReservation(ReservationData data)
        {
            IReservationItem result;

            // This method is for creating "normal" reservations - not FDT or repair or recurring.

            if (IsFacilityDownTimeActivity(data.ActivityID))
            {
                throw new Exception("Use LNF.Web.Scheduler.FacilityDownTimeUtility.InsertFacilityDownTime");
            }

            if (IsRepairActivity(data.ActivityID))
            {
                throw new Exception("Use LNF.Web.Scheduler.RepairUtility.StartRepair");
            }

            var args = GetInsertReservationArgs(data, 0);

            result = Provider.Scheduler.Reservation.InsertReservation(args);
            HandlePracticeReservation(result, data.Invitees, args.ModifiedByClientID);

            InsertReservationInvitees(result.ReservationID, data.Invitees);
            InsertReservationProcessInfos(result.ReservationID, data.ProcessInfos);

            Provider.Scheduler.Email.EmailOnUserCreate(result.ReservationID, data.ClientID);
            Provider.Scheduler.Email.EmailOnInvited(result.ReservationID, data.Invitees, data.ClientID);

            return(result);
        }
Пример #3
0
        public IReservationItem ModifyReservation(IReservationItem rsv, ReservationData data)
        {
            IReservationItem result;
            bool             insert = false;

            if (IsFacilityDownTimeActivity(rsv.ActivityID))
            {
                result = Provider.Scheduler.Reservation.UpdateFacilityDownTime(rsv.ReservationID, data.Duration.BeginDateTime, data.Duration.EndDateTime, data.ClientID);
                HandleFacilityDowntimeReservation(result, data.ClientID);
            }
            else
            {
                if (CreateForModification(rsv, data.Duration))
                {
                    var args = GetInsertReservationArgs(data, rsv.ReservationID);
                    Provider.Scheduler.Reservation.CancelReservation(rsv.ReservationID, string.Empty, args.ModifiedByClientID);
                    result = Provider.Scheduler.Reservation.InsertForModification(args);
                    Provider.Scheduler.Reservation.AppendNotes(rsv.ReservationID, $"Cancelled for modification. New ReservationID: {result.ReservationID}");
                    insert = true;
                }
                else
                {
                    // at this point data does not Contain
                    var args = GetUpdateReservationArgs(data, rsv.ReservationID);
                    result = Provider.Scheduler.Reservation.UpdateReservation(args);
                }

                HandlePracticeReservation(result, data.Invitees, data.ClientID);
            }

            if (insert)
            {
                InsertReservationInvitees(result.ReservationID, data.Invitees);
                InsertReservationProcessInfos(result.ReservationID, data.ProcessInfos);
            }
            else
            {
                UpdateReservationInvitees(data.Invitees);
                UpdateReservationProcessInfos(data.ProcessInfos);
            }

            Provider.Scheduler.Email.EmailOnUserUpdate(result.ReservationID, data.ClientID);
            Provider.Scheduler.Email.EmailOnInvited(result.ReservationID, data.Invitees, data.ClientID, ReservationModificationType.Modified);
            Provider.Scheduler.Email.EmailOnUninvited(rsv.ReservationID, data.Invitees, data.ClientID);

            return(result);
        }
Пример #4
0
 public UpdateReservationArgs GetUpdateReservationArgs(ReservationData data, int reservationId) => data.CreateUpdateArgs(Now, reservationId);
Пример #5
0
 public InsertReservationArgs GetInsertReservationArgs(ReservationData data, int linkedReservationId) => data.CreateInsertArgs(Now, linkedReservationId);