Exemplo n.º 1
0
        public Tra_PlanModel Post([Bind] Tra_PlanModel model)
        {
            #region Validate
            string message       = string.Empty;
            var    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Tra_PlanModel>(model, "Tra_Plan", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            #endregion

            #region Check kiểm tra cột sum quantity
            ActionService service = new ActionService(UserLogin);
            string        status  = string.Empty;
            if (model.ID != null)
            {
                var planDetailServices = new Tra_PlanDetailServices();
                var lstObjPlanDetail   = new List <object>();
                lstObjPlanDetail.Add(null);
                lstObjPlanDetail.Add(1);
                lstObjPlanDetail.Add(int.MaxValue - 1);
                var lstPlanDetail         = planDetailServices.GetData <Tra_PlanDetailEntity>(lstObjPlanDetail, ConstantSql.hrm_tra_sp_get_PlanDetail, UserLogin, ref status).ToList();
                var lstPlanDetailByPlanID = lstPlanDetail.Where(s => s.PlanID == model.ID).ToList();
                if (lstPlanDetailByPlanID != null)
                {
                    if (model.SumQuantity < lstPlanDetailByPlanID.Count)
                    {
                        model.ActionStatus = ConstantMessages.WarningQuantityPlanMustBeGreaterQuantityPlandetail.TranslateString();
                        return(model);
                    }
                }
            }
            #endregion

            return(service.UpdateOrCreate <Tra_PlanEntity, Tra_PlanModel>(model));
        }
Exemplo n.º 2
0
        public Tra_TraineeModel Post([Bind]Tra_TraineeModel model)
        {
            #region Validate
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Tra_TraineeModel>(model, "Tra_Trainee", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            #endregion
        
            var traineeServices = new Tra_TraineeServices();
            ActionService service = new ActionService(UserLogin);
            var isTraineeInRequireDetail = traineeServices.IsAddTraineeDependOnRequirementDetail();
            var traineeTopicServices = new Tra_TraineeTopicServices();
            var planServices = new Tra_PlanServices();
            var status = string.Empty;
            var lstObjPlan = new List<object>();
            lstObjPlan.Add(null);
            lstObjPlan.Add(null);
            lstObjPlan.Add(null);
            lstObjPlan.Add(null);
            lstObjPlan.Add(1);
            lstObjPlan.Add(int.MaxValue - 1);
            var lstPlan = planServices.GetData<Tra_PlanEntity>(lstObjPlan, ConstantSql.hrm_tra_sp_get_Plan, UserLogin, ref status).ToList();


            var planDetailServices = new Tra_PlanDetailServices();
            var lstObjPlanDetail = new List<object>();
            lstObjPlanDetail.Add(null);
            lstObjPlanDetail.Add(1);
            lstObjPlanDetail.Add(int.MaxValue - 1);
            var lstPlanDetail = planDetailServices.GetData<Tra_PlanDetailEntity>(lstObjPlanDetail, ConstantSql.hrm_tra_sp_get_PlanDetail, UserLogin, ref status).ToList();

            var classServices = new Tra_ClassServices();
            var lstObjClass = new List<object>();
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(1);
            lstObjClass.Add(int.MaxValue - 1);
            var lstClass = classServices.GetData<Tra_ClassEntity>(lstObjClass, ConstantSql.hrm_tra_sp_get_Class, UserLogin, ref status).ToList();

            var lstObjTraineeInClass = new List<object>();
            lstObjTraineeInClass.Add(model.ClassID);
            var lstTraineeInClass = classServices.GetData<Tra_ClassEntity>(lstObjTraineeInClass, ConstantSql.hrm_cat_sp_get_TraineeByClassID, UserLogin, ref status).ToList();

            var courseTopicServices = new Tra_TraineeTopicServices();
            var objCourseTopic = new List<object>();
            objCourseTopic.Add(1);
            objCourseTopic.Add(int.MaxValue - 1);
            var lstCourseTopic = courseTopicServices.GetData<Tra_CourseTopicEntity>(objCourseTopic, ConstantSql.hrm_tra_sp_get_CourseTopic, UserLogin, ref status);


            var classEntity = lstClass.Where(s => s.ID == model.ClassID).FirstOrDefault();
            var profileServices = new Hre_ProfileServices();
            var profileEntity = profileServices.GetData<Hre_ProfileEntity>(model.ProfileID, ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();

            var requirementServices = new Tra_RequirementTrainServices();
            var objRequirement = new List<object>();
            objRequirement.AddRange(new object[7]);
            objRequirement[5] = 1;
            objRequirement[6] = int.MaxValue - 1;
            var lstRequirement = requirementServices.GetData<Tra_RequirementTrainEntity>(objRequirement, ConstantSql.hrm_tra_sp_get_RequirementTrain, UserLogin, ref status).ToList();

            var requirementDetailServices = new Tra_RequirementTrainDetailServices();
            var objRequirementDetail = new List<object>();
            objRequirementDetail.Add(null);
            objRequirementDetail.Add(1);
            objRequirementDetail.Add(int.MaxValue - 1);
            var lstRequirementDetail = requirementDetailServices.GetData<Tra_RequirementTrainDetailEntity>(objRequirementDetail, ConstantSql.hrm_tra_sp_get_RequirementDetail, UserLogin, ref status).ToList();

            var objTrainee = new List<object>();
            objTrainee.AddRange(new object[15]);
            objTrainee[13] = 1;
            objTrainee[14] = int.MaxValue - 1;
            var lstObjTrainee = traineeServices.GetData<Tra_TraineeEntity>(objTrainee, ConstantSql.hrm_tra_sp_get_Trainee, UserLogin, ref status).ToList();
            var traineeEntity = lstObjTrainee.Where(s => s.ClassID == model.ClassID && model.ProfileID == s.ProfileID).ToList();

            #region Check Học Viên
            if(model.ID == Guid.Empty)
            {
                if (isTraineeInRequireDetail)
                {
                    if (traineeEntity.Count > 0)
                    {
                        model.ActionStatus = ConstantMessages.WarningProfileHaveClass.ToString().TranslateString();
                        return model;
                    }
                    if (classEntity != null)
                    {

                        if (classEntity.PlanID != null)
                        {
                            var lstRequirementByPlanID = lstRequirement.Where(s => s.PlanID != null && s.PlanID.Value == classEntity.PlanID).ToList();
                            foreach (var item in lstRequirementByPlanID)
                            {
                                var requirementDetailEntity = lstRequirementDetail.Where(s => item.ID == s.RequirementTrainID && s.CourseID == classEntity.CourseID && s.ProfileID == model.ProfileID).FirstOrDefault();
                                if (requirementDetailEntity != null)
                                {
                                    model = service.UpdateOrCreate<Tra_TraineeEntity, Tra_TraineeModel>(model);

                                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                                    foreach (var courseTopic in lstCourseTopicByCourseID)
                                    {
                                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                                        traineeTopicEntity.TopicID = courseTopic.TopicID;
                                        traineeTopicEntity.TraineeID = model.ID;
                                        message = traineeTopicServices.Add(traineeTopicEntity);
                                    }
                                    // edit classID trong RequirementDetail
                                    requirementDetailEntity.ClassID = model.ClassID;
                                    message = requirementDetailServices.Edit(requirementDetailEntity);
                                }
                                else
                                {
                                    model.ActionStatus = ConstantMessages.WarningProfileNotInRequirement.ToString().TranslateString();
                                }
                            }
                        }
                        else
                        {
                            model.ActionStatus = ConstantMessages.WarningProfileNotInRequirement.ToString().TranslateString();
                        }
                        model.ActionStatus = ConstantMessages.WarningProfileNotInRequirement.ToString().TranslateString();
                    }
                    if (message == NotificationType.Success.ToString())
                    {
                        model.ActionStatus = message;
                    }
                    return model;

                    //if (classEntity != null)
                    //{
                    //    if (classEntity.PlanID != null)
                    //    {
                    //        var planEntity = lstPlan.Where(s => s.ID == classEntity.PlanID.Value).FirstOrDefault();
                    //        if (planEntity != null)
                    //        {
                    //            var lstPlanDetailByPlanID = lstPlanDetail.Where(s => s.PlanID == planEntity.ID).ToList();

                    //            foreach (var item in lstPlanDetailByPlanID)
                    //            {
                    //                var lstTraineeInClassForOrg = lstTraineeInClass.Where(s => s.OrgStructureID.Value == item.OrgStructureID.Value).ToList();
                    //                //Kiểm tra số lượng của plan detail với sumQuantity của plan
                    //                if (planEntity.SumQuantity == lstPlanDetailByPlanID.Sum(s => s.Quantity))
                    //                {
                    //                    if (lstTraineeInClass.Count < lstPlanDetailByPlanID.Sum(s => s.Quantity))
                    //                    {
                    //                        // Xử Lý kiểm tra nv có thuộc phòng ban trong plan detail ko
                    //                        if (profileEntity != null)
                    //                        {
                    //                            if (lstTraineeInClassForOrg.Count < item.Quantity)
                    //                            {
                    //                                if (profileEntity.OrgStructureID.Value == item.OrgStructureID.Value)
                    //                                {
                    //                                    var traineeEntity = new Tra_TraineeEntity();
                    //                                    model.OrgStructureID = profileEntity.OrgStructureID != null ? profileEntity.OrgStructureID.Value : profileEntity.OrgStructureID;

                    //                                    model = service.UpdateOrCreate<Tra_TraineeEntity, Tra_TraineeModel>(model);

                    //                                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                    //                                    foreach (var courseTopic in lstCourseTopicByCourseID)
                    //                                    {
                    //                                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                    //                                        traineeTopicEntity.TopicID = courseTopic.TopicID;
                    //                                        traineeTopicEntity.TraineeID = model.ID;
                    //                                        message = traineeTopicServices.Add(traineeTopicEntity);
                    //                                    }
                    //                                    return model;  
                    //                                }
                    //                                model.ActionStatus = ConstantMessages.WarningProfileNotDependantOrgStructure.TranslateString();
                    //                            }
                    //                            else
                    //                            {
                    //                                model.ActionStatus = ConstantMessages.WarningTraineeOverLimit.TranslateString();
                    //                            }
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        model.ActionStatus = ConstantMessages.WarningTraineeOverLimit.TranslateString();
                    //                    }
                    //                }
                    //                if (planEntity.SumQuantity > lstPlanDetailByPlanID.Sum(s => s.Quantity))
                    //                {
                    //                        model = service.UpdateOrCreate<Tra_TraineeEntity, Tra_TraineeModel>(model);
                    //                        var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                    //                        foreach (var courseTopic in lstCourseTopicByCourseID)
                    //                        {
                    //                            var traineeTopicEntity = new Tra_TraineeTopicEntity();
                    //                            traineeTopicEntity.TopicID = courseTopic.TopicID;
                    //                            traineeTopicEntity.TraineeID = model.ID;
                    //                            message = traineeTopicServices.Add(traineeTopicEntity);
                    //                        }
                    //                        return model;  
                    //                }

                    //            }

                    //            return model;
                    //        }
                    //    }
                    //}

                }
                if (classEntity != null)
                {
                    if (traineeEntity.Count > 0)
                    {
                        model.ActionStatus = ConstantMessages.WarningProfileHaveClass.ToString().TranslateString();
                        return model;
                    }

                    model = service.UpdateOrCreate<Tra_TraineeEntity, Tra_TraineeModel>(model);

                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                    if (lstCourseTopicByCourseID.Count == 0)
                    {
                        return model;
                    }
                    foreach (var courseTopic in lstCourseTopicByCourseID)
                    {
                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                        traineeTopicEntity.TopicID = courseTopic.TopicID;
                        traineeTopicEntity.TraineeID = model.ID;
                        model.ActionStatus = traineeTopicServices.Add(traineeTopicEntity);
                    }


                    return model;

                }
            }

            return service.UpdateOrCreate<Tra_TraineeEntity, Tra_TraineeModel>(model);

            



            #endregion
        }
Exemplo n.º 3
0
        public Tra_PlanModel Post([Bind]Tra_PlanModel model)
        {
            #region Validate
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Tra_PlanModel>(model, "Tra_Plan", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            #endregion

            #region Check kiểm tra cột sum quantity
            ActionService service = new ActionService(UserLogin);
            string status = string.Empty;
            if(model.ID != null)
            {
                var planDetailServices = new Tra_PlanDetailServices();
                var lstObjPlanDetail = new List<object>();
                lstObjPlanDetail.Add(null);
                lstObjPlanDetail.Add(1);
                lstObjPlanDetail.Add(int.MaxValue - 1);
                var lstPlanDetail = planDetailServices.GetData<Tra_PlanDetailEntity>(lstObjPlanDetail, ConstantSql.hrm_tra_sp_get_PlanDetail,UserLogin, ref status).ToList();
                var lstPlanDetailByPlanID = lstPlanDetail.Where(s => s.PlanID == model.ID).ToList();
                if (lstPlanDetailByPlanID != null)
                {
                   
                       if (model.SumQuantity < lstPlanDetailByPlanID.Count)
                       {
                           model.ActionStatus = ConstantMessages.WarningQuantityPlanMustBeGreaterQuantityPlandetail.TranslateString();
                           return model;
                       }
                   
                }
            }
            #endregion
           
            return service.UpdateOrCreate<Tra_PlanEntity, Tra_PlanModel>(model);
        }
Exemplo n.º 4
0
        public  string ApprovedTraineeRegister (List<Guid> selectedIds , Guid UserId)
        {
            using (var context = new VnrHrmDataContext())
            {
                var message = string.Empty;
                var status = string.Empty;
                var UserLogin = string.Empty;
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var firstApproved = EnumDropDown.TraineeRegisterStatus.E_SUBMIT.ToString();
                var approved = EnumDropDown.TraineeRegisterStatus.E_APPROVED.ToString();
                var objTraineeRegister = new List<object>();
                objTraineeRegister.AddRange(new object[12]);
                objTraineeRegister[10] = 1;
                objTraineeRegister[11] = int.MaxValue - 1;
                var lstTraineeRegister = GetData<Tra_TraineeRegisterEntity>(objTraineeRegister, ConstantSql.hrm_tra_sp_get_TraineeRegister,UserLogin, ref status).ToList();

               var repo_UserApproved = new CustomBaseRepository<Sys_UserApprove>(unitOfWork);
               var lstUserApproved = repo_UserApproved.GetAll().Where(s => s.IsDelete == null).ToList();

                if (selectedIds.Count > 0)
                {
                    lstTraineeRegister = lstTraineeRegister.Where(s => selectedIds.Contains(s.ID)).ToList();
                }

                var traineeServices = new Tra_TraineeServices();
                var isTraineeInRequireDetail = traineeServices.IsAddTraineeDependOnRequirementDetail();
                var traineeTopicServices = new Tra_TraineeTopicServices();
                var planServices = new Tra_PlanServices();
                var lstObjPlan = new List<object>();
                lstObjPlan.Add(null);
                lstObjPlan.Add(null);
                lstObjPlan.Add(null);
                lstObjPlan.Add(null);
                lstObjPlan.Add(1);
                lstObjPlan.Add(int.MaxValue - 1);
                var lstPlan = planServices.GetData<Tra_PlanEntity>(lstObjPlan, ConstantSql.hrm_tra_sp_get_Plan,UserLogin, ref status).ToList();


                var planDetailServices = new Tra_PlanDetailServices();
                var lstObjPlanDetail = new List<object>();
                lstObjPlanDetail.Add(null);
                lstObjPlanDetail.Add(1);
                lstObjPlanDetail.Add(int.MaxValue - 1);
                var lstPlanDetail = planDetailServices.GetData<Tra_PlanDetailEntity>(lstObjPlanDetail, ConstantSql.hrm_tra_sp_get_PlanDetail, UserLogin, ref status).ToList();

                var classServices = new Tra_ClassServices();
                var lstObjClass = new List<object>();
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(1);
                lstObjClass.Add(int.MaxValue - 1);
                var lstClass = classServices.GetData<Tra_ClassEntity>(lstObjClass, ConstantSql.hrm_tra_sp_get_Class, UserLogin, ref status).ToList();

                //var lstObjTraineeInClass = new List<object>();
                //lstObjTraineeInClass.Add(model.ClassID);
                //var lstTraineeInClass = classServices.GetData<Tra_ClassEntity>(lstObjTraineeInClass, ConstantSql.hrm_cat_sp_get_TraineeByClassID, ref status).ToList();

                var courseTopicServices = new Tra_TraineeTopicServices();
                var objCourseTopic = new List<object>();
                objCourseTopic.Add(1);
                objCourseTopic.Add(int.MaxValue - 1);
                var lstCourseTopic = courseTopicServices.GetData<Tra_CourseTopicEntity>(objCourseTopic, ConstantSql.hrm_tra_sp_get_CourseTopic, UserLogin, ref status);


                //var classEntity = lstClass.Where(s => s.ID == model.ClassID).FirstOrDefault();
                var profileServices = new Hre_ProfileServices();

                var requirementServices = new Tra_RequirementTrainServices();
                var objRequirement = new List<object>();
                objRequirement.AddRange(new object[7]);
                objRequirement[5] = 1;
                objRequirement[6] = int.MaxValue - 1;
                var lstRequirement = requirementServices.GetData<Tra_RequirementTrainEntity>(objRequirement, ConstantSql.hrm_tra_sp_get_RequirementTrain, UserLogin, ref status).ToList();

                var requirementDetailServices = new Tra_RequirementTrainDetailServices();
                var objRequirementDetail = new List<object>();
                objRequirementDetail.Add(null);
                objRequirementDetail.Add(1);
                objRequirementDetail.Add(int.MaxValue - 1);
                var lstRequirementDetail = requirementDetailServices.GetData<Tra_RequirementTrainDetailEntity>(objRequirementDetail, ConstantSql.hrm_tra_sp_get_RequirementDetail, UserLogin, ref status).ToList();

                var objTrainee = new List<object>();
                objTrainee.AddRange(new object[15]);
                objTrainee[13] = 1;
                objTrainee[14] = int.MaxValue - 1;
                var lstObjTrainee = traineeServices.GetData<Tra_TraineeEntity>(objTrainee, ConstantSql.hrm_tra_sp_get_Trainee, UserLogin, ref status).ToList();

                foreach (var registerEntity in lstTraineeRegister)
                {
                    var classEntity = lstClass.Where(s => s.ID == registerEntity.ClassID).FirstOrDefault();
                    var traineeEntityInClass = lstObjTrainee.Where(s => s.ClassID == registerEntity.ClassID && registerEntity.ProfileID == s.ProfileID).ToList();

                    #region người duyệt đầu
                    if (registerEntity.UserApproveID1 != null && registerEntity.UserApproveID1.Value == UserId)
                    {
                        var userApprovedEntity = lstUserApproved.Where(s => registerEntity.UserApproveID1.Value == s.UserApproveID && s.Type == ApproveType.E_TRA_TRAINEEREGISTER.ToString()).FirstOrDefault();
                        if (userApprovedEntity != null)
                        {
                            if (userApprovedEntity.IsMasterApprove == null || userApprovedEntity.IsMasterApprove.Value == false)
                            {
                                registerEntity.Status = firstApproved;
                                message = Edit(registerEntity);
                            }
                        }
                    }
	                #endregion

                    #region người duyệt cuối
                    if (registerEntity.UserApproveID2 != null && registerEntity.UserApproveID2.Value == UserId)
                    {
                        var userApprovedEntity = lstUserApproved.Where(s => registerEntity.UserApproveID2.Value == s.UserApproveID && s.Type == ApproveType.E_TRA_TRAINEEREGISTER.ToString()).FirstOrDefault();
                        if (userApprovedEntity != null)
                        {
                            if (userApprovedEntity.IsMasterApprove != null && userApprovedEntity.IsMasterApprove.Value)
                            {
                                #region Cập Nhập Status lại vào bảng Tra_TraineeRegister
                                registerEntity.Status = approved;
                                message = Edit(registerEntity);
                                #endregion

                                #region Tạo hv vào bảng Tra_Trainee

                                if (isTraineeInRequireDetail)
                                {
                                    if (traineeEntityInClass.Count > 0)
                                    {
                                        message = ConstantMessages.WarningProfileHaveClass.ToString().TranslateString();
                                        return message;
                                    }
                                    if (registerEntity.ClassID != null)
                                    {
                                        if (classEntity != null && classEntity.PlanID != null)
                                        {
                                            var lstRequirementByPlanID = lstRequirement.Where(s => s.PlanID != null && s.PlanID.Value == classEntity.PlanID).ToList();
                                            foreach (var item in lstRequirementByPlanID)
                                            {
                                                var requirementDetailEntity = lstRequirementDetail.Where(s => item.ID == s.RequirementTrainID && s.CourseID == classEntity.CourseID && s.ProfileID == item.ProfileID).FirstOrDefault();
                                                if (requirementDetailEntity != null)
                                                {
                                                    var traineeEntity = new Tra_TraineeEntity();
                                                    traineeEntity.ProfileID = registerEntity.ProfileID.Value;
                                                    traineeEntity.ClassID = registerEntity.ClassID.Value;
                                                    traineeEntity.TraineeRegisterID = (Guid?)registerEntity.ID;
                                                    traineeServices.Add(traineeEntity);

                                                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                                                    foreach (var courseTopic in lstCourseTopicByCourseID)
                                                    {
                                                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                                                        traineeTopicEntity.TopicID = courseTopic.TopicID;
                                                        traineeTopicEntity.TraineeID = traineeEntity.ID;
                                                        message = traineeTopicServices.Add(traineeTopicEntity);
                                                    }

                                                }
                                                else
                                                {
                                                    message = ConstantMessages.WarningProfileNotInRequirement.ToString().TranslateString();
                                                }
                                            }
                                        }
                                    }
                                }

                                if (classEntity != null)
                                {
                                    if (traineeEntityInClass.Count > 0)
                                    {
                                        message = ConstantMessages.WarningProfileHaveClass.ToString().TranslateString();
                                        return message;
                                    }

                                    var traineeEntity = new Tra_TraineeEntity();
                                    traineeEntity.ProfileID = registerEntity.ProfileID.Value;
                                    traineeEntity.ClassID = registerEntity.ClassID.Value;
                                    traineeEntity.TraineeRegisterID = (Guid?)registerEntity.ID;
                                    traineeServices.Add(traineeEntity);

                                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                                    foreach (var courseTopic in lstCourseTopicByCourseID)
                                    {
                                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                                        traineeTopicEntity.TopicID = courseTopic.TopicID;
                                        traineeTopicEntity.TraineeID = traineeEntity.ID;
                                        message = traineeTopicServices.Add(traineeTopicEntity);
                                    }



                                }
                                #endregion
                            }
                        }
                    }
                    #endregion

                }
                return message;
            }
            
        }
Exemplo n.º 5
0
        public string ApprovedTraineeRegister(List <Guid> selectedIds, Guid UserId)
        {
            using (var context = new VnrHrmDataContext())
            {
                var message            = string.Empty;
                var status             = string.Empty;
                var UserLogin          = string.Empty;
                var unitOfWork         = (IUnitOfWork)(new UnitOfWork(context));
                var firstApproved      = EnumDropDown.TraineeRegisterStatus.E_SUBMIT.ToString();
                var approved           = EnumDropDown.TraineeRegisterStatus.E_APPROVED.ToString();
                var objTraineeRegister = new List <object>();
                objTraineeRegister.AddRange(new object[12]);
                objTraineeRegister[10] = 1;
                objTraineeRegister[11] = int.MaxValue - 1;
                var lstTraineeRegister = GetData <Tra_TraineeRegisterEntity>(objTraineeRegister, ConstantSql.hrm_tra_sp_get_TraineeRegister, UserLogin, ref status).ToList();

                var repo_UserApproved = new CustomBaseRepository <Sys_UserApprove>(unitOfWork);
                var lstUserApproved   = repo_UserApproved.GetAll().Where(s => s.IsDelete == null).ToList();

                if (selectedIds.Count > 0)
                {
                    lstTraineeRegister = lstTraineeRegister.Where(s => selectedIds.Contains(s.ID)).ToList();
                }

                var traineeServices          = new Tra_TraineeServices();
                var isTraineeInRequireDetail = traineeServices.IsAddTraineeDependOnRequirementDetail();
                var traineeTopicServices     = new Tra_TraineeTopicServices();
                var planServices             = new Tra_PlanServices();
                var lstObjPlan = new List <object>();
                lstObjPlan.Add(null);
                lstObjPlan.Add(null);
                lstObjPlan.Add(null);
                lstObjPlan.Add(null);
                lstObjPlan.Add(1);
                lstObjPlan.Add(int.MaxValue - 1);
                var lstPlan = planServices.GetData <Tra_PlanEntity>(lstObjPlan, ConstantSql.hrm_tra_sp_get_Plan, UserLogin, ref status).ToList();


                var planDetailServices = new Tra_PlanDetailServices();
                var lstObjPlanDetail   = new List <object>();
                lstObjPlanDetail.Add(null);
                lstObjPlanDetail.Add(1);
                lstObjPlanDetail.Add(int.MaxValue - 1);
                var lstPlanDetail = planDetailServices.GetData <Tra_PlanDetailEntity>(lstObjPlanDetail, ConstantSql.hrm_tra_sp_get_PlanDetail, UserLogin, ref status).ToList();

                var classServices = new Tra_ClassServices();
                var lstObjClass   = new List <object>();
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(null);
                lstObjClass.Add(1);
                lstObjClass.Add(int.MaxValue - 1);
                var lstClass = classServices.GetData <Tra_ClassEntity>(lstObjClass, ConstantSql.hrm_tra_sp_get_Class, UserLogin, ref status).ToList();

                //var lstObjTraineeInClass = new List<object>();
                //lstObjTraineeInClass.Add(model.ClassID);
                //var lstTraineeInClass = classServices.GetData<Tra_ClassEntity>(lstObjTraineeInClass, ConstantSql.hrm_cat_sp_get_TraineeByClassID, ref status).ToList();

                var courseTopicServices = new Tra_TraineeTopicServices();
                var objCourseTopic      = new List <object>();
                objCourseTopic.Add(1);
                objCourseTopic.Add(int.MaxValue - 1);
                var lstCourseTopic = courseTopicServices.GetData <Tra_CourseTopicEntity>(objCourseTopic, ConstantSql.hrm_tra_sp_get_CourseTopic, UserLogin, ref status);


                //var classEntity = lstClass.Where(s => s.ID == model.ClassID).FirstOrDefault();
                var profileServices = new Hre_ProfileServices();

                var requirementServices = new Tra_RequirementTrainServices();
                var objRequirement      = new List <object>();
                objRequirement.AddRange(new object[7]);
                objRequirement[5] = 1;
                objRequirement[6] = int.MaxValue - 1;
                var lstRequirement = requirementServices.GetData <Tra_RequirementTrainEntity>(objRequirement, ConstantSql.hrm_tra_sp_get_RequirementTrain, UserLogin, ref status).ToList();

                var requirementDetailServices = new Tra_RequirementTrainDetailServices();
                var objRequirementDetail      = new List <object>();
                objRequirementDetail.Add(null);
                objRequirementDetail.Add(1);
                objRequirementDetail.Add(int.MaxValue - 1);
                var lstRequirementDetail = requirementDetailServices.GetData <Tra_RequirementTrainDetailEntity>(objRequirementDetail, ConstantSql.hrm_tra_sp_get_RequirementDetail, UserLogin, ref status).ToList();

                var objTrainee = new List <object>();
                objTrainee.AddRange(new object[15]);
                objTrainee[13] = 1;
                objTrainee[14] = int.MaxValue - 1;
                var lstObjTrainee = traineeServices.GetData <Tra_TraineeEntity>(objTrainee, ConstantSql.hrm_tra_sp_get_Trainee, UserLogin, ref status).ToList();

                foreach (var registerEntity in lstTraineeRegister)
                {
                    var classEntity          = lstClass.Where(s => s.ID == registerEntity.ClassID).FirstOrDefault();
                    var traineeEntityInClass = lstObjTrainee.Where(s => s.ClassID == registerEntity.ClassID && registerEntity.ProfileID == s.ProfileID).ToList();

                    #region người duyệt đầu
                    if (registerEntity.UserApproveID1 != null && registerEntity.UserApproveID1.Value == UserId)
                    {
                        var userApprovedEntity = lstUserApproved.Where(s => registerEntity.UserApproveID1.Value == s.UserApproveID && s.Type == ApproveType.E_TRA_TRAINEEREGISTER.ToString()).FirstOrDefault();
                        if (userApprovedEntity != null)
                        {
                            if (userApprovedEntity.IsMasterApprove == null || userApprovedEntity.IsMasterApprove.Value == false)
                            {
                                registerEntity.Status = firstApproved;
                                message = Edit(registerEntity);
                            }
                        }
                    }
                    #endregion

                    #region người duyệt cuối
                    if (registerEntity.UserApproveID2 != null && registerEntity.UserApproveID2.Value == UserId)
                    {
                        var userApprovedEntity = lstUserApproved.Where(s => registerEntity.UserApproveID2.Value == s.UserApproveID && s.Type == ApproveType.E_TRA_TRAINEEREGISTER.ToString()).FirstOrDefault();
                        if (userApprovedEntity != null)
                        {
                            if (userApprovedEntity.IsMasterApprove != null && userApprovedEntity.IsMasterApprove.Value)
                            {
                                #region Cập Nhập Status lại vào bảng Tra_TraineeRegister
                                registerEntity.Status = approved;
                                message = Edit(registerEntity);
                                #endregion

                                #region Tạo hv vào bảng Tra_Trainee

                                if (isTraineeInRequireDetail)
                                {
                                    if (traineeEntityInClass.Count > 0)
                                    {
                                        message = ConstantMessages.WarningProfileHaveClass.ToString().TranslateString();
                                        return(message);
                                    }
                                    if (registerEntity.ClassID != null)
                                    {
                                        if (classEntity != null && classEntity.PlanID != null)
                                        {
                                            var lstRequirementByPlanID = lstRequirement.Where(s => s.PlanID != null && s.PlanID.Value == classEntity.PlanID).ToList();
                                            foreach (var item in lstRequirementByPlanID)
                                            {
                                                var requirementDetailEntity = lstRequirementDetail.Where(s => item.ID == s.RequirementTrainID && s.CourseID == classEntity.CourseID && s.ProfileID == item.ProfileID).FirstOrDefault();
                                                if (requirementDetailEntity != null)
                                                {
                                                    var traineeEntity = new Tra_TraineeEntity();
                                                    traineeEntity.ProfileID         = registerEntity.ProfileID.Value;
                                                    traineeEntity.ClassID           = registerEntity.ClassID.Value;
                                                    traineeEntity.TraineeRegisterID = (Guid?)registerEntity.ID;
                                                    traineeServices.Add(traineeEntity);

                                                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                                                    foreach (var courseTopic in lstCourseTopicByCourseID)
                                                    {
                                                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                                                        traineeTopicEntity.TopicID   = courseTopic.TopicID;
                                                        traineeTopicEntity.TraineeID = traineeEntity.ID;
                                                        message = traineeTopicServices.Add(traineeTopicEntity);
                                                    }
                                                }
                                                else
                                                {
                                                    message = ConstantMessages.WarningProfileNotInRequirement.ToString().TranslateString();
                                                }
                                            }
                                        }
                                    }
                                }

                                if (classEntity != null)
                                {
                                    if (traineeEntityInClass.Count > 0)
                                    {
                                        message = ConstantMessages.WarningProfileHaveClass.ToString().TranslateString();
                                        return(message);
                                    }

                                    var traineeEntity = new Tra_TraineeEntity();
                                    traineeEntity.ProfileID         = registerEntity.ProfileID.Value;
                                    traineeEntity.ClassID           = registerEntity.ClassID.Value;
                                    traineeEntity.TraineeRegisterID = (Guid?)registerEntity.ID;
                                    traineeServices.Add(traineeEntity);

                                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                                    foreach (var courseTopic in lstCourseTopicByCourseID)
                                    {
                                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                                        traineeTopicEntity.TopicID   = courseTopic.TopicID;
                                        traineeTopicEntity.TraineeID = traineeEntity.ID;
                                        message = traineeTopicServices.Add(traineeTopicEntity);
                                    }
                                }
                                #endregion
                            }
                        }
                    }
                    #endregion
                }
                return(message);
            }
        }
Exemplo n.º 6
0
        public Tra_TraineeModel Post([Bind] Tra_TraineeModel model)
        {
            #region Validate
            string message       = string.Empty;
            var    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Tra_TraineeModel>(model, "Tra_Trainee", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            #endregion

            var           traineeServices          = new Tra_TraineeServices();
            ActionService service                  = new ActionService(UserLogin);
            var           isTraineeInRequireDetail = traineeServices.IsAddTraineeDependOnRequirementDetail();
            var           traineeTopicServices     = new Tra_TraineeTopicServices();
            var           planServices             = new Tra_PlanServices();
            var           status     = string.Empty;
            var           lstObjPlan = new List <object>();
            lstObjPlan.Add(null);
            lstObjPlan.Add(null);
            lstObjPlan.Add(null);
            lstObjPlan.Add(null);
            lstObjPlan.Add(1);
            lstObjPlan.Add(int.MaxValue - 1);
            var lstPlan = planServices.GetData <Tra_PlanEntity>(lstObjPlan, ConstantSql.hrm_tra_sp_get_Plan, UserLogin, ref status).ToList();


            var planDetailServices = new Tra_PlanDetailServices();
            var lstObjPlanDetail   = new List <object>();
            lstObjPlanDetail.Add(null);
            lstObjPlanDetail.Add(1);
            lstObjPlanDetail.Add(int.MaxValue - 1);
            var lstPlanDetail = planDetailServices.GetData <Tra_PlanDetailEntity>(lstObjPlanDetail, ConstantSql.hrm_tra_sp_get_PlanDetail, UserLogin, ref status).ToList();

            var classServices = new Tra_ClassServices();
            var lstObjClass   = new List <object>();
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(null);
            lstObjClass.Add(1);
            lstObjClass.Add(int.MaxValue - 1);
            var lstClass = classServices.GetData <Tra_ClassEntity>(lstObjClass, ConstantSql.hrm_tra_sp_get_Class, UserLogin, ref status).ToList();

            var lstObjTraineeInClass = new List <object>();
            lstObjTraineeInClass.Add(model.ClassID);
            var lstTraineeInClass = classServices.GetData <Tra_ClassEntity>(lstObjTraineeInClass, ConstantSql.hrm_cat_sp_get_TraineeByClassID, UserLogin, ref status).ToList();

            var courseTopicServices = new Tra_TraineeTopicServices();
            var objCourseTopic      = new List <object>();
            objCourseTopic.Add(1);
            objCourseTopic.Add(int.MaxValue - 1);
            var lstCourseTopic = courseTopicServices.GetData <Tra_CourseTopicEntity>(objCourseTopic, ConstantSql.hrm_tra_sp_get_CourseTopic, UserLogin, ref status);


            var classEntity     = lstClass.Where(s => s.ID == model.ClassID).FirstOrDefault();
            var profileServices = new Hre_ProfileServices();
            var profileEntity   = profileServices.GetData <Hre_ProfileEntity>(model.ProfileID, ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();

            var requirementServices = new Tra_RequirementTrainServices();
            var objRequirement      = new List <object>();
            objRequirement.AddRange(new object[7]);
            objRequirement[5] = 1;
            objRequirement[6] = int.MaxValue - 1;
            var lstRequirement = requirementServices.GetData <Tra_RequirementTrainEntity>(objRequirement, ConstantSql.hrm_tra_sp_get_RequirementTrain, UserLogin, ref status).ToList();

            var requirementDetailServices = new Tra_RequirementTrainDetailServices();
            var objRequirementDetail      = new List <object>();
            objRequirementDetail.Add(null);
            objRequirementDetail.Add(1);
            objRequirementDetail.Add(int.MaxValue - 1);
            var lstRequirementDetail = requirementDetailServices.GetData <Tra_RequirementTrainDetailEntity>(objRequirementDetail, ConstantSql.hrm_tra_sp_get_RequirementDetail, UserLogin, ref status).ToList();

            var objTrainee = new List <object>();
            objTrainee.AddRange(new object[15]);
            objTrainee[13] = 1;
            objTrainee[14] = int.MaxValue - 1;
            var lstObjTrainee = traineeServices.GetData <Tra_TraineeEntity>(objTrainee, ConstantSql.hrm_tra_sp_get_Trainee, UserLogin, ref status).ToList();
            var traineeEntity = lstObjTrainee.Where(s => s.ClassID == model.ClassID && model.ProfileID == s.ProfileID).ToList();

            #region Check Học Viên
            if (model.ID == Guid.Empty)
            {
                if (isTraineeInRequireDetail)
                {
                    if (traineeEntity.Count > 0)
                    {
                        model.ActionStatus = ConstantMessages.WarningProfileHaveClass.ToString().TranslateString();
                        return(model);
                    }
                    if (classEntity != null)
                    {
                        if (classEntity.PlanID != null)
                        {
                            var lstRequirementByPlanID = lstRequirement.Where(s => s.PlanID != null && s.PlanID.Value == classEntity.PlanID).ToList();
                            foreach (var item in lstRequirementByPlanID)
                            {
                                var requirementDetailEntity = lstRequirementDetail.Where(s => item.ID == s.RequirementTrainID && s.CourseID == classEntity.CourseID && s.ProfileID == model.ProfileID).FirstOrDefault();
                                if (requirementDetailEntity != null)
                                {
                                    model = service.UpdateOrCreate <Tra_TraineeEntity, Tra_TraineeModel>(model);

                                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                                    foreach (var courseTopic in lstCourseTopicByCourseID)
                                    {
                                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                                        traineeTopicEntity.TopicID   = courseTopic.TopicID;
                                        traineeTopicEntity.TraineeID = model.ID;
                                        message = traineeTopicServices.Add(traineeTopicEntity);
                                    }
                                    // edit classID trong RequirementDetail
                                    requirementDetailEntity.ClassID = model.ClassID;
                                    message = requirementDetailServices.Edit(requirementDetailEntity);
                                }
                                else
                                {
                                    model.ActionStatus = ConstantMessages.WarningProfileNotInRequirement.ToString().TranslateString();
                                }
                            }
                        }
                        else
                        {
                            model.ActionStatus = ConstantMessages.WarningProfileNotInRequirement.ToString().TranslateString();
                        }
                        model.ActionStatus = ConstantMessages.WarningProfileNotInRequirement.ToString().TranslateString();
                    }
                    if (message == NotificationType.Success.ToString())
                    {
                        model.ActionStatus = message;
                    }
                    return(model);

                    //if (classEntity != null)
                    //{
                    //    if (classEntity.PlanID != null)
                    //    {
                    //        var planEntity = lstPlan.Where(s => s.ID == classEntity.PlanID.Value).FirstOrDefault();
                    //        if (planEntity != null)
                    //        {
                    //            var lstPlanDetailByPlanID = lstPlanDetail.Where(s => s.PlanID == planEntity.ID).ToList();

                    //            foreach (var item in lstPlanDetailByPlanID)
                    //            {
                    //                var lstTraineeInClassForOrg = lstTraineeInClass.Where(s => s.OrgStructureID.Value == item.OrgStructureID.Value).ToList();
                    //                //Kiểm tra số lượng của plan detail với sumQuantity của plan
                    //                if (planEntity.SumQuantity == lstPlanDetailByPlanID.Sum(s => s.Quantity))
                    //                {
                    //                    if (lstTraineeInClass.Count < lstPlanDetailByPlanID.Sum(s => s.Quantity))
                    //                    {
                    //                        // Xử Lý kiểm tra nv có thuộc phòng ban trong plan detail ko
                    //                        if (profileEntity != null)
                    //                        {
                    //                            if (lstTraineeInClassForOrg.Count < item.Quantity)
                    //                            {
                    //                                if (profileEntity.OrgStructureID.Value == item.OrgStructureID.Value)
                    //                                {
                    //                                    var traineeEntity = new Tra_TraineeEntity();
                    //                                    model.OrgStructureID = profileEntity.OrgStructureID != null ? profileEntity.OrgStructureID.Value : profileEntity.OrgStructureID;

                    //                                    model = service.UpdateOrCreate<Tra_TraineeEntity, Tra_TraineeModel>(model);

                    //                                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                    //                                    foreach (var courseTopic in lstCourseTopicByCourseID)
                    //                                    {
                    //                                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                    //                                        traineeTopicEntity.TopicID = courseTopic.TopicID;
                    //                                        traineeTopicEntity.TraineeID = model.ID;
                    //                                        message = traineeTopicServices.Add(traineeTopicEntity);
                    //                                    }
                    //                                    return model;
                    //                                }
                    //                                model.ActionStatus = ConstantMessages.WarningProfileNotDependantOrgStructure.TranslateString();
                    //                            }
                    //                            else
                    //                            {
                    //                                model.ActionStatus = ConstantMessages.WarningTraineeOverLimit.TranslateString();
                    //                            }
                    //                        }
                    //                    }
                    //                    else
                    //                    {
                    //                        model.ActionStatus = ConstantMessages.WarningTraineeOverLimit.TranslateString();
                    //                    }
                    //                }
                    //                if (planEntity.SumQuantity > lstPlanDetailByPlanID.Sum(s => s.Quantity))
                    //                {
                    //                        model = service.UpdateOrCreate<Tra_TraineeEntity, Tra_TraineeModel>(model);
                    //                        var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                    //                        foreach (var courseTopic in lstCourseTopicByCourseID)
                    //                        {
                    //                            var traineeTopicEntity = new Tra_TraineeTopicEntity();
                    //                            traineeTopicEntity.TopicID = courseTopic.TopicID;
                    //                            traineeTopicEntity.TraineeID = model.ID;
                    //                            message = traineeTopicServices.Add(traineeTopicEntity);
                    //                        }
                    //                        return model;
                    //                }

                    //            }

                    //            return model;
                    //        }
                    //    }
                    //}
                }
                if (classEntity != null)
                {
                    if (traineeEntity.Count > 0)
                    {
                        model.ActionStatus = ConstantMessages.WarningProfileHaveClass.ToString().TranslateString();
                        return(model);
                    }

                    model = service.UpdateOrCreate <Tra_TraineeEntity, Tra_TraineeModel>(model);

                    var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                    if (lstCourseTopicByCourseID.Count == 0)
                    {
                        return(model);
                    }
                    foreach (var courseTopic in lstCourseTopicByCourseID)
                    {
                        var traineeTopicEntity = new Tra_TraineeTopicEntity();
                        traineeTopicEntity.TopicID   = courseTopic.TopicID;
                        traineeTopicEntity.TraineeID = model.ID;
                        model.ActionStatus           = traineeTopicServices.Add(traineeTopicEntity);
                    }


                    return(model);
                }
            }

            return(service.UpdateOrCreate <Tra_TraineeEntity, Tra_TraineeModel>(model));



            #endregion
        }
Exemplo n.º 7
0
        // Son.Vo - Thêm học viên vào lớp học
        public string AddTraineeToClass(List<Guid> lstTraineeIDs, Guid classID, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                string message = string.Empty;
                var planServices = new Tra_PlanServices();
                #region Tin.Nguyen
                var lstObjPlan = new List<object>();
                lstObjPlan.Add(null);
                lstObjPlan.Add(null);
                lstObjPlan.Add(null);
                lstObjPlan.Add(1);
                lstObjPlan.Add(int.MaxValue - 1);
                var lstPlan = planServices.GetData<Tra_PlanEntity>(lstObjPlan, ConstantSql.hrm_tra_sp_get_Plan, UserLogin, ref status).ToList();

                var planDetailServices = new Tra_PlanDetailServices();
                var lstObjPlanDetail = new List<object>();
                lstObjPlanDetail.Add(null);
                lstObjPlanDetail.Add(1);
                lstObjPlanDetail.Add(int.MaxValue - 1);
                var lstPlanDetail = planDetailServices.GetData<Tra_PlanDetailEntity>(lstObjPlanDetail, ConstantSql.hrm_tra_sp_get_PlanDetail, UserLogin, ref status).ToList();

                var classServices = new Tra_ClassServices();
                var objClass = new List<object>();
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(1);
                objClass.Add(int.MaxValue - 1);
                var lstClass = classServices.GetData<Tra_ClassEntity>(objClass, ConstantSql.hrm_tra_sp_get_Class, UserLogin, ref status).ToList();

                var lstObjTraineeInClass = new List<object>();
                lstObjTraineeInClass.Add(classID);
                var lstTraineeInClass = classServices.GetData<Tra_ClassEntity>(lstObjTraineeInClass, ConstantSql.hrm_cat_sp_get_TraineeByClassID, UserLogin, ref status).ToList();

                var traineeTopicServices = new Tra_TraineeTopicServices();
                var courseTopicServices = new Tra_TraineeTopicServices();
                var objCourseTopic = new List<object>();
                objCourseTopic.Add(1);
                objCourseTopic.Add(int.MaxValue - 1);
                var lstCourseTopic = courseTopicServices.GetData<Tra_CourseTopicEntity>(objCourseTopic, ConstantSql.hrm_tra_sp_get_CourseTopic, UserLogin, ref status);

                var classEntity = lstClass.Where(s => s.ID == classID).FirstOrDefault();
                var profileServices = new Hre_ProfileServices();
                var objProfile = new List<object>();
                objProfile.AddRange(new object[18]);
                objProfile[16] = 1;
                objProfile[17] = int.MaxValue - 1;
                var lstProfileSelected = profileServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_Profile, UserLogin, ref status).ToList();
                if(lstTraineeIDs != null)
                {
                    lstProfileSelected = lstProfileSelected.Where(s => lstTraineeIDs.Contains(s.ID)).ToList();
                }

                var traineeServices = new Tra_TraineeServices();

                var requirementServices = new Tra_RequirementTrainServices();
                var objRequirement = new List<object>();
                objRequirement.AddRange(new object[7]);
                objRequirement[5] = 1;
                objRequirement[6] = int.MaxValue - 1;
                var lstRequirement = requirementServices.GetData<Tra_RequirementTrainEntity>(objRequirement, ConstantSql.hrm_tra_sp_get_RequirementTrain, UserLogin, ref status).ToList();

                var requirementDetailServices = new Tra_RequirementTrainDetailServices();
                var objRequirementDetail = new List<object>();
                objRequirementDetail.Add(null);
                objRequirementDetail.Add(1);
                objRequirementDetail.Add(int.MaxValue - 1);
                var lstRequirementDetail = requirementDetailServices.GetData<Tra_RequirementTrainDetailEntity>(objRequirementDetail, ConstantSql.hrm_tra_sp_get_RequirementDetail, UserLogin, ref status).ToList();

                foreach (var profileEntity in lstProfileSelected)
                {
                    if (classEntity != null)
                    {
                        if (classEntity.PlanID != null)
                        {
                            var planEntity = lstPlan.Where(s => s.ID == classEntity.PlanID.Value).FirstOrDefault();
                            if (planEntity != null)
                            {
                                var lstPlanDetailByPlanID = lstPlanDetail.Where(s => s.PlanID == planEntity.ID).ToList();

                                foreach (var item in lstPlanDetailByPlanID)
                                {
                                    var lstTraineeInClassForOrg = lstTraineeInClass.Where(s => s.OrgStructureID.Value == item.OrgStructureID.Value).ToList();
                                    //Kiểm tra số lượng của plan detail với sumQuantity của plan
                                    if (planEntity.SumQuantity == lstPlanDetailByPlanID.Sum(s => s.Quantity))
                                    {
                                        if (lstTraineeInClass.Count < lstPlanDetailByPlanID.Sum(s => s.Quantity))
                                        {
                                            // Xử Lý kiểm tra nv có thuộc phòng ban trong plan detail ko
                                            if (profileEntity != null)
                                            {
                                                if (lstTraineeInClassForOrg.Count < item.Quantity)
                                                {
                                                    if (profileEntity.OrgStructureID.Value == item.OrgStructureID.Value)
                                                    {
                                                        var traineeEntity = new Tra_TraineeEntity();
                                                      
                                                        traineeEntity.ProfileID = profileEntity.ID;
                                                        traineeEntity.ClassID = classID;
                                                        traineeEntity.OrgStructureID = profileEntity.OrgStructureID != null ? profileEntity.OrgStructureID.Value : profileEntity.OrgStructureID;

                                                        message = traineeServices.Add(traineeEntity);
                                                        


                                                        var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                                                        foreach (var courseTopic in lstCourseTopicByCourseID)
                                                        {
                                                            var traineeTopicEntity = new Tra_TraineeTopicEntity();
                                                            traineeTopicEntity.TopicID = courseTopic.TopicID;
                                                            traineeTopicEntity.TraineeID = traineeEntity.ID;
                                                            message = traineeTopicServices.Add(traineeTopicEntity);
                                                        }
                                                        return message;
                                                    }
                                                    message = ConstantMessages.WarningProfileNotDependantOrgStructure.TranslateString();
                                                }
                                                else
                                                {
                                                    message = ConstantMessages.WarningTraineeOverLimit.TranslateString();
                                                }
                                            }
                                        }
                                        else
                                        {
                                            message = ConstantMessages.WarningTraineeOverLimit.TranslateString();
                                        }
                                    }
                                    if (planEntity.SumQuantity > lstPlanDetailByPlanID.Sum(s => s.Quantity))
                                    {
                                        var traineeEntity = new Tra_TraineeEntity();

                                        traineeEntity.ProfileID = profileEntity.ID;
                                        traineeEntity.ClassID = classID;
                                        traineeEntity.OrgStructureID = profileEntity.OrgStructureID != null ? profileEntity.OrgStructureID.Value : profileEntity.OrgStructureID;

                                        message = traineeServices.Add(traineeEntity);



                                        var lstCourseTopicByCourseID = lstCourseTopic.Where(s => s.CourseID == classEntity.CourseID).ToList();
                                        foreach (var courseTopic in lstCourseTopicByCourseID)
                                        {
                                            var traineeTopicEntity = new Tra_TraineeTopicEntity();
                                            traineeTopicEntity.TopicID = courseTopic.TopicID;
                                            traineeTopicEntity.TraineeID = traineeEntity.ID;
                                            message = traineeTopicServices.Add(traineeTopicEntity);
                                        }
                                        return message;
                                    }

                                }

                                return message;
                            }
                        }
                    }
                }
                #endregion
                return message;
            }
        }