public async Task <IActionResult> ExecuteAsync(int countryId, SaveCountry saveCountry, CancellationToken cancellationToken) { var country = await _countryRepository.Get(countryId, cancellationToken); if (country == null) { return(new NotFoundResult()); } _saveCountryToCountryMapper.Map(saveCountry, country); country = await _countryRepository.Update(country, cancellationToken); var countryViewModel = _countryToCountryMapper.Map(country); return(new OkObjectResult(countryViewModel)); }
public async Task <IActionResult> ExecuteAsync(SaveCountry saveCountry, CancellationToken cancellationToken) { var listCountry = await _countryRepository.GetAll(cancellationToken); var selectCountry = listCountry.SingleOrDefault(x => x.Name == saveCountry.Name || x.IsoCode2 == saveCountry.IsoCode2); if (selectCountry != null) { return(new NoContentResult()); } var country = _saveCountryToCountryMapper.Map(saveCountry); // add created by //var user = _httpContextAccessor.HttpContext.User; //if (user == null) // return new NotFoundResult(); //var claims = user.Claims.ToList(); //if (claims.Count < 1) // return new NotFoundResult(); //var userId = claims.FirstOrDefault(claimRecord => claimRecord.Type == "sub").Value; //if (country.CreatedBy == null) // country.CreatedBy = userId; //country.ModifiedBy = userId; // end created by country = await _countryRepository.Add(country, cancellationToken); var countryViewModel = _countryToCountryMapper.Map(country); return(new CreatedAtRouteResult( CountriesControllerRoute.GetCountry, new { countryId = countryViewModel.Id }, countryViewModel)); }
public Task <IActionResult> Put( [FromServices] IPutCountryCommand command, int countryId, [FromBody] SaveCountry country, CancellationToken cancellationToken) => command.ExecuteAsync(countryId, country, cancellationToken);