public JSONBooking[][] RemoveBooking(string Date, JSONBooking booking, string i) { HAP.Data.SQL.WebEvents.Log(DateTime.Now, "BookingSystem.Remove", ((HAP.AD.User)Membership.GetUser()).UserName, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Browser.Platform, HttpContext.Current.Request.Browser.Browser + " " + HttpContext.Current.Request.Browser.Version, HttpContext.Current.Request.UserHostName, "Removing " + booking.Name); HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)); Booking b = bs.getBooking(booking.Room, booking.Lesson)[int.Parse(i)]; try { BookingRules.Execute(b, hapConfig.Current.BookingSystem.Resources[b.Room], bs, BookingRuleType.Booking, true); } catch (Exception ex) { HAP.Web.Logging.EventViewer.Log("Booking System JSON API", ex.ToString() + "\nMessage:\n" + ex.Message + "\nStack Trace:\n" + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error); } try { if (!string.IsNullOrEmpty(b.uid) && hapConfig.Current.SMTP.Enabled) { iCalGenerator.GenerateCancel(b, DateTime.Parse(Date)); if (hapConfig.Current.BookingSystem.Resources[booking.Room].EmailAdmins) { iCalGenerator.GenerateCancel(b, DateTime.Parse(Date), true); } } } catch (Exception ex) { HAP.Web.Logging.EventViewer.Log("Booking System JSON API", ex.ToString() + "\nMessage:\n" + ex.Message + "\nStack Trace:\n" + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error); } XmlDocument doc = HAP.BookingSystem.BookingSystem.BookingsDoc; XmlNodeList nodes = doc.SelectNodes("/Bookings/Booking[@date='" + DateTime.Parse(Date).ToShortDateString() + "' and @lesson[contains(., '" + booking.Lesson + "')] and @room='" + booking.Room + "']"); doc.SelectSingleNode("/Bookings").RemoveChild(nodes[int.Parse(i)]); HAP.BookingSystem.BookingSystem.BookingsDoc = doc; return(LoadRoom(Date, booking.Room)); }
public JSONBooking[][] Return(string Date, string Resource, string lesson) { hapConfig config = hapConfig.Current; HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)); Booking b = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)).getBooking(Resource, lesson)[0]; XmlDocument doc = HAP.BookingSystem.BookingSystem.BookingsDoc; List <string> newlesson = new List <string>(); bool go = false; foreach (Lesson l in config.BookingSystem.Lessons) { if (b.Lesson.StartsWith(l.Name)) { go = true; } if (go) { newlesson.Add(l.Name); } if (l.Name == lesson) { go = false; } } doc.SelectSingleNode("/Bookings/Booking[@date='" + DateTime.Parse(Date).ToShortDateString() + "' and @lesson[contains(., '" + lesson + "')] and @room='" + Resource + "']").Attributes["lesson"].Value = string.Join(", ", newlesson.ToArray()); b.Lesson = string.Join(", ", newlesson.ToArray()); // update b.Lesson to reflect what just went into the XML above (ready for booking rules) HAP.BookingSystem.BookingSystem.BookingsDoc = doc; try { BookingRules.Execute(b, hapConfig.Current.BookingSystem.Resources[b.Room], bs, BookingRuleType.Return, false); } catch (Exception ex) { HAP.Web.Logging.EventViewer.Log("Booking System JSON API", ex.ToString() + "\nMessage:\n" + ex.Message + "\nStack Trace:\n" + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error); } if (config.SMTP.Enabled) { iCalGenerator.GenerateCancel(b, DateTime.Parse(Date)); if (config.BookingSystem.Resources[b.Room].EmailAdmins) { iCalGenerator.GenerateCancel(b, DateTime.Parse(Date), true); } } return(LoadRoom(Date, Resource)); }
public JSONBooking[][] LoadRoom(string Date, string Resource) { Resource = HttpUtility.UrlDecode(Resource, System.Text.Encoding.Default).Replace("%20", " "); List <JSONBooking[]> bookings = new List <JSONBooking[]>(); HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)); foreach (Lesson lesson in hapConfig.Current.BookingSystem.Lessons) { List <JSONBooking> js = new List <JSONBooking>(); foreach (Booking b in bs.getBooking(Resource, lesson.Name)) { object result = null; JSONBooking j = null; if (b.Name == "FREE") { result = BookingRules.Execute(b, hapConfig.Current.BookingSystem.Resources[Resource], bs, BookingRuleType.PreProcess, false); if (result != null) { j = new JSONBooking((Booking)result); } } if (j == null) { j = new JSONBooking(b); } if (b.Resource.Type == ResourceType.Loan) { j.Lesson = lesson.Name; } if (b.Name == "CHARGING" || b.Name == "UNAVAILABLE") { js.Add(j); break; } js.Add(j); } bookings.Add(js.ToArray()); } WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json; return(bookings.ToArray()); }
public JSONBooking[][] Book(string Date, JSONBooking booking) { HAP.Data.SQL.WebEvents.Log(DateTime.Now, "BookingSystem.Book", ((HAP.AD.User)Membership.GetUser()).UserName, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Browser.Platform, HttpContext.Current.Request.Browser.Browser + " " + HttpContext.Current.Request.Browser.Version, HttpContext.Current.Request.UserHostName, "Booking " + booking.Name); try { HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)); if (booking.Static) { if (!bs.isStatic(booking.Room, booking.Lesson)) { bs.addStaticBooking(new Booking { Name = booking.Name, Lesson = booking.Lesson, Username = booking.Username, Room = booking.Room, Day = bs.DayNumber }); } else { throw new Exception("Static Booking Already Exists for period " + booking.Lesson + " with resource " + booking.Room); } } else { hapConfig config = hapConfig.Current; if (!config.BookingSystem.Resources[booking.Room].CanShare) { // if bookings can't be shared, need to check here that booking doesn't already exist Booking[] existing = bs.getBooking(booking.Room, booking.Lesson); if (existing[0] != null && !existing[0].Static && existing[0].Name != "FREE") { throw new Exception("Booking Already Exists for period " + booking.Lesson + " with resource " + booking.Room); } } XmlDocument doc = HAP.BookingSystem.BookingSystem.BookingsDoc; XmlElement node = doc.CreateElement("Booking"); node.SetAttribute("date", DateTime.Parse(Date).ToShortDateString()); node.SetAttribute("lesson", booking.Lesson); if (config.BookingSystem.Resources[booking.Room].Type == ResourceType.Laptops) { node.SetAttribute("ltroom", booking.LTRoom); node.SetAttribute("ltheadphones", booking.LTHeadPhones.ToString()); } else if (config.BookingSystem.Resources[booking.Room].Type == ResourceType.Equipment || config.BookingSystem.Resources[booking.Room].Type == ResourceType.Loan) { node.SetAttribute("equiproom", booking.EquipRoom); } node.SetAttribute("room", booking.Room); node.SetAttribute("uid", booking.Username + DateTime.Now.ToString(iCalGenerator.DateFormat)); node.SetAttribute("username", booking.Username); node.SetAttribute("count", booking.Count.ToString()); node.SetAttribute("name", booking.Name); if (booking.Count >= 0) { node.SetAttribute("count", booking.Count.ToString()); } if (!string.IsNullOrWhiteSpace(booking.Notes)) { node.SetAttribute("notes", booking.Notes); } doc.SelectSingleNode("/Bookings").AppendChild(node); HAP.BookingSystem.BookingSystem.BookingsDoc = doc; Booking[] b1 = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)).getBooking(booking.Room, booking.Lesson); Booking b = b1[b1.Length - 1]; if (config.SMTP.Enabled) { iCalGenerator.Generate(b, DateTime.Parse(Date)); if (config.BookingSystem.Resources[b.Room].EmailAdmins) { iCalGenerator.Generate(b, DateTime.Parse(Date), true); } } BookingRules.Execute(b, config.BookingSystem.Resources[b.Room], new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)), BookingRuleType.Booking, false); } } catch (Exception e) { HAP.Web.Logging.EventViewer.Log(HttpContext.Current.Request.RawUrl, e.ToString() + "\nMessage:\n" + e.Message + "\n\nStack Trace:\n" + e.StackTrace, System.Diagnostics.EventLogEntryType.Error); } return(LoadRoom(Date, booking.Room)); }