예제 #1
0
        public async Task <ActionResult> EditProfile(RegisteredUserEditVM registeredUserEditVM)
        {
            countryApi = new CountryApiClient();

            if (ModelState.IsValid)
            {
                registeredUserApi = new RegisteredUserApiClient();

                string  code    = registeredUserEditVM.SelectedCountry.Substring(0, 2);
                Country country = await countryApi.GetCountry(code);

                registeredUserEditVM.Country = country;

                RegisteredUser registeredUser = await registeredUserApi.EditUserProfile(registeredUserEditVM);

                if (registeredUser != null)
                {
                    Session["RegisteredUser"] = registeredUser;

                    return(RedirectToAction("UserProfile", "Account"));
                }
            }

            List <Country> countries = await countryApi.GetCountries();

            SelectList selectListItemCountries = new SelectList(countries);

            registeredUserEditVM.Countries = selectListItemCountries;

            return(View(registeredUserEditVM));
        }
예제 #2
0
        public async Task <ActionResult> EditProfile(int id)
        {
            countryApi = new CountryApiClient();

            List <Country> countries = await countryApi.GetCountries();

            SelectList selectListItemCountries = new SelectList(countries);

            registeredUserApi = new RegisteredUserApiClient();

            RegisteredUser registeredUser = await registeredUserApi.GetRegisteredUser(id);

            RegisteredUserEditVM registeredUserEditVM = new RegisteredUserEditVM()
            {
                Username  = registeredUser.Username,
                Email     = registeredUser.Email,
                FirstName = registeredUser.FirstName,
                LastName  = registeredUser.LastName,
                Address   = registeredUser.Location.Address,
                City      = registeredUser.Location.City.Name,
                Countries = selectListItemCountries
            };

            return(View(registeredUserEditVM));
        }
예제 #3
0
        public async Task <bool> UpdateRegisteredUser(RegisteredUserEditVM registeredUserEditVM)
        {
            StringContent       content  = GetStringContent(registeredUserEditVM);
            HttpClient          request  = new HttpClient();
            HttpResponseMessage response = await request.PutAsync($"{ API_URL }/EditRegisteredUser", content);

            if (response.IsSuccessStatusCode)
            {
                bool result = await response.Content.ReadAsAsync <bool>();

                return(result);
            }
            return(false);
        }
예제 #4
0
        public async Task <RegisteredUser> EditUserProfile(RegisteredUserEditVM registeredUserEditVM)
        {
            StringContent       content  = GetStringContent(registeredUserEditVM);
            HttpClient          request  = new HttpClient();
            HttpResponseMessage response = await request.PutAsync($"{ API_URL }/EditUserProfile", content);

            if (response.IsSuccessStatusCode)
            {
                RegisteredUser registeredUser = await response.Content.ReadAsAsync <RegisteredUser>();

                return(registeredUser);
            }
            return(null);
        }
예제 #5
0
        public RegisteredUser EditUserProfile(RegisteredUserEditVM registeredUserEditVM)
        {
            Password password = CreateHashedPasswordAndSalt(registeredUserEditVM.Password);

            string  inputAddress  = registeredUserEditVM.Address;
            string  inputCityName = registeredUserEditVM.City;
            Country inputCountry  = registeredUserEditVM.Country;

            Country country = unitOfWork.Countries.Get(inputCountry.Id);

            bool cityExists = unitOfWork.Cities.Exists(inputCityName, country.Id);

            City city = cityExists ?
                        unitOfWork.Cities.GetCityWithCountry(inputCityName, country.Id) :
                        new City()
            {
                Name = inputCityName, Country = country
            };

            bool locationExists = unitOfWork.Locations.Exists(inputAddress, city.Id, city.Country.Id);

            Location location = locationExists ?
                                unitOfWork.Locations.GetLocationWithCity(inputAddress, city.Id, city.Country.Id) :
                                new Location()
            {
                Address = inputAddress, City = city
            };

            RegisteredUser registeredUser = unitOfWork.RegisteredUsers.Get(registeredUserEditVM.Id);

            registeredUser.Username     = registeredUserEditVM.Username;
            registeredUser.PasswordHash = password.Hash;
            registeredUser.PasswordSalt = password.Salt;
            registeredUser.FirstName    = registeredUserEditVM.FirstName;
            registeredUser.LastName     = registeredUserEditVM.LastName;
            registeredUser.Email        = registeredUserEditVM.Email;
            registeredUser.Location     = location;

            int success = unitOfWork.Complete();

            if (success > 0)
            {
                return(registeredUser);
            }
            return(null);
        }
예제 #6
0
        private async Task UpdateRegisteredUser()
        {
            if (ValidateInputs())
            {
                RegisteredUserEditVM registeredUserEditVM = new RegisteredUserEditVM()
                {
                    Id        = registeredUser.Id,
                    Username  = TbUsername.Text,
                    Password  = TbPassword.Password,
                    Email     = TbEmail.Text,
                    FirstName = TbFirstName.Text,
                    LastName  = TbLastName.Text,
                    Address   = TbAddress.Text,
                    City      = TbCity.Text,
                    Country   = (Country)CbCountries.SelectedItem
                };

                ls.LblLoading.Text = "Editing";
                ls.Show();
                bool success = await registeredUserApi.UpdateRegisteredUser(registeredUserEditVM);

                ls.Close();

                if (success)
                {
                    Close();
                }
                else
                {
                    MessageBox.Show("Fail");
                }
            }
            else
            {
                MessageBox.Show("All input fields are required and Password must match Confirm password!");
            }
        }