Exemple #1
0
        // 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));
        }
Exemple #5
0
        // GET: Countries/Create
        public ActionResult Create()
        {
            CreateCountryViewModel createCountryViewModel = new CreateCountryViewModel();

            createCountryViewModel.Cities = _citysService.All().cityList;


            return(View(createCountryViewModel));
        }
Exemple #6
0
 public ActionResult Create(CreateCountryViewModel createCountryViewModel)
 {
     if (ModelState.IsValid)
     {
         _countrysService.Add(createCountryViewModel);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(createCountryViewModel));
 }
Exemple #7
0
        public Country Edit(int id, CreateCountryViewModel edit)
        {
            Country editedcountry = new Country()
            {
                CountryId = id, CountryName = edit.CountryName
            };

            return(_countryRepo.Update(editedcountry));
        }
Exemple #8
0
        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));
        }
Exemple #9
0
        public Country Edit(int id, CreateCountryViewModel country)
        {
            Country editCountry = new Country()
            {
                Name = country.Name, Id = id
            };

            return(_countriesRepo.Update(editCountry));

            throw new NotImplementedException();
        }
Exemple #10
0
        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)));
        }
Exemple #11
0
        // 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)));
        }
Exemple #15
0
        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));
        }
Exemple #16
0
        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" }));
        }
Exemple #17
0
        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());
        }
Exemple #18
0
        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());
        }
Exemple #20
0
        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>());
        }
Exemple #21
0
        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"));
        }
Exemple #22
0
        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));
            }
        }
Exemple #23
0
        // 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);
        }
Exemple #24
0
 public CountryViewModel FindBy(CreateCountryViewModel search)
 {
     //CountryViewModel
     //return _countriesRepo.Read();
     throw new NotImplementedException();
 }
Exemple #25
0
 public Country Add(CreateCountryViewModel createCountryViewModel)
 {
     return(_countryRepo.Create(createCountryViewModel.CountryName));
 }
        // GET: CountryController/Create
        public ActionResult Create()
        {
            CreateCountryViewModel createCountry = new CreateCountryViewModel();

            return(View(createCountry));
        }
Exemple #27
0
        public ActionResult Edit(CreateCountryViewModel editCountry)
        {
            _countryService.Edit(editCountry.CountryId, editCountry);

            return(RedirectToAction(nameof(ShowCountry)));
        }