Esempio n. 1
0
        public async Task <IActionResult> Profile(FacultyProfileViewModel vm)
        {
            var states = new List <string> {
                "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "District of Columbia", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"
            };

            ViewBag.states = new SelectList(states);

            var countries = new List <string> {
                "Afghanistan", "Albanien", "Algeriet", "Angola", "Antigua och Barbuda", "Argentina", "Australien", "Azerbajdzjan", "Österrike", "Östtimor", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belgien", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnien och Hercegovina", "Botswana", "Brasilien", "Brunei Darussalam", "Bulgarien", "Burkina Faso", "Burundi", "Centralafrikanska Republiken", "Chile", "Colombia", "Costa Rica", "Cypern", "Danmark", "Demokratiska Republiken Kongo", "Dominikanska Republiken", "Ecuador", "Egypten", "El Salvador", "Elfenbenskusten", "Estland", "Etiopien", "Färöarna", "Förenade Arabemiraten", "Filippinerna", "Finland", "Frankrike", "Gabon", "Georgien", "Ghana", "Gibraltar", "Grönland", "Grekland", "Grenada", "Guatemala", "Honduras", "Hong Kong", "Indien", "Indonesien", "Irak", "Iran", "Irland", "Island", "Israel", "Italien", "Jamaica", "Japan", "Jemen", "Jersey", "Jordanien", "Kambodja", "Kanada", "Kazakstan", "Kenya", "Kina", "Kiribati", "Kroatien", "Kuba", "Kuwait", "Laos", "Lettland", "Libanon", "Libyen", "Litauen", "Luxemburg", "Madagaskar", "Makedonien", "Malawi", "Malaysia", "Maldiverna", "Mali", "Malta", "Marocko", "Mauritius", "Mexiko", "Mocambique", "Monaco", "Mongoliet", "Myanmar", "Namibia", "Nederländerna", "Nederländska Antillerna", "Nepal", "Nicaragua", "Niger", "Nigeria", "Norge", "Nya Zeeland", "Oman", "Pakistan", "Panama", "Paraguay", "Peru", "Polen", "Portugal", "Puerto Rico", "Qatar", "Rumänien", "Rwanda", "Ryssland", "Saint Lucia", "Saint Vincent och Grenadinerna", "Samoa", "San Marino", "Sao Tome och Principe", "Saudiarabien", "Schweiz", "Senegal", "Serbien och Montenegro", "Seychellerna", "Sierra Leone", "Singapore", "Slovakien", "Slovenien", "Somalia", "Spanien", "Sri Lanka", "Sudan", "Surinam", "Sverige", "Swaziland", "Sydafrika", "Sydkorea", "Syrien", "Taiwan", "Tanzania", "Thailand", "Tjeckien", "Trinidad och Tobago", "Tunisien", "Turkiet", "Tyskland", "Uganda", "Ukraina", "Ungern", "Uruguay", "USA", "Uzbekistan", "Venezuela", "Vietnam", "Vitryssland", "Zambia", "Zimbabwe"
            };

            ViewBag.countries = new SelectList(countries);

            var specialities = _repository.GetSpecialties().Select(m => m.SpecialtyTitle).OrderBy(m => m);

            ViewBag.specialties = new SelectList(specialities);

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }
            var dbFaculty = await _userManager.FindByIdAsync(vm.Id);

            if (dbFaculty.UserName != vm.UserName)
            {
                var result = await _userManager.SetEmailAsync(dbFaculty, vm.UserName);

                if (!result.Succeeded)
                {
                    AddErrors(result);
                    return(View(vm));
                }

                result = await _userManager.SetUserNameAsync(dbFaculty, vm.UserName);

                if (!result.Succeeded)
                {
                    AddErrors(result);
                    return(View(vm));
                }
            }

            Mapper.Map(vm, dbFaculty);

            if (_repository.SaveAll())
            {
                return(RedirectToAction("Index"));
            }
            return(View(vm));
        }
Esempio n. 2
0
        public async Task <IActionResult> EditFaculty(FacultyProfileViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var dbFaculty = await _repository.GetFaculty(vm.Id);

                if (dbFaculty.UserName != vm.UserName)
                {
                    var result = await _userManager.SetEmailAsync(dbFaculty, vm.UserName);

                    if (!result.Succeeded)
                    {
                        AddErrors(result);
                        return(View(vm));
                    }

                    result = await _userManager.SetUserNameAsync(dbFaculty, vm.UserName);

                    if (!result.Succeeded)
                    {
                        AddErrors(result);
                        return(View(vm));
                    }
                }

                Mapper.Map(vm, dbFaculty);

                if (_repository.SaveAll())
                {
                    return(RedirectToAction("Faculty"));
                }
                return(View(vm));
            }

            ViewBag.states = new SelectList(GetStates());

            ViewBag.countries = new SelectList(GetCountries());

            ViewBag.specialties = new SelectList(_repository.GetSpecialties().Select(m => m.SpecialtyTitle).OrderBy(m => m));

            return(View(vm));
        }