public async Task <IActionResult> Post([FromBody] CountryAddViewModel country) { if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResultCus(ModelState)); } var countryModel = mapper.Map <Country>(country); await countryRepository.AddCountryAsync(countryModel); if (!await unitOfWork.SaveAsync()) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error when Add")); } var countryResource = mapper.Map <CountryResource>(countryModel); var links = CreateCountryLinks(countryModel.Id); var result = countryResource.ToDynamic() as IDictionary <string, object>; result.Add("links", links); return(CreatedAtAction(nameof(GetCountry), new { id = countryResource.Id }, result)); }
public CountryMutation(ICountryRepository _repo) { FieldAsync <CountryType>( "addCountry", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <InputCountryType> > { Name = "country" } ), resolve: async context => { var country = context.GetArgument <Country>("country"); return(await _repo.AddCountryAsync(country)); }); }
public async Task <int> AddCountryAsync(Country country) { return(await _countryRepository.AddCountryAsync(country)); }