public void AutoMoveCoopPlayers(DayOfWeek day, DateTime gameDate) { List <Pool> pools = Manager.Pools.FindAll(pool => pool.DayOfWeek == day); if (pools.Count != 2) { return; } Pool highPool = Manager.Pools.Find(pool => pool.DayOfWeek == day && !pool.IsLowPool); Pool lowPool = Manager.Pools.Find(pool => pool.DayOfWeek == day && pool.IsLowPool); if (highPool.AutoCoopReserve && Manager.EastDateTimeToday == gameDate.Date && Manager.EastDateTimeNow.Hour >= highPool.ReservHourForCoop) { //Set last coop date for each coop player CalculatelastCoopDate(highPool, gameDate); Game highPoolGame = highPool.FindGameByDate(gameDate); Game lowPoolGame = lowPool.FindGameByDate(gameDate); int moveIntern = CalculateMoveIntern(highPool, lowPool, highPoolGame, lowPoolGame); if (moveIntern == -1 && Manager.EastDateTimeNow.Hour < highPool.SettleHourForCoop) { Dropin coopDropin = FindBestCoopCandidateToMoveBackOrignalPool(highPool, highPoolGame, lowPoolGame); if (coopDropin != null) { Player coopPlayer = Manager.FindPlayerById(coopDropin.PlayerId); MoveReservation(lowPool, lowPoolGame, coopPlayer); Manager.ReCalculateFactor(lowPool, gameDate); //Manager.ReCalculateFactor(highPool, gameDate); String wechatMessage = String.Format("Sorry, but we had to move your spot back to pool {0} for tonight's volleyball in order to balance the players in each pool. However we may move your spot again later when things change.", lowPool.Name); Manager.WechatNotifier.AddNotifyWechatMessage(coopPlayer, wechatMessage); Manager.AddReservationNotifyWechatMessage(coopPlayer.Id, CurrentUser.Id, Constants.MOVED, lowPool, highPool, lowPoolGame.Date); LogHistory log = CreateLog(Manager.EastDateTimeNow, gameDate.Date, GetUserIP(), lowPool.Name, coopPlayer.Name, "Moved from " + highPool.Name, "Admin"); Manager.Logs.Add(log); DataAccess.Save(Manager); } return; } //Check to see if moving coop to high level pool required, and number of reserved coop players already reaches maximum while (moveIntern == 1 && DropinSpotAvailableForCoop(highPool, gameDate)) { //Find the best coop Dropin coopDropin = FindNextCoopCandidateToMoveHighPool(highPool, highPoolGame, lowPoolGame); if (coopDropin == null) { break; } Player coopPlayer = Manager.FindPlayerById(coopDropin.PlayerId); MoveReservation(highPool, highPoolGame, coopPlayer); Manager.ReCalculateFactor(lowPool, gameDate); //Manager.ReCalculateFactor(highPool, gameDate); String wechatMessage = String.Format("We have moved your spot from pool {0} to pool {1} for tonight's volleyball in order to balance the players in each pool. However we may move you back later when things change." // + " if you don't receive any further notification by {2} o'clock, then this is the final arrangement.", lowPool.Name, highPool.Name, highPool.SettleHourForCoop); Manager.WechatNotifier.AddNotifyWechatMessage(coopPlayer, wechatMessage); Manager.AddReservationNotifyWechatMessage(coopPlayer.Id, null, Constants.MOVED, highPool, lowPool, lowPoolGame.Date); LogHistory log = CreateLog(Manager.EastDateTimeNow, gameDate.Date, GetUserIP(), highPool.Name, coopPlayer.Name, "Moved from " + lowPool.Name, "Admin"); Manager.Logs.Add(log); DataAccess.Save(Manager); moveIntern = CalculateMoveIntern(highPool, lowPool, highPoolGame, lowPoolGame); } } }
public void AssignDropinSpotToWaiting(Pool thePool, Game theGame) { if (IsReservationLocked(theGame.Date) || theGame.WaitingList.Count == 0 || !IsSpotAvailable(thePool, theGame.Date)) { return; } Waiting waiting = theGame.WaitingList[0]; String playerId = waiting.PlayerId; Player player = Manager.FindPlayerById(playerId); ReserveSpot(thePool, theGame, player); Manager.ReCalculateFactor(thePool, theGame.Date); theGame.WaitingList.Remove(playerId); Manager.AddReservationNotifyWechatMessage(playerId, null, Constants.WAITING_TO_RESERVED, thePool, thePool, theGame.Date); LogHistory log = CreateLog(Manager.EastDateTimeNow, theGame.Date, GetUserIP(), thePool.Name, Manager.FindPlayerById(playerId).Name, "Reserved", "Admin"); Manager.Logs.Add(log); theGame.WaitingList.Remove(playerId); //Cancel the member spot in another pool on same day Pool sameDayPool = Manager.Pools.Find(pool => pool.Name != thePool.Name && pool.DayOfWeek == thePool.DayOfWeek); if (CancelSpot(sameDayPool, sameDayPool.FindGameByDate(theGame.Date), player)) { Manager.ReCalculateFactor(sameDayPool, theGame.Date); Manager.AddReservationNotifyWechatMessage(playerId, null, Constants.CANCELLED, sameDayPool, sameDayPool, theGame.Date); AssignDropinSpotToWaiting(sameDayPool, sameDayPool.FindGameByDate(theGame.Date)); } }
public void AutoCancelUnconfirmedReservations() { if (Manager.EastDateTimeNow.Hour < Manager.AutoCancelHour || Manager.EastDateTimeNow.Hour >= Manager.LockReservationHour) { return; } foreach (Pool pool in Manager.Pools) { Game game = pool.FindGameByDate(Manager.EastDateTimeToday); if (game == null) { continue; } foreach (Attendee member in game.Members.Items.FindAll(m => !m.Confirmed)) { Player player = Manager.FindPlayerById(member.PlayerId); member.Status = InOutNoshow.Out; member.Confirmed = true; String message = "Your reservation of tonight's volleyball is cancelled by system"; Manager.WechatNotifier.AddNotifyWechatMessage(player, message); message = "Your reservation is cancelled. Currently we have " + game.NumberOfReservedPlayers + " players for tonight volleyball games"; Manager.WechatNotifier.AddNotifyWechatMessage(pool, player, message); LogHistory log = CreateLog(Manager.EastDateTimeNow, game.Date, GetUserIP(), pool.Name, player.Name, "Cancelled", "Admin"); Manager.Logs.Add(log); //Assing the spot to waiting list if (game.WaitingList.Count > 0) { AssignDropinSpotToWaiting(pool, game); } DataAccess.Save(Manager); } } }
protected void SaveBtn_Click(object sender, EventArgs e) { Player currentUser = Manager.FindPlayerById(Request.Cookies[Constants.PRIMARY_USER][Constants.USER_ID]); if (this.MonthDDL.SelectedValue.Length > 0 && this.DayDDL.SelectedValue.Length > 0) { currentUser.Birthday = MonthDDL.SelectedValue + "/" + this.DayDDL.SelectedValue; LogHistory log = new LogHistory(Manager.EastDateTimeNow, Manager.EastDateTimeToday, currentUser.Name, "", currentUser.Name, "Birthday: " + currentUser.Birthday, currentUser.Name); Manager.Logs.Add(log); DataAccess.Save(Manager); Response.Redirect(Constants.POOL_LINK_LIST_PAGE); } }
private void No_Show_Confirm_Click(object sender, EventArgs e) { String playerId = Session[Constants.CURRENT_PLAYER_ID].ToString(); Game game = CurrentPool.FindGameByDate(TargetGameDate); Player player = Manager.FindPlayerById(playerId); Handler.MarkNoShow(CurrentPool, game, player); String message = String.Format("[System Info] Hi, {0}. Admin marked you as no-show on the reservation of {1}. If you have any question, contact the admin", player.Name, game.Date.ToString("MM/dd/yyyy")); Manager.WechatNotifier.AddNotifyWechatMessage(player, message); LogHistory log = Handler.CreateLog(Manager.EastDateTimeNow, game.Date, Handler.GetUserIP(), CurrentPool.Name, Manager.FindPlayerById(playerId).Name, "Marked no-show", CurrentUser.Name); Manager.Logs.Add(log); Manager.ReCalculateFactor(CurrentPool, TargetGameDate); DataAccess.Save(Manager); Response.Redirect(Constants.RESERVE_PAGE); }
protected void Reserve_Confirm_Click(object sender, EventArgs e) { String playerId = Session[Constants.CURRENT_PLAYER_ID].ToString(); Player player = Manager.FindPlayerById(playerId); Game game = CurrentPool.FindGameByDate(TargetGameDate); if (Handler.ReserveSpot(CurrentPool, game, player)) { Manager.ReCalculateFactor(CurrentPool, TargetGameDate); Manager.AddReservationNotifyWechatMessage(player.Id, CurrentUser.Id, Constants.RESERVED, CurrentPool, CurrentPool, TargetGameDate); LogHistory log = Handler.CreateLog(Manager.EastDateTimeNow, game.Date, Handler.GetUserIP(), CurrentPool.Name, Manager.FindPlayerById(playerId).Name, "Reserved", CurrentUser.Name); Manager.Logs.Add(log); Handler.AutoMoveCoopPlayers(CurrentPool.DayOfWeek, game.Date); DataAccess.Save(Manager); } Response.Redirect(Constants.RESERVE_PAGE); }
//Cancel waiting protected void Cancel_Waiting_Click(object sender, EventArgs e) { if (Handler.IsReservationLocked(TargetGameDate) && !Manager.ActionPermitted(Actions.Change_After_Locked, CurrentUser.Role)) { ShowMessage(appLockedMessage); return; } ImageButton lbtn = (ImageButton)sender; String playerId = lbtn.ID; Game game = CurrentPool.FindGameByDate(TargetGameDate); game.WaitingList.Remove(playerId); LogHistory log = Handler.CreateLog(Manager.EastDateTimeNow, game.Date, Handler.GetUserIP(), CurrentPool.Name, Manager.FindPlayerById(playerId).Name, "Cancel waitinglist", CurrentUser.Name); Manager.Logs.Add(log); DataAccess.Save(Manager); this.PopupModal.Hide(); Response.Redirect(Constants.RESERVE_PAGE); }
private void MoveSpot(Pool pool, Game game, Player player) { Pool originalPool = Handler.MoveReservation(pool, game, player); Manager.ReCalculateFactor(CurrentPool, TargetGameDate); if (originalPool == null) { Manager.AddReservationNotifyWechatMessage(player.Id, CurrentUser.Id, Constants.RESERVED, pool, pool, game.Date); LogHistory log = Handler.CreateLog(Manager.EastDateTimeNow, game.Date, Handler.GetUserIP(), pool.Name, Manager.FindPlayerById(player.Id).Name, "Reserved", CurrentUser.Name); Manager.Logs.Add(log); } else { Manager.AddReservationNotifyWechatMessage(player.Id, CurrentUser.Id, Constants.MOVED, pool, originalPool, game.Date); LogHistory log = Handler.CreateLog(Manager.EastDateTimeNow, game.Date, Handler.GetUserIP(), pool.Name, Manager.FindPlayerById(player.Id).Name, "Moved from " + originalPool.Name, CurrentUser.Name); Manager.Logs.Add(log); } Handler.AutoMoveCoopPlayers(pool.DayOfWeek, game.Date); DataAccess.Save(Manager); Response.Redirect(Constants.RESERVE_PAGE); }
protected void Confirm_Click(object sender, EventArgs e) { if (Handler.IsReservationLocked(TargetGameDate) && !Manager.ActionPermitted(Actions.Change_After_Locked, CurrentUser.Role)) { ShowMessage(appLockedMessage); return; } ImageButton lbtn = (ImageButton)sender; String playerId = lbtn.ID; Game game = CurrentPool.FindGameByDate(TargetGameDate); Attendee member = game.Members.FindByPlayerId(playerId); member.Confirmed = true; LogHistory log = Handler.CreateLog(Manager.EastDateTimeNow, game.Date, Handler.GetUserIP(), CurrentPool.Name, Manager.FindPlayerById(playerId).Name, "Confirmed", CurrentUser.Name); Manager.Logs.Add(log); String message = String.Format("You confirmed your reservation for the volleyball game on {0}. If you change your mind, please cancel it. Thanks", game.Date.ToString("MM/dd/yyyy")); Manager.WechatNotifier.AddNotifyWechatMessage(Manager.FindPlayerById(playerId), message); DataAccess.Save(Manager); ShowMessage("Your reservation is confirmed !"); //Response.Redirect(Constants.RESERVE_PAGE); }
protected void AddWaitingList_Confirm_Click(object sender, ImageClickEventArgs e) { String playerId = Session[Constants.CURRENT_PLAYER_ID].ToString(); Game game = CurrentPool.FindGameByDate(TargetGameDate); if (game.WaitingList.Exists(playerId)) { return; } Pool otherPool = Manager.Pools.Find(p => p.Name != CurrentPool.Name && p.DayOfWeek == CurrentPool.DayOfWeek); if (otherPool != null && otherPool.Members.Exists(playerId) && !otherPool.FindGameByDate(TargetGameDate).Members.Items.Exists(member => member.PlayerId == playerId && member.Status == InOutNoshow.In)) { //Changed to allow holding a member spot in another pool when putting into waiting list // ShowMessage("Sorry, But you have aleady reserved a spot in pool " + pool.Name + " on the same day. Cancel that spot before adding onto the waiting list"); //return; } if (otherPool != null && otherPool.Dropins.Exists(playerId) && otherPool.FindGameByDate(TargetGameDate).Dropins.Items.Exists(dropin => dropin.PlayerId == playerId && dropin.Status == InOutNoshow.In)) { ShowMessage("Sorry, But you have aleady reserved a dropin spot in pool " + otherPool.Name + " on the same day. Cancel that spot beforeadding onto the waiting list"); return; } else if (otherPool.FindGameByDate(TargetGameDate).WaitingList.Exists(playerId)) { ShowMessage("Sorry, But you are on waiting list in pool " + otherPool.Name + " on the same day. Cancel that before adding onto the waiting list"); return; } Handler.AddToWaitingList(CurrentPool, game, Manager.FindPlayerById(playerId)); Manager.AddReservationNotifyWechatMessage(playerId, CurrentUser.Id, Constants.WAITING, CurrentPool, CurrentPool, TargetGameDate); LogHistory log = Handler.CreateLog(Manager.EastDateTimeNow, game.Date, Handler.GetUserIP(), CurrentPool.Name, Manager.FindPlayerById(playerId).Name, "Added to waiting list", CurrentUser.Name); Manager.Logs.Add(log); Handler.AutoMoveCoopPlayers(CurrentPool.DayOfWeek, game.Date); DataAccess.Save(Manager); Response.Redirect(Constants.RESERVE_PAGE); }