Esempio n. 1
0
 public Table AddTable(Table table)
 {
     if (string.IsNullOrEmpty(table?.Name))
     {
         throw new ArgumentNullException(nameof(table));
     }
     using (var context = new XoContext())
     {
         if (context.Table.Any(t => t.Name == table.Name))
         {
             return(context.Table.FirstOrDefault(x => x.Name == table.Name));
         }
         var owner = _currentUserUserRepository.GetUserSession();
         table = new Table
         {
             Id      = Guid.NewGuid(),
             Owner   = owner,
             OwnerId = _currentUserUserRepository.GetUserSession()?.Id ?? Guid.Empty,
             Players = new List <Registered> {
                 _currentUserUserRepository.GetUserSession()
             },
             Name = table.Name
         };
         context.Entry(table.Owner).State = EntityState.Unchanged;
         context.Table.Add(table);
         context.SaveChanges();
     }
     return(table);
 }
Esempio n. 2
0
        public IHttpActionResult IsAuthorized(Registered player)
        {
            if (player == null)
            {
                return(BadRequest());
            }

            // check if there is an active session
            var sessionPlayer = _userSessionUserRepository.GetUserSession();

            if (sessionPlayer != null)
            {
                return(Ok(sessionPlayer));
            }

            // if User is authenticated succeccfully data is saved in session and response code 200 is returned
            var currentPlayer = _playerBusinessModel.UserExists(player.Name, player.Password);

            if (currentPlayer != null)
            {
                _userSessionUserRepository.SetUserSession(currentPlayer);
                return(Ok(currentPlayer));
            }
            return(BadRequest());
        }
Esempio n. 3
0
        // GET: Home
        public ActionResult Index()
        {
            var player = _userSessionUserModel.GetUserSession();

            ViewBag.authenticated = player == null ? "0" : "1";
            if (player == null)
            {
                ViewBag.currentPlayer = new {}
            }
            ;
            else
            {
                ViewBag.currentPlayer = player;
            }
            return(View());
        }