コード例 #1
0
        public async Task <IActionResult> SelectCountry(string methodName, string controllerName)
        {
            int countryId = 0;

            if (this.HttpContext.Session.Keys.Contains("CountryId"))
            {
                countryId = JsonConvert.DeserializeObject <int>(this.HttpContext.Session.GetString("CountryId"));
            }
            else if (this.User.Identity.IsAuthenticated)
            {
                var user = await this.userManager.GetUserAsync(this.User);

                countryId = user.CountryId;
            }

            this.ViewBag.CallerMethod     = methodName;
            this.ViewBag.CallerController = controllerName;

            var viewModel = new SelectCountryViewModel
            {
                CountryId      = countryId,
                CountriesItems = await this.countriesService.GetAllAsKeyValuePairsAsync(),
            };

            return(this.View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> Index(SelectCountryViewModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                var viewModel = new SelectCountryViewModel
                {
                    CountriesItems = await this.countriesService.GetAllAsKeyValuePairsAsync(),
                };

                return(this.View(viewModel));
            }

            this.HttpContext.Session.SetString("CountryId", JsonConvert.SerializeObject(inputModel.CountryId));

            var countryId = inputModel.CountryId;

            return(this.RedirectToAction(nameof(this.IndexCars), new { countryId }));
        }
コード例 #3
0
        public async Task <IActionResult> Index()
        {
            if (this.HttpContext.Session.Keys.Contains("CountryId"))
            {
                var countryId = JsonConvert.DeserializeObject <int>(this.HttpContext.Session.GetString("CountryId"));

                return(this.RedirectToAction(nameof(this.IndexCars), new { countryId }));
            }

            var viewModel = new SelectCountryViewModel
            {
                CountriesItems = await this.countriesService.GetAllAsKeyValuePairsAsync(),
            };

            if (this.User.Identity.IsAuthenticated)
            {
                var user = await this.userManager.GetUserAsync(this.User);

                viewModel.CountryId = user.CountryId;
            }

            return(this.View(viewModel));
        }