示例#1
0
        /// <summary>
        /// Gets the training history by identifier.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException">userId</exception>
        /// <exception cref="ArgumentNullException">loggedUserDetails</exception>
        public ITrainingHistoryViewModel getTrainingHistoryById(int userId)
        {
            if (userId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }

            //Get The Curretly Logged In User Information
            var loggedUserDetails = usersRepository.GetUserById(userId);

            if (loggedUserDetails == null)
            {
                throw new ArgumentNullException(nameof(loggedUserDetails));
            }

            //Company ID of the Logged In User, HR/CompanyAdmin
            var companyId = loggedUserDetails.CompanyId;

            var companyCollection     = this.companyRepository.GetCompaniesForHR(loggedUserDetails.Username);
            var trainingCollection    = new List <ITraining>();
            var certificateCollection = new List <ICertificationModel>();
            var trainingReport        = new List <ITrainingReport>();

            foreach (var item in companyCollection)
            {
                trainingCollection.AddRange(trainingRepository.GetAllMyTrainings(item.CompanyId));
                certificateCollection.AddRange(certificationRepository.GetCertificateById(item.CompanyId));
                trainingReport.AddRange(lookupRepository.GetTrainingReportByCompanyID(item.CompanyId));
            }

            var viewModel =
                this.trainingViewModelFactory.CreateTrainingHistoryView(certificateCollection, trainingCollection, trainingReport, userId);

            return(viewModel);
        }