public ActionResult <Country> Post(int id, [FromBody] Country country) { log("Post"); try { countRepos.AddCountry(country, id); return(CreatedAtAction(nameof(GetCountry), new { continentId = id, countryId = country.CountryId }, country)); } catch (GeoException ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> CreateCountry([FromBody] CountryAddDto countryDto) { if (countryDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var country = _mapper.Map <Country>(countryDto); _countryRepository.AddCountry(country); if (!await _unitOfWork.SaveAsync()) { throw new Exception("Error occured when adding"); } var countryAddDto = Mapper.Map <CountryDto>(country); //hateos return(CreatedAtRoute("GetCountry", new { }, countryAddDto)); }
public async Task <IActionResult> CreateCountryCollection( [FromBody] IEnumerable <CountryAddResource> countries) { if (countries == null) { return(BadRequest()); } var countriesModel = _mapper.Map <IEnumerable <Country> >(countries); foreach (var country in countriesModel) { _countryRepository.AddCountry(country); } if (!await _unitOfWork.SaveAsync()) { return(StatusCode(500, "Error occurred when adding")); } var countryResources = _mapper.Map <IEnumerable <CountryResource> >(countriesModel); var idsStr = string.Join(",", countryResources.Select(x => x.Id)); return(CreatedAtRoute("GetCountryCollection", new { ids = idsStr }, countryResources)); }
public IActionResult AddPost(CountryViewModel countryViewModels) { var CountryList = _country.GetCountries(); ViewBag.Country = CountryList; if (countryViewModels.Id == 0) { ModelState.Remove("Id"); if (ModelState.IsValid) { var country = _mapper.Map <Country>(countryViewModels); _country.AddCountry(country); _toastNotification.AddSuccessToastMessage("تم أضافةالبلد بنجاح"); return(RedirectToAction(nameof(Index))); } return(View(nameof(Index), countryViewModels)); } else { if (ModelState.IsValid) { var country = _mapper.Map <Country>(countryViewModels); _country.UpdateCountry(countryViewModels.Id, country); _toastNotification.AddSuccessToastMessage("تم تعديل البلد بنجاح"); return(RedirectToAction(nameof(Index))); } return(View(nameof(Index), countryViewModels)); } }
public int AddCountry(CountryDTO dto) { int id = 0; try { log.Debug(CountryDTO.FormatCountryDTO(dto)); R_Country t = CountryDTO.ConvertDTOtoEntity(dto); // add id = Repository.AddCountry(t); dto.CountryId = id; log.Debug("result: 'success', id: " + id); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } return(id); }
public ActionResult Countries(Country model) { var values = ViewData.ModelState.Values; var errorMessage = _validationService.CheckModelHasErrorMessage(values); if (string.IsNullOrEmpty(errorMessage)) { var result = _countryRepository.AddCountry(model); if (result) { ViewData["Success"] = WarningMessages.AddCountrySuccess; ModelState.Clear(); } else { ViewData["Error"] = WarningMessages.AddCountryFail; } } else { ViewData["Error"] = errorMessage; } ViewBag.countries = _countryRepository.GetCountry(); return(View()); }
public IActionResult AddCountry(CountryViewModel countryVM) { if (ModelState.IsValid) { City cityDB; Region regionDB; if (_cityRepository.CheckExistCity(countryVM.CapitalName) == "EXIST") { cityDB = _cityRepository.GetCityByName(countryVM.CapitalName); } else { _cityRepository.AddCity(new City { Name = countryVM.CapitalName }); cityDB = _cityRepository.GetCityByName(countryVM.CapitalName); } if (_regionRepository.CheckExistRegion(countryVM.RegionName) == "EXIST") { regionDB = _regionRepository.GetRegionByName(countryVM.RegionName); } else { _regionRepository.AddRegion(new Region { Name = countryVM.RegionName }); regionDB = _regionRepository.GetRegionByName(countryVM.RegionName); } if (_countryRepository.CheckExistCountry(countryVM.Country.CountryCode) == "NOT EXIST") { _countryRepository.AddCountry(countryVM.Country, cityDB.Name, regionDB.Name); TempData["successMessage"] = string.Format($"{countryVM.Country.Name}" + " has been successfully added to the database."); return(RedirectToAction("Index")); } else { _countryRepository.UpdateCountry(countryVM.Country, cityDB.Name, regionDB.Name); TempData["successMessage"] = string.Format($"{countryVM.Country.Name} has been successfully updated."); return(RedirectToAction("Index")); } } else { return(View(countryVM)); } }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } repo.AddCountry(Country); return(RedirectToPage("IndexCountry")); }
public async Task <IActionResult> Get() { // throw new Exception("test"); var newCountry = new Country() { ChineseName = "俄罗斯", EnglishName = "Russia", Abbreviation = "Russia" }; _countryRepository.AddCountry(newCountry); await _unitOfWork.SaveAsync(); var countries = await _countryRepository.GetCountriesAsync(); var countryVMs = _mapper.Map <List <CountryVM> >(countries); return(Ok(countryVMs)); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Country.EventList = new Dictionary <int, Event>(); repo.AddCountry(Country); return(RedirectToPage("IndexCountry")); }
/// <summary> /// Adds new country. /// </summary> /// <param name="countryModel">Country view model.</param> /// <returns></returns> public async Task AddCountry(CountryModel countryModel) { // Check if city already exists. var city = await cityRepository.GetCityByName(countryModel.Capital); if (city == null) { // City not found, add it and get Id. await cityRepository.AddCity(new City { Name = countryModel.Capital }); city = await cityRepository.GetCityByName(countryModel.Capital); } // Check if region already exists. var region = await regionRepository.GetRegionByName(countryModel.Region); if (region == null) { // Region not found, add it and get Id. await regionRepository.AddRegion(new Region { Name = countryModel.Region }); region = await regionRepository.GetRegionByName(countryModel.Region); } // Check if country with the provided code already exists. var countryExtracted = await countryRepository.GetCountryByCode(countryModel.Code); if (countryExtracted == null) { // Country by code not found, add new country. await countryRepository.AddCountry(new Country { Name = countryModel.Name, Code = countryModel.Code, Area = countryModel.Area, Population = countryModel.Population, RegionId = region.Id, CapitalId = city.Id, }); } else { // Update existing country. countryExtracted.Name = countryModel.Name; countryExtracted.Code = countryModel.Code; countryExtracted.Area = countryModel.Area; countryExtracted.Population = countryModel.Population; countryExtracted.RegionId = region.Id; countryExtracted.CapitalId = city.Id; countryExtracted.Region = region; countryExtracted.Capital = city; await countryRepository.UpdateCountry(countryExtracted); } }
public async Task <CountryModel> AddCountry(CountryModel country) { country.Validate(); var getcountry = await _contryRepo.GetCountry(country.CountryId); if (getcountry.CountryId != 0) { return(await _contryRepo.UpdateCountry(country)); } else { return(await _contryRepo.AddCountry(country)); } }
public async Task <IActionResult> CreateCountry([FromBody] CountryAddResource country) { if (country == null) { return(BadRequest()); } var countryModel = _mapper.Map <Country>(country); _countryRepository.AddCountry(countryModel); if (!await _unitOfWork.SaveAsync()) { throw new Exception("Error occurred when adding"); } var countryResource = Mapper.Map <CountryResource>(countryModel); var links = CreateLinksForCountry(countryModel.Id); var linkedCountryResource = countryResource.ToDynamic() as IDictionary <string, object>; linkedCountryResource.Add("links", links); return(CreatedAtRoute("GetCountry", new { id = linkedCountryResource["Id"] }, linkedCountryResource)); }
public HttpResponseMessage AddCountry([FromBody] CountryViewModel model) { try { var data = repo.AddCountry(model); if (data != null) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result = model, message = "The record has suucessfully been created" })); } return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, result = model, message = "There was error creating this record" })); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, result = model, message = $"There was error creating this record {e.Message}" })); } }
public async Task <IActionResult> CreateCountry([FromBody] CountryAddResource country) { if (country == null) { return(BadRequest()); } var countryModel = _mapper.Map <Country>(country); _countryRepository.AddCountry(countryModel); if (!await _unitOfWork.SaveAsync()) { return(StatusCode(500, "保存数据出错")); } var countryResource = _mapper.Map <CountryResource>(countryModel); return(CreatedAtRoute("GetCountry", new { id = countryModel.Id }, countryResource)); }
public Country SaveCountry(CountryDTO countryDTO) { Country country = new Country { Name = countryDTO.Name, Code = countryDTO.Code, Area = countryDTO.Area, Population = countryDTO.Population, Capital = new City { Name = countryDTO.Capital }, Region = new Region { Name = countryDTO.Region } }; var capital = FindCityInDB(country.Capital.Name); if (capital == null) { capital = _cityRepository.AddCity(country.Capital); } country.CapitalId = capital.Id; country.Capital = capital; var region = FindRegionInDB(country.Region.Name); if (region == null) { region = _regionRepository.AddRegion(country.Region); } country.RegionId = region.Id; country.Region = region; var countryInDB = FindCountryInDB(country.Code); if (countryInDB == null) { return(_countryRepository.AddCountry(country)); } else { return(_countryRepository.UpdateCountry(countryInDB)); } }
public async Task <IActionResult> Get() { var newCountry = new Country { ChineseName = "俄罗斯", EnglishName = "Russia", Abbreviation = "Russia" }; _repository.AddCountry(newCountry); await _unitOfWork.SaveAsync(); var countries = await _repository.GetCountriesAsync(); var countryResources = _mapper.Map <List <CountryResource> >(countries); return(Ok(countryResources)); }
public async Task <IActionResult> CreateCountry([FromBody] CountryAddResource country) { if (country == null) { return(BadRequest()); } var countryModel = _mapper.Map <Country>(country); _countryRepository.AddCountry(countryModel); if (!await _unitOfWork.SaveAsync()) { throw new Exception("Error occurred when adding"); } var countryResource = Mapper.Map <CountryResource>(countryModel); return(CreatedAtRoute("GetCountry", new { id = countryModel.Id }, countryResource)); }
private void InsertAvailableCountries(List <CountryLocaleList> availableCountries) { CountryText countryLocale; foreach (CountryLocaleList countryRowRecord in availableCountries) { // Insert for each locale country information. foreach (CountryInfo countryInfo in countryRowRecord.Countries) { countryLocale = new CountryText(); // Insert Country countryLocale.CountryId = _dbRepository.AddCountry(countryInfo); countryLocale.Locale = countryRowRecord.Locale; countryLocale.Name = countryInfo.CountryName; _dbRepository.AddOrUpdateCountryLocale(countryLocale); } } }
public IActionResult CreateCountry([FromBody] Country country) { if (country == null) { return(BadRequest()); } if (country.Name == string.Empty) { ModelState.AddModelError("Name", "The name of the Country shouldn't be empty"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdEmployee = _countryRepository.AddCountry(country); return(Created("country", country)); }
public void SaveCountry(CountryDto country) { countryRepository.AddCountry(country); }
public IActionResult Create(Country country) { _countryRepository.AddCountry(country); return(RedirectToAction("Index")); }
public IActionResult Create(Country country) { _countryRepository.AddCountry(country); return(View()); }
public async Task <ActionResult> Post(Country country) { await _countryRepository.AddCountry(country); return(NoContent()); }