public void cancelReservation(string resid, int day, int month, int year) { ReservationConsole.getInstance().cancelReservation(Int32.Parse(resid)); GlobalHost.ConnectionManager.GetHubContext <CalendarHub>().Clients.Group(User.Identity.GetUserId()).incomingMessage("Reservation has been successfully cancelled"); getReservations(); updateCalendar(year, month, day); }
//Techiincally asp/signarl autmatically converts to json when you pass an object to javascript but here we just convert it into an easy to digest object public List <object> convertToJsonObject(List <Reservation> reservationList) { int firstTimeSlot; int lastTimeSlot; List <object> list = new List <object>(); for (int i = 0; i < (reservationList.Count()); i++) { firstTimeSlot = reservationList[i].timeSlots[0].hour; lastTimeSlot = reservationList[i].timeSlots[reservationList[i].timeSlots.Count() - 1].hour; list.Add(new { initialTimeslot = firstTimeSlot, finalTimeslot = lastTimeSlot, roomId = reservationList[i].roomID, description = reservationList[i].description, userName = ReservationConsole.getInstance().getUserCatalog().First(x => x.userID == reservationList[i].userID).name, reservationId = reservationList[i].reservationID, userId = reservationList[i].userID, date = reservationList[i].date.Date }); } return(list); }
public void updateCalendar(int year, int month, int day) { DateTime date = new DateTime(year, month, day); var hubContext = GlobalHost.ConnectionManager.GetHubContext <CalendarHub>(); hubContext.Clients.All.updateCalendar(convertToJsonObject(ReservationConsole.getInstance().findByDate(date))); hubContext.Clients.All.updateWaitlist(ReservationConsole.getInstance().getAllTimeSlots(), convertToJsonObject(ReservationConsole.getInstance().findByDate(date)), ReservationConsole.getInstance().getUserCatalog()); }
public User isValid(string username, string password) { //go through the usercatalog to find the user foreach (User user in ReservationConsole.getInstance().getUserCatalog()) { if (user.username == username && user.password == password) { return(user); } } return(null); }
public void getReservations() { if (User.Identity.IsAuthenticated) { var hubContext = GlobalHost.ConnectionManager.GetHubContext <CalendarHub>(); var JsonListofReservations = convertToJsonObject(ReservationConsole.getInstance().findByUser(Int32.Parse(User.Identity.GetUserId()))); hubContext.Clients.All.populateReservations(JsonListofReservations); //returns a list of reservations in the js function } else { var hubContext = GlobalHost.ConnectionManager.GetHubContext <CalendarHub>(); var JsonListofReservations = convertToJsonObject(ReservationConsole.getInstance().getAllReservations()); hubContext.Clients.All.populateReservations(JsonListofReservations); } }
public void modifyReservation(int roomId, string date, int initialTimeslot, int finalTimeslot, int resid, int day, int month, int year, string description) { string[] dateArray = date.Split('-'); var userID = Int32.Parse(User.Identity.GetUserId()); var dateOfRes = new DateTime(Int32.Parse(dateArray[0]), Int32.Parse(dateArray[1]), Int32.Parse(dateArray[2])); var weeklyConstraint = ReservationConsole.getInstance().weeklyConstraintCheck(userID, dateOfRes); var dailyConstraint = ReservationConsole.getInstance().dailyConstraintCheck(userID, dateOfRes, initialTimeslot, initialTimeslot); if (dailyConstraint && weeklyConstraint) { ReservationConsole.getInstance().modifyReservation(resid, roomId, description, dateOfRes, initialTimeslot, finalTimeslot - 1); GlobalHost.ConnectionManager.GetHubContext <CalendarHub>().Clients.Group(User.Identity.GetUserId()).incomingMessage("Reservation has been successfully modifed"); getReservations(); updateCalendar(year, month, day); } }
public void makeReservation(int room, string description, int day, int month, int year, int firstTimeSlot, int lastTimeSlot) { if (Monitor.TryEnter(_lockobject[room], TimeSpan.FromSeconds(59))) { var userID = Int32.Parse(User.Identity.GetUserId()); var date = new DateTime(year, month, day); var weeklyConstraint = ReservationConsole.getInstance().weeklyConstraintCheck(userID, date); var dailyConstraint = ReservationConsole.getInstance().dailyConstraintCheck(userID, date, firstTimeSlot, lastTimeSlot); if (dailyConstraint && weeklyConstraint) { Thread.Sleep(4000); //sleep function for the room lock, make reservation takes ReservationConsole.getInstance().makeReservation(userID, room, description, date, firstTimeSlot, lastTimeSlot); GlobalHost.ConnectionManager.GetHubContext <CalendarHub>().Clients.Group(User.Identity.GetUserId()).incomingMessage("Reservation has been successfully created"); updateCalendar(year, month, day); } Monitor.Exit(_lockobject[room]); } }