Ejemplo n.º 1
0
        /// <summary>
        /// End date needs to have time = 23 and start time = 0 or 1
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="roomId">The room id.</param>
        /// <returns></returns>
        public static IEnumerable <AppointmentObj> GetAppointmentObjsWithRecurring(ref UrbanDataContext db, DateTime startDate, DateTime endDate, int roomId)
        {
            var apptList = new List <AppointmentObj>();
            var aList    = db.Manager.RoomAvailability.GetByRoomAndDateRange(startDate, endDate, roomId);

            if (aList.Any(t => t.EndDate != null && (t.StartDate.Add(t.StartTime) >= ((DateTime)t.EndDate).Add(t.EndTime) || ((DateTime)t.EndDate).Add(t.EndTime) <= t.StartDate.Add(t.StartTime))))
            {
                throw new Exception("Date Ranges Are Not Valid");
            }

            foreach (var date in aList)
            {
                if (date.Days == null) // Non Recurring Dates
                {
                    apptList.Add(new AppointmentObj("Available", DateUtil.CombineDateAndTime(date.StartDate, date.StartTime), DateUtil.CombineDateAndTime(date.EndDate, date.EndTime), "", "", "", date.Room.UserID, false, date.Id));
                }
                else // Recurring Dates
                {
                    var reccuringApptDates = CalculateRecurringFromAvailble(date, endDate);
                    apptList.AddRange(reccuringApptDates);
                }
            }
            return(apptList);
        }