/// <summary>
        /// use this function to modify employment data
        /// </summary>
        /// <param name="headCountHR"></param>
        /// <returns></returns>
        public bool UpdateHeadCountHR(HeadCountHR headCountHR)
        {
            bool   _Success = false;
            string _JobFunctionItem = "", _TitleItem = "";

            //just get item list once can approve performance
            _JobFunctionItem = headCountHR.Account.StartsWith("L") ? "JobFunction" : "JobFunctionKSZ";
            _TitleItem       = headCountHR.Account.StartsWith("L") ? "Title" : "TitleKSZ";
            List <ItemCatalog>             _ItemCatalog = this._itemCatalogService.GetAll().ToList();
            List <Budget_DepartmentReport> _Budget_DepartmentReportList = this._budget_DepartmentReportService.GetAll().ToList();
            Budget_HeadCountHR             _HeadCountHR = this._budget_HeadCountHRService.GetByID(headCountHR.Id);

            _HeadCountHR.Id        = headCountHR.Id;
            _HeadCountHR.Account   = headCountHR.Account;
            _HeadCountHR.AltwName  = headCountHR.AltwName;
            _HeadCountHR.ItemId_HR = _ItemCatalog.Where(x => x.ClassName == "HR" && x.Name.Trim() == headCountHR.HR.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == "HR" && x.Name == headCountHR.HR).First().ItemId : "";

            _HeadCountHR.ItemId_DirectType = _ItemCatalog.Where(x => x.ClassName == "DirectType" && x.Name.Trim() == headCountHR.DirectType.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == "DirectType" && x.Name.Trim() == headCountHR.DirectType.Trim()).First().ItemId : "";

            _HeadCountHR.ItemId_JobFunction = _ItemCatalog.Where(x => x.ClassName == _JobFunctionItem && x.Name.Trim() == headCountHR.JobFunction.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == _JobFunctionItem && x.Name.Trim() == headCountHR.JobFunction.Trim()).First().ItemId : "";

            _HeadCountHR.ItemId_Title = _ItemCatalog.Where(x => x.ClassName == _TitleItem && x.Name.Trim() == headCountHR.Title.Trim()) != null?_ItemCatalog.Where(x => x.ClassName == _TitleItem && x.Name.Trim() == headCountHR.Title.Trim()).First().ItemId : "";

            this._budget_HeadCountHRService.Update(_HeadCountHR);
            _Success = true;
            return(_Success);
        }
        /// <summary>
        /// peggy login get employment data
        /// </summary>
        /// <returns></returns>
        public List <HeadCountHR> GetHeadCountHRList()
        {
            List <HeadCountHR> _HeadCountHRList = new List <HeadCountHR>();
            List <ItemCatalog> _ItemCatalog     = this._itemCatalogService.GetAll().ToList();
            //var results = this._budget_HeadCountHRService.GetAll().Join(this._budget_DepartmentReportService.GetAll(),
            //    p => p.DepartmentId, q => q.DepartmentId, (p, q) => new { p, q }).Select(x => new
            //    {
            //        Id = x.p.Id,
            //        // DepartmentId = x.p.DepartmentId,
            //        Account = x.p.Account,
            //        AltwName = x.p.AltwName,
            //        //  DirectStaff = x.p.DirectStaff,
            //        ItemId_HR = x.p.ItemId_HR,
            //        //  PartTime = x.p.PartTime,
            //        ItemId_DirectType = x.p.ItemId_DirectType,
            //        IsDel = x.p.IsDel,
            //        ItemId_JobFunction = x.p.ItemId_JobFunction,
            //        DepartmentName = x.q.DepartmentName,
            //        ItemId_Title = x.p.ItemId_Title
            //    }).ToList();
            var results = this._budget_HeadCountHRService.GetAll().OrderByDescending(x => x.Id).ToList();

            foreach (var r in results.Distinct())
            {
                string      _JobFunction = "", _HR = "", _Title = "", _DirectType = "", _JobFunctionItem = "", _TitleItem = "";
                HeadCountHR _HeadCountHR = new HeadCountHR();
                _HeadCountHR.Id = r.Id;
                //_HeadCountHR.DepartmentId = r.DepartmentId;
                _HeadCountHR.Account  = r.Account;
                _JobFunctionItem      = r.Account.StartsWith("L") ? "JobFunction" : "JobFunctionKSZ";
                _TitleItem            = r.Account.StartsWith("L") ? "Title" : "TitleKSZ";
                _HeadCountHR.AltwName = r.AltwName;
                if (r.ItemId_DirectType != null)
                {
                    _DirectType = _ItemCatalog.Where(x => x.ClassName == "DirectType" && x.ItemId.Trim() == r.ItemId_DirectType.Trim()).ToList().Count > 0 ? _ItemCatalog.Where(x => x.ClassName == "DirectType" && x.ItemId.Trim() == r.ItemId_DirectType.Trim()).First().Name : "";
                }
                _HeadCountHR.DirectType = _DirectType;
                if (r.ItemId_JobFunction != null)
                {
                    _JobFunction = _ItemCatalog.Where(x => x.ClassName == _JobFunctionItem && x.ItemId.Trim() == r.ItemId_JobFunction.Trim()).ToList().Count > 0 ? _ItemCatalog.Where(x => x.ClassName == _JobFunctionItem && x.ItemId.Trim() == r.ItemId_JobFunction.Trim()).First().Name : "";
                }
                _HeadCountHR.JobFunction = _JobFunction;
                if (r.ItemId_HR != null)
                {
                    _HR = _ItemCatalog.Where(x => x.ClassName == "HR" && x.ItemId.Trim() == r.ItemId_HR.Trim()).ToList().Count > 0 ? _ItemCatalog.Where(x => x.ClassName == "HR" && x.ItemId.Trim() == r.ItemId_HR.Trim()).First().Name : "";
                }
                _HeadCountHR.HR = _HR;
                if (r.ItemId_Title != null)
                {
                    _Title = _ItemCatalog.Where(x => x.ClassName == _TitleItem && x.ItemId.Trim() == r.ItemId_Title.Trim()).ToList().Count > 0 ? _ItemCatalog.Where(x => x.ClassName == _TitleItem && x.ItemId.Trim() == r.ItemId_Title.Trim()).First().Name : "";
                }
                _HeadCountHR.Title = _Title;
                //_HeadCountHR.DepartmentName = r.DepartmentName;
                _HeadCountHRList.Add(_HeadCountHR);
            }
            return(_HeadCountHRList);
        }
Beispiel #3
0
        public bool Put(HeadCountHR headCountHR)
        {
            bool _OK = false;

            this._budgetExcelUploadService.UpdateHeadCount(headCountHR);
            this._budgetExcelUploadService.UpdateHeadCountHR(headCountHR);
            _OK = true;
            return(_OK);
        }
        /// <summary>
        /// if you change employee account ,and  synchronize headcount data
        /// </summary>
        /// <param name="headCountHR"></param>
        /// <returns></returns>
        public bool UpdateHeadCount(HeadCountHR headCountHR)
        {
            bool _Success = false;

            try
            {
                Budget_HeadCountHR _HeadCountHR = this._budget_HeadCountHRService.GetByID(headCountHR.Id);
                if (headCountHR.Account != _HeadCountHR.Account)
                {
                    List <Budget_HeadCount> _HeadCountList = this._budget_HeadCountService.GetAll().Where(x => x.Account == _HeadCountHR.Account).ToList();
                    foreach (Budget_HeadCount h in _HeadCountList)
                    {
                        h.Account = headCountHR.Account;
                        this._budget_HeadCountService.Update(h);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            _Success = true;
            return(_Success);
        }