public async Task <IActionResult> Add([FromBody] PlanetResponseViewModel planet) { var(Name, RotationPeriod, OrbitalPeriod, Diameter, Climate, Gravity, Terrain, SurfaceWater, Population, Residents, Films) = planet; var newPlanet = new Planet { Name = Name, RotationPeriod = RotationPeriod, OrbitalPeriod = OrbitalPeriod, Diameter = Diameter, Climate = Climate, Gravity = Gravity, Terrain = Terrain, SurfaceWater = SurfaceWater, Population = Population }; if (Films != null) { var planetFilms = Films.Select(f => new FilmPlanet { PlanetId = newPlanet.Id, FilmId = f.Id }).ToList(); newPlanet.Films = planetFilms; } if (Residents != null) { var planetResidents = Residents.Select(p => new People { Id = p.Id }).ToList(); newPlanet.Residents = planetResidents; } bool planetAdded = await _planetRepository.Add(newPlanet); if (planetAdded) { return(Ok(new { status = "success", data = "planet added" })); } return(Ok(new { status = "error", data = "error adding planet" })); }
public WebGameMutation( IPlayerRepository playerRepository, IPlanetRepository planetRepository, ICountryRepository countryRepository, ICityRepository cityRepository ) { //Name = "CreatePlayerMutation"; Field <PlayerType>( "createPlayer", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <PlayerInputType> > { Name = "player" } ), resolve: context => { var player = context.GetArgument <Player>("player"); return(playerRepository.Add(player)); }); Field <PlanetType>( "createPlanet", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <PlanetInputType> > { Name = "planet" } ), resolve: context => { var planet = context.GetArgument <Planet>("planet"); return(planetRepository.Add(planet)); }); Field <CountryType>( "createCountry", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <CountryInputType> > { Name = "country" } ), resolve: context => { var country = context.GetArgument <Country>("country"); return(countryRepository.Add(country)); }); Field <CityType>( "createCity", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <CityInputType> > { Name = "city" } ), resolve: context => { var city = context.GetArgument <City>("city"); return(cityRepository.Add(city)); }); Field <CityType>( "addCity", arguments: new QueryArguments(new[] { new QueryArgument <NonNullGraphType <AddCityInputType> > { Name = "cityLink" }, } ), resolve: context => { var dico = (Dictionary <string, object>)context.Arguments["cityLink"]; var country = (int)dico["country"]; var city = (int)dico["city"]; return(countryRepository.Add(country, city)); }); Field <PlanetType>( "addCoutry", arguments: new QueryArguments(new[] { new QueryArgument <NonNullGraphType <AddCountryInputType> > { Name = "countryLink" }, } ), resolve: context => { var dico = (Dictionary <string, object>)context.Arguments["countryLink"]; var planet = (int)dico["planet"]; var country = (int)dico["country"]; return(planetRepository.Add(planet, country)); }); Field <PlayerType>( "setCity", arguments: new QueryArguments(new[] { new QueryArgument <NonNullGraphType <SetCityInputType> > { Name = "cityLink" }, } ), resolve: context => { var dico = (Dictionary <string, object>)context.Arguments["cityLink"]; var player = (int)dico["player"]; var city = (int)dico["city"]; return(playerRepository.Add(player, city)); }); }
public Planet Add(Planet planet) { //TODO: Realizar buscar de quantidade de filmes return(_planetRepository.Add(planet)); }
private async void SavePlanetClick(object sender, RoutedEventArgs e) { await _planetRepository.Add(_planet.Model); this.Close(); }