Пример #1
0
        public async Task ValidateForCreate(IPrincipal currentPrincipal, GamePositionCreateModel model)
        {
            if (!(await ValidateExistingUserId(model.PlayerId)))
            {
                AddError("There is no such user.");
            }

            await ValidateCurrentUser(currentPrincipal, model.PlayerId);

            ValidateShipsPositions(model.Ships);

            HandleErrors();
        }
Пример #2
0
        public async Task <IHttpActionResult> Create(int gameId, GamePositionCreateModel model)
        {
            IPrincipal principal = RequestContext.Principal;
            await validationService.ValidateForCreate(principal, model);

            try
            {
                await positionService.CreateAsync(gameId, model);
            }
            catch (ShipsAlreadyAddedException)
            {
                return(Conflict("Ships already added for this user."));
            }

            return(base.NoContent());
        }
Пример #3
0
        public async Task CreateAsync(int gameId, GamePositionCreateModel model)
        {
            Game game = (await context.Games.Where(x => x.Id == gameId)
                         .Include("FirstSide")
                         .Include("FirstSide.Ships")
                         .Include("SecondSide")
                         .Include("SecondSide.Ships")
                         .ToListAsync()).FirstOrDefault();

            if (game.FirstSide.PlayerFK == model.PlayerId)
            {
                HandleAddingShips(game, game.FirstSide, game.SecondSide, model.Ships);
            }
            else
            {
                HandleAddingShips(game, game.SecondSide, game.FirstSide, model.Ships);
            }

            await context.SaveChangesAsync();
        }