public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO country) { return(await _mediator.Send(new CreateCountryRequest() { Country = country })); }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO countryDTO) { if (!ModelState.IsValid) { _logger.LogError($"Invalid POST attempt in {nameof(CreateCountry)}"); return(BadRequest(ModelState)); } countryDTO.Name = char.ToUpper(countryDTO.Name[0]) + countryDTO.Name.Substring(1).ToLower(); countryDTO.ShortName = countryDTO.ShortName.ToUpper(); var existedCountry = await _unitOfWork.Countries.Get(p => p.Name == countryDTO.Name && p.ShortName == countryDTO.ShortName); if (existedCountry == null) { var country = _mapper.Map <Country>(countryDTO); await _unitOfWork.Countries.Insert(country); await _unitOfWork.Save(); return(CreatedAtRoute("GetCountry", new { id = country.Id }, country)); } else { return(BadRequest("This Country already exists with same Short Name")); } }
public ActionResult <Country> CreateNewCountry(CreateCountryDTO countryDTO) { LoginToken <Administrator> admin_token = DesirializeToken(); string uri = null; Country country = _mapper.Map <Country>(countryDTO); try { country.Id = _loggedInAdministratorFacade.CreateNewCountry(admin_token, country); if (country.Id == 0) { return(Conflict()); } _countriesManager.SetCountry(admin_token, country); uri = _linkGenerator.GetPathByAction(nameof(AnonymousFacadeController.GetCountryById), "AnonymousFacade", new { id = country.Id }); } catch (RecordAlreadyExistsException) { return(Conflict()); } return(Created(uri, country)); }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO countryDTO) { if (!ModelState.IsValid) { _logger.LogError($"Invalid POST attempt in {nameof(CreateCountry)}"); return(BadRequest(ModelState)); } var country = _mapper.Map <Country>(countryDTO); await _unitOfWork.Countries.Insert(country); await _unitOfWork.Save(); return(CreatedAtRoute("GetCountry", new { id = country.Id }, country)); }
public async Task Create(CreateCountryDTO dto) { var CountryDTo = _mapper.Map <CreateCountryDTO, CountryEntity>(dto); //var createdCountry = new CountryEntity() //{ // NameAr = dto.NameAr, // NameEn = dto.NameEn, //}; await _Db.Countries.AddAsync(CountryDTo); _Db.SaveChanges(); }
internal static async Task Create_Country_For_Tests(HttpClient httpClient, CreateCountryDTO createCountryDTO = null) { await Main_Admin_Login(httpClient); if (createCountryDTO == null) { createCountryDTO = new CreateCountryDTO { Name = "Israel" } } ; await httpClient.PostAsync("api/countries", new StringContent(JsonSerializer.Serialize(createCountryDTO), Encoding.UTF8, MediaTypeNames.Application.Json)); }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO countryDTO) { _logger.LogInformation("Creating new Country!"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var country = _mapper.Map <Country>(countryDTO); await _unitOfWork.Countries.Insert(country); await _unitOfWork.Save(); var result = _mapper.Map <CountryDTO>(country); return(CreatedAtRoute(nameof(countryDTO), new { id = country.Id }, result)); }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO countryDTO) //[FromBody] means the request has a data in the body and we retrieve that data { if (!ModelState.IsValid) { _logger.LogError($"Invalid Post Attempt In {nameof(CreateCountry)}"); return(BadRequest(ModelState)); } var country = _mapper.Map <Country>(countryDTO); await _unitOfWork.Countries.Insert(country); await _unitOfWork.Save(); return(CreatedAtRoute("GetCountry", new { id = country.Id }, country)); }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO countryDTO) { try { var country = _mapper.Map <Country>(countryDTO); await _unitOfWork.Countries.Insert(country); await _unitOfWork.Save(); return(CreatedAtRoute("GetCountry", new { id = country.Id }, country)); } catch (Exception ex) { _logger.LogError(ex, $"Something went wrong in the {nameof(CreateCountry)}"); return(StatusCode(500, "Internal server error. Please try again later")); } }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO countryDTO) { if (!ModelState.IsValid) { _logger.LogError($"Invalid Post attempt: {nameof(CreateCountry)}"); return(BadRequest(ModelState)); } try { var country = _mapper.Map <Country>(countryDTO); await _unitofWork.Countries.Insert(country); await _unitofWork.Save(); return(CreatedAtRoute("GetCountry", new { id = country.Id }, country)); } catch (Exception ex) { _logger.LogError(ex, $"Something went wrong in the {nameof(CreateCountry)}"); return(StatusCode(500, "Internal Server Error")); } }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO countryDTO) { if (!ModelState.IsValid) { _logger.LogError($"Invalid POST attempt in {nameof(CreateCountry)}"); return(BadRequest(ModelState)); } try { // CountryDTO の値を取り出す var country = _mapper.Map <Country>(countryDTO); await _unitOfWork.Countries.Insert(country); await _unitOfWork.Save(); // GetHotel に作成後移動 return(CreatedAtRoute("GetCountry", new { id = country.Id }, country)); } catch (Exception ex) { _logger.LogError(ex, $"Something Went Wrong in the {nameof(CreateCountry)}"); return(StatusCode(500, "Internal Server Error. Please Try Again Later.")); } }
public async Task <IActionResult> CreateCountry([FromBody] CreateCountryDTO countryDTO) { var location = GetControllerActionNames(); if (!ModelState.IsValid) { _logger.LogError($"{location}: Invalid POST attempt"); return(BadRequest(ModelState)); } try { var country = _mapper.Map <Country>(countryDTO); await _unitOfWork.Countries.Insert(country); await _unitOfWork.Save(); return(CreatedAtRoute("GetCountry", new { id = country.Id }, country)); } catch (Exception ex) { return(InternalError($"{location}: Error", ex)); } }
public async Task <IActionResult> CreateAsync([FromForm] CreateCountryDTO dto) { await _CountryService.Create(dto); return(Ok(GetRespons())); }