コード例 #1
0
        public IActionResult Index()
        {
            UserInfoViewModel vm = new UserInfoViewModel();
            var userInfo         = _userInfoService.GetUserInfo(User.Identity.Name);

            vm.StartUserInfo = userInfo;
            if (User.IsInRole(ProfilerRoles.Student))
            {
                var currentStudent = _studentService.GetCurrentStudentByUserInfo(userInfo.Id);
                var currentResume  = _resumeService.GetResumeByStudentId(currentStudent.Id);

                vm.Stream         = _streamService.GetStreamByStudentId(currentStudent.Id);
                vm.IsResumeExists = currentResume != null ? true : false;

                return(View(vm));
            }
            else if (User.IsInRole(ProfilerRoles.HR))
            {
                return(RedirectToAction(nameof(HrManagerController.Index), "HrManager"));
            }
            else if (User.IsInRole(ProfilerRoles.Trainer))
            {
                return(RedirectToAction(nameof(TrainerController.Index), "Trainer"));
            }

            return(View(vm));
        }
コード例 #2
0
        public IActionResult Index(int resumeId)
        {
            var currentStudent = _studentService.GetStudentByResumeId(resumeId);
            //Get all data for Resume from all tables
            ResumeReviewViewModel vm = new ResumeReviewViewModel
            {
                ResumeId         = resumeId,
                ResumeStatus     = _resumeService.GetResumeById(resumeId).Status,
                UserInfo         = _userInfoService.GetUserInfo(User.Identity.Name),
                Stream           = _streamService.GetStreamByStudentId(currentStudent.Id),
                Summary          = _summaryService.GetSummaryByResumeId(resumeId),
                Skills           = _skillService.GetAllSkillsForStudent(currentStudent.Id).ToArray(),
                ForeignLanguages = _languageService.GetAllForeignLanguagesForResume(resumeId).ToArray(),
                Educations       = _educationService.GetAllEducationsForResume(resumeId).ToArray(),
                Courses          = _courseService.GetAllCoursesForResume(resumeId).ToArray(),
                Certificates     = _certificateService.GetAllCertificatesForResume(resumeId).ToArray(),
                Exams            = _examService.GetAllExamsForResume(resumeId).ToArray(),
                WorkExperience   = _workExperienceService.GetWorkExperienceForResume(resumeId).ToArray(),
                Portfolio        = _portfolioService.GetPortfolioForResume(resumeId).ToArray(),
                MilitaryStatus   = _militaryStatusService.GetMilitaryStatusForResume(resumeId),
                AdditionalInfo   = _additionalInfoService.GetAdditionalInfo(resumeId),
                Recommendations  = _recommendationService.GetAllRecommendationsForResume(resumeId).ToArray()
            };

            return(View(vm));
        }
コード例 #3
0
        public IActionResult Index()
        {
            //get list of students
            IList <Student> students = _studentService.GetAllStudents();

            if (students.Count() == 0)
            {
                return(NotFound());
            }

            HrManagerViewModel viewModel = new HrManagerViewModel();

            viewModel.TableData = new List <TableRow>();

            //fill all rows of the model
            foreach (Student st in students)
            {
                //since we need to manually format many columns from UserInfo
                //it is assigned to a separate var
                UserInfo studentInfo = _studentService.GetUserInfo(st);

                TableRow row = new TableRow();

                //take from UserInfo
                row.DateOfBirth = studentInfo.DateOfBirth.ToShortDateString();
                row.PhoneNumber = studentInfo.Phone;
                row.UserInfo    = studentInfo;

                //take from Student
                row.DateOfGraduation = st.DateOfGraduation.ToShortDateString();
                row.Student          = st;

                //take from Stream
                row.Stream = _streamService.GetStreamByStudentId(st.Id);

                //take from User
                row.TrainerEmail = _userManager.FindByIdAsync(st.TrainerId).GetAwaiter().GetResult().Email;

                //add to list
                viewModel.TableData.Add(row);
            }


            return(View(viewModel));
        }
