예제 #1
0
        public Rec_CandidateModel Post([Bind]Rec_CandidateModel model)
        {
            #region Validate
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Rec_CandidateModel>(model, "Rec_Candidate", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
           
            if(model != null && model.DateExpiresPassport !=null && model.DateIssuePassport != null)
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Rec_CandidateModel>(model, "Rec_CandidateCheckDate", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return model;
                }
            }
            #endregion
            ActionService service = new ActionService(UserLogin);
            Rec_RecruitmentHistoryServices recruimentHistoryService = new Rec_RecruitmentHistoryServices();
            #region Check trùng và xử lý lưu or edit lại dòng cũ
            BaseService baseservice = new BaseService();
            string status = string.Empty;
            List<object> lstObj = new List<object>();
            lstObj.Add(model.ID);
            lstObj.Add(model.IdentifyNumber);
            lstObj.Add(model.CandidateName);
            lstObj.Add(model.DateOfBirth);
            var candidate = baseservice.GetData<Rec_CandidateModel>(lstObj, ConstantSql.hrm_rec_sp_checkduplidatecandidate, UserLogin,ref status).FirstOrDefault();
            if (candidate != null)
            {
                model.PassFilterResume = null;
                model.Status = HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_NEW.ToString();
                model.ID = candidate.ID;
            }

            // Làm theo task 0048666 - edit mà thay đổi ngày nộp thì update trạng thái = null - task 0049801 sửa lại thành E_NEW
            if (model.ID != Guid.Empty)
            {
                var candidateEntity = baseservice.GetData<Rec_CandidateEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_rec_sp_get_CandidateById, UserLogin, ref status).FirstOrDefault();
                
                if (candidateEntity != null && candidateEntity.DateApply != model.DateApply && candidateEntity.Status != model.Status)
                {
                    model.Status = model.Status;
                }
                if (candidateEntity != null && candidateEntity.DateApply == model.DateApply && candidateEntity.Status != model.Status)
                {
                    model.Status = model.Status;
                }
                if (candidateEntity != null && candidateEntity.DateApply != model.DateApply && model.Status == candidateEntity.Status)
                {
                    model.Status = HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_NEW.ToString();
                }
            }

            // theo task 0049799 - tạo mới trạng thái e_new
            if(model.ID == Guid.Empty)
            {
                model.Status = HRM.Infrastructure.Utilities.EnumDropDown.CandidateStatus.E_NEW.ToString();
            }

            var userCreateID = Guid.Empty;
            Guid.TryParse(model.UserCreateID, out userCreateID);

            var candidateModel = service.UpdateOrCreate<Rec_CandidateEntity, Rec_CandidateModel>(model, userCreateID);
            #region Xử lý lưu lịch sử ứng viên
            DoActionAfterImport doActionImport = new DoActionAfterImport();
            List<Guid> lstID = new List<Guid>();
            lstID.Add(model.ID);
            doActionImport.ImportRecruitmentHistory(lstID,UserLogin); 
            #endregion
            #endregion
            return model;
        }
