Пример #1
0
        /// <summary>
        /// Erstellt ein ErrorViewModel basierend auf einer Exception
        /// </summary>
        /// <param name="error">Exception die aufgetreten ist</param>
        /// <param name="defaultTitle">Default ErrorTitle</param>
        /// <returns>ErrorViewModel</returns>
        public static ErrorViewModel CreateFromError(Exception error, String defaultTitle)
        {
            ErrorViewModel viewmodel = new ErrorViewModel();
            viewmodel.ErrorTitle = defaultTitle;
            viewmodel.HasError = error != null;
            if (viewmodel.HasError)
            {
                //if (error is CustomException1)
                //{
                //    viewmodel.ErrorTitle = "Custom Exception 1";
                //}

                //if (error is CustomException2)
                //{
                //    viewmodel.ErrorTitle = "Custom Exception 2";
                //}

                viewmodel.ErrorText = error.ToString();
            }

            return viewmodel;
        }
Пример #2
0
        public static ViewResultBase ItemNotFound(Controller trigger, String message)
        {
            ObjectServices.Logger.CreateLogger(trigger.GetType()).Warn("Item Not Found! Message = {0}", message);

            ErrorViewModel viewmodel = new ErrorViewModel();
            viewmodel.ErrorText = message;
            viewmodel.ErrorRequestPath = trigger.HttpContext.Request.Url.AbsoluteUri;

            if (trigger.Request.UrlReferrer != null)
            {
                viewmodel.ReturnUrl = trigger.Request.UrlReferrer.AbsoluteUri;
            }

            ViewDataDictionary viewData = new ViewDataDictionary
            {
                Model = viewmodel
            };

            ViewResultBase viewresult = trigger.Request.IsAjaxRequest() ? (ViewResultBase)new PartialViewResult() : (ViewResultBase)new ViewResult();
            viewresult.ViewName = "ItemNotFound";
            viewresult.ViewData = viewData;

            return viewresult;
        }
Пример #3
0
 public ActionResult PageNotFound(String aspxerrorpath)
 {
     ErrorViewModel viewmodel = new ErrorViewModel();
     viewmodel.ErrorText = String.Format(CultureInfo.CurrentCulture, "Page {0} not found", aspxerrorpath);
     return View(viewmodel);
 }