protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { var gridView1DataKey = GridView1.DataKeys[e.NewEditIndex]; if (gridView1DataKey != null) { string id = gridView1DataKey.Value.ToString(); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["InventoryConnectionString"].ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand("select * from Country where CountryID='" + id + "'", connection); SqlDataAdapter adp = new SqlDataAdapter(command); DataTable dt = new DataTable(); adp.Fill(dt); if (dt.Rows.Count > 0) { /*txtCountryID.Text = dt.Rows[0]["CountryID"].ToString(); * txtCountry.Text = dt.Rows[0]["Country"].ToString();*/ CountryClass cc = new CountryClass() { CountryId = dt.Rows[0]["CountryID"].ToString(), Country = dt.Rows[0]["Country"].ToString() }; CountryList.Add(cc); } connection.Close(); Response.Redirect("CountryForm.aspx"); } } }
public static void InitializeCovidDB(CovidDBContext context) { context.Database.EnsureCreated(); if (context.Countries.Any()) { return; } var Countries = new CountryClass[] { new CountryClass { Code = "HU", Country = "Hungary", Slug = "hungary" }, new CountryClass { Code = "AU", Country = "Australia", Slug = "australia" } }; foreach (CountryClass item in Countries) { context.Countries.Add(item); } context.SaveChanges(); }
public IActionResult GetCountry(int Id) { CountryClass country = context.Countries.Where(x => x.Id == Id).FirstOrDefault(); return(Ok(new Response { Status = "Success", Message = "Successful", Data = country })); }
public ActionResult EditCountry(int countryId) { foreach (var data in Bc.GetCountryListByCountryId(countryId)) { CountryClass cc = new CountryClass() { CountryId = data.CountryID, Country = data.Country1 }; CountryClassList.Add(cc); } return(RedirectToAction("CountryForm")); }
public ActionResult Show(string code) { Dictionary <object, object> model = new Dictionary <object, object>(); List <CountryClass> newList = CountryClass.GetAll(); List <CityClass> newCityList = CityClass.GetAll(); string currentName = ""; string currentContinent = ""; int currentPopulation = 0; string currentGov = ""; string currentCode = ""; CountryClass currentCountry = new CountryClass(currentName, currentContinent, currentPopulation, currentGov, currentCode); foreach (CountryClass country in newList) { if (country.GetCode() == code) { currentCountry.SetName(country.GetName()); currentCountry.SetContinent(country.GetContinent()); currentCountry.SetPopulation(country.GetPopulation()); currentCountry.SetGovernment(country.GetGovernment()); currentCountry.SetCode(country.GetCode()); model.Add("country", currentCountry); } } List <CityClass> totalCityList = new List <CityClass>() { }; foreach (CityClass city in newCityList) { if (city.GetCode() == code) { string cityName = city.GetName(); string cityCode = city.GetCode(); string cityDistrict = city.GetDistrict(); int cityPopulation = city.GetPopulation(); CityClass currentCity = new CityClass(cityName, cityCode, cityDistrict, cityPopulation); totalCityList.Add(currentCity); } } model.Add("cities", totalCityList); return(View(model)); }
public ActionResult Edit(int id, CountryClass model) { try { Response response = Utilities.UtilityClass.WebRequestWithToken <CountryClass>("api/UAECovid/UpdateCountry", RestSharp.Method.PUT, model, null, _httpContextAccessor.HttpContext.Request.Cookies["Token"]); if (response.Status == "Success") { return(RedirectToAction(nameof(Index))); } else { return(View()); } } catch { return(View()); } }
public async Task <IActionResult> UpdateCountry(CountryClass country) { if (ModelState.IsValid) { try { context.Countries.Update(country); await context.SaveChangesAsync(); return(Ok(new Response { Status = "Success", Message = "Update Success", Data = null })); } catch (DbUpdateException ex) { return(Ok(new Response { Status = "Error", Message = ex.Message, Data = null })); } } return(BadRequest()); }
public async Task <IActionResult> DeleteCountry(int countryCode) { if (ModelState.IsValid) { try { CountryClass country = context.Countries.Where(x => x.Id == countryCode).FirstOrDefault(); context.Countries.Remove(country); await context.SaveChangesAsync(); return(Ok(new Response { Status = "Success", Message = "Delete Success", Data = null })); } catch (DbUpdateException ex) { return(Ok(new Response { Status = "Error", Message = ex.Message, Data = null })); } } return(BadRequest()); }
public async Task <IActionResult> AddCountryToDB(CountryClass country) { if (ModelState.IsValid) { try { context.Countries.Add(new CountryClass { Country = country.Country, Slug = country.Slug, Code = country.Code }); await context.SaveChangesAsync(); return(Ok(new Response { Status = "Success", Message = "Successful Insertion", Data = country.Id })); } catch (DbUpdateException ex) { return(Ok(new Response { Status = "Error", Message = ex.Message, Data = null })); } } return(BadRequest()); }
public static void Initialize() { Countries.Add(new CountryClass("United Kingdom", "GB")); Countries.Add(new CountryClass("Argentina", "AR")); Countries.Add(new CountryClass("Australia", "AU")); Countries.Add(new CountryClass("Austria", "AT")); Countries.Add(new CountryClass("Belgium", "BE")); Countries.Add(new CountryClass("Brazil", "BR")); Countries.Add(new CountryClass("Canada", "CA")); Countries.Add(new CountryClass("Croatia", "HR")); Countries.Add(new CountryClass("Bosnia", "BA")); Countries.Add(new CountryClass("Cyprus", "CY")); Countries.Add(new CountryClass("Czech", "CZ")); Countries.Add(new CountryClass("Denmark", "DK")); Countries.Add(new CountryClass("Finland", "FI")); Countries.Add(new CountryClass("France", "FR")); Countries.Add(new CountryClass("Georgia", "GE")); Countries.Add(new CountryClass("Germany", "DE")); Countries.Add(new CountryClass("Greece", "GR")); Countries.Add(new CountryClass("Hongkong", "HK")); Countries.Add(new CountryClass("Hungary", "HU")); Countries.Add(new CountryClass("Iceland", "IS")); Countries.Add(new CountryClass("India", "IN")); Countries.Add(new CountryClass("Indonesia", "ID")); Countries.Add(new CountryClass("Iran", "IR")); Countries.Add(new CountryClass("Iraq", "IQ")); Countries.Add(new CountryClass("Ireland", "IE")); Countries.Add(new CountryClass("Israel", "IL")); Countries.Add(new CountryClass("Italy", "IT")); Countries.Add(new CountryClass("Japan", "JP")); Countries.Add(new CountryClass("Liechtenstein", "LI")); Countries.Add(new CountryClass("Luxembourg", "LU")); Countries.Add(new CountryClass("Malaysia", "MY")); Countries.Add(new CountryClass("Malta", "MT")); Countries.Add(new CountryClass("Mexico", "MX")); Countries.Add(new CountryClass("Morocco", "MA")); Countries.Add(new CountryClass("Netherlands", "NL")); Countries.Add(new CountryClass("Newzealand", "NZ")); Countries.Add(new CountryClass("Norway", "NO")); Countries.Add(new CountryClass("Poland", "PL")); Countries.Add(new CountryClass("Portugal", "PT")); Countries.Add(new CountryClass("Puertorico", "PR")); Countries.Add(new CountryClass("Romania", "RO")); Countries.Add(new CountryClass("Russia", "RU")); Countries.Add(new CountryClass("Singapore", "SG")); Countries.Add(new CountryClass("South Africa", "ZA")); Countries.Add(new CountryClass("Spain", "ES")); Countries.Add(new CountryClass("Sweden", "SE")); Countries.Add(new CountryClass("Switzerland", "CH")); Countries.Add(new CountryClass("Turkey", "TR")); Countries.Add(new CountryClass("USA", "US")); Countries.Add(new CountryClass("Unknown", "UN")); Countries.Add(new CountryClass("Blank 1", "B1")); Countries.Add(new CountryClass("Blank 2", "B2")); Countries.Add(new CountryClass("Blank 3", "B3")); Countries.Add(new CountryClass("Chile", "CL")); Countries.Add(new CountryClass("Serbia", "RS")); Countries.Add(new CountryClass("Slovenia", "SI")); Countries.Add(new CountryClass("Lebanon", "LB")); Countries.Add(new CountryClass("Moldova", "MO")); Countries.Add(new CountryClass("Ukraine", "UA")); Countries.Add(new CountryClass("Latvia", "LV")); Countries.Add(new CountryClass("Slovakia", "SK")); Countries.Add(new CountryClass("Costa Rica", "CR")); Countries.Add(new CountryClass("Estonia", "EE")); Countries.Add(new CountryClass("China", "CN")); Countries.Add(new CountryClass("Colombia", "CO")); Countries.Add(new CountryClass("Ecuador", "EC")); Countries.Add(new CountryClass("Uruguay", "UY")); Countries.Add(new CountryClass("Venezuela", "VE")); Countries.Add(new CountryClass("Lithuania", "LT")); Countries.Add(new CountryClass("Bulgaria", "BG")); Countries.Add(new CountryClass("Egypt", "EG")); Countries.Add(new CountryClass("Saudi Arabia", "SA")); Countries.Add(new CountryClass("South Korea", "KR")); Countries.Add(new CountryClass("Belarus", "BY")); Countries.Add(new CountryClass("Peru", "PE")); Countries.Add(new CountryClass("Algeria", "DZ")); Countries.Add(new CountryClass("Kazakhstan", "KZ")); Countries.Add(new CountryClass("El Salvador", "SV")); Countries.Add(new CountryClass("Taiwan", "TW")); Countries.Add(new CountryClass("Jamaica", "JM")); Countries.Add(new CountryClass("Guatemala", "GT")); Countries.Add(new CountryClass("Marshall Islands", "MH")); Countries.Add(new CountryClass("Macedonia", "MK")); Countries.Add(new CountryClass("United Arab Emirates", "AE")); DefaultCountry = GetCountryByID(49); }
public ActionResult Index() { List <CountryClass> newList = CountryClass.GetAll(); return(View(newList)); }