Пример #1
0
        /// <summary>
        /// 修改岗位
        /// </summary>
        /// <param name="entity">岗位信息实例</param>
        public void PostUpdate(T_HR_POST entity)
        {
            try
            {
                var temp = dal.GetObjects().FirstOrDefault(s => s.T_HR_DEPARTMENT.DEPARTMENTID == entity.T_HR_DEPARTMENT.DEPARTMENTID &&
                                                           s.T_HR_POSTDICTIONARY.POSTCODE == entity.T_HR_POSTDICTIONARY.POSTCODE && s.POSTID != entity.POSTID);
                if (temp != null)
                {
                    throw new Exception("Repetition");
                }
                var ents = from ent in dal.GetObjects()
                           where ent.POSTID == entity.POSTID
                           select ent;
                if (ents.Count() > 0)
                {
                    var ent = ents.FirstOrDefault();
                    Utility.CloneEntity <T_HR_POST>(entity, ent);
                    ////岗位编置有变动就需要发起工作流
                    //if (ent.POSTNUMBER.GetValueOrDefault() != ent.POSTNUMBER.GetValueOrDefault())
                    //{
                    //    WorkflowUtility.CallWorkflow("岗位编制变更申请工作流", ent);
                    //}

                    //岗位字典
                    ent.T_HR_POSTDICTIONARYReference.EntityKey =
                        new System.Data.EntityKey(qualifiedEntitySetName + "T_HR_POSTDICTIONARY", "POSTDICTIONARYID", entity.T_HR_POSTDICTIONARY.POSTDICTIONARYID);
                    //部门
                    ent.T_HR_DEPARTMENTReference.EntityKey =
                        new System.Data.EntityKey(qualifiedEntitySetName + "T_HR_DEPARTMENT", "DEPARTMENTID", entity.T_HR_DEPARTMENT.DEPARTMENTID);

                    //如果审核状态为审核通过则添加岗位历史
                    if (entity.CHECKSTATE == Convert.ToInt32(CheckStates.Approved).ToString())
                    {
                        T_HR_POSTHISTORY postHis = new T_HR_POSTHISTORY();
                        postHis.RECORDSID = Guid.NewGuid().ToString();
                        //postHis = Utility.CloneObject<T_HR_POSTHISTORY>(entity);
                        postHis.CHANGEPOST        = entity.CHANGEPOST;
                        postHis.COMPANYID         = entity.COMPANYID;
                        postHis.CREATEUSERID      = entity.CREATEUSERID;
                        postHis.CREATEDATE        = entity.CREATEDATE;
                        postHis.DEPARTMENTNAME    = entity.DEPARTMENTNAME;
                        postHis.FATHERPOSTID      = entity.FATHERPOSTID;
                        postHis.OWNERCOMPANYID    = entity.OWNERCOMPANYID;
                        postHis.OWNERDEPARTMENTID = entity.OWNERDEPARTMENTID;
                        postHis.OWNERID           = entity.OWNERID;
                        postHis.OWNERPOSTID       = entity.OWNERPOSTID;
                        postHis.POSTFUNCTION      = entity.POSTFUNCTION;
                        postHis.POSTGOAL          = entity.POSTGOAL;
                        postHis.POSTID            = entity.POSTID;
                        postHis.POSTNUMBER        = entity.POSTNUMBER;
                        postHis.UNDERNUMBER       = entity.UNDERNUMBER;
                        postHis.UPDATEDATE        = entity.UPDATEDATE;
                        postHis.UPDATEUSERID      = entity.UPDATEUSERID;
                        postHis.PROMOTEDIRECTION  = entity.PROMOTEDIRECTION;
                        postHis.DEPARTMENTID      = entity.T_HR_DEPARTMENT.DEPARTMENTID;
                        if (entity.T_HR_POSTDICTIONARY != null)
                        {
                            postHis.T_HR_POSTDICTIONARYReference.EntityKey =
                                new System.Data.EntityKey(qualifiedEntitySetName + "T_HR_POSTDICTIONARY", "POSTDICTIONARYID", entity.T_HR_POSTDICTIONARY.POSTDICTIONARYID);
                        }
                        postHis.REUSEDATE = DateTime.Now;
                        if (entity.EDITSTATE == Convert.ToInt32(EditStates.PendingCanceled).ToString())
                        {
                            postHis.CANCELDATE = DateTime.Now;
                        }
                        //DataContext.AddObject("T_HR_POSTHISTORY", postHis);
                        dal.AddToContext(postHis);
                    }
                    dal.SaveContextChanges();
                    //DataContext.SaveChanges();
                    CacheManager.RemoveCache("T_HR_POST");
                    //WorkflowUtility.CallWorkflow("岗位变更申请审核工作流", ent);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }