コード例 #1
0
        public ActionResult GivenCertificateDetails(string givenCertificateIdentificator)
        {
            var givenCertificate = _context.givenCertificateRepository.GetGivenCertificateById(givenCertificateIdentificator);
            var certificate      = _context.certificateRepository.GetCertificateById(givenCertificate.Certificate);

            var user      = _context.userRepository.GetUserByGivenCertificateId(givenCertificate.GivenCertificateIdentificator);
            var companies = _context.companyRepository.GetCompaniesById(user.CompanyRoleManager.Concat(user.CompanyRoleWorker).Distinct().ToList());

            var course   = _context.courseRepository.GetCourseById(givenCertificate.Course);
            var meetings = _context.meetingRepository.GetMeetingsById(course.Meetings);

            List <string> instructorsIdentificators = new List <string>();

            meetings.ToList().ForEach(z => z.Instructors.ToList().ForEach(s => instructorsIdentificators.Add(s)));
            instructorsIdentificators.Distinct();

            var instructors = _context.userRepository.GetInstructorsById(instructorsIdentificators);

            DisplayCourseViewModel courseViewModel = _mapper.Map <DisplayCourseViewModel>(course);

            courseViewModel.Branches = _context.branchRepository.GetBranchesById(courseViewModel.Branches);

            List <DisplayMeetingWithoutCourseViewModel> meetingsViewModel = new List <DisplayMeetingWithoutCourseViewModel>();

            foreach (var meeting in meetings)
            {
                DisplayMeetingWithoutCourseViewModel singleMeeting = _mapper.Map <DisplayMeetingWithoutCourseViewModel>(meeting);
                singleMeeting.Instructors = _mapper.Map <List <DisplayCrucialDataUserViewModel> >(instructors.Where(z => meeting.Instructors.Contains(z.Id)).ToList());

                meetingsViewModel.Add(singleMeeting);
            }

            List <DisplayCompanyViewModel> companiesViewModel = _mapper.Map <List <DisplayCompanyViewModel> >(companies);

            DisplayAllUserInformationViewModel userViewModel = _mapper.Map <DisplayAllUserInformationViewModel>(user);

            userViewModel.Roles = _context.userRepository.TranslateRoles(userViewModel.Roles);

            List <DisplayCrucialDataWithContactUserViewModel> instructorsViewModel = _mapper.Map <List <DisplayCrucialDataWithContactUserViewModel> >(instructors);

            DisplayCertificateViewModel certificateViewModel = _mapper.Map <DisplayCertificateViewModel>(certificate);

            certificateViewModel.Branches = _context.branchRepository.GetBranchesById(certificateViewModel.Branches);

            GivenCertificateDetailsViewModel verifiedGivenCertificate = new GivenCertificateDetailsViewModel();

            verifiedGivenCertificate.GivenCertificate             = _mapper.Map <DisplayGivenCertificateToUserWithoutCourseExtendedViewModel>(givenCertificate);
            verifiedGivenCertificate.GivenCertificate.Certificate = certificateViewModel;

            verifiedGivenCertificate.Course   = courseViewModel;
            verifiedGivenCertificate.Meetings = meetingsViewModel;

            verifiedGivenCertificate.User        = userViewModel;
            verifiedGivenCertificate.Instructors = instructorsViewModel;
            verifiedGivenCertificate.Companies   = companiesViewModel;

            return(View(verifiedGivenCertificate));
        }
