public bool CreateCountry(CountryCreateDto countryToCreateDto) { var countryToCreate = MapConfig.Mapper.Map <Country>(countryToCreateDto); _countryContext.Add(countryToCreate); return(Save()); }
public async Task <IActionResult> CreateCountry([FromBody] CountryCreateDto model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var newCountry = new Country() { Name = model.Name, Description = model.Description, BestDayToVisit = model.BestDayToVisit, IsCool = model.IsCool, CurrencyId = model.CurrencyId }; _context.Countries.Add(newCountry); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetCountryById), new { id = newCountry.Id }, model)); }
public async Task <ActionResult> Create(CountryCreateDto model) { var result = await _countryService.Create(model); return(CreatedAtAction( "GetById", new { id = result.CountryId }, result )); }
public ActionResult <CountryReadDto> Post(CountryCreateDto country) { var countryModel = _mapper.Map <Country>(country); _repository.Create(countryModel); _repository.SaveChanges(); var countryReadDto = _mapper.Map <CountryReadDto>(countryModel); return(CreatedAtRoute(nameof(Get), new { Id = countryReadDto.id }, countryReadDto)); }
public async Task <CountryDto> Create(CountryCreateDto model) { var result = new Country { Name = model.Name }; await _context.AddAsync(result); await _context.SaveChangesAsync(); return(_mapper.Map <CountryDto>(result)); }
public async Task AddCountry(CountryCreateDto country) { var countryAsJson = new StringContent(JsonSerializer.Serialize(country), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("api/countries", countryAsJson); if (!response.IsSuccessStatusCode) { throw new Exception("Error in server - Please contact your administrator"); } }
public async Task <IActionResult> CreateCountry([FromBody] CountryCreateDto countyDto) { if (!ModelState.IsValid) { _logger.LogError($"Invalid POST attempt in{nameof(CreateCountry)}"); return(BadRequest(ModelState)); } var country = _mapper.Map <Country>(countyDto); await _unitOfWork.Countries.Insert(country); await _unitOfWork.Save(); return(CreatedAtRoute("GetCountry", new { id = country.Id }, country)); }
public async Task <IActionResult> CreateCountry(CountryCreateDto country) { if (country == null) { return(BadRequest("CountryCreateDto object is null.")); } else { var countryEntity = _mapper.Map <Country>(country); _repository.Country.CreateCountry(countryEntity); await _repository.SaveAsync(); var countryToReturn = _mapper.Map <CountryDto>(countryEntity); return(CreatedAtRoute("GetCountry", new { id = countryToReturn.Id }, countryToReturn)); } }
public IActionResult CreateCountry([FromBody] CountryCreateDto newCountry) { if (newCountry == null) { return(BadRequest(ModelState)); } if (_unitOfWork.CountryRepository.CountryExists(newCountry.Id)) { ModelState.AddModelError("", "Such country Exists!"); return(StatusCode(404, ModelState)); } if (!_unitOfWork.CountryRepository.CreateCountry(newCountry)) { ModelState.AddModelError("", $"Something went wrong saving the country " + $"{newCountry.CountryName}"); return(StatusCode(500, ModelState)); } _unitOfWork.Commit(); return(CreatedAtRoute("GetCountryById", new { countryId = newCountry.Id }, newCountry)); }
public void CreateCountry(CountryCreateDto countryDto) { var country = Mapper.Map <CountryCreateDto, Country>(countryDto); _countryRepository.Save(country); }