Beispiel #1
0
        public async Task <UserProfileListViewModel> GetAllAsync(int pageIndex, int itemsPage, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - UserProfileService_GetAllAsync called.");

            try
            {
                var listItems = (await _userProfileRepository.GetAllAsync(requestId)).ToList();
                Guard.Against.Null(listItems, nameof(listItems), requestId);

                var userProfileListViewModel = new UserProfileListViewModel();
                foreach (var item in listItems)
                {
                    userProfileListViewModel.ItemsList.Add(await _userProfileHelpers.ToViewModelAsync(item));
                }

                if (userProfileListViewModel.ItemsList.Count == 0)
                {
                    _logger.LogWarning($"RequestId: {requestId} - UserProfileService_GetAllAsync no items found");
                    throw new NoItemsFound($"RequestId: {requestId} - Method name: UserProfileService_GetAllAsync - No Items Found");
                }

                return(userProfileListViewModel);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - UserProfileService_GetAllAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - UserProfileService_GetAllAsync Service Exception: {ex}");
            }
        }
Beispiel #2
0
        public IActionResult DashBoard()
        {
            var  userListProfile = new UserProfileListViewModel();
            var  person          = new UserProfileViewModel();
            long currentId       = Convert.ToInt32(_signInManager.UserManager.GetUserId(User));
            var  currentUserDto  = _userService.GetUserById(currentId);

            person.PersonalData = _mapper.Map <UserDetailedViewModel>(currentUserDto);

            var modulesDto = _moduleService.GetModules();
            var modules    = _mapper.Map <IList <ModuleViewModel> >(modulesDto);
            var themesDto  = _themeService.GetThemes();
            var themes     = _mapper.Map <IList <ThemeViewModel> >(themesDto);

            person.Modules = modules;
            person.Themes  = themes;

            var marks = new MarksViewModel();

            if (User.IsInRole("Intern"))
            {
                var themeMarksDto = _themeMarkService.GetThemeMarksByUserId(currentId);
                marks.ThemeMarks = _mapper.Map <IList <ThemeMarkViewModel> >(themeMarksDto);
                var examMarksDto = _examMarkService.GetExamMarksByUserId(currentId);
                marks.ExamMarks             = _mapper.Map <IList <ExamMarkViewModel> >(examMarksDto);
                person.Marks                = marks;
                userListProfile.UserProfile = person;

                return(View("../DashBoard/Index", userListProfile));
            }
            else if (User.IsInRole("Menthor") || User.IsInRole("Admin"))
            {
                var themeMarksDto = _themeMarkService.GetThemeMarks();
                marks.ThemeMarks = _mapper.Map <IList <ThemeMarkViewModel> >(themeMarksDto);
                var examMarksDto = _examMarkService.GetExamMarks();
                marks.ExamMarks = _mapper.Map <IList <ExamMarkViewModel> >(examMarksDto);

                person.Marks = marks;

                if (User.IsInRole("Admin"))
                {
                    var usersDto = _userService.GetUsersDetails();

                    userListProfile.UserProfile = person;
                    userListProfile.Users       = _mapper.Map <IList <UserDetailedViewModel> >(usersDto);

                    return(View("../DashBoard/Index", userListProfile));
                }

                userListProfile.UserProfile = person;
                return(View("../DashBoard/Index", userListProfile));
            }
            return(View("Error"));
        }
Beispiel #3
0
        public async Task <ActionResult> List()
        {
            var users = await userProfileService.GetAllUserProfilesAsync(u => u.User);

            var orderedUsers = users.OrderBy(u => u.Name);
            var model        = new UserProfileListViewModel()
            {
                UserProfiles = Mapper.Map <IEnumerable <UserProfile>, IEnumerable <UserProfileViewModel> >(orderedUsers.AsEnumerable())
            };

            return(View(model));
        }
Beispiel #4
0
        public async Task <IHttpActionResult> Update(UserProfileListViewModel model)
        {
            try
            {
                var p = _uow.UserProfile.Get(model.Id);
                if (p == null)
                {
                    throw new BusinessException("Không tìm thấy thông tin thành viên này");
                }
                bool isChangeRole = (p.Role != model.Role);
                p.Id             = model.Id;
                p.FullName       = model.FullName;
                p.Email          = model.Email;
                p.Mobile         = model.Mobile;
                p.Level          = model.Level;
                p.Role           = model.Role;
                p.ExpiredDate    = model.ExpiredDate;
                p.IsVerifyEmail  = model.IsVerifyEmail;
                p.IsVerifyMobile = model.IsVerifyMobile;
                //p.IsOffAlert = model.IsOffAlert;
                await _uow.UserProfile.UpdateProfile(p);

                if (isChangeRole)
                {
                    await _uow.UserProfile.ChangeRole(p.Id, model.Role);
                }
                await _repoUser.UpdateClaimAsync(model.Id, new System.Security.Claims.Claim("Level", model.Level.ToString()));

                return(Ok());
            }
            catch (BusinessException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                return(BadRequest(this.General_Err));
            }
        }