Example #1
0
        //public async Task<JsonResult> GetCitiesAsync(int countryId)
        //{
        //    var country = await _countryRepository.GetCountryWithCitiesAsync(countryId);
        //    return this.Json(country.Cities.OrderBy(c => c.Name));
        //}

        public async Task <IActionResult> ChangeUserAdmin()
        {
            var user = await _userHelper.GetUserByEmailAsync(this.User.Identity.Name);

            var model = new ChangeUserAdminViewModel();

            if (user != null)
            {
                model.Name           = user.Name;
                model.VAT            = user.VAT;
                model.Username       = user.UserName;
                model.EmailConfirmed = user.EmailConfirmed;

                //var city = await _countryRepository.GetCityAsync(user.CityId);
                //if (city != null)
                //{
                //    var country = await _countryRepository.GetCountryAsync(city);
                //    if (country != null)
                //    {
                //        model.CountryId = country.Id;
                //        model.Cities = _countryRepository.GetComboCities(country.Id);
                //        model.Countries = _countryRepository.GetComboCountries();
                //        model.CityId = user.CityId;
                //    }
                //}
            }

            //model.Cities = _countryRepository.GetComboCities(model.CountryId);
            //model.Countries = _countryRepository.GetComboCountries();
            return(this.View(model));
        }
Example #2
0
        public async Task <IActionResult> ChangeUserAdmin(ChangeUserAdminViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await _userHelper.GetUserByEmailAsync(this.User.Identity.Name);

                if (user != null)
                {
                    //var city = await _countryRepository.GetCityAsync(model.CityId);

                    user.Name            = model.Name;
                    user.VAT             = model.VAT;
                    user.UserName        = model.Username;
                    model.EmailConfirmed = user.EmailConfirmed;
                    //user.CityId = model.CityId;
                    //user.City = city;

                    var respose = await _userHelper.UpdateUserAsync(user);

                    if (respose.Succeeded)
                    {
                        this.ViewBag.UserMessage = "User updated!";
                    }
                    else
                    {
                        this.ModelState.AddModelError(string.Empty, respose.Errors.FirstOrDefault().Description);
                    }
                }
                else
                {
                    this.ModelState.AddModelError(string.Empty, "User not found.");
                }
            }

            return(this.View(model));
        }