public IActionResult AddSitting(Sitting sitting) { var a = _sittingRepository.GetSittingWithType().Where(e => e.SittingTypeId == sitting.SittingTypeId).FirstOrDefault(); //validate the time is not within in the existing list var validateDate = _sittingRepository.ValidateDate(sitting); if (sitting.Start < sitting.End && sitting.Start < DateTime.Now.AddDays(90)) { if (validateDate) { _sittingRepository.AddSitting(sitting); return(RedirectToAction("SittingList")); } else { ViewBag.ErrorMessage = "These Time already exists. Please choose another time."; ViewBag.SittingTypes = context.SittingTypes.ToList(); return(View(sitting)); } } else { ViewBag.ErrorMessage = "Sorry,Start Time must be before End Time or schedule must be within 90 days. Please choose another time."; ViewBag.SittingTypes = context.SittingTypes.ToList(); return(View(sitting)); } }
public async Task <bool> PressTheButton(Dictionary <int, int[]> t) { if (!await dbContext.Tables.AnyAsync()) { return(false); } foreach (var i in t) { var x = await Sitting(i.Key); if (i.Value.Length == 0 && x.Status) { var s = new Sitting(); s = x; s.Status = false; dbContext.Attach(s); await dbContext.SaveChangesAsync(); } else if (!x.Status && i.Value.Length != 0) { var s = new Sitting(); s = x; s.Status = true; dbContext.Attach(s); await dbContext.SaveChangesAsync(); } } return(true); }
public async Task <IActionResult> Edit(int id, [Bind("SittingTypeId,Id,Start,End,Capacity")] Sitting sitting) { if (id != sitting.Id) { return(NotFound()); } if (ModelState.IsValid) { try { sitting.RestuarantId = 1; _db.Update(sitting); await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SittingExists(sitting.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var sittingTypes = await _db.SittingTypes.ToListAsync(); //pull the data first! ViewBag.SittingTypeId = new SelectList(sittingTypes, "Id", "Name"); //collection , name of the prop== value/ name of display return(View(sitting)); }
public async Task <IActionResult> Edit(int id, [Bind("SittingTypeId,Id,Start,End,Capacity")] Sitting sitting) { if (id != sitting.Id) { return(NotFound()); } if (ModelState.IsValid) { try { sitting.RestuarantId = 1; _db.Update(sitting); await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SittingExists(sitting.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } // ViewData["RestuarantId"] = new SelectList(_db.Restuarants, "Id", "Id", sitting.RestuarantId); // ViewBag.SittingTypeId = new SelectList(_db.SittingTypes, "Id", "Name"); return(View(sitting)); }
public Session(long id, MoneyType moneyType, RoomType roomType, GameManager gameManager, long betValue) { this._hubContext = GlobalHost.ConnectionManager.GetHubContext <GameHub>(); this._connectionHandler = GlobalHost.DependencyResolver.Resolve <ConnectionHandler>(); this._gameManager = gameManager; this._locker = new object(); this._lockerBet = new object(); this.Id = id; this.MoneyType = moneyType; this.RoomType = roomType; this._players = new ConcurrentDictionary <long, Player>(); this.Sitting = new ConcurrentDictionary <int, Player>(); this.MaxPlayer = roomType == RoomType.TWELVE ? 12 : 50; if (roomType == RoomType.TWELVE) { Enumerable.Range(0, 12).Select(i => { return(Sitting.TryAdd(i + 1, null)); }).ToList(); } else { Enumerable.Range(0, 13).Select(i => { return(Sitting.TryAdd(i + 1, null)); }).ToList(); } this.SessionId = -1; this._deactive = false; this.BetValue = betValue; this.Banker = -1; this._lastSync = DateTime.Now; this.Result = -1; _timer = new Timer(new TimerCallback(Update), null, Timeout.Infinite, Timeout.Infinite); this._logic = new GameLogic(roomType, moneyType); this._alivePlayers = new ConcurrentQueue <long>(); this.History = new ConcurrentQueue <int>(); this._lockState = new object(); }
public Player Sit(long accountId, int position) { var player = GetPlayer(accountId); if (player == null) { throw new PlayerNotFoundException(); } lock (_locker) { if (Sitting.Values.ToList().Exists(x => x != null && x.AccountId == accountId)) { throw new AlreadySitException(); } if (Sitting[position] == null) { Sitting.AddOrUpdate(position, player, (k, v) => v = player); } else { throw new AlreadySitException(); } return(player); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,RestaurantId,Start,End,Capacity,Open,SittingTypeId")] Sitting sitting) { if (id != sitting.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(sitting); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SittingExists(sitting.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["RestaurantId"] = new SelectList(_context.Restaurants, "Id", "Id", sitting.RestaurantId); ViewData["SittingTypeId"] = new SelectList(_context.SittingTypes, "Id", "Description", sitting.SittingTypeId); return(View(sitting)); }
public void RemovePlayer(Player player, int reason) { lock (_locker) { if (_players.TryRemove(player.AccountId, out player)) { player.LeaveGame(); var lstConnection = _connectionHandler.GetConnections(player.AccountId); foreach (var connection in lstConnection) { _hubContext.Groups.Remove(connection, $"room_{Id}").Wait(); } _hubContext.Clients.Clients(lstConnection.ToList()).playerLeave(player.AccountId, reason, 0, 0); bool found = false; foreach (var s in Sitting) { if (s.Value != null && s.Value.AccountId == player.AccountId) { Player p = null; Sitting.AddOrUpdate(s.Key, p, (k, v) => v = p); _hubContext.Clients.Group($"room_{Id}").playerLeave(player.AccountId, reason, TotalPlayer, MaxPlayer); found = true; break; } } if (RoomType == RoomType.TWELVE) { if (player.AccountId == Banker) { Banker = -1; } } if (!found) { _hubContext.Clients.Group($"room_{Id}").ccu(TotalPlayer, MaxPlayer); } if (_players.Count == 0 && _currentState == State.WAITING) { this._deactive = true; this._timer.Change(-1, -1); _gameManager.DeactiveSession(this.Id); } else if (_players.Count == 0) { NextState(State.SHOW_RESULT, true); } } } }
public void UpdateSittingsDuration(EditSittingViewModel command) //Update Sittings start and end time { Sitting s = GetSittingById(command.SittingID); s.Sitting_StartTime = command.Sitting_StartTime; s.Sitting_EndTime = command.Sitting_EndTime; //update Database _context.SaveChanges(); }
public async Task <IActionResult> Create([Bind("Id,RestaurantId,Start,End,Capacity,Open,SittingTypeId")] Sitting sitting) { if (ModelState.IsValid) { _context.Add(sitting); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["RestaurantId"] = new SelectList(_context.Restaurants, "Id", "Id", sitting.RestaurantId); ViewData["SittingTypeId"] = new SelectList(_context.SittingTypes, "Id", "Description", sitting.SittingTypeId); return(View(sitting)); }
public async Task <IActionResult> Create([Bind("SittingTypeId,Start,End,Capacity")] Sitting sitting) { if (ModelState.IsValid) { sitting.RestuarantId = 1; _db.Add(sitting); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //ViewData["RestuarantId"] = new SelectList(_db.Restuarants, "Id", "Id", sitting.RestuarantId); // ViewBag.SittingTypeName = new SelectList(_db.SittingTypes, "Id", "Name"); return(View(sitting)); }
public IActionResult Detail(ReservationDeteailsViewModel m) { if (ModelState.IsValid) { // getting the New sitting ID based on its name Sitting s = _services.GetSittingByName(m.SittingName); // setting it to the model m.SittingID = s.SittingID; // using the model data to update the DB _services.UpdateReservation(m); // return to the Staf Page (Reservations list) return(RedirectToAction("Index")); } // stay in the details page if modelState is not valid return(View(m.ReservationID)); }
public IActionResult Detail(int id, string errormessage) { //get the reservation data from the database Reservation r = _services.GetReservationById(id); //get the Customer Data from the database Customer c = _services.GetCustomerById(r.CustomerID); //get the Sitting Data from the database Sitting s = _services.GetSittingById(r.SittingID); //get the Tables List of this reservation from the database List <Table_Reservation> tds = _services.GetTRList_byReservationID(r.ReservationID); //get the Area Name from the database string MyArea = _services.GetAreaByID(id); ReservationDeteailsViewModel model = new ReservationDeteailsViewModel() { //Sitting SittingID = s.SittingID, SittingName = s.SittingName, //Reservation ReservationID = r.ReservationID, NumberOfGuests = r.NumberOfGuests, AdditionalRequirements = r.AdditionalRequirements, Date = r.Date, StartTime = r.StartTime, EndTime = r.EndTime, Status = r.Status, Source = r.Source, //Customer CustomerId = c.CustomerID, FirstName = c.FirstName, LastName = c.LastName, Email = c.Email, PhoneNumber = c.PhoneNumber, //tables NumberOfTables = tds.Count, MyTR = tds, Area = MyArea }; //setting new error message model.Errormessage = errormessage; return(View(model)); }
public void CreateSittingAndTableSitting_ValidTest() { //Set up DB with InMemoryDatabase var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "T2RMSWS").Options; using (var ctext = new ApplicationDbContext(options)) { // Arrange var sitting = new Sitting { SittingTypeId = 1, StartDateTime = new DateTime(2020, 05, 29, 07, 00, 00, 0000000), EndDateTime = new DateTime(2020, 05, 20, 10, 00, 00, 0000000), Capacity = 100, SittingStatusId = 1, }; var tableSitting = new TableSitting() { SittingId = sitting.Id, TableId = 1 }; //Act ctext.Sittings.Add(sitting); ctext.TableSittings.Add(tableSitting); ctext.SaveChanges(); } using (var ctext = new ApplicationDbContext(options)) { //Act var sitting = ctext.Sittings.ToList(); var tableSitting = ctext.TableSittings .Include(s => s.Sitting) .ToList(); int expectedSitting = 1; int actualSitting = sitting.Count(); int expectedTS = 1; int actualTS = tableSitting.Count(); //Assert Assert.Equal(expectedSitting, actualSitting); Assert.Equal(expectedTS, actualTS); } }
public void SittingTest() { Sitting sitting = new Sitting { RestuarantId = 1, SittingTypeId = 1, Start = new DateTime(2020, 12, 20, 8, 30, 00), End = new DateTime(2020, 12, 20, 12, 30, 00), Capacity = 100, }; CreateReservation create = new CreateReservation(); create.Sitting = sitting; Assert.IsNotNull(create.Sitting); Assert.AreEqual(1, create.Sitting.RestuarantId); Assert.AreEqual(1, create.Sitting.SittingTypeId); Assert.AreEqual(new DateTime(2020, 12, 20, 8, 30, 00), create.Sitting.Start); Assert.AreEqual(new DateTime(2020, 12, 20, 12, 30, 00), create.Sitting.End); }
public IActionResult EditSitting(int id) { try { Sitting s = _services.GetSittingById(id); EditSittingViewModel Smodel = new EditSittingViewModel() { SittingID = s.SittingID, SittingName = s.SittingName, Sitting_EndTime = s.Sitting_EndTime, Sitting_StartTime = s.Sitting_StartTime }; return(View(Smodel)); } catch { return(RedirectToAction("Index")); } }
public async Task <IActionResult> Create([Bind("SittingTypeId,Start,End,Capacity")] Sitting sitting) { if (ModelState.IsValid) { sitting.RestuarantId = 1; _db.Add(sitting); await _db.SaveChangesAsync(); return (RedirectToAction(nameof(Index))); } //ViewData["RestuarantId"] = new SelectList(_db.Restuarants, "Id", "Id", sitting.RestuarantId); // ViewBag.SittingTypeName = new SelectList(_db.SittingTypes, "Id", "Name"); var sittingTypes = await _db.SittingTypes.ToListAsync(); //pull the data first! ViewBag.SittingTypeId = new SelectList(sittingTypes, "Id", "Name"); //collection , name of the prop== value/ name of display return(View(sitting)); }
public int AddPlayer(Player player) { long balance = this.MoneyType == MoneyType.GOLD ? player.Gold : player.Coin; if (balance < BetValue) { throw new NotEnoughMoneyException(); } lock (_locker) { if (this._deactive) { throw new RoomHasBeenDeactiveException(); } if (_players.Count == MaxPlayer) { throw new RoomFullException(); } player.RoomId = Id; player.SessionId = SessionId; _players.AddOrUpdate(player.AccountId, player, (k, v) => v = player); if (RoomType == RoomType.TWELVE & Banker == -1) { if (balance >= _logic.GetWinnerMulti(Gate.Even) * 2) { Banker = player.AccountId; } } this._alivePlayers.Enqueue(player.AccountId); foreach (var s in Sitting) { if (s.Value == null) { Sitting.AddOrUpdate(s.Key, player, (k, v) => v = player); return(s.Key); } } return(0); } }
public RedirectToActionResult Edit(Sitting sitting) { Sitting updatedSitting = _sittingRepository.Update(sitting); return(RedirectToAction("Detail", new { id = updatedSitting.SittingId })); }
public IActionResult Detail(int id) { Sitting model = _sittingRepository.GetSitting(id); return(View(model)); }