public async Task <IActionResult> AddCountry(string countryName, string continentName, int infectedNo, int recoveredNo, int deathNo) { var continent = await _continentService.GetContinentAsync(continentName); var country = new Country() { ContinentId = continent.Id, DeathNo = deathNo, InfectedNo = infectedNo, RecoveredNo = recoveredNo, RefreshDate = DateTime.Now, Name = countryName }; var exCountry = await _countryService.GetCountryAsync(countryName); if (exCountry != null) { TempData["Error"] = "مشکلی در درج کشور پیش آمد! کشور از قبل وجود دارد"; return(RedirectToAction("Index")); } var isSucceeded = await _countryService.AddCountryAsync(country); if (!isSucceeded) { TempData["Error"] = "مشکلی در درج اطلاعات کشور پیش آمد! لطفا اطلاعات وارد شده را بررسی کنید"; return(RedirectToAction("Index")); } TempData["Success"] = "اطلاعات کشور موردنظر با موفقیت ثبت گردید"; return(RedirectToAction("Index")); }
public async Task <IActionResult> AddCountryAsync(PostCountryInputModel model) { var country = _mapper.Map <Country>(model); var result = await _countryService.AddCountryAsync(country); return(Ok(ResponseResult.SucceededWithData(result))); }
public async Task <IActionResult> Create([Bind("Name, Code")] CountryVM country) { if (ModelState.IsValid) { await service.AddCountryAsync(country.Adapt <CountryDTO>()); return(RedirectToAction(nameof(Index))); } return(View(country)); }
public async Task <IActionResult> Post(int organizationId, [FromBody] CreateCountryModel createCountryModel) { string email = User.Identity.Name; await countryService.AddCountryAsync( organizationId, mapper.Map <CreateCountryModel, CreateCountryDto>(createCountryModel), email ); return(Ok()); }
private async Task AddCountryAsync() { var result = await _countryService.AddCountryAsync(CountryInput); if (result.Type != ResultType.Ok) { MessageBox.Show(result.Error); return; } Countrylist.Add(Mapper.Map <CountryDto, CountryViewModel>(result.Data)); }
public async Task <IActionResult> Import() { // If you are a commercial business and have // purchased commercial licenses use the static property // LicenseContext of the ExcelPackage class: ExcelPackage.LicenseContext = LicenseContext.Commercial; // If you use EPPlus in a noncommercial context // according to the Polyform Noncommercial license: ExcelPackage.LicenseContext = LicenseContext.NonCommercial; var path = Path.Combine(_env.ContentRootPath, String.Format("Source/worldcities.xlsx")); using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (var ep = new ExcelPackage(stream)) { // get the first worksheet var ws = ep.Workbook.Worksheets[0]; // initialize the record counters var nCountries = 0; var nCities = 0; #region Import all Countries // create a list containing all the countries // already existing into the Database (it // will be empty on first run). var countries = await _countryService.GetCountriesAsync(); //var countryModel = _mapper.Map<List<CountryModel>>(countries); var lstCountries = countries; // iterates through all rows, skipping the // first one for (int nRow = 2; nRow <= ws.Dimension.End.Row; nRow++) { var row = ws.Cells[nRow, 1, nRow, ws.Dimension.End.Column]; var name = row[nRow, 5].GetValue <string>(); // Did we already created a country with // that name? if (lstCountries.Where(c => c.Name == name).Count() == 0) { // create the Country entity and fill it // with xlsx data var model = new PostCountryInputModel(); model.Name = name; model.ISO2 = row[nRow, 6].GetValue <string>(); model.ISO3 = row[nRow, 7].GetValue <string>(); // save it into the Database var country = _mapper.Map <Country>(model); var result = await _countryService.AddCountryAsync(country); // store the country to retrieve // its Id later on lstCountries.Add(country); // increment the counter nCountries++; } } #endregion #region Import all Cities // iterates through all rows, skipping the // first one for (int nRow = 2; nRow <= ws.Dimension.End.Row; nRow++) { var row = ws.Cells[nRow, 1, nRow, ws.Dimension.End.Column]; // create the City entity and fill it // with xlsx data var model = new PostCityInoutModel(); model.Name = row[nRow, 1].GetValue <string>(); model.Name_ASCII = row[nRow, 2].GetValue <string>(); model.Latitude = row[nRow, 3].GetValue <decimal>(); model.Longtitude = row[nRow, 4].GetValue <decimal>(); // retrieve CountryId var countryName = row[nRow, 5].GetValue <string>(); var country = lstCountries.Where(c => c.Name == countryName).FirstOrDefault(); model.CountryId = country.Id; // save the city into the Database var city = _mapper.Map <City>(model); var result = await _cityService.AddCityAsync(city); // increment the counter nCities++; } #endregion return(new JsonResult(new { Cities = nCities, Countries = nCountries })); } } }
// POST: api/Countries public async Task <Result <CountryDto> > Post([FromBody] string name) { return(await _countryService.AddCountryAsync(name)); }