예제 #2
0
파일: ImportService.cs 프로젝트: dtafe/vnr
        /// <summary>
        /// Convert và lưu dữ liệu import vào database.
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="listImportData"></param>
        /// <returns></returns>
        public bool Save(Guid userID, IList listImportData, string userLogin)
        {
            bool result = false;

            if (!isDataSaved)
            {
                if (listImportData != null && listImportData.Count > 0)
                {
                    using (var context = new VnrHrmDataContext())
                    {
                        IUnitOfWork unitOfWork = new UnitOfWork(context);
                        var objectType = listImportData[0].GetPropertyValue(Constant.ObjectType);

                        IList listObj = new ArrayList();
                        var status = DataErrorCode.Success;

                        if (objectType != null)
                        {
                            if (this.ImportMode == ImportDataMode.Update || this.ImportMode == ImportDataMode.Skip)
                            {
                                var listObjectID = listImportData.AsQueryable().Select(Constant.ID).GetList().OfType<Guid>().Distinct().ToArray();
                                listEntityResult = unitOfWork.CreateQueryable(Guid.Empty, (Type)objectType, "@0.Contains(outerIt." + Constant.ID + ")", listObjectID).GetList();

                                foreach (var importData in listImportData)
                                {
                                    var objectID = importData.GetPropertyValue(Constant.ID).TryGetValue<Guid>();
                                    var objectDuplicate = listEntityResult.AsQueryable().Where(Constant.ID + " = @0", objectID).FirstOrDefault();

                                    if (objectDuplicate != null)
                                    {
                                        //Copy dữ liệu import vào dữ liệu trong database
                                        importData.CopyData(objectDuplicate, Constant.ID);
                                    }
                                    else if (this.ImportMode == ImportDataMode.Skip)
                                    {
                                        objectDuplicate = ((Type)objectType).CreateInstance();
                                        importData.CopyData(objectDuplicate, Constant.ID);
                                        unitOfWork.AddObject((Type)objectType, objectDuplicate);
                                    }

                                    if (objectDuplicate != null)
                                    {
                                        listObj.Add(objectDuplicate);
                                    }

                                    var currentIndex = listImportData.IndexOf(importData);

                                    if ((currentIndex + 1) == listImportData.Count || (currentIndex > 0
                                        && listImportData.IndexOf(importData) % 9999 == 0))
                                    {
                                        status = unitOfWork.SaveChanges(userID, true);
                                    }

                                    if (ProgressChanged != null)
                                    {
                                        double percent = ((double)listImportData.IndexOf(importData) / (double)listImportData.Count) * 100;
                                        ProgressChanged(new ProgressEventArgs
                                        {
                                            ID = UserID,
                                            Name = "SaveData",
                                            Value = "SaveData".TranslateString(),
                                            Percent = (int)percent
                                        });
                                    }
                                }

                                result = true;
                            }
                            else
                            {
                                listEntityResult = ((Type)objectType).CreateList();

                                foreach (var importData in listImportData)
                                {
                                    var objectDuplicate = ((Type)objectType).CreateInstance();
                                    importData.CopyData(objectDuplicate, Constant.ID);
                                    unitOfWork.AddObject((Type)objectType, objectDuplicate);

                                    var currentIndex = listImportData.IndexOf(importData);

                                    if ((currentIndex + 1) == listImportData.Count || (currentIndex > 0
                                        && listImportData.IndexOf(importData) % 9999 == 0))
                                    {
                                        status = unitOfWork.SaveChanges(userID, true);
                                    }

                                    if (ProgressChanged != null)
                                    {
                                        double percent = ((double)listImportData.IndexOf(importData) / (double)listImportData.Count) * 100;
                                        ProgressChanged(new ProgressEventArgs
                                        {
                                            ID = UserID,
                                            Name = "SaveData",
                                            Value = "SaveData".TranslateString(),
                                            Percent = (int)percent
                                        });
                                    }
                                }

                                listObj = listEntityResult;
                                result = true;
                            }

                            isDataSaved = true;

                            //Xử lý task vụ sau khi import
                            if (status == DataErrorCode.Success)
                            {
                                if ((Type)objectType == typeof(Rec_Candidate))
                                {
                                    if (listObj.Count > 0)
                                    {
                                        var listGuidID = new List<Guid>();

                                        foreach (var item in listObj)
                                        {
                                            if (item != null)
                                            {
                                                listGuidID.Add((Guid)item.GetPropertyValue(Constant.ID));
                                            }
                                        }

                                        DoActionAfterImport afterImport = new DoActionAfterImport();
                                        afterImport.ImportRecruitmentHistory(listGuidID, userLogin);
                                    }
                                }
                            }
                            else
                            {
                                result = false;
                            }

                            #region ImportCompleted

                            if (ProgressChanged != null)
                            {
                                ProgressChanged(new ProgressEventArgs
                                {
                                    ID = UserID,
                                    Name = "SaveData",
                                    Value = "SaveData".TranslateString(),
                                    Percent = 100
                                });
                            }

                            #endregion
                        }
                    }
                }
            }

            return result;
        }