public async Task <IActionResult> Edit(string userId)
        {
            if (userId == null)
            {
                _loggerService.LogError("User id is null");

                return(NotFound());
            }
            var user = await _userService.GetUserAsync(userId);

            var currentUserId = _userManager.GetUserId(User);
            var currentUser   = await _userService.GetUserAsync(currentUserId);

            if (!(userId == currentUserId || await _userManagerService.IsInRoleAsync(currentUser, Roles.Admin)))
            {
                _loggerService.LogError($"User (id: {currentUserId}) hasn't access to edit profile (id: {userId})");
                return(StatusCode(StatusCodes.Status403Forbidden));
            }

            if (user != null)
            {
                var genders            = _mapper.Map <IEnumerable <GenderDTO>, IEnumerable <GenderViewModel> >(await _userPersonalDataService.GetAllGendersAsync());
                var placeOfStudyUnique = _mapper.Map <IEnumerable <EducationDTO>, IEnumerable <EducationViewModel> >(await _userPersonalDataService.GetAllEducationsGroupByPlaceAsync());
                var specialityUnique   = _mapper.Map <IEnumerable <EducationDTO>, IEnumerable <EducationViewModel> >(await _userPersonalDataService.GetAllEducationsGroupBySpecialityAsync());
                var placeOfWorkUnique  = _mapper.Map <IEnumerable <WorkDTO>, IEnumerable <WorkViewModel> >(await _userPersonalDataService.GetAllWorkGroupByPlaceAsync());
                var positionUnique     = _mapper.Map <IEnumerable <WorkDTO>, IEnumerable <WorkViewModel> >(await _userPersonalDataService.GetAllWorkGroupByPositionAsync());
                var upuDegrees         = _mapper.Map <IEnumerable <UpuDegreeDTO>, IEnumerable <UpuDegreeViewModel> >(await _userPersonalDataService.GetAllUpuDegreesAsync());

                var educView = new UserEducationViewModel {
                    PlaceOfStudyID = user.UserProfile.EducationId, SpecialityID = user.UserProfile.EducationId, PlaceOfStudyList = placeOfStudyUnique, SpecialityList = specialityUnique
                };
                var workView = new UserWorkViewModel {
                    PlaceOfWorkID = user.UserProfile.WorkId, PositionID = user.UserProfile.WorkId, PlaceOfWorkList = placeOfWorkUnique, PositionList = positionUnique
                };
                var model = new EditUserViewModel()
                {
                    User          = _mapper.Map <UserDTO, UserViewModel>(user),
                    Nationalities = _mapper.Map <IEnumerable <NationalityDTO>, IEnumerable <NationalityViewModel> >(await _userPersonalDataService.GetAllNationalityAsync()),
                    Religions     = _mapper.Map <IEnumerable <ReligionDTO>, IEnumerable <ReligionViewModel> >(await _userPersonalDataService.GetAllReligionsAsync()),
                    EducationView = educView,
                    WorkView      = workView,
                    Degrees       = _mapper.Map <IEnumerable <DegreeDTO>, IEnumerable <DegreeViewModel> >(await _userPersonalDataService.GetAllDegreesAsync()),
                    Genders       = genders,
                    UpuDegrees    = upuDegrees,
                };

                return(Ok(model));
            }
            _loggerService.LogError($"User not found. UserId:{userId}");
            return(NotFound());
        }
        public List <UserWorkViewModel> GetUserWorks()
        {
            StatisticsViewModel temp = new StatisticsViewModel();

            temp.AllDreamUsers     = helper.getServiceProviders(CoreController.UserWorkCode.Dream.ToString(), CoreController.UserStatus.Active.ToString()).Count();
            temp.AllRouqiaUsers    = helper.getServiceProviders(CoreController.UserWorkCode.Rouqia.ToString(), CoreController.UserStatus.Active.ToString()).Count();
            temp.AllIftaaUsers     = helper.getServiceProviders(CoreController.UserWorkCode.Iftaa.ToString(), CoreController.UserStatus.Active.ToString()).Count();
            temp.AllIstasharaUsers = helper.getServiceProviders(CoreController.UserWorkCode.Istishara.ToString(), CoreController.UserStatus.Active.ToString()).Count();
            temp.AllMedicalUsers   = helper.getServiceProviders(CoreController.UserWorkCode.Medical.ToString(), CoreController.UserStatus.Active.ToString()).Count();
            List <UserWork>          UserWorks = db.UserWorks.Where(a => a.Enabled).ToList();
            List <UserWorkViewModel> result    = new List <UserWorkViewModel>();

            foreach (var item in UserWorks)
            {
                UserWorkViewModel u = new UserWorkViewModel();
                u.UserWork = item;

                if (item.Code.Equals(CoreController.UserWorkCode.Dream.ToString()))
                {
                    u.UserCount = temp.AllDreamUsers;
                }

                else if (item.Code.Equals(CoreController.UserWorkCode.Rouqia.ToString()))
                {
                    u.UserCount = temp.AllRouqiaUsers;
                }
                else if (item.Code.Equals(CoreController.UserWorkCode.Iftaa.ToString()))
                {
                    u.UserCount = temp.AllIftaaUsers;
                }
                else if (item.Code.Equals(CoreController.UserWorkCode.Istishara.ToString()))
                {
                    u.UserCount = temp.AllIstasharaUsers;
                }
                else if (item.Code.Equals(CoreController.UserWorkCode.Medical.ToString()))
                {
                    u.UserCount = temp.AllMedicalUsers;
                }
                result.Add(u);
            }
            return(result);
        }
