Пример #1
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());
        }
Пример #2
0
        public async Task <IActionResult> Edit(string userId)
        {
            if (userId == null)
            {
                _loggerService.LogError("User id is null");
                return(RedirectToAction("HandleError", "Error", new { code = 500 }));
            }

            try
            {
                var user = await _userService.GetUserAsync(userId);

                var genders = (from item in await _genderService.GetAllAsync() select new SelectListItem {
                    Text = item.Name, Value = item.ID.ToString()
                });

                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 EducationUserViewModel {
                    PlaceOfStudyID = user.UserProfile.EducationId, SpecialityID = user.UserProfile.EducationId, PlaceOfStudyList = placeOfStudyUnique, SpecialityList = specialityUnique
                };
                var workView = new WorkUserViewModel {
                    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(View(model));
            }
            catch (Exception e)
            {
                _loggerService.LogError($"Exception: { e.Message}");
                return(RedirectToAction("HandleError", "Error", new { code = 500 }));
            }
        }