public CountryBase AddCountry(CountryAdd newItem) { if (!CurrentDbContext.CountryDB.Any(a => a.Name.Contains(newItem.Name))) { var addedItem = CurrentDbContext.CountryDB.Add(Mapper.Map <Country>(newItem)); addedItem.SeoName = SeoManager.GetSeoLocation(addedItem.Name); CurrentDbContext.SaveChanges(); return((addedItem == null) ? null : Mapper.Map <CountryBase>(addedItem)); } return(null); }
public static void Runbase() { var _country = CountryAdd.country(); var _district = DistrictAdd.districts(); var _city = CityAdd.CityList(); var _neighborhood = NeighborhoodAdd.neighborhoods(); var _query = from country in _country join district in _district on country.District equals district.DistrictName join city in _city on district.City equals city.NeighborhoodCity join neighborhood in _neighborhood on city.Neighborhood equals neighborhood.NeighborhoodName select new { neighborhood.StreetName }; foreach (var item in _query) { Console.WriteLine($"Street: {item.StreetName}"); } //var _query = from country in _country // group country by country.CountryName into newGroup // select new // { // countryname = newGroup.Key, // streetname = from fdCountry in newGroup // join district in _district on fdCountry.District equals district.DistrictName // join city in _city on district.City equals city.NeighborhoodCity // join neighborhood in _neighborhood on city.Neighborhood equals neighborhood.NeighborhoodName // select new { neighborhood.StreetName } // }; //foreach (var item in _query) // { // Console.WriteLine($"Country: {item.countryname}"); // Console.WriteLine(""); // foreach (var subitem in item.streetname) // { // Console.WriteLine($"Street: {subitem.StreetName}"); // } // Console.WriteLine(Environment.NewLine); // } }
public ActionResult CreateCountry(CountryAdd newItem) { if (!ModelState.IsValid) { return(View(newItem)); } var addedItem = AdminManager.AddCountry(newItem); if (addedItem == null) { return(View(newItem)); } else { return(RedirectToAction("Country")); } }
public ActionResult add_country(CountryAdd AddCountry) { var error_message = new object(); if (string.IsNullOrWhiteSpace(AddCountry.countryAdd)) { error_message = "error, input empty basd request"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } Country country = new Country { CountryName = AddCountry.countryAdd, Description = AddCountry.adminCountryDesc }; //first check if this country exists Country temp = new Country(); using (var api = new HttpClient()) { api.BaseAddress = new Uri("https://localhost:44343/api/country/"); api.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var post = api.PostAsJsonAsync <string>("search/name", AddCountry.countryAdd); post.Wait(); var result = post.Result; if (result.StatusCode == HttpStatusCode.OK) { var s = result.Content.ReadAsAsync <Country>(); s.Wait(); temp = s.Result; } else if (result.StatusCode == HttpStatusCode.NotFound) { var s = result.Content.ReadAsAsync <Country>(); s.Wait(); temp = s.Result; } else { error_message = "error, internal server error please try again later"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } } if (temp != null && (temp.CountryName != null) && (temp.CountryName == country.CountryName)) { error_message = "error, country exists"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } //ad this country bool flag = false; using (var api = new HttpClient()) { api.BaseAddress = new Uri("https://localhost:44343/api/country/"); api.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var post = api.PostAsJsonAsync <Country>("new", country); post.Wait(); var result = post.Result; if (result.StatusCode == HttpStatusCode.Created) { var s = result.Content.ReadAsAsync <bool>(); s.Wait(); flag = s.Result; } else if (result.StatusCode == HttpStatusCode.NotFound) { var s = result.Content.ReadAsAsync <bool>(); s.Wait(); flag = s.Result; } else { error_message = "error, internal server error please try again later"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } } if (!flag) { error_message = "error, internal server error please try again later"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } else { error_message = Url.Action("home", "admin"); return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } }