Esempio n. 1
0
        /// <summary>
        /// 创建一个社保种类
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据库上下文</param>
        /// <param name="entity">一个社保种类</param>
        /// <returns></returns>
        public bool Create(ref ValidationErrors validationErrors, SysEntities db, InsuranceKind entity)
        {
            int count = 1;

            foreach (string item in entity.PoliceOperationId.GetIdSort())
            {
                PoliceOperation sys = new PoliceOperation {
                    Id = Convert.ToInt32(item)
                };
                db.PoliceOperation.Attach(sys);
                entity.PoliceOperation.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// 创建
        /// </summary>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public Common.ClientResult.Result Post([FromBody] PoliceOperation entity)
        {
            Common.ClientResult.Result result = new Common.ClientResult.Result();
            if (entity != null && ModelState.IsValid)
            {
                //string currentPerson = GetCurrentPerson();
                //entity.CreateTime = DateTime.Now;
                //entity.CreatePerson = currentPerson;


                string returnValue = string.Empty;
                if (m_BLL.Create(ref validationErrors, entity))
                {
                    LogClassModels.WriteServiceLog(Suggestion.InsertSucceed + ",政策手续的信息的Id为" + entity.Id, "政策手续"
                                                   );//写入日志
                    result.Code    = Common.ClientCode.Succeed;
                    result.Message = Suggestion.InsertSucceed;
                    return(result); //提示创建成功
                }
                else
                {
                    if (validationErrors != null && validationErrors.Count > 0)
                    {
                        validationErrors.All(a =>
                        {
                            returnValue += a.ErrorMessage;
                            return(true);
                        });
                    }
                    LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",政策手续的信息," + returnValue, "政策手续"
                                                   );//写入日志
                    result.Code    = Common.ClientCode.Fail;
                    result.Message = Suggestion.InsertFail + returnValue;
                    return(result); //提示插入失败
                }
            }

            result.Code    = Common.ClientCode.FindNull;
            result.Message = Suggestion.InsertFail + ",请核对输入的数据的格式"; //提示输入的数据的格式不对
            return(result);
        }
Esempio n. 3
0
 /// <summary>
 /// 编辑一个政策手续
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entity">一个政策手续</param>
 /// <returns>是否编辑成功</returns>
 public bool Edit(ref ValidationErrors validationErrors, PoliceOperation entity)
 {
     try
     {
         using (TransactionScope transactionScope = new TransactionScope())
         {
             if (Edit(ref validationErrors, db, entity))
             {
                 transactionScope.Complete();
                 return(true);
             }
             else
             {
                 Transaction.Current.Rollback();
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return(false);
 }
Esempio n. 4
0
        /// <summary>
        /// 根据ID获取数据模型
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns></returns>
        public PoliceOperation Get(int id)
        {
            PoliceOperation item = m_BLL.GetById(id);

            return(item);
        }
Esempio n. 5
0
        /// <summary>
        /// 编辑一个社保种类
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="db">数据上下文</param>
        /// <param name="entity">一个社保种类</param>
        /// <returns>是否编辑成功</returns>
        public bool Edit(ref ValidationErrors validationErrors, SysEntities db, InsuranceKind entity)
        {  /*
            * 不操作 原有 现有
            * 增加   原没 现有
            * 删除   原有 现没
            */
            if (entity == null)
            {
                return(false);
            }
            int count = 1;

            List <string> addPoliceOperationId    = new List <string>();
            List <string> deletePoliceOperationId = new List <string>();

            DataOfDiffrent.GetDiffrent(entity.PoliceOperationId.GetIdSort(), entity.PoliceOperationIdOld.GetIdSort(), ref addPoliceOperationId, ref deletePoliceOperationId);
            List <PoliceOperation> listEntityPoliceOperation = new List <PoliceOperation>();

            if (deletePoliceOperationId != null && deletePoliceOperationId.Count() > 0)
            {
                foreach (var item in deletePoliceOperationId)
                {
                    PoliceOperation sys = new PoliceOperation {
                        Id = Convert.ToInt32(item)
                    };
                    listEntityPoliceOperation.Add(sys);
                    entity.PoliceOperation.Add(sys);
                }
            }

            InsuranceKind editEntity = repository.Edit(db, entity);


            if (addPoliceOperationId != null && addPoliceOperationId.Count() > 0)
            {
                foreach (var item in addPoliceOperationId)
                {
                    PoliceOperation sys = new PoliceOperation {
                        Id = Convert.ToInt32(item)
                    };
                    db.PoliceOperation.Attach(sys);
                    editEntity.PoliceOperation.Add(sys);
                    count++;
                }
            }
            if (deletePoliceOperationId != null && deletePoliceOperationId.Count() > 0)
            {
                foreach (PoliceOperation item in listEntityPoliceOperation)
                {
                    editEntity.PoliceOperation.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return(true);
            }
            else
            {
                validationErrors.Add("编辑社保种类出错了");
            }
            return(false);
        }