protected override void OnException(ExceptionContext filterContext) { filterContext.ExceptionHandled = true; string error; if (filterContext.Exception is KnownException) { error = filterContext.Exception.Message; } else { if (Request.QueryString["debug"] == SettingContext.Instance.DebugKey) { error = filterContext.Exception.GetAllMessages(); } else { error = "服务器未知错误,请重试。如果该问题一直存在,请联系管理员。感谢您的支持。"; } } if (Request.QueryString["ajax"] == "true") { var result = new StandardJsonResult(); result.Fail(error); filterContext.Result = result; } else { var model = new LayoutViewModel(); model.Error = error; filterContext.Result = this.View(this.GetErrorViewPath(), model); } }
protected override void OnException(ExceptionContext filterContext) { //Logger.Error("XprepayControllerBase.OnException", filterContext.Exception); //只记录系统错误. if (filterContext.Exception is Exception) { Log4Net.Error(filterContext.Exception.Source, filterContext.Exception); } if (_actionReturnType == null) { base.OnException(filterContext); return; } string error; if (filterContext.Exception is KnownException) { error = filterContext.Exception.Message; } else { error = filterContext.Exception.GetAllMessages(); } if (_actionReturnType == typeof(StandardJsonResult) || (_actionReturnType == typeof(StandardJsonResult <>))) { var result = new StandardJsonResult(); result.Fail(error); filterContext.Result = result; } else if (_actionReturnType == typeof(PartialViewResult)) { filterContext.Result = new ContentResult() { Content = error }; } else { filterContext.Result = Error(error); } filterContext.ExceptionHandled = true; }
protected override void OnException(ExceptionContext filterContext) { filterContext.ExceptionHandled = true; log4net.ILog log = log4net.LogManager.GetLogger("BCControllerBase"); log.Error(filterContext.Controller + "\r\n" + filterContext.Exception); Response.AddHeader("Access-Control-Allow-Origin", "*"); string error; if (filterContext.Exception is AppAuthorizeFailedException) { error = filterContext.Exception.Message; filterContext.Result = Json(new { LoginFailed = true, Message = error }, JsonRequestBehavior.AllowGet); return; } else if (filterContext.Exception is KnownException) { error = filterContext.Exception.Message; } else { error = "服务器未知错误,请重试。如果该问题一直存在,请联系管理员。感谢您的支持。"; #if DEBUG error = filterContext.Exception.GetAllMessages(); #endif } if (Request.IsAjaxRequest()) { var result = new StandardJsonResult(); result.Fail(error); filterContext.Result = result; } else { var model = new LayoutViewModel(); model.Error = error; filterContext.Result = this.View(this.GetErrorViewPath(), model); } }
public ActionResult AddSceneItem(SceneItemNewModel model) { string _enterpriseID = BCSession.User.EnterpriseID; int? _departmentID = BCSession.User.DepartmentID; string _userID = BCSession.User.UserID; var result = new StandardJsonResult <bool>(); result.Try(() => { if (!ModelState.IsValid) { throw new KnownException(ModelState.GetFirstError()); } var files = Request.Files; //if (model.files == null || model.files[0] == null) model.files = new List<HttpPostedFileBase>(); //HttpFileCollectionBase files = HttpContext.Request.Files; int fileCount = files.Count; if (model.SceneItemType == SceneItemType.Checkin || model.SceneItemType == SceneItemType.Checkout) { model.content = " "; } if (string.IsNullOrEmpty(model.content) && files.Count == 0) { result.Fail("没有图片且没有内容."); } else { Guid guid = Guid.NewGuid(); List <string> imagesUrl = new List <string>(); if (fileCount > 0) { for (int i = 0; i < files.Count; i++) { var file = files[i]; int idx = file.FileName.LastIndexOf(".") + 1; string suffix = file.FileName.Substring(idx); //判断图片格式 if (idx > 1 && suffix.Equals("jpg") || suffix.Equals("jpeg") || suffix.Equals("png") || suffix.Equals("gif")) { //TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); string fileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "." + suffix;//Convert.ToInt64(ts.TotalMilliseconds).ToString() + "." + suffix; Picture pic = new Picture(); pic.PictureGuid = guid; pic.PictureName = fileName; byte[] s = new byte[file.InputStream.Length]; file.InputStream.Read(s, 0, s.Length); MemoryStream ms = new MemoryStream(s); pic.PictureStream = ms; try { var r = _sceneItemService.SavePicture(pic); } catch (Exception e) { result.Message = e.Message; } } else { fileCount = fileCount - 1; } } } var cmt = new SceneItem { Address = "电脑发布", Comments = new List <Comment>(), Description = model.content, CreateTime = DateTime.Now, Type = model.SceneItemType, SceneID = model.SceneID, UserID = _userID, GPS = "", Count = fileCount }; if (fileCount > 0) { cmt.PictureGuid = guid; } result.Value = _sceneItemService.Add(cmt) != null; } }); return(result); }
public ActionResult GetSceneItemList(SceneItemSearchModel model) { var result = new StandardJsonResult <SceneItemResultModel>(); bool sucessFlag = true; if (!ModelState.IsValid) { throw new KnownException(ModelState.GetFirstError()); } result.Try(() => { if (model.page < 1) { model.page = 1; } if (model.rows < 1) { model.rows = 10; } int amount; //判断有无权限查看完工数据 try { if ((int)_sceneService.GetOneScene(model.SceneID).Status == 3 && !HasFunction(Functions.Root_AppPermission_SceneManage_ViewAchievedScene)) { result.Value = new SceneItemResultModel(); result.Fail("服务器:没有权限查看完工数据"); sucessFlag = false; return; } } catch (Exception) { result.Value = new SceneItemResultModel(); result.Fail("服务器:发生异常"); sucessFlag = false; return; } var temp = _sceneItemService.GetAllByStatus(model.SceneID, ItemStatus.All, model.rows, model.page, out amount); result.Value = new SceneItemResultModel(); result.Value.rows = new List <SceneItemViewModel>(); foreach (var item in temp) { SceneItemViewModel sceneItem = (SceneItemViewModel)item; foreach (var comment in sceneItem.comments) { if (string.IsNullOrEmpty(comment.UserName)) { try { var userc = _userService.GetFrontUserByUserID(comment.UserID); if (userc == null) { comment.UserName = "******"; } else { comment.UserName = userc.Name; } } catch (Exception) { comment.UserName = "******"; } } comment.Stime = comment.Time.ToString("yyyy-MM-dd HH:mm"); } result.Value.rows.Add(sceneItem); } result.Value.total = amount; }); if (!sucessFlag) { result.Success = false; } return(result); }