예제 #1
0
        public async Task <IActionResult> Index(SettingIndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.LogoFormFile != null)
            {
                model.Logo = await _fileProvider.UploadFileAsync("", model.LogoFormFile);
            }

            if (model.FaviconFormFile != null)
            {
                model.Favicon = await _fileProvider.UploadFileAsync("", model.FaviconFormFile);
            }

            await _appSettingsService.SaveAppSettingsAsync(_mapper.Map <AppSettings>(model));

            _notificationService.SuccessNotification("Ayarlar güncelleştirildi.");

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> Index(IndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Task <string> uploadFileName = null;

            if (model.ProfilePhotoFile != null)
            {
                uploadFileName = _libFileProvider.UploadFileAsync("media/users", model.ProfilePhotoFile);
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var email = user.Email;

            if (model.Email != email)
            {
                var setEmailResult = await _userManager.SetEmailAsync(user, model.Email);

                if (!setEmailResult.Succeeded)
                {
                    throw new ApplicationException(
                              $"Unexpected error occurred setting email for user with ID '{user.Id}'.");
                }
            }

            if (model.Username != user.UserName)
            {
                var setUserNameResult = await _userManager.SetUserNameAsync(user, model.Username);

                if (!setUserNameResult.Succeeded)
                {
                    throw new ApplicationException(
                              $"Unexpected error occurred setting email for user with ID '{user.Id}'.");
                }
            }

            var phoneNumber = user.PhoneNumber;

            if (model.PhoneNumber != phoneNumber)
            {
                var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, model.PhoneNumber);

                if (!setPhoneResult.Succeeded)
                {
                    throw new ApplicationException(
                              $"Unexpected error occurred setting phone number for user with ID '{user.Id}'.");
                }
            }

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;

            if (uploadFileName != null)
            {
                user.ProfilFoto = await uploadFileName;
            }

            await _userManager.UpdateAsync(user);

            _notificationService.SuccessNotification("Profiliniz başarıyla güncelleştirildi.");
            return(RedirectToAction(nameof(Index)));
        }