コード例 #2
0
        public ActionResult WorkerGivenCertificateDetails(string givenCertificateIdentificator)
        {
            var givenCertificate = _context.givenCertificateRepository.GetGivenCertificateById(givenCertificateIdentificator);
            var certificate      = _context.certificateRepository.GetCertificateById(givenCertificate.Certificate);

            var course   = _context.courseRepository.GetCourseById(givenCertificate.Course);
            var meetings = _context.meetingRepository.GetMeetingsById(course.Meetings);

            List <string> instructorsIdentificators = new List <string>();

            meetings.ToList().ForEach(z => z.Instructors.ToList().ForEach(s => instructorsIdentificators.Add(s)));
            instructorsIdentificators.Distinct();

            var instructors = _context.userRepository.GetInstructorsById(instructorsIdentificators);

            DisplayCourseViewModel courseViewModel = _mapper.Map <DisplayCourseViewModel>(course);

            courseViewModel.Branches = _context.branchRepository.GetBranchesById(courseViewModel.Branches);

            List <DisplayMeetingWithoutCourseViewModel> meetingsViewModel = new List <DisplayMeetingWithoutCourseViewModel>();

            foreach (var meeting in meetings)
            {
                DisplayMeetingWithoutCourseViewModel singleMeeting = _mapper.Map <DisplayMeetingWithoutCourseViewModel>(meeting);
                singleMeeting.Instructors = _mapper.Map <List <DisplayCrucialDataUserViewModel> >(instructors.Where(z => meeting.Instructors.Contains(z.Id)).ToList());

                meetingsViewModel.Add(singleMeeting);
            }

            DisplayCertificateViewModel certificateViewModel = _mapper.Map <DisplayCertificateViewModel>(certificate);

            certificateViewModel.Branches = _context.branchRepository.GetBranchesById(certificateViewModel.Branches);

            WorkerGivenCertificateDetailsViewModel givenCertificateDetails = new WorkerGivenCertificateDetailsViewModel();

            givenCertificateDetails.GivenCertificate             = _mapper.Map <DisplayGivenCertificateToUserWithoutCourseExtendedViewModel>(givenCertificate);
            givenCertificateDetails.GivenCertificate.Certificate = certificateViewModel;

            givenCertificateDetails.Course   = courseViewModel;
            givenCertificateDetails.Meetings = meetingsViewModel;

            givenCertificateDetails.UserIdentificator = _context.userRepository.GetUserByGivenCertificateId(givenCertificateIdentificator).Id;

            if (this.User.IsInRole("Company"))
            {
                return(View("CompanyWorkerGivenCertificateDetails", givenCertificateDetails));
            }

            return(View(givenCertificateDetails));
        }
