Пример #1
0
        public async Task <ActionResult <Player> > Post(Player player)
        {
            await _playersService.CreatePlayer(player);

            //TODO: autoincrement
            return(CreatedAtAction("Post", new { id = player.Id }, player));
        }
Пример #2
0
        public async Task <PlayerModel> CreatePlayer([FromBody] CreatePlayerCommand command)
        {
            if (command == null)
            {
                throw new ArgumentException(nameof(command));
            }

            return(await playerService.CreatePlayer(command));
        }
Пример #3
0
        public async Task <IActionResult> CreatePlayer(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = CREATE_PLAYER)] HttpRequest req,
            ILogger log)
        {
            try
            {
                log.LogInformation($"C# HTTP trigger function processed a request {nameof(CreatePlayer)}.");

                string requestBodyJson = await new StreamReader(req.Body).ReadToEndAsync();
                var    createPlayerDto = JsonConvert.DeserializeObject <CreatePlayerDto>(requestBodyJson);

                var newPlayerDto = await _playersService.CreatePlayer(createPlayerDto);

                var response = new ResponseModel <PlayerDto, CreatePlayerDto>(newPlayerDto, req.Path, createPlayerDto);
                return(new OkObjectResult(response));
            }
            catch (Exception ex)
            {
                log.LogError(ex, "_");
                throw;
            }
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var town = _townsService.GetTownByName <Town>(Input.Town);

                if (town == null)
                {
                    town = _townsService.CreateTown(Input.Town);
                }

                var user = new FooteoUser
                {
                    UserName  = Input.Username,
                    Email     = Input.Email,
                    FirstName = Input.FirstName,
                    LastName  = Input.LastName,
                    Age       = Input.Age,
                    Town      = town
                };

                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    var role = Input.Role;

                    if (_userManager.Users.Count() == GlobalConstants.UserCountCheckForAdmin)
                    {
                        await _userManager.AddToRoleAsync(user, GlobalConstants.AdminRoleName);
                    }
                    else
                    {
                        await _userManager.AddToRoleAsync(user, role);

                        if (role == GlobalConstants.PlayerRoleName)
                        {
                            var player = new Player
                            {
                                FullName = $"{user.FirstName} {user.LastName}"
                            };
                            _playersService.CreatePlayer(user, player);
                        }

                        if (role == GlobalConstants.RefereeRoleName)
                        {
                            var referee = new Referee
                            {
                                FullName = $"{user.FirstName} {user.LastName}"
                            };

                            _refereesService.CreateReferee(user, referee);
                        }
                    }

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Пример #5
0
        public IActionResult Create(Player player)
        {
            var result = _playersService.CreatePlayer(player);

            return(Ok(result));
        }