Exemple #3
0
        public async Task <IActionResult> Edit(string userId)
        {
            if (userId == null)
            {
                _loggerService.LogError("User id is null");

                return(NotFound());
            }
            var user = await _userService.GetUserAsync(userId);

            if (user != null)
            {
                var genders            = _mapper.Map <IEnumerable <GenderDTO>, IEnumerable <GenderViewModel> >(await _genderService.GetAllAsync());
                var placeOfStudyUnique = _mapper.Map <IEnumerable <EducationDTO>, IEnumerable <EducationViewModel> >(await _educationService.GetAllGroupByPlaceAsync());
                var specialityUnique   = _mapper.Map <IEnumerable <EducationDTO>, IEnumerable <EducationViewModel> >(await _educationService.GetAllGroupBySpecialityAsync());
                var placeOfWorkUnique  = _mapper.Map <IEnumerable <WorkDTO>, IEnumerable <WorkViewModel> >(await _workService.GetAllGroupByPlaceAsync());
                var positionUnique     = _mapper.Map <IEnumerable <WorkDTO>, IEnumerable <WorkViewModel> >(await _workService.GetAllGroupByPositionAsync());

                var educView = new UserEducationViewModel {
                    PlaceOfStudyID = user.UserProfile.EducationId, SpecialityID = user.UserProfile.EducationId, PlaceOfStudyList = placeOfStudyUnique, SpecialityList = specialityUnique
                };
                var workView = new UserWorkViewModel {
                    PlaceOfWorkID = user.UserProfile.WorkId, PositionID = user.UserProfile.WorkId, PlaceOfWorkList = placeOfWorkUnique, PositionList = positionUnique
                };
                var model = new EditUserViewModel()
                {
                    User          = _mapper.Map <UserDTO, UserViewModel>(user),
                    Nationalities = _mapper.Map <IEnumerable <NationalityDTO>, IEnumerable <NationalityViewModel> >(await _nationalityService.GetAllAsync()),
                    Religions     = _mapper.Map <IEnumerable <ReligionDTO>, IEnumerable <ReligionViewModel> >(await _religionService.GetAllAsync()),
                    EducationView = educView,
                    WorkView      = workView,
                    Degrees       = _mapper.Map <IEnumerable <DegreeDTO>, IEnumerable <DegreeViewModel> >(await _degreeService.GetAllAsync()),
                    Genders       = genders,
                };

                return(Ok(model));
            }
            _loggerService.LogError($"User not found. UserId:{userId}");
            return(NotFound());
        }