コード例 #3
0
        public ActionResult VerifyUserCompetences(string userIdentificator, bool anonymousVerification = true)
        {
            var user = _context.userRepository.GetUserById(userIdentificator);

            if (user != null)
            {
                var givenCertificates = _context.givenCertificateRepository.GetGivenCertificatesById(user.GivenCertificates);
                var givenDegrees      = _context.givenDegreeRepository.GetGivenDegreesById(user.GivenDegrees);

                var companiesRoleWorker  = _context.companyRepository.GetCompaniesById(user.CompanyRoleWorker);
                var companiesRoleManager = _context.companyRepository.GetCompaniesById(user.CompanyRoleManager);

                List <Company> companies = companiesRoleWorker.ToList();

                foreach (var company in companiesRoleManager)
                {
                    if (companies.Where(z => z.CompanyIdentificator == company.CompanyIdentificator).Count() == 0)
                    {
                        companies.Add(company);
                    }
                }

                if (anonymousVerification)
                {
                    List <DisplayGivenCertificateToUserWithoutCourseViewModel> listOfGivenCertificates = new List <DisplayGivenCertificateToUserWithoutCourseViewModel>();

                    if (givenCertificates.Count != 0)
                    {
                        foreach (var givenCertificate in givenCertificates)
                        {
                            var certificate = _context.certificateRepository.GetCertificateById(givenCertificate.Certificate);

                            DisplayCrucialDataCertificateViewModel certificateViewModel = _mapper.Map <DisplayCrucialDataCertificateViewModel>(certificate);

                            DisplayGivenCertificateToUserWithoutCourseViewModel singleGivenCertificate = _mapper.Map <DisplayGivenCertificateToUserWithoutCourseViewModel>(givenCertificate);
                            singleGivenCertificate.Certificate = certificateViewModel;

                            listOfGivenCertificates.Add(singleGivenCertificate);
                        }
                    }

                    List <DisplayGivenDegreeToUserViewModel> listOfGivenDegrees = new List <DisplayGivenDegreeToUserViewModel>();

                    if (givenDegrees.Count != 0)
                    {
                        foreach (var givenDegree in givenDegrees)
                        {
                            var degree = _context.degreeRepository.GetDegreeById(givenDegree.Degree);

                            DisplayCrucialDataDegreeViewModel degreeViewModel = _mapper.Map <DisplayCrucialDataDegreeViewModel>(degree);

                            DisplayGivenDegreeToUserViewModel singleGivenDegree = _mapper.Map <DisplayGivenDegreeToUserViewModel>(givenDegree);
                            singleGivenDegree.Degree = degreeViewModel;

                            listOfGivenDegrees.Add(singleGivenDegree);
                        }
                    }

                    List <DisplayCompanyViewModel> ListOfCompanies = _mapper.Map <List <DisplayCompanyViewModel> >(companies);

                    UserDetailsForAnonymousViewModel verifiedUser = _mapper.Map <UserDetailsForAnonymousViewModel>(user);
                    verifiedUser.GivenCertificates = listOfGivenCertificates;
                    verifiedUser.GivenDegrees      = listOfGivenDegrees;
                    verifiedUser.Companies         = ListOfCompanies;

                    return(Ok(verifiedUser));
                }
                else
                {
                    var courses = _context.courseRepository.GetCoursesById(user.Courses);

                    List <DisplayCourseViewModel> listOfCourses = new List <DisplayCourseViewModel>();

                    if (courses.Count != 0)
                    {
                        foreach (var course in courses)
                        {
                            DisplayCourseViewModel singleCourse = _mapper.Map <DisplayCourseViewModel>(course);
                            singleCourse.Branches = _context.branchRepository.GetBranchesById(course.Branches);

                            listOfCourses.Add(singleCourse);
                        }
                    }

                    List <DisplayGivenCertificateToUserViewModel> listOfGivenCertificates = new List <DisplayGivenCertificateToUserViewModel>();

                    if (givenCertificates.Count != 0)
                    {
                        foreach (var givenCertificate in givenCertificates)
                        {
                            var course      = _context.courseRepository.GetCourseById(givenCertificate.Course);
                            var certificate = _context.certificateRepository.GetCertificateById(givenCertificate.Certificate);

                            DisplayCrucialDataCourseViewModel courseViewModel = _mapper.Map <DisplayCrucialDataCourseViewModel>(course);

                            DisplayCrucialDataCertificateViewModel certificateViewModel = _mapper.Map <DisplayCrucialDataCertificateViewModel>(certificate);

                            DisplayGivenCertificateToUserViewModel singleGivenCertificate = _mapper.Map <DisplayGivenCertificateToUserViewModel>(givenCertificate);
                            singleGivenCertificate.Certificate = certificateViewModel;
                            singleGivenCertificate.Course      = courseViewModel;

                            listOfGivenCertificates.Add(singleGivenCertificate);
                        }
                    }

                    List <DisplayGivenDegreeToUserViewModel> listOfGivenDegrees = new List <DisplayGivenDegreeToUserViewModel>();

                    if (givenDegrees.Count != 0)
                    {
                        foreach (var givenDegree in givenDegrees)
                        {
                            var degree = _context.degreeRepository.GetDegreeById(givenDegree.Degree);

                            DisplayCrucialDataDegreeViewModel degreeViewModel = _mapper.Map <DisplayCrucialDataDegreeViewModel>(degree);

                            DisplayGivenDegreeToUserViewModel singleGivenDegree = _mapper.Map <DisplayGivenDegreeToUserViewModel>(givenDegree);
                            singleGivenDegree.Degree = degreeViewModel;

                            listOfGivenDegrees.Add(singleGivenDegree);
                        }
                    }

                    List <DisplayCompanyViewModel> listOfCompanies = _mapper.Map <List <DisplayCompanyViewModel> >(companies);

                    UserDetailsViewModel verifiedUser = _mapper.Map <UserDetailsViewModel>(user);
                    verifiedUser.Roles = _context.userRepository.TranslateRoles(verifiedUser.Roles);

                    verifiedUser.GivenCertificates = listOfGivenCertificates;
                    verifiedUser.GivenDegrees      = listOfGivenDegrees;
                    verifiedUser.Courses           = listOfCourses;
                    verifiedUser.Companies         = listOfCompanies;

                    return(Ok(verifiedUser));
                }
            }
            else
            {
                return(BadRequest("Użytkownik nie został odnaleziony"));
            }
        }
コード例 #4
0
        public ActionResult VerifyGivenCertificate(string givenCertificateIdentificator, bool anonymousVerification = true)
        {
            try
            {
                ObjectId.Parse(givenCertificateIdentificator);
            }
            catch (System.Exception)
            {
                return(BadRequest("Błędny format identyfikatora"));
            }

            var givenCertificate = _context.givenCertificateRepository.GetGivenCertificateById(givenCertificateIdentificator);

            if (givenCertificate != null)
            {
                var certificate = _context.certificateRepository.GetCertificateById(givenCertificate.Certificate);
                var user        = _context.userRepository.GetUserByGivenCertificateId(givenCertificate.GivenCertificateIdentificator);
                var companies   = _context.companyRepository.GetCompaniesById(user.CompanyRoleManager.Concat(user.CompanyRoleWorker).Distinct().ToList());

                if (anonymousVerification)
                {
                    List <DisplayCompanyViewModel> companiesViewModel                     = _mapper.Map <List <DisplayCompanyViewModel> >(companies);
                    DisplayCrucialDataWithBirthDateUserViewModel userViewModel            = _mapper.Map <DisplayCrucialDataWithBirthDateUserViewModel>(user);
                    DisplayCrucialDataCertificateViewModel       certificateViewModel     = _mapper.Map <DisplayCrucialDataCertificateViewModel>(certificate);
                    GivenCertificateDetailsForAnonymousViewModel verifiedGivenCertificate = new GivenCertificateDetailsForAnonymousViewModel();

                    verifiedGivenCertificate.GivenCertificate             = _mapper.Map <DisplayGivenCertificateToUserWithoutCourseViewModel>(givenCertificate);
                    verifiedGivenCertificate.GivenCertificate.Certificate = certificateViewModel;
                    verifiedGivenCertificate.User      = userViewModel;
                    verifiedGivenCertificate.Companies = companiesViewModel;

                    return(Ok(verifiedGivenCertificate));
                }
                else
                {
                    var course   = _context.courseRepository.GetCourseById(givenCertificate.Course);
                    var meetings = _context.meetingRepository.GetMeetingsById(course.Meetings);

                    List <string> instructorsIdentificators = new List <string>();
                    meetings.ToList().ForEach(z => z.Instructors.ToList().ForEach(s => instructorsIdentificators.Add(s)));
                    instructorsIdentificators.Distinct();

                    var instructors = _context.userRepository.GetInstructorsById(instructorsIdentificators);

                    DisplayCourseViewModel courseViewModel = _mapper.Map <DisplayCourseViewModel>(course);
                    courseViewModel.Branches = _context.branchRepository.GetBranchesById(courseViewModel.Branches);

                    List <DisplayMeetingWithoutCourseViewModel> meetingsViewModel = new List <DisplayMeetingWithoutCourseViewModel>();

                    foreach (var meeting in meetings)
                    {
                        DisplayMeetingWithoutCourseViewModel singleMeeting = _mapper.Map <DisplayMeetingWithoutCourseViewModel>(meeting);
                        singleMeeting.Instructors = _mapper.Map <List <DisplayCrucialDataUserViewModel> >(instructors.Where(z => meeting.Instructors.Contains(z.Id)).ToList());

                        meetingsViewModel.Add(singleMeeting);
                    }

                    List <DisplayCompanyViewModel> companiesViewModel = _mapper.Map <List <DisplayCompanyViewModel> >(companies);

                    DisplayAllUserInformationViewModel userViewModel = _mapper.Map <DisplayAllUserInformationViewModel>(user);
                    userViewModel.Roles = _context.userRepository.TranslateRoles(userViewModel.Roles);

                    List <DisplayCrucialDataWithContactUserViewModel> instructorsViewModel = _mapper.Map <List <DisplayCrucialDataWithContactUserViewModel> >(instructors);

                    DisplayCertificateViewModel certificateViewModel = _mapper.Map <DisplayCertificateViewModel>(certificate);
                    certificateViewModel.Branches = _context.branchRepository.GetBranchesById(certificateViewModel.Branches);

                    GivenCertificateDetailsViewModel verifiedGivenCertificate = new GivenCertificateDetailsViewModel();
                    verifiedGivenCertificate.GivenCertificate             = _mapper.Map <DisplayGivenCertificateToUserWithoutCourseExtendedViewModel>(givenCertificate);
                    verifiedGivenCertificate.GivenCertificate.Certificate = certificateViewModel;

                    verifiedGivenCertificate.Course   = courseViewModel;
                    verifiedGivenCertificate.Meetings = meetingsViewModel;

                    verifiedGivenCertificate.User        = userViewModel;
                    verifiedGivenCertificate.Instructors = instructorsViewModel;
                    verifiedGivenCertificate.Companies   = companiesViewModel;

                    return(Ok(verifiedGivenCertificate));
                }
            }
            else
            {
                return(BadRequest("Certyfikat nie został odnaleziony"));
            }
        }