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(); }
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()); }
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(); }