/// <summary> /// Splits the over multple days. /// </summary> /// <param name = "appObj">The app obj.</param> /// <returns></returns> private static IEnumerable <AppointmentTemporaryObj> SplitOverMultpleDays(AppointmentTemporaryObj appObj) { var list = new List <AppointmentTemporaryObj>(); //If Enddate is null or start date matches endate if (appObj.EndDate == null || appObj.StartDate == appObj.EndDate) { list.Add(appObj); return(list); } var dayList = RoomAvailabilityUtilities.ParseDayString(appObj.Days); //Iterate over each date in range for (var date = appObj.StartDate; date.Date < appObj.EndDate; date = date.AddDays(1)) { //If the current day doesn't exist in the current list of days then continue. if (dayList.Count > 0 && !dayList.Contains(date.DayOfWeek)) { continue; } //Create new Appoint Temp Obj list.Add(new AppointmentTemporaryObj { AllDay = appObj.AllDay, Days = appObj.Days, EndDate = date, StartDate = date, StartTime = appObj.StartTime, EndTime = appObj.EndTime }); } return(list); }
/// <summary> /// Rebinds the grid and scheduler. /// </summary> private void RebindGridAndScheduler() { _rgAvailableTimes.Rebind(); var db = new UrbanDataContext(); var selectedDate = _rsReservations.SelectedDate; Appointments = RoomAvailabilityUtilities.GetAppointmentObjsWithRecurring(ref db, new DateTime(selectedDate.Year, selectedDate.Month, 1), new DateTime(selectedDate.Year, selectedDate.Month, 1).AddMonths(1).AddDays(-1), Utilities.GetQueryStringInt("roomId")).ToList(); _rsReservations.DataSource = Appointments; }
/// <summary> /// Handles the OnNavigationComplete event of the _rsReservations control. /// </summary> /// <param name = "sender">The source of the event.</param> /// <param name = "e">The <see cref = "Telerik.Web.UI.SchedulerNavigationCompleteEventArgs" /> instance containing the event data.</param> protected void _rsReservations_OnNavigationComplete(object sender, SchedulerNavigationCompleteEventArgs e) { var db = new UrbanDataContext(); var selectedDate = _rsReservations.SelectedDate; Appointments = RoomAvailabilityUtilities.GetAppointmentObjsWithRecurring(ref db, new DateTime(selectedDate.Year, selectedDate.Month, 1), new DateTime(selectedDate.Year, selectedDate.Month, 1).AddMonths(1).AddDays(-1), Utilities.GetQueryStringInt("roomId")).ToList(); _rsReservations.DataSource = Appointments; _rsReservations.Rebind(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init"/> event to initialize the page. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); if (!IsPostBack) { var db = new UrbanDataContext(); ViewState["Appointments"] = RoomAvailabilityUtilities.GetAppointmentObjsWithRecurring(ref db, new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1), Utilities.GetQueryStringInt("RoomId")); } _rsReservations.DataSource = Appointments; }
/// <summary> /// Overlapses the with no end dates. /// </summary> /// <param name = "a">A.</param> /// <param name = "b">The b.</param> /// <returns></returns> private static bool OverlapsWithNoEndDates(AppointmentTemporaryObj a, AppointmentTemporaryObj b) { var aDays = RoomAvailabilityUtilities.ParseDayString(a.Days); var bDays = RoomAvailabilityUtilities.ParseDayString(b.Days); var overLapList = aDays.Where(bDays.Contains).ToList(); if (overLapList.Count == 0) { return(false); } //Compare start time vs end time return(!(b.EndTime <= a.StartTime || a.EndTime <= b.StartTime)); }
/// <summary> /// Handles the Click event of the _btnAddDates control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void _btnAddDates_Click(object sender, EventArgs e) { var date = (DateTime)_rdpDate.DbSelectedDate; var startTime = ((DateTime)_rtpStartTime.DbSelectedDate).TimeOfDay; var endTime = ((DateTime)_rtpEndTime.DbSelectedDate).TimeOfDay; var appt = new AppointmentObj { Busy = true, Days = String.Empty, End = date.Add(endTime), Start = date.Add(startTime), }; var isVald = GetIsValdAddDates(startTime, endTime); if (isVald == false) { return; } foreach (var d in ReservedAppt) { if ((d.ToAppointmentObj().Start == appt.Start && d.ToAppointmentObj().End == appt.End) || (d.ToAppointmentObj().Start.Date == date && !appt.AllowedToAdd(d.ToAppointmentObj()))) { WriteToBothFeedback(FeedbackType.Error, "Date conflicts with existing reserved date"); return; } } var db = new UrbanDataContext(); var currentAvailabilityDates = RoomAvailabilityUtilities.GetAppointmentObjsWithRecurring(ref db, DateTime.MinValue, DateTime.MaxValue, RoomId).Where(t => t.Start.Date == date && t.End.Date == date).ToList(); var validToAdd = false; foreach (var c in currentAvailabilityDates) { if (c.Busy == false && appt.AllowedToAdd(c)) { validToAdd = true; } else if (c.Busy == true && appt.OverlapsWith(c)) { validToAdd = false; break; } } if (validToAdd) { WriteToBothFeedback(FeedbackType.Success, "Date Added"); ReservedAppt.Add(new ReserveRoomTempObject { Date = date, End = endTime, Start = startTime }); } else { WriteFeedBackMaster(FeedbackType.Error, "Date is not valid or overlaps with another date"); } _rgAvailableTimes.Rebind(); }