public async Task <IActionResult> PutMtnCountry([FromRoute] int id, [FromBody] MtnCountry mtnCountry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != mtnCountry.CountryId) { return(BadRequest()); } _context.Entry(mtnCountry).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MtnCountryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <CountryResponse> CreateCountry(Country countryModel) { var userId = await _loginRepository.GetUserIdByAuthToken(""); var countryExisting = GetCountryByName(countryModel.countryName); if (countryExisting != null) { var response = new CountryResponse { status = false, message = "Country already exists", countryList = null }; return(response); } else { var country = new MtnCountry() { CountryName = countryModel.countryName, CreatedBy = userId }; var loginSessionEntry = _context.MtnCountry.Add(country); await _context.SaveChangesAsync(); var countryList = new List <Country>(); countryList.Add(new Country { countryId = Convert.ToString(country.CountryId), countryName = country.CountryName }); var response = new CountryResponse { status = true, countryList = countryList }; return(response); } }