// GET: CountryController/Create public ActionResult CreateCountry() { CreateCountryViewModel ctyVM = new CreateCountryViewModel(); ctyVM.CityList = _cityService.All(); return(View(ctyVM)); }
public ActionResult Create(CreateCountryViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var Country = _mapper.Map <Country>(model); var isSuccess = _countryRepository.Create(Country); if (!isSuccess) { return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "در ثبت اطلاعات مشکلی به وجود آمده است"); return(View(model)); } }
public Country Add(CreateCountryViewModel createCountry) { Country country = new Country(); country.Name = createCountry.Name; country.Cities = createCountry.CityList; return(_countryRepo.Create(country)); }
public ActionResult Create() { CreateCountryViewModel createCountryViewModel = new CreateCountryViewModel(); //createCountryViewModel.CityList = _cityService.All(); //Why sending in cCVM with all? return(View(createCountryViewModel)); }
// GET: Countries/Create public ActionResult Create() { CreateCountryViewModel createCountryViewModel = new CreateCountryViewModel(); createCountryViewModel.Cities = _citysService.All().cityList; return(View(createCountryViewModel)); }
public ActionResult Create(CreateCountryViewModel createCountryViewModel) { if (ModelState.IsValid) { _countrysService.Add(createCountryViewModel); return(RedirectToAction(nameof(Index))); } return(View(createCountryViewModel)); }
public Country Edit(int id, CreateCountryViewModel edit) { Country editedcountry = new Country() { CountryId = id, CountryName = edit.CountryName }; return(_countryRepo.Update(editedcountry)); }
public ActionResult CountryDetails(int id) { CreateCountryViewModel ctyVM = new CreateCountryViewModel(); Country ctyDetails = _countryService.FindBy(id); ctyVM.CountryId = ctyDetails.CountryId; ctyVM.CountryName = ctyDetails.CountryName; ctyVM.CityList = _countryService.FindAllCity(id); return(View(ctyVM)); }
public Country Edit(int id, CreateCountryViewModel country) { Country editCountry = new Country() { Name = country.Name, Id = id }; return(_countriesRepo.Update(editCountry)); throw new NotImplementedException(); }
public ActionResult Edit(Country country) { CreateCountryViewModel createCountrie = new CreateCountryViewModel(); createCountrie.Name = country.Name; createCountrie.Cities = country.Cities; Country editCountrie = _countrysService.Edit(country.Id, createCountrie); return(RedirectToAction(nameof(Index))); }
// GET: CountryController/Details/5 public ActionResult CountryDetails(int id) { CreateCountryViewModel ctyVM = new CreateCountryViewModel(); Country ctyDetails = _countryService.FindBy(id); ctyVM.CountryId = ctyDetails.CountryId; ctyVM.CountryName = ctyDetails.CountryName; //ctyVM.CityList = _cityService.All(); //gives all the cities in the database and not for this particular country ctyVM.CityList = _countryService.FindAllCity(id); //gives all the cities in the database for this particular country return(View(ctyVM)); }
public async Task CreateCountryAsync(CreateCountryViewModel createCountryViewModel) { string jsonStringBody = JsonSerializer.Serialize(createCountryViewModel); using StringContent stringContent = new StringContent(jsonStringBody, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _httpClient.PostAsync("country/create-country", stringContent); if (!response.IsSuccessStatusCode) { throw new ApplicationException($"{response.ReasonPhrase}: The status code is: {(int)response.StatusCode}"); } }
public ActionResult Create(CreateCountryViewModel createCountry) { if (ModelState.IsValid) { _countryService.Add(createCountry); //I'm not sure solving return(RedirectToAction(nameof(Index))); } else { return(View(createCountry)); } }
public async Task <IActionResult> CreateCountry(CreateCountryViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var createModel = _mapper.Map <CountryServiceModel>(model); await _adminService.CreateCountry(createModel); return(RedirectToAction(nameof(Countries))); }
public ActionResult Edit(int id) { CreateCountryViewModel ctyVM = new CreateCountryViewModel(); Country editCountry = _countryService.FindBy(id); ctyVM.CountryName = editCountry.CountryName; ctyVM.CountryId = editCountry.CountryId; List <City> allCities = _cityService.All(); ctyVM.CityList = allCities; return(View("Edit", ctyVM)); }
public async Task <IActionResult> Add(CreateCountryViewModel pCreateModel) { if (!this.ModelState.IsValid) { pCreateModel.Errors = this.ModelState.Values.SelectMany(val => val.Errors).Select(err => err.ErrorMessage).ToList(); return(View(pCreateModel)); } // map to Dto var lDtoToCreate = Mapping.Mapper.Map <CreateCountryDto>(pCreateModel); await this._referenceServices.CreateCountry(lDtoToCreate); return(RedirectToAction("Index", new { successMessage = "Country successfully created" })); }
public ActionResult Create(CreateCountryViewModel country) { if (ModelState.IsValid) { var urlPhoto = UploadPhoto(country.Photo); country.UrlPhoto = urlPhoto; var client = new RestClient(); var request = new RestRequest("http://localhost:63454/api/countries/", DataFormat.Json); request.AddJsonBody(country); var response = client.Post <CreateCountryViewModel>(request); return(Redirect("/country/index")); } return(BadRequest()); }
public Country Add(CreateCountryViewModel createCountryViewModel) { List <City> cityInCountry = new List <City>(); foreach (int cityID in createCountryViewModel.ListCityID) { City city = _cityRepo.Read(cityID); cityInCountry.Add(city); } Country country = _countryRepo.Create(cityInCountry, createCountryViewModel.CountryName); return(country); }
public ActionResult Create(CreateCountryViewModel createCountryViewModel) { if (ModelState.IsValid) { var client = new RestClient(); var request = new RestRequest("http://localhost:5000/api/countries", DataFormat.Json); var urlPhoto = UploadPhotoFriend(createCountryViewModel.PhotoFile); createCountryViewModel.Flag = urlPhoto; request.AddJsonBody(createCountryViewModel); var response = client.Post <CreateCountryViewModel>(request); return(Redirect("/country/index")); } return(BadRequest()); }
public async Task TestAddFailure() { CreateCountryViewModel lCreateCountryViewModel = new CreateCountryViewModel() { Name = "England" }; this.countryController.ModelState.AddModelError("aa", "error"); IActionResult lResult = await this.countryController.Add(lCreateCountryViewModel); ViewResult lViewResult = lResult as ViewResult; var lViewModel = lViewResult.Model as CreateCountryViewModel; Assert.AreEqual("England", lViewModel.Name); await this.ReferenceServices.Received(0).CreateCountry(Arg.Any <CreateCountryDto>()); }
public async Task TestAdd() { this.ReferenceServices.CreateCountry(Arg.Any <CreateCountryDto>()).Returns(new CountryDto { Id = 50 }); CreateCountryViewModel lCreateCountryViewModel = new CreateCountryViewModel() { Name = "England" }; IActionResult lResult = await this.countryController.Add(lCreateCountryViewModel); RedirectToActionResult lViewResult = lResult as RedirectToActionResult; Assert.AreEqual("Country successfully created", lViewResult.RouteValues["successMessage"]); await this.ReferenceServices.Received(1).CreateCountry(Arg.Is <CreateCountryDto>(dto => dto.Name == "England")); }
public ActionResult CreateCountry(CreateCountryViewModel ctyVM) { if (ModelState.IsValid) { Country country = _countryService.Add(ctyVM); if (country == null) { ModelState.AddModelError("msg", "Database Problem"); return(View(ctyVM)); } return(RedirectToAction(nameof(ShowCountry))); } else { return(View(ctyVM)); } }
// GET: CountryController public ActionResult ShowCountry() { /*CreateCountryViewModel ctyVM = new CreateCountryViewModel(); * * Country cty = new Country(); * * cty.CountryName = "Default Country"; * cty.CountryId = 0; * * List<Country> countryList = new List<Country>(); * countryList.Add(cty); * * ctyVM.CountryList = countryList;*/ CreateCountryViewModel ctyVM = new CreateCountryViewModel(); ctyVM.CountryList = _countryService.All(); return(View(ctyVM)); //return View("ShowCountry",ctyVM); }
public CountryViewModel FindBy(CreateCountryViewModel search) { //CountryViewModel //return _countriesRepo.Read(); throw new NotImplementedException(); }
public Country Add(CreateCountryViewModel createCountryViewModel) { return(_countryRepo.Create(createCountryViewModel.CountryName)); }
// GET: CountryController/Create public ActionResult Create() { CreateCountryViewModel createCountry = new CreateCountryViewModel(); return(View(createCountry)); }
public ActionResult Edit(CreateCountryViewModel editCountry) { _countryService.Edit(editCountry.CountryId, editCountry); return(RedirectToAction(nameof(ShowCountry))); }