Exemplo n.º 1
0
        public IActionResult End([FromBody] GameDTO gameDto)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(Unauthorized());
            }
            var game = _gameRepository.FindById(gameDto.GameId);

            if (game == null)
            {
                return(NotFound(gameDto.GameId));
            }
            for (int i = 0; i < game.Players.Count; i++)
            {
                var user = _userRepository.FindByLogin(game.Players[i]);
                if (user != null)
                {
                    user.Guessed       += game.Scores[i].Guessed;
                    user.AlmostGuessed += game.Scores[i].AlmostGuessed;
                    user.PlusGame();
                    if (user.Record < game.Scores[i].Record)
                    {
                        user.Record = game.Scores[i].Record;
                    }
                    _userRepository.UpdateUser(user);
                }
            }
            //game.Status = Status.Ended;
            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Login([FromBody] UserDTO userDTO)
        {
            var user = userRepository.FindByLogin(userDTO.Login);

            if (user == null)
            {
                return(NotFound(userDTO.Login));
            }
            if (user.Password.CompareTo(DecodePassword(userDTO.Password)) != 0)
            {
                return(NotFound(userDTO.Password));
            }
            await Authenticate(userDTO.Login);

            return(Ok(userDTO));
        }
Exemplo n.º 3
0
        public IActionResult Profile([FromRoute] string login)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                return(Unauthorized());
            }
            var user = _userRepository.FindByLogin(login);

            if (user == null)
            {
                return(NotFound());
            }
            var profile = new UserProfileDTO
            {
                Login         = user.Login,
                Photo         = user.Photo,
                CountGames    = user.CountGames,
                Record        = user.Record,
                Guessed       = user.Guessed,
                AlmostGuessed = user.AlmostGuessed
            };

            return(Json(profile));
        }