コード例 #4
0
        public IActionResult Index()
        {
            var vm = new ResumeViewModel();

            #region Fill data to viewmodel (if it's exist)

            // Get info about current user
            vm.UserInfo = _userInfo;
            var currentStudent = _studentService.GetCurrentStudentByUserInfo(vm.UserInfo.Id);

            //Get current Resume Id
            Resume resume = _resumeService.GetResumeByStudentId(currentStudent.Id);

            //create new resume if it doesn't exist
            if (resume == null)
            {
                _resumeService.CreateResumeForStudent(currentStudent.Id);
            }

            //Fill data to viewmodel
            int resumeId = _resumeService.GetResumeByStudentId(currentStudent.Id).Id;
            vm.ResumeId          = resumeId;
            vm.CurrentResumeStep = _resumeService.GetResumeByStudentId(currentStudent.Id).CurrentStep;

            var stream = _streamService.GetStreamByStudentId(currentStudent.Id);
            if (stream != null)
            {
                vm.StreamFullName = stream.StreamFullName;
            }

            var summary = _summaryService.GetSummaryByResumeId(resumeId);
            if (summary != null)
            {
                vm.Summary = summary.Text;
            }

            string [] existingStudentsSkill = _skillService.GetAllSkillsForStudent(currentStudent.Id).ToArray();
            if (existingStudentsSkill.Length != 0)
            {
                vm.Skills = _skillService.GetAllSkillsForStudent(currentStudent.Id).ToArray();
            }
            else
            {
                //If Student hasn't skills in DB, get the default skills by stream
                vm.Skills = _skillService.GetDefaultSkillsByStream(stream.Id).ToArray();
            }

            vm.ForeignLanguages = _languageService.GetAllForeignLanguagesForResume(resumeId).ToDictionary(x => x.LanguageId, x => x.LanguageLevelId);
            vm.Educations       = _educationService.GetAllEducationsForResume(resumeId).ToArray();
            vm.Courses          = _courseService.GetAllCoursesForResume(resumeId).ToArray();
            vm.Certificates     = _certificateService.GetAllCertificatesForResume(resumeId).ToArray();
            vm.Exams            = _examService.GetAllExamsForResume(resumeId).ToArray();

            WorkExperience[] workExperiences = _workExperienceService.GetWorkExperienceForResume(resumeId).ToArray();
            vm.WorkExperiences = new WorkExperienceViewModel[workExperiences.Length];
            if (workExperiences.Count() != 0)
            {
                for (int i = 0; i < workExperiences.Count(); i++)
                {
                    vm.WorkExperiences[i] = new WorkExperienceViewModel(workExperiences[i]);
                }
            }

            vm.Portfolios      = _portfolioService.GetPortfolioForResume(resumeId).ToArray();
            vm.MilitaryStatus  = _militaryStatusService.GetMilitaryStatusForResume(resumeId);
            vm.Recommendations = _recommendationService.GetAllRecommendationsForResume(resumeId).ToArray();
            vm.AdditionalInfo  = _additionalInfoService.GetAdditionalInfo(resumeId);

            #endregion

            #region Fill data to dropdown lists

            //Get all languages from table Languages
            List <Language> languages = _languageService.GetAllLanguages().ToList();
            languages.Insert(0, languages.First(l => l.Name == "English"));
            var index = languages.FindLastIndex(l => l.Name == "English");
            languages.RemoveAt(index);
            //Fill data to dropdownlist Languages
            vm.Languages = languages;

            //Get all language levels from table LanguageLevels
            List <LanguageLevel> languageLevels = _languageService.GetAllLanguageLevels().ToList();
            languageLevels.Insert(0, new LanguageLevel {
                LevelName = "---", Id = 0
            });
            //Fill data to dropdownlist language levels
            vm.LanguageLevels = languageLevels;

            //Get all skills from table Skills
            vm.SkillList = _skillService.GetAllSkills().ToList();

            //Get all Months, Years from DateService
            vm.Months = _dateService.GetAllMonths();
            vm.Years  = _dateService.GetAllYears().ToList();

            //Fill data to dropdownlist Education Levels
            vm.EducationLevels = _educationService.GetEducationLevels().ToList();

            #endregion

            //TODO: add more other statuses, when they will be implemented
            if (resume != null && resume.Status == ResumeStatuses.Submitted)
            {
                return(RedirectToAction(nameof(ResumeReviewController.Index), "ResumeReview", new { resumeId = resume.Id }));
            }
            else
            {
                return(View("Index", vm));
            }
        }
