Пример #1
0
        public ActionResult Create(SysDepartment entity)
        {
            if (entity != null && ModelState.IsValid)
            {
                string currentPerson = GetCurrentPerson();
                entity.CreateTime = DateTime.Now;
                entity.CreatePerson = currentPerson;

                entity.Id = Result.GetNewId();
                string returnValue = string.Empty;
                if (m_BLL.Create(ref validationErrors, entity))
                {
                    LogClassModels.WriteServiceLog(Suggestion.InsertSucceed  + ",部门的信息的Id为" + entity.Id,"部门"
                        );//写入日志
                    return Json(Suggestion.InsertSucceed);
                }
                else
                {
                    if (validationErrors != null && validationErrors.Count > 0)
                    {
                        validationErrors.All(a =>
                        {
                            returnValue += a.ErrorMessage;
                            return true;
                        });
                    }
                    LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",部门的信息," + returnValue,"部门"
                        );//写入日志
                    return Json(Suggestion.InsertFail  + returnValue); //提示插入失败
                }
            }

            return Json(Suggestion.InsertFail + ",请核对输入的数据的格式"); //提示输入的数据的格式不对
        }
Пример #2
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, SysDocument entity)
        {
            int count = 1;

            foreach (string item in entity.SysPersonId.GetIdSort())
            {
                SysPerson sys = new SysPerson { Id = item };
                db.SysPerson.Attach(sys);
                entity.SysPerson.Add(sys);
                count++;
            }

            foreach (string item in entity.SysDepartmentId.GetIdSort())
            {
                SysDepartment sys = new SysDepartment { Id = item };
                db.SysDepartment.Attach(sys);
                entity.SysDepartment.Add(sys);
                count++;
            }

            repository.Create(db, entity);
            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("创建出错了");
            }
            return false;
        }
Пример #3
0
        public ActionResult Edit(string id, SysDepartment entity)
        {
            if (entity != null && ModelState.IsValid)
            {   //数据校验

                string currentPerson = GetCurrentPerson();
                entity.UpdateTime = DateTime.Now;
                entity.UpdatePerson = currentPerson;

                string returnValue = string.Empty;
                if (m_BLL.Edit(ref validationErrors, entity))
                {
                    LogClassModels.WriteServiceLog(Suggestion.UpdateSucceed + ",部门信息的Id为" + id,"部门"
                        );//写入日志
                    return Json(Suggestion.UpdateSucceed); //提示更新成功
                }
                else
                {
                    if (validationErrors != null && validationErrors.Count > 0)
                    {
                        validationErrors.All(a =>
                        {
                            returnValue += a.ErrorMessage;
                            return true;
                        });
                    }
                    LogClassModels.WriteServiceLog(Suggestion.UpdateFail + ",部门信息的Id为" + id + "," + returnValue, "部门"
                        );//写入日志
                    return Json(Suggestion.UpdateFail  + returnValue); //提示更新失败
                }
            }
            return Json(Suggestion.UpdateFail + "请核对输入的数据的格式"); //提示输入的数据的格式不对
        }
Пример #4
0
 /// <summary>
 /// 创建一个部门
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entity">一个部门</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, SysDepartment entity)
 {
     try
     {
         using (TransactionScope transactionScope = new TransactionScope())
         {
             if (Create(ref validationErrors, db, entity))
             {
                 transactionScope.Complete();
                 return true;
             }
             else
             {
                 Transaction.Current.Rollback();
             }
         }
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);
     }
     return false;
 }
Пример #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, SysDepartment entity)
        {
            /*
                           * 不操作 原有 现有
                           * 增加   原没 现有
                           * 删除   原有 现没
                           */
            if (entity == null)
            {
                return false;
            }
            int count = 1;

            List<string> addSysDocumentId = new List<string>();
            List<string> deleteSysDocumentId = new List<string>();
            DataOfDiffrent.GetDiffrent(entity.SysDocumentId.GetIdSort(), entity.SysDocumentIdOld.GetIdSort(), ref addSysDocumentId, ref deleteSysDocumentId);
            List<SysDocument> listEntitySysDocument = new List<SysDocument>();
            if (deleteSysDocumentId != null && deleteSysDocumentId.Count() > 0)
            {
                foreach (var item in deleteSysDocumentId)
                {
                    SysDocument sys = new SysDocument { Id = item };
                    listEntitySysDocument.Add(sys);
                    entity.SysDocument.Add(sys);
                }
            }

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

            if (addSysDocumentId != null && addSysDocumentId.Count() > 0)
            {
                foreach (var item in addSysDocumentId)
                {
                    SysDocument sys = new SysDocument { Id = item };
                    db.SysDocument.Attach(sys);
                    editEntity.SysDocument.Add(sys);
                    count++;
                }
            }
            if (deleteSysDocumentId != null && deleteSysDocumentId.Count() > 0)
            {
                foreach (SysDocument item in listEntitySysDocument)
                {
                    editEntity.SysDocument.Remove(item);
                    count++;
                }
            }

            if (count == repository.Save(db))
            {
                return true;
            }
            else
            {
                validationErrors.Add("编辑部门出错了");
            }
            return false;
        }
Пример #6
0
        /// <summary>
        /// 设置一个部门
        /// </summary>
        /// <param name="validationErrors">返回的错误信息</param>
        /// <param name="entity">一个部门</param>
        /// <returns>是否设置成功</returns>
        public bool SetSysDepartment(ref ValidationErrors validationErrors, SysDocument entity)
        {
            bool bResult = false;
            int count = 0;
            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    SysDocument editEntity = repository.GetById(db, entity.Id);

                    List<string> addSysDepartmentId = new List<string>();
                    List<string> deleteSysDepartmentId = new List<string>();
                    if (entity.SysDepartmentId != null)
                    {
                        addSysDepartmentId = entity.SysDepartmentId.Split(',').ToList();
                    }
                    if (entity.SysDepartmentIdOld != null)
                    {
                        deleteSysDepartmentId = entity.SysDepartmentIdOld.Split(',').ToList();
                    }
                    DataOfDiffrent.GetDiffrent(addSysDepartmentId, deleteSysDepartmentId, ref addSysDepartmentId, ref deleteSysDepartmentId);

                    if (addSysDepartmentId != null && addSysDepartmentId.Count() > 0)
                    {
                        foreach (var item in addSysDepartmentId)
                        {
                            SysDepartment sys = new SysDepartment { Id = item };
                            db.SysDepartment.Attach(sys);
                            editEntity.SysDepartment.Add(sys);
                            count++;
                        }
                    }
                    if (deleteSysDepartmentId != null && deleteSysDepartmentId.Count() > 0)
                    {
                        List<SysDepartment> listEntity = new List<SysDepartment>();
                        foreach (var item in deleteSysDepartmentId)
                        {
                            SysDepartment sys = new SysDepartment { Id = item };
                            listEntity.Add(sys);
                            db.SysDepartment.Attach(sys);
                        }
                        foreach (SysDepartment item in listEntity)
                        {
                            editEntity.SysDepartment.Remove(item);//查询数据库
                            count++;
                        }
                    }

                    if (count > 0 && count == repository.Save(db))
                    {
                       transactionScope.Complete();
                       bResult = true;
                    }
                    else if(count == 0 )
                    {
                        validationErrors.Add("数据没有改变");
                    }
                }
                catch (Exception ex)
                {
                    Transaction.Current.Rollback();
                    ExceptionsHander.WriteExceptions(ex);
                    validationErrors.Add("编辑出错了。原因"+ex.Message);
                }
            }

            return bResult;
        }