Esempio n. 1
0
        /// <summary>
        /// Index view to all the user to manage their profile
        /// </summary>
        /// <returns>View</returns>
        public IActionResult Index()
        {
            var user = _userSettingRepo.Read(User.Identity.Name);

            // When the user is not found redirect to a login page
            if (user == null)
            {
                return(LocalRedirect("/Identity/Account/Login"));
            }

            // Get all the news categories that the user does not have
            var subtracted = _newsCategoryRepo.ReadAll().Where(n => !n.UserSettingNewsCategories.Select(news => news.NewsCategory.Name).Contains(n.Name)).ToList();

            // Get all the news categories of the user
            var newsCatList = _newsCategoryRepo.Read(user.Id).UserSettingNewsCategories.ToList();

            // Instantiate a new profile manager view model
            var userVM = new ProfileManageVM {
                Username  = user.User.UserName,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Language  = user.Language,
                Country   = user.Country,
                SubtractedNewsCategoriesOptions = subtracted,
                UserSettingNewsCategories       = newsCatList
            };

            return(View(userVM));
        }
Esempio n. 2
0
        public IActionResult Edit(ProfileManageVM profileVM)
        {
            // When the model state is valid
            if (ModelState.IsValid)
            {
                // Get the current user setting
                var currentUser = _userSettingRepo.Read(User.Identity.Name);
                // Get the user setting from the identity user found
                var userSetting = profileVM.GetInstance(currentUser);

                // Update the user's setting profile to what the user wants
                _userSettingRepo.Update(User.Identity.Name, userSetting, profileVM.NewsCategoryNames);
                return(RedirectToAction("Index"));
            }

            return(View(profileVM));
        }