コード例 #5
0
        public HRStudentDataViewModel GetAllStudentViewData()
        {
            IList <Student> students = _studentService.GetAllStudents();

            if (students.Count == 0)
            {
                return(null);
            }

            HRStudentDataViewModel viewModel = new HRStudentDataViewModel
            {
                LanguageLevels = _languageService.GetAllLanguageLevels(),
                Streams        = _streamService.GetAllStreams(),
                TableData      = new List <HRStudentDataViewModel.TableRow>()
            };

            foreach (Student st in students)
            {
                UserInfo studentInfo = _studentService.GetUserInfo(st);
                Resume   resume      = _resumeService.GetResumeByStudentId(st.Id);
                HRStudentDataViewModel.TableRow row = new HRStudentDataViewModel.TableRow()
                {
                    StudentId                   = st.Id,
                    Choose                      = false,
                    Stream                      = _streamService.GetStreamByStudentId(st.Id),
                    RuName                      = studentInfo?.RuName,
                    RuSurname                   = studentInfo.RuSurname,
                    DateOfBirth                 = studentInfo.DateOfBirth,
                    Email                       = studentInfo.Email,
                    Phone                       = studentInfo.Phone,
                    TrainerEmail                = "*****@*****.**",
                    DateOfGraduation            = st.DateOfGraduation,
                    GraduationMark              = st.GraduationMark,
                    ParticipationOnPracticalLab = false,
                    Comments                    = null
                };

                if (resume == null)
                {
                    row.Languages       = null;
                    row.Status          = "new";
                    row.Specializations = null;
                }
                else
                {
                    row.Languages       = _languageService.GetAllForeignLanguagesForResume(resume.Id);
                    row.Status          = resume.Status;
                    row.Specializations = resume.Educations?.Select(s => s.Specialization);
                }

                var skills = _skillService.GetAllSkillsForStudent(st.Id);
                if (skills.Count() == 0)
                {
                    row.StudentSkills = _skillService.GetDefaultSkillsByStream(_streamService.GetStreamByStudentId(st.Id).Id);
                }
                else
                {
                    row.StudentSkills = skills;
                }
                viewModel.TableData.Add(row);
            }
            return(viewModel);
        }
