/// <summary>
 /// 创建一个异常处理
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="db">数据库上下文</param>
 /// <param name="entity">一个异常处理</param>
 /// <returns></returns>
 public bool Create(ref ValidationErrors validationErrors, SysException entity)
 {
     try
     {
         repository.Create(entity);
         return true;
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         //ExceptionsHander.WriteExceptions(ex);                
     }
     return false;
 }
        /// <summary>
        /// 将异常信息写入数据库,或者文本文件
        /// </summary>
        /// <param name="ex"></param>
        public static void WriteExceptions(Exception ex)
        {
           
            SysException sysException = new SysException();
            sysException.CreateTime = DateTime.Now;
            sysException.Remark = ex.StackTrace;
            sysException.Result= ex.Message;
            sysException.LeiXing = "异常";
            sysException.Message = (ex.InnerException == null) ? string.Empty : ex.InnerException.Message;
            sysException.Id = Result.GetNewId();

            using (SysExceptionBLL sysExceptionRepository = new SysExceptionBLL())
            {
                ValidationErrors validationErrors = new ValidationErrors();
                sysExceptionRepository.Create(ref validationErrors, sysException);
                return;
            }

        }
        public ActionResult Create(SysException 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 + ",请核对输入的数据的格式"); //提示输入的数据的格式不对 
        }
 public ActionResult Edit(string id, SysException 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 + "请核对输入的数据的格式"); //提示输入的数据的格式不对               
   
 }
 /// <summary>
 /// Create a new SysException object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static SysException CreateSysException(global::System.String id)
 {
     SysException sysException = new SysException();
     sysException.Id = id;
     return sysException;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the SysException EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSysException(SysException sysException)
 {
     base.AddObject("SysException", sysException);
 }
  /// <summary>
 /// 编辑一个异常处理
 /// </summary>
 /// <param name="validationErrors">返回的错误信息</param>
 /// <param name="entity">一个异常处理</param>
 /// <returns></returns>
 public bool Edit(ref ValidationErrors validationErrors, SysException entity)
 {
     try
     { 
         repository.Edit(db, entity);
         repository.Save(db);
         return true;
     }
     catch (Exception ex)
     {
         validationErrors.Add(ex.Message);
         ExceptionsHander.WriteExceptions(ex);                
     }
     return false;
 }