public ReservationDuration GetReservationDuration() { var beginDateTime = Helper.Context.Request.SelectedDate().AddHours(Convert.ToInt32(StartTimeHourSelectedValue)).AddMinutes(Convert.ToInt32(StartTimeMinuteSelectedValue)); var duration = GetCurrentDurationMinutes(); var result = new ReservationDuration(beginDateTime, TimeSpan.FromMinutes(duration)); return(result); }
public ReservationData GetReservationData(ReservationDuration rd) { var infos = GetReservationProcessInfos(); var invitees = GetInvitees(); return(new ReservationData(infos, invitees) { ClientID = CurrentUser.ClientID, ResourceID = Resource.ResourceID, ActivityID = ActivityID, AccountID = AccountID, RecurrenceID = RecurrenceID, Duration = rd, Notes = Notes, AutoEnd = AutoEnd, KeepAlive = KeepAlive }); }
public IReservationItem CreateOrModifyReservation(ReservationDuration duration) { var isCreating = IsCreating(); Helper.AppendLog($"ReservationModel.CreateOrModifyReservation: isCreating = {isCreating}"); Helper.Context.Session.Remove("ReservationProcessInfoJsonData"); if (IsThereAlreadyAnotherReservation(duration, out string alert)) { throw new Exception(alert); } Helper.Context.Session["ReservationProcessInfoJsonData"] = ReservationProcessInfoJson; // Overwrite other reservations OverwriteReservations(); var data = GetReservationData(duration); var util = Reservations.Create(Helper.Provider, Now); // this will be the result reservation - either a true new reservation when creating, a new reservation for modification, or the existing rsv when modifying non-duration data IReservationItem result; if (isCreating) { result = util.CreateReservation(data); } else { result = util.ModifyReservation(Reservation, data); } // Remove session data to avoid accidently reusing on another reservation. It also gets removed when Reservation.aspx loads // but there have been cases where ReservationProcessInfo from one reservation mysteriously shows up on another reservation. // Note that the session data is retrieved when GetReservationData is called above. Helper.Context.Session.Remove($"ReservationProcessInfos#{Resource.ResourceID}"); Helper.Context.Session.Remove($"ReservationInvitees#{Resource.ResourceID}"); Helper.Context.Session.Remove($"AvailableInvitees#{Resource.ResourceID}"); Helper.AppendLog($"ReservationModel.CreateOrModifyReservation: result.ReservationID = {result.ReservationID}"); return(result); }
private ReservationData GetReservationData(int resourceId, int clientId, int accountId, int activityId, bool autoEnd, bool keepAlive, string notes, DateTime selectedDate, int startTimeHour, int startTimeMinute, int duration) { var beginDateTime = selectedDate.AddHours(startTimeHour).AddMinutes(startTimeMinute); var rd = ReservationDuration.FromMinutes(beginDateTime, duration); var result = new ReservationData() { ResourceID = resourceId, ClientID = clientId, AccountID = accountId, ActivityID = activityId, AutoEnd = autoEnd, KeepAlive = keepAlive, Notes = notes, ReservationDuration = rd }; return(result); }
public void CanCreateAndModifyReservationWithInsertForModification() { ReservationItem rsv1, rsv2; ResourceItem res; int resourceId = 62020; DateTime beginDateTime = DateTime.Parse("2016-10-02 08:00:00"); using (ContextManager.StartRequest(1600)) { // Step 0: Purge int purgedRows = PurgeReservations(resourceId, beginDateTime, beginDateTime.AddHours(24)); Console.WriteLine("Purged rows: {0}", purgedRows); // Step 1: Get a resource res = CacheManager.Current.ResourceTree().GetResource(resourceId).GetResourceItem(); Assert.AreEqual(res.ResourceName, "EnerJet Evaporator"); // Step 2: Create a reservation // Step 2.1: Init process info, and add var processInfos = new Models.Scheduler.ReservationProcessInfoItem[] { new Models.Scheduler.ReservationProcessInfoItem() { ProcessInfoLineID = 110, Value = 100 } }; // Step 2.2: Create the new Reservation rsv1 = ReservationUtility.Create(new ReservationData(processInfos) { ClientID = 1301, ResourceID = res.ResourceID, AccountID = 67, ActivityID = 6, AutoEnd = true, KeepAlive = true, Notes = "created by unit test", ReservationDuration = new ReservationDuration(beginDateTime, res.Granularity) }); Assert.IsTrue(rsv1.ReservationID > 0); Console.WriteLine("Created ReservationID: {0}", rsv1.ReservationID); } using (ContextManager.StartRequest(1600)) { // Step 4: Modify existing // Step 4.1: Init process info, change value var processInfos = ServiceProvider.Current.Use <IProcessInfoManager>().GetReservationProcessInfos(rsv1.ReservationID); processInfos.First().Value = 200; // Step 4.2: Modify the existing Reservation rsv2 = ReservationUtility.Modify(rsv1, new ReservationData(processInfos) { ClientID = 1301, ResourceID = res.ResourceID, AccountID = rsv1.AccountID, ActivityID = rsv1.ActivityID, AutoEnd = true, KeepAlive = true, Notes = "modified by unit test", ReservationDuration = ReservationDuration.FromMinutes(beginDateTime, res.Granularity.TotalMinutes * 2) }); Assert.IsFalse(ReferenceEquals(rsv1, rsv2)); Assert.IsTrue(rsv2.ReservationID > 0); Console.WriteLine("Modified ReservationID: {0}", rsv2.ReservationID); } using (ContextManager.StartRequest(1600)) { var processInfos1 = ServiceProvider.Current.Use <IProcessInfoManager>().GetReservationProcessInfos(rsv1.ReservationID); Assert.AreEqual(1, processInfos1.Count); Assert.AreEqual(100, processInfos1.First().Value); var processInfos2 = ServiceProvider.Current.Use <IProcessInfoManager>().GetReservationProcessInfos(rsv2.ReservationID); Assert.AreEqual(1, processInfos2.Count); Assert.AreEqual(200, processInfos2.First().Value); } }
public bool IsThereAlreadyAnotherReservation(ReservationDuration rd, out string alert) { // This is called twice: once after btnSubmit is clicked (before the confirmation message is shown) and again // after btnConfirmYes is clicked (immediately before creating the reservation). // Check for other reservations made during this time // Select all reservations for this resource during the time of current reservation if (Helper.Provider == null) { throw new Exception("Provider is null."); } if (Resource == null) { throw new Exception("Resource is null."); } int reservationId = 0; if (Reservation != null) { reservationId = Reservation.ReservationID; } Helper.AppendLog($"ReservationModel.IsThereAlreadyAnotherReservation: Reservation is {(Reservation == null ? "null" : "not null")}, reservationId = {reservationId}"); var authLevel = GetCurrentAuthLevel(); var otherReservations = Helper.Provider.Scheduler.Reservation.SelectOverwritable(Resource.ResourceID, rd.BeginDateTime, rd.EndDateTime) ?? new List <IReservation>(); var count = otherReservations.Count(); Helper.AppendLog($"ReservationModel.IsThereAlreadyAnotherReservation: count = {count}"); if (count > 0) { bool isSameReservation; if (count == 1) { var other = otherReservations.First(); isSameReservation = other.ReservationID == reservationId; } else { isSameReservation = false; } Helper.AppendLog($"ReservationModel.IsThereAlreadyAnotherReservation: isSameReservation = {isSameReservation}, authLevel = {authLevel}"); if (!isSameReservation) { if (authLevel == ClientAuthLevel.ToolEngineer) { _overwriteReservations = otherReservations; } else { string[] conflicts = otherReservations.Select(x => $"ReservationID: {x.ReservationID}, Start: {x.BeginDateTime:yyyy-MM-dd HH:mm:ss}, End: {x.EndDateTime:yyyy-MM-dd HH:mm:ss}").ToArray(); string list = string.Join(Environment.NewLine, conflicts); alert = $"Cannot {(IsCreating() ? "create" : "modify")}. Another reservation has already been made for this time. [ReservationID: {reservationId}, Start: {rd.BeginDateTime:yyyy-MM-dd HH:mm:ss}, End: {rd.EndDateTime:yyyy-MM-dd HH:mm:ss}, Conflicts: {list}]"; return(true); } } } alert = string.Empty; return(false); }