Beispiel #1
0
        public async Task <IActionResult> PostUsers([FromHeader] string UserName, [FromHeader] string UserPassword)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Users.Add(new Users {
                UserName = UserName, UserPassword = UserPassword
            });
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (UsersExists(UserName))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Beispiel #2
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            else
            {
                if (Password != Password2)
                {
                    Result = "Паролі не збігаються";
                    return(Page());
                }

                _context.Users.Add(new Users {
                    UserName = UserName, UserPassword = Password
                });
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateException)
                {
                    if (UsersExists(UserName))
                    {
                        Result = "Користувач з таким іменем вже зареєстрований";

                        return(Page());
                    }
                }

                return(Redirect("/LoginPage/" + UserName));
            }
        }
        public async Task <List <string> > PostScores([FromBody] Scores userscores)
        {
            _context.Scores.Add(userscores);

            await _context.SaveChangesAsync();

            var best_score = _context.Scores.ToList().Where(a => a.UserName == userscores.UserName).OrderByDescending(a => a.Score).Take(10);

            List <string> userscore = new List <string>();

            foreach (var item in best_score)
            {
                userscore.Add(item.Score.ToString());
            }

            return(userscore);
        }