コード例 #6
0
        public async Task <IActionResult> EditResume(int resumeId)
        {
            var student = _studentService.GetStudentByResumeId(resumeId);

            ResumeViewModel vm = new ResumeViewModel
            {
                ResumeId         = resumeId,
                UserInfo         = _userInfo,
                StreamFullName   = _streamService.GetStreamByStudentId(student.Id).StreamFullName,
                Summary          = _summaryService.GetSummaryByResumeId(resumeId).Text,
                Skills           = _skillService.GetAllSkillsForStudent(student.Id).ToArray(),
                ForeignLanguages = _languageService.GetAllForeignLanguagesForResume(resumeId).ToDictionary(x => x.LanguageId, x => x.LanguageLevelId),
                Educations       = _educationService.GetAllEducationsForResume(resumeId).ToArray(),
                Courses          = _courseService.GetAllCoursesForResume(resumeId).ToArray(),
                Certificates     = _certificateService.GetAllCertificatesForResume(resumeId).ToArray(),
                Exams            = _examService.GetAllExamsForResume(resumeId).ToArray(),
                Portfolios       = _portfolioService.GetPortfolioForResume(resumeId).ToArray(),
                MilitaryStatus   = _militaryStatusService.GetMilitaryStatusForResume(resumeId),
                AdditionalInfo   = _additionalInfoService.GetAdditionalInfo(resumeId),
                Recommendations  = _recommendationService.GetAllRecommendationsForResume(resumeId).ToArray()
            };

            WorkExperience[] workExperiences = _workExperienceService.GetWorkExperienceForResume(resumeId).ToArray();
            vm.WorkExperiences = new WorkExperienceViewModel[workExperiences.Length];
            if (workExperiences.Count() != 0)
            {
                for (int i = 0; i < workExperiences.Count(); i++)
                {
                    vm.WorkExperiences[i] = new WorkExperienceViewModel(workExperiences[i]);
                }
            }
            #region Fill data to dropdown lists

            //Get all languages from table Languages
            List <Language> languages = _languageService.GetAllLanguages().ToList();
            languages.Insert(0, languages.First(l => l.Name == "English"));
            var index = languages.FindLastIndex(l => l.Name == "English");
            languages.RemoveAt(index);
            //Fill data to dropdownlist Languages
            vm.Languages = languages;

            //Get all language levels from table LanguageLevels
            List <LanguageLevel> languageLevels = _languageService.GetAllLanguageLevels().ToList();
            languageLevels.Insert(0, new LanguageLevel {
                LevelName = "---", Id = 0
            });
            //Fill data to dropdownlist language levels
            vm.LanguageLevels = languageLevels;

            //Get all skills from table Skills
            vm.SkillList = _skillService.GetAllSkills().ToList();

            //Get all Months, Years from DateService
            vm.Months = _dateService.GetAllMonths();
            vm.Years  = _dateService.GetAllYears().ToList();

            //Fill data to dropdownlist Education Levels
            vm.EducationLevels = _educationService.GetEducationLevels().ToList();

            #endregion


            return(View(vm));
        }
コード例 #7
0
        public async Task <IActionResult> ImportStudentAccounts(ImportAccountsViewModel viewModel)
        {
            //Keep track of added users
            //Use this vars to minimize database quering
            Dictionary <String, String> generatedPasswords = new Dictionary <string, string>();
            List <ApplicationUser>      usersToNotify      = new List <ApplicationUser>();
            List <UserInfo>             userInfosToNotify  = new List <UserInfo>();

            string spreadsheetId = "";

            try
            {
                //break the link and extrach the id
                spreadsheetId = viewModel.ApiKey.Split(new[] { '/' })[5];
            }
            catch
            {
                ModelState.AddModelError("WrongLink", "There was an issue processing your request. Please verify the link you are pasting are from a google spreadsheet.");
                await PopulateViewModel(viewModel);

                return(View("ImportAccounts", viewModel));
            }

            //get the api key
            ApplicationUser loggedUser = await GetUserAsync();

            //Define the web request params
            string sheetRange = "A2:Z";
            string apiKey     = _userInfoService.GetUserInfo(loggedUser?.Email).GoogleApiKey;
            string requestUrl = "https://sheets.googleapis.com/v4/spreadsheets/" + spreadsheetId + "/values/" + sheetRange + "?key=" + apiKey;

            //create request
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(requestUrl);

            using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse())
            {
                //read the response stream
                StreamReader reader     = new StreamReader(webResponse.GetResponseStream());
                var          jsonString = reader.ReadToEnd();

                //parse the response stream
                JObject deserealizedJson       = JsonConvert.DeserializeObject(jsonString) as JObject;
                IEnumerable <JToken> tableRows = deserealizedJson.GetSheetRow(2);

                //check if the spreadsheet contains duplicate emails
                List <string> ssEmails = new List <string>();
                foreach (JToken row in tableRows)
                {
                    ssEmails.Add(row.GetElementValue(7));
                }
                if (ssEmails.Count != ssEmails.Distinct().Count())
                {
                    ModelState.AddModelError("DuplicateEmails", "It seems that the Google table contains duplicate emails. Please check the table and try again.");
                    await PopulateViewModel(viewModel);

                    return(View("ImportAccounts", viewModel));
                }

                //get teh list of current students' emails in the database
                IList <string> databaseStudentEmails = _studentService.GetStudentEmailsByRoleName(ProfilerRoles.Student);

                foreach (JToken row in tableRows)
                {
                    string trainerEmail = row.GetElementValue(0);

                    string sheetRowEmail = row.GetElementValue(7);

                    //check if mentioned trainer exists
                    ApplicationUser trainer = await _userManager.FindByEmailAsync(trainerEmail);

                    if (trainer != null)
                    {
                        //check if the email is already present in the system
                        if (!databaseStudentEmails.Contains(sheetRowEmail))
                        {
                            //pick values from the spreadsheet for the new user
                            ApplicationUser user = new ApplicationUser()
                            {
                                UserName = sheetRowEmail, Email = sheetRowEmail
                            };

                            //generate a password
                            string password = PasswordGenerator.Generate(6, 0);

                            var result = await _userManager.CreateAsync(user, password);

                            if (result.Succeeded)
                            {
                                //add to the dictionary (for testing only)
                                generatedPasswords.Add(user.UserName, password);

                                //add to the role Students
                                var currentUser = await _userManager.FindByNameAsync(user.UserName);

                                await _userManager.AddToRoleAsync(currentUser, ProfilerRoles.Student);

                                //add user info
                                //TODO: parse the number
                                UserInfo userInfo = new UserInfo
                                {
                                    UserId      = currentUser.Id,
                                    EnName      = row.GetElementValue(1),
                                    EnSurname   = row.GetElementValue(2),
                                    RuSurname   = row.GetElementValue(3),
                                    RuName      = row.GetElementValue(4),
                                    DateOfBirth = ParseDateTimeToBLRStandard(row.GetElementValue(6)),
                                    Email       = row.GetElementValue(7),
                                    Phone       = row.GetElementValue(8)
                                };

                                await _userInfoService.AddUserInfoAsync(userInfo);

                                //bind userInfo to applicationUser
                                currentUser.UserInfo = userInfo;

                                //keep track of the new email
                                usersToNotify.Add(currentUser);
                                userInfosToNotify.Add(userInfo);

                                try
                                {
                                    //save changes to the database
                                    await _db.SaveChangesAsync();
                                }
                                catch
                                {
                                    ModelState.AddModelError("Import failed", $"Server error: can’t create new account for {userInfo.Email}. Please try again later.");
                                    await PopulateViewModel(viewModel);

                                    return(View("ImportAccounts", viewModel));
                                }

                                //pick the created userInfo
                                UserInfo userInfoCreated = _userInfoService.GetUserInfo(currentUser.Email);

                                //TODO: verify datetime
                                Student student = new Student
                                {
                                    TrainerId        = trainer.Id,
                                    UserInfoId       = userInfoCreated.Id,
                                    DateOfGraduation = ParseDateTimeToBLRStandard(row.GetElementValue(9)),
                                    GraduationMark   = Convert.ToInt32(row.GetElementValue(11))
                                };

                                try
                                {
                                    //save the changes
                                    await _studentService.AddOrUpdateStudentAsync(student);

                                    await _db.SaveChangesAsync();
                                }
                                catch
                                {
                                    ModelState.AddModelError("Import failed", $"Server error: can’t create new student for {userInfoCreated.Email}. Please try again later.");
                                    await PopulateViewModel(viewModel);

                                    return(View("ImportAccounts", viewModel));
                                }

                                //pick the stream
                                Model.Models.Stream stream = _streamService.GetStreamByShortName(row.Children <JToken>().ElementAt(10).Value <string>());

                                if (stream != null)
                                {
                                    try
                                    {
                                        //bind stream to the student and save the changes
                                        await _studentService.AddStream(student, stream);

                                        await _db.SaveChangesAsync();
                                    }
                                    catch
                                    {
                                        ModelState.AddModelError("Import failed", $"Server error: can’t create new student for {userInfoCreated.Email}. Please try again later.");
                                        await PopulateViewModel(viewModel);

                                        return(View("ImportAccounts", viewModel));
                                    }
                                }
                                //if the spreadsheet has an abbreviation not present in the database
                                else
                                {
                                    ModelState.AddModelError("Import failed", $"Server error: can’t create new student for {userInfoCreated.Email}. Please check the field \"Stream\" in the google table.");
                                    await PopulateViewModel(viewModel);

                                    return(View("ImportAccounts", viewModel));
                                }
                            }
                        }
                        //if the email already exists
                        else
                        {
                            //check the stream
                            UserInfo            userInfo        = _db.UserInfo.FirstOrDefault(ui => ui.Email == sheetRowEmail);
                            Student             existingStudent = _studentService.GetCurrentStudentByUserInfo(_userInfoService.GetUserInfo(sheetRowEmail).Id);
                            Model.Models.Stream stream          = _streamService.GetStreamByStudentId(existingStudent.Id);

                            string spreadsheetRowStream = row.GetElementValue(10);

                            //if the stream is different, create new student
                            if (stream.StreamShortName != spreadsheetRowStream)
                            {
                                //TODO: verify datetime
                                Student student = new Student
                                {
                                    TrainerId        = trainer.Id,
                                    UserInfoId       = userInfo.Id,
                                    DateOfGraduation = ParseDateTimeToBLRStandard(row.GetElementValue(9)),
                                    GraduationMark   = Convert.ToInt32(row.GetElementValue(11))
                                };
                                try
                                {
                                    //save changes
                                    await _studentService.AddOrUpdateStudentAsync(student);

                                    await _db.SaveChangesAsync();
                                }
                                catch
                                {
                                    ModelState.AddModelError("Import failed", $"Server error: can’t create new student for {userInfo.Email}. Please try again later.");
                                    await PopulateViewModel(viewModel);

                                    return(View("ImportAccounts", viewModel));
                                }

                                //pick the stream
                                Model.Models.Stream streamToAdd = _streamService.GetStreamByShortName(spreadsheetRowStream);
                                try
                                {
                                    //bind stream to the student
                                    await _studentService.AddStream(student, streamToAdd);

                                    await _db.SaveChangesAsync();
                                }
                                catch
                                {
                                    ModelState.AddModelError("Import failed", $"Server error: can’t create new student for {userInfo.Email}. Please try again later.");
                                    await PopulateViewModel(viewModel);

                                    return(View("ImportAccounts", viewModel));
                                }
                            }
                        }
                    }
                }
            }

            ////send emails
            //foreach (ApplicationUser userToNotify in usersToNotify)
            //{
            //    UserInfo thisUserInfo = userInfosToNotify.FirstOrDefault(x => x.UserId == userToNotify.Id);
            //    string userPassword = generatedPasswords.FirstOrDefault(x => x.Key == userToNotify.Email).Value;
            //    string appLink = _configuration.GetSection("ProfileAppLink").Value;

            //    EmailSender emailSender = new EmailSender();
            //    StringBuilder sb = new StringBuilder();
            //    sb.AppendLine("Здравствуйте, " + thisUserInfo.RuName + " " + thisUserInfo.RuSurname + ".");
            //    sb.AppendLine("");
            //    sb.AppendLine("Для вас была создана учетная запись в системе PROFILE.");
            //    //sb.AppendLine("Please use this link: " + appLink + " and this password: "******" to log in to your account.");
            //    sb.AppendLine("Для входа в систему используйте ваш пароль - " + userPassword);
            //    await emailSender.SendEmailAsync(userToNotify.Email, "Данные вашей учетной записи в Системе PROFILE Образовательного центра ПВТ", sb.ToString());
            //}

            return(View("ImportAccountsResult", generatedPasswords));
        }