public async Task Launch(Reference <Ship> ship, Reference <Player> player) { using var dbContextScope = dbContextScopeFactory.Create(); var s = Ship.Launch(ship, player); await shipRepository.Save(s); await dbContextScope.SaveChangesAsync(); }
public ActionResult <ShipDto> AddShip(ApiVersion version, [FromBody] ShipCreateDto shipCreateDto) { if (shipCreateDto == null) { return(BadRequest()); } ShipEntity toAdd = _mapper.Map <ShipEntity>(shipCreateDto); _shipRepository.Add(toAdd); if (!_shipRepository.Save()) { throw new Exception("Creating a ship failed on save."); } ShipEntity newShipItem = _shipRepository.GetSingle(toAdd.ShipId); return(CreatedAtRoute(nameof(GetSingleShip), new { version = version.ToString(), id = newShipItem.ShipId }, _mapper.Map <ShipDto>(newShipItem))); }