예제 #1
0
        /// <summary>
        /// Get a array id of competencies that the Trainee are missing from Job Fucntion
        /// </summary>
        /// <param name="jobFunctionId">A jobFunctionId that identify a Job Function</param>
        /// <param name="traineeId">A traineeId that identify a Trainee</param>
        /// <returns>Array id of competencies that the Trainee are missing from Job Fucntion</returns>
        private int[] GetExecuteData(int jobFunctionId, int traineeId)
        {
            try
            {
                int[] missingCompetencies = null;

                //Get job function and trainee by there ids
                JobFunctionDTO targetJobFunction = _jobFunctionAppService.GetJobFunctionById(jobFunctionId);
                Trainee        sourceTrainee     = _traineeRepository.FirstOrDefault(traineeId);

                //compare the list of competence required by the job function with the list of
                //competence gained by trainee

                missingCompetencies = _compareAppService.missingCompetencies(
                    sourceTrainee.ArrayOfCompetence, targetJobFunction.RequiredCompetencies.ToArray());

                return(missingCompetencies);
            }
            catch
            {
                return(null);
            }
        }
예제 #2
0
        public ResponseMessageDTO CompleteTraining(CompleteTrainingInputDTO completeTrainingInput)
        {
            try
            {
                if (completeTrainingInput.TrainingId <= 0)
                {
                    return(new ResponseMessageDTO(false, L("CompleteTraining_Fail")));
                }
                else
                {
                    var training = _trainingRepository.Get(completeTrainingInput.TrainingId);

                    if (training.StatusId == _trainingStatusRepository.GetTrainingStatusIdByName(TrainingStatus.CANCELED) ||
                        training.StatusId == _trainingStatusRepository.GetTrainingStatusIdByName(TrainingStatus.PLANNED))
                    {
                        //training already canceled or planed -> cant completed
                        return(new ResponseMessageDTO(false, L("")));
                    }
                    else
                    {
                        //Update status of training to completed
                        training.StatusId = _trainingStatusRepository.GetTrainingStatusIdByName(TrainingStatus.COMPLETED);

                        var updateTraining = _trainingRepository.Update(training);

                        if (updateTraining.Id == 0)
                        {
                            return(new ResponseMessageDTO(false, L("CreatTraining")));
                        }

                        #region Update Competencies of trainees assigned

                        //Get list of trainees selected by user to update Competencies
                        TraineeTrainingOutcomeDTO[] trainees = JsonConvert.DeserializeObject <TraineeTrainingOutcomeDTO[]>(completeTrainingInput.TraineeTrainingOutcome);

                        //Update Competencies of trainees above
                        foreach (TraineeTrainingOutcomeDTO trainee in trainees.ToList())
                        {
                            //Get the list of Competencies that the trainee used to update
                            List <int> competenciesUpdate = new List <int>();

                            var traineeEntity = _traineeRepository.Get(trainee.TraineeId);

                            //Get the list of Competencies that the trainee already has
                            int[] sourceCompetencies = traineeEntity.ArrayOfCompetence;

                            //Compare the sourceCompetencies with the selectedCompetencies to determine the
                            //Competencies which used to add to the trainee
                            int[] missingCompetencies = _compareAppService.missingCompetencies(sourceCompetencies, trainee.SelectedCompetencies);

                            //Add there missing Competencies to the list source Competencies
                            List <int> listSourceCompetencies  = sourceCompetencies.ToList();
                            List <int> listMissingCompetencies = missingCompetencies.ToList();

                            foreach (int competence in listMissingCompetencies)
                            {
                                listSourceCompetencies.Add(competence);
                            }

                            //Use the list source Competencies to update
                            competenciesUpdate = listSourceCompetencies.Distinct().ToList();

                            //Update trainee's Competencies
                            traineeEntity.ArrayOfCompetence = competenciesUpdate.ToArray();

                            var udTrainee = _traineeRepository.Update(traineeEntity);

                            if (udTrainee.Id == 0)
                            {
                                return(new ResponseMessageDTO(false, L("UpdateTraining_FailError")));
                            }
                        }

                        #endregion

                        #region Update trainings targeted and training attended of trainees assigned

                        List <int> listTraineesIDAssigned = updateTraining.ArrayOfAssignedTrainees.ToList();

                        foreach (int traineeIDAssigned in listTraineesIDAssigned)
                        {
                            var traineeAssigned = _traineeRepository.Get(traineeIDAssigned);

                            List <int> listTrainingsTargeted = traineeAssigned.ArrayOfTargetedTraining.ToList();
                            List <int> listTrainingsAttended = traineeAssigned.ArrayOfAttendedTraining.ToList();

                            var itemToRemove = listTrainingsTargeted.SingleOrDefault(r => r == completeTrainingInput.TrainingId);

                            if (itemToRemove != 0)
                            {
                                //Remove training from training targeted
                                listTrainingsTargeted.Remove(itemToRemove);
                            }

                            //Add training to training attended
                            listTrainingsAttended.Add(completeTrainingInput.TrainingId);
                            listTrainingsAttended = listTrainingsAttended.Distinct().ToList();

                            //update trainee
                            traineeAssigned.ArrayOfTargetedTraining = listTrainingsTargeted.ToArray();
                            traineeAssigned.ArrayOfAttendedTraining = listTrainingsAttended.ToArray();

                            var updateOldTrainee = _traineeRepository.Update(traineeAssigned);

                            if (updateOldTrainee.Id == 0)
                            {
                                return(new ResponseMessageDTO(false, L("UpdateTraining_FailError")));
                            }
                        }

                        #endregion

                        return(new ResponseMessageDTO(true, L("UpdateTraining_Success")));
                    }
                }
            }
            catch
            {
                return(new ResponseMessageDTO(false, L("UpdateTraining_FailError")));
            }
        }