public BaseResponse <bool> AddOfficerRecord(AddOfficerParameter parameter)
        {
            //1. 添加干部基础信息
            //2. 添加此干部的积分申请(并设置为审批通过)
            //3. 修改当前积分
            //4. 添加积分变更记录
            BaseResponse <bool> response = new BaseResponse <bool>();
            //iCMSDbContext dbContext = new iCMSDbContext();
            OperationResult operResult = null;

            try
            {
                ExecuteDB.ExecuteTrans((dbContext) =>
                {
                    ValidateAddOfficer(dbContext, parameter);

                    Officer officer            = new Officer();
                    officer.Name               = parameter.Name;
                    officer.Gender             = parameter.Gender;
                    officer.IdentifyCardNumber = parameter.IdentifyNumber;
                    var birth       = DateTime.MinValue;
                    var birthdayStr = Utilitys.GetBrithdayFromIdCard(parameter.IdentifyNumber);
                    if (DateTime.TryParse(birthdayStr, out birth))
                    {
                        officer.Birthday = birth;
                    }

                    officer.OrganizationID = parameter.OrganizationID;
                    officer.PositionStr    = parameter.PositionStr;
                    officer.LevelID        = parameter.LevelID;

                    DateTime onOfficerDate = DateTime.MinValue;
                    if (DateTime.TryParse(parameter.OnOfficeDate, out onOfficerDate))
                    {
                        officer.OnOfficeDate = onOfficerDate;
                    }
                    officer.InitialScore     = parameter.InitialScore;
                    officer.CurrentScore     = officer.InitialScore;
                    officer.LastUpdateDate   = DateTime.Now;
                    officer.LastUpdateUserID = parameter.AddUserID;
                    officer.AddUserID        = parameter.AddUserID;

                    operResult = dbContext.Officers.AddNew <Officer>(dbContext, officer);
                    if (operResult.ResultType != EnumOperationResultType.Success)
                    {
                        throw new Exception("数据库操作异常");
                    }

                    #region 操作日志
                    new LogManager().AddOperationLog(parameter.AddUserID, "添加干部", parameter.RequestIP);
                    #endregion

                    var scoreItemArray = scoreItemRepository.GetDatas <ScoreItem>(t => !t.IsDeleted, true).ToList();

                    int extraScore = 0;
                    if (parameter.ApplyItemList.Any())
                    {
                        parameter.ApplyItemList.ForEach(t =>
                        {
                            ScoreApply scApply = new ScoreApply();
                            scApply.OfficerID  = officer.OfficerID;
                            scApply.ItemID     = t.ItemID;
                            var tempscoreItem  = scoreItemArray.Where(s => s.ItemID == t.ItemID).FirstOrDefault();
                            if (tempscoreItem == null)
                            {
                                throw new Exception("积分条目已被删除");
                            }

                            scApply.ItemScore = tempscoreItem.ItemScore;

                            scApply.ApplyStatus      = 1;//自动设置为审批通过
                            scApply.ProposeID        = officer.AddUserID;
                            scApply.AddUserID        = officer.AddUserID;
                            scApply.LastUpdateDate   = DateTime.Now;
                            scApply.LastUpdateUserID = officer.AddUserID;
                            scApply.ApplySummary     = t.ApplySummary;
                            scApply.IsDeleted        = false;

                            operResult = dbContext.ScoreApplies.AddNew <ScoreApply>(dbContext, scApply);
                            if (operResult.ResultType != EnumOperationResultType.Success)
                            {
                                throw new Exception("数据库操作异常");
                            }
                            //保存变化的分值,最后更新CurrentScore
                            extraScore += scApply.ItemScore;

                            //保存积分更新历史记录表
                            ScoreChangeHistory his = new ScoreChangeHistory();
                            his.ApplyID            = scApply.ApplyID;
                            his.OfficerID          = scApply.OfficerID;
                            his.ItemID             = scApply.ItemID;
                            his.ItemScore          = scApply.ItemScore;
                            his.ProcessUserID      = null;
                            his.ProposeID          = scApply.ProposeID;
                            his.AddUserID          = scApply.AddUserID;
                            var scoreItem          = dbContext.ScoreItems.Where(x => x.ItemID == his.ItemID).FirstOrDefault();
                            if (scoreItem != null)
                            {
                                var off = dbContext.Officers.Where(o => !o.IsDeleted && o.OfficerID == his.OfficerID).FirstOrDefault();
                                if (off != null)
                                {
                                    var organ = dbContext.Organizations.Where(or => !or.IsDeleted && or.OrganID == off.OrganizationID).FirstOrDefault();
                                    if (organ != null)
                                    {
                                        his.Content = string.Format("{0}  {1} {2}", organ.OrganFullName, off.Name, scoreItem.ItemDescription);
                                        operResult  = dbContext.ScoreChangeHistories.AddNew <ScoreChangeHistory>(dbContext, his);
                                        if (operResult.ResultType != EnumOperationResultType.Success)
                                        {
                                            throw new Exception("数据库操作异常");
                                        }
                                    }
                                }
                            }
                        });
                    }

                    var officeIndb = dbContext.Officers.Where(t => t.OfficerID == officer.OfficerID && !t.IsDeleted).FirstOrDefault();
                    if (officeIndb != null)
                    {
                        officeIndb.CurrentScore += extraScore;
                        dbContext.Officers.Update <Officer>(dbContext, officeIndb);
                    }
                });
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(e);
                response.IsSuccessful = false;
                response.Reason       = e.Message;
            }

            return(response);
        }
示例#2
0
        public BaseResponse <bool> AddOfficerRecord(AddOfficerParameter parameter)
        {
            //1. 添加干部基础信息
            //2. 添加此干部的积分申请(并设置为审批通过)
            //3. 修改当前积分
            //4. 添加积分变更记录
            BaseResponse <bool> response = new BaseResponse <bool>();

            //iCMSDbContext dbContext = new iCMSDbContext();

            try
            {
                ExecuteDB.ExecuteTrans((dbContext) =>
                {
                    Officer officer            = new Officer();
                    officer.Name               = parameter.Name;
                    officer.Gender             = parameter.Gender;
                    officer.IdentifyCardNumber = parameter.IdentifyNumber;
                    officer.Birthday           = parameter.Birthday;
                    officer.OrganizationID     = parameter.OrganizationID;
                    officer.PositionID         = parameter.PositionID;
                    officer.LevelID            = parameter.LevelID;
                    officer.OnOfficeDate       = parameter.OnOfficeDate;
                    officer.InitialScore       = parameter.InitialScore;
                    officer.CurrentScore       = officer.InitialScore;
                    officer.LastUpdateDate     = DateTime.Now;
                    officer.LastUpdateUserID   = parameter.AddUserID;
                    dbContext.Officers.AddNew <Officer>(dbContext, officer);

                    int extraScore = 0;
                    if (parameter.ApplyItemList.Any())
                    {
                        parameter.ApplyItemList.ForEach(t =>
                        {
                            ScoreApply scApply   = new ScoreApply();
                            scApply.OfficerID    = officer.OfficerID;
                            scApply.ItemID       = t.ItemID;
                            scApply.ItemScore    = t.ItemScore;
                            scApply.ApplyStatus  = 1;//自动设置为审批通过
                            scApply.ProposeID    = officer.AddUserID;
                            scApply.AddUserID    = officer.AddUserID;
                            scApply.ApplySummary = t.ApplySummary;
                            scApply.IsDeleted    = false;

                            dbContext.ScoreApplies.AddNew <ScoreApply>(dbContext, scApply);
                            //保存变化的分值,最后更新CurrentScore
                            extraScore += scApply.ItemScore;

                            //保存积分更新历史记录表
                            ScoreChangeHistory his = new ScoreChangeHistory();
                            his.ApplyID            = scApply.ApplyID;
                            his.OfficerID          = scApply.OfficerID;
                            his.ItemID             = scApply.ItemID;
                            his.ItemScore          = scApply.ItemScore;
                            his.ProcessUserID      = null;
                            his.ProposeID          = scApply.ProposeID;
                            his.AddUserID          = scApply.AddUserID;
                            var scoreItem          = dbContext.ScoreItems.Where(x => x.ItemID == his.ItemID).First();
                            his.Content            = string.Format("{0}  {1} {2}", his.ItemScore, his.AddDate, scoreItem.ItemDescription);

                            dbContext.ScoreChangeHistories.AddNew <ScoreChangeHistory>(dbContext, his);
                        });
                    }

                    var officeIndb = dbContext.Officers.Where(t => t.OfficerID == officer.OfficerID && !t.IsDeleted).FirstOrDefault();
                    if (officeIndb != null)
                    {
                        officeIndb.CurrentScore += extraScore;
                        dbContext.Officers.Update <Officer>(dbContext, officeIndb);
                    }
                });
            }
            catch (Exception e)
            {
                response.IsSuccessful = false;
                response.Reason       = "添加干部发生异常!";
            }

            return(response);
        }