public ActionResult Index(PlayerViewModel playerViewModel) { PlayerDAL playerDAL = new PlayerDAL(); List <Player> ListOfPlayers = playerDAL.GetAll(); bool IsExisting = false; foreach (var player in ListOfPlayers) { if (playerViewModel.Nick == player.Nick) { IsExisting = true; } } if (IsExisting) { Session["username"] = playerViewModel.Nick; //jesli istnieje to logujemy } else { playerDAL.Add(new Player { Nick = playerViewModel.Nick }); Session["username"] = playerViewModel.Nick; //dodajemy do sesji } return(View(playerViewModel)); }
public ActionResult Room() { RoomViewModel roomViewModel = new RoomViewModel(); roomViewModel.UsPlayer = PlayerDAL.GetByName(Session["username"].ToString()); roomViewModel.ListOfRooms = RoomDAL.GetAll(); if (roomViewModel.UsPlayer.Room != null) { roomViewModel.Room = RoomDAL.Get(Convert.ToInt32(roomViewModel.UsPlayer.Room)); roomViewModel.PlayersInRoom = PlayerDAL.GetAll().Where(x => x.Room == roomViewModel.Room.Id).ToList(); roomViewModel.GamesInRoom = GameDAL.GetAll().Where(x => x.Room == roomViewModel.Room.Id).ToList(); } return(View(roomViewModel)); }