Exemplo n.º 1
0
        public ListSuitableTraineeDTO GetAllTrainee()
        {
            ListSuitableTraineeDTO listSuitableTraineeDto = new ListSuitableTraineeDTO();

            List <ShortTraineeDetailDTO> shortTraineeDetailDtos = new List <ShortTraineeDetailDTO>();

            var traineeList = _traineeRepository.GetAllList();

            foreach (var trainee in traineeList)
            {
                ShortTraineeDetailDTO shortTraineeDetailDto =
                    new ShortTraineeDetailDTO(trainee.Id, trainee.Person.Name, trainee.DefaultDepartment);

                shortTraineeDetailDtos.Add(shortTraineeDetailDto);
            }

            listSuitableTraineeDto.ListSuitableTrainees = shortTraineeDetailDtos;

            return(listSuitableTraineeDto);
        }
Exemplo n.º 2
0
        public TrainingDetailDTO GetTrainingDetailByID(int trainingID)
        {
            try
            {
                TrainingDetailDTO returnTraining = new TrainingDetailDTO();

                //Call a DAL method to get Training by TrainingId
                Training training = _trainingRepository.Get(trainingID);


                returnTraining.TrainingId = training.Id;
                returnTraining.ProgramId  = training.ProgramId;

                var program = _programRepository.Get(training.ProgramId);

                returnTraining.ProgramName    = program.ProgramTitle;
                returnTraining.StatusId       = training.StatusId;
                returnTraining.StatusName     = training.TrainingStatus.StatusName; //need to check
                returnTraining.StartDate      = training.StartDate.ToString();
                returnTraining.EndDate        = training.EndDate.ToString();
                returnTraining.TotalDuration  = training.TotalDuration;
                returnTraining.MaxHoursPerDay = _configurationRepository.GetMaximumHoursPerDay();

                #region Get array trainees assigned

                List <ShortTraineeDetailDTO> listTraineesAssigned = new List <ShortTraineeDetailDTO>();

                //Call a DAL method to get trainees by array traineeIDs
                List <Trainee> listTrainees = _traineeRepository.getTraineesByArrayId(training.ArrayOfAssignedTrainees);

                foreach (var x in listTrainees)
                {
                    ShortTraineeDetailDTO trainee = new ShortTraineeDetailDTO();

                    trainee.TraineeId = x.Id;

                    var person = _personRepository.Get(x.PersonId);

                    trainee.Name = person.Name;

                    listTraineesAssigned.Add(trainee);
                }

                returnTraining.TraineesAssigned = listTraineesAssigned;

                #endregion

                #region Get array trainers assigned

                List <ShortTrainerDetailDTO> listTrainersAssigned = new List <ShortTrainerDetailDTO>();

                //Call a DAL method to get trainers by array trainerIDs
                List <Trainer> trainerList = _trainerRepository.GetTrainersByArrayId(training.ArrayOfAssignedTrainers);

                foreach (var x in trainerList)
                {
                    ShortTrainerDetailDTO trainer = new ShortTrainerDetailDTO();

                    trainer.TrainerId = x.Id;

                    var person = _personRepository.Get(x.PersonId);

                    trainer.Name = person.Name;

                    listTrainersAssigned.Add(trainer);
                }

                returnTraining.TrainersAssigned = listTrainersAssigned;

                #endregion

                #region Get array modules included

                List <ShortModuleDetailDTO> listModulesIncluded = new List <ShortModuleDetailDTO>();

                //Array moduleIDs
                ModuleArrangementDTO[] arrayModulesArrangement = JsonConvert.DeserializeObject <ModuleArrangementDTO[]>(training.ModuleArrangement);

                foreach (ModuleArrangementDTO moduleArrangement in arrayModulesArrangement.ToList())
                {
                    ShortModuleDetailDTO shortModule = new ShortModuleDetailDTO();

                    //Get id and TrainTime of module
                    shortModule.ModuleId  = moduleArrangement.ModuleId;
                    shortModule.TrainTime = moduleArrangement.TrainTime;
                    //With each ModuleId, we get module data from database by that ModuleId
                    Module module = _moduleRepository.Get(moduleArrangement.ModuleId);

                    shortModule.ModuleTitle = module.Title;
                    shortModule.Duration    = module.Theory + module.Pratical;

                    //Get TotalDate
                    if ((shortModule.Duration % shortModule.TrainTime) != 0)
                    {
                        double temp = shortModule.Duration / shortModule.TrainTime;
                        shortModule.TotalDate = Math.Truncate(temp) + 1;
                    }
                    else
                    {
                        shortModule.TotalDate = shortModule.Duration / shortModule.TrainTime;
                    }

                    //Get Competencies trained by this module
                    List <CompetenceDTO> listCompetenciesTrained = new List <CompetenceDTO>();
                    List <Competence>    competencies            =
                        _competenceRepository.GetCompetenciesByCompetenceID(module.ArrayOfTrainingCompetencies);

                    foreach (var competence in competencies)
                    {
                        CompetenceDTO competenceDto = new CompetenceDTO();

                        competenceDto.CompetenceID = competence.Id;
                        competenceDto.Name         = competence.Name;
                        competenceDto.Description  = competence.Description;

                        listCompetenciesTrained.Add(competenceDto);
                    }

                    shortModule.Competencies = listCompetenciesTrained;

                    listModulesIncluded.Add(shortModule);
                }

                returnTraining.ModulesArrangement = listModulesIncluded;

                #endregion

                return(returnTraining);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        public ProgramDetailDTO GetProgramDetailByID(int programID)
        {
            try
            {
                ProgramDetailDTO programDetailDTO = new ProgramDetailDTO();

                //Call a DAL method to get program detail by id
                var program = _programRepository.Get(programID);

                programDetailDTO.ProgramId      = program.Id;
                programDetailDTO.ProgramTitle   = program.ProgramTitle;
                programDetailDTO.MaxHoursPerDay = _configurationRepository.GetMaximumHoursPerDay();

                #region Get modules included to program

                List <ShortModuleDetailDTO> listModulesIncluded = new List <ShortModuleDetailDTO>();

                //Call a DAL method to get list module
                List <Module> modules = _moduleRepository.GetModulesByArrayID(program.ArrayOfIncludedModules).ToList();

                foreach (Module module in modules)
                {
                    ShortModuleDetailDTO shortModule = new ShortModuleDetailDTO();

                    //Get id and TrainTime of module
                    shortModule.ModuleId    = module.Id;
                    shortModule.TrainTime   = _configurationRepository.GetMaximumHoursPerDay();
                    shortModule.ModuleTitle = module.Title;
                    shortModule.Duration    = module.Theory + module.Pratical;

                    //Get TotalDate
                    if ((shortModule.Duration % shortModule.TrainTime) != 0)
                    {
                        double temp = shortModule.Duration / shortModule.TrainTime;
                        shortModule.TotalDate = Math.Truncate(temp) + 1;
                    }
                    else
                    {
                        shortModule.TotalDate = shortModule.Duration / shortModule.TrainTime;
                    }

                    //Get Competencies trained by this module
                    List <CompetenceDTO> listCompetenciesTrained = new List <CompetenceDTO>();
                    List <Competence>    CompetenciesTrained     =
                        _competenceRepository.GetCompetenciesByCompetenceID(module.ArrayOfTrainingCompetencies);

                    foreach (var competence in CompetenciesTrained)
                    {
                        CompetenceDTO competenceDto = new CompetenceDTO();

                        competenceDto.CompetenceID = competence.Id;
                        competenceDto.Name         = competence.Name;
                        competenceDto.Description  = competence.Description;

                        listCompetenciesTrained.Add(competenceDto);
                    }

                    shortModule.Competencies = listCompetenciesTrained;

                    listModulesIncluded.Add(shortModule);
                }

                programDetailDTO.ModulesIncluded = listModulesIncluded;

                #endregion

                #region Get potential trainees

                List <ShortTraineeDetailDTO> listPotentialTrainees = new List <ShortTraineeDetailDTO>();

                //Call a DAL method to get list potentail trainees
                List <Trainee> potentailTrainees = _traineeRepository.getTraineesByArrayId(program.ArrayOfNeedByPotentialTrainees);

                foreach (Trainee trainee in potentailTrainees)
                {
                    ShortTraineeDetailDTO Shotttrainee = new ShortTraineeDetailDTO();

                    Shotttrainee.TraineeId = trainee.Id;

                    var person = _personRepository.Get(trainee.PersonId);

                    Shotttrainee.Name = person.Name;

                    listPotentialTrainees.Add(Shotttrainee);
                }

                programDetailDTO.NeedByPotentialTrainees = listPotentialTrainees;

                #endregion

                #region Get total Duration

                double totalDuration = 0;

                foreach (ShortModuleDetailDTO module in programDetailDTO.ModulesIncluded)
                {
                    totalDuration += module.Duration;
                }

                programDetailDTO.TotalDuration = totalDuration;

                #endregion

                return(programDetailDTO);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        public ListSuitableTraineeDTO GetSuitableTrainees(int programID)
        {
            try
            {
                ListSuitableTraineeDTO suitableTrainees = new ListSuitableTraineeDTO();

                List <ShortTraineeDetailDTO> listSuitableTrainees = new List <ShortTraineeDetailDTO>();

                #region Get Competencies trained by the program, we will use it to compare with trainee's Competencies

                List <int> competenciesTrainedID = new List <int>();

                //Get program by ProgramId
                var program = _programRepository.Get(programID);

                int[] modulesIncludedID = program.ArrayOfIncludedModules;

                //Get list module by array ModuleId
                var modulesIncluded = _moduleRepository.GetModulesByArrayID(modulesIncludedID);

                foreach (Module module in modulesIncluded)
                {
                    //Get list Competencies trained by module
                    List <int> competenciesTrainedIDByModule = module.ArrayOfTrainingCompetencies.ToList();

                    //Add there Competencies to list Competencies trained by program
                    foreach (int competenceID in competenciesTrainedIDByModule)
                    {
                        competenciesTrainedID.Add(competenceID);
                    }
                }

                //Remove the duplicate Competencies
                competenciesTrainedID = competenciesTrainedID.Distinct().ToList();

                #endregion

                #region Get all the trainee in database, we will findout the suitable trainees

                var trainees = _traineeRepository.GetAllIncluding(trainee => trainee.Person);

                foreach (Trainee trainee in trainees)
                {
                    int[] competenciesGained = trainee.ArrayOfCompetence;

                    if (_compareAppService.IsMissingCompetencies(competenciesGained, competenciesTrainedID.ToArray()))
                    {
                        //This one is a suitable trainee
                        ShortTraineeDetailDTO suitableTrainee = new ShortTraineeDetailDTO();

                        suitableTrainee.TraineeId         = trainee.Id;
                        suitableTrainee.Name              = trainee.Person.Name;
                        suitableTrainee.DefaultDepartment = trainee.DefaultDepartment;

                        listSuitableTrainees.Add(suitableTrainee);
                    }
                }

                suitableTrainees.ListSuitableTrainees = listSuitableTrainees;

                #endregion

                return(suitableTrainees);
            }
            catch (Exception e)
            {
                return(null);
            }
        }