Repository navigation
Expand file tree
/
Copy pathSmartController.cs
More file actions
128 lines (109 loc) · 3.85 KB
/
Copy pathSmartController.cs
File metadata and controls
128 lines (109 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Web.Mvc;
using SmartStore.Core;
using SmartStore.Core.Infrastructure;
using SmartStore.Core.Localization;
using SmartStore.Core.Logging;
namespace SmartStore.Web.Framework.Controllers
{
[SetWorkingCulture]
[Notify]
public abstract partial class SmartController : Controller
{
private readonly Lazy<INotifier> _notifier;
protected SmartController()
{
this.Logger = NullLogger.Instance;
this.T = NullLocalizer.Instance;
this._notifier = EngineContext.Current.Resolve<Lazy<INotifier>>();
}
public ILogger Logger { get; set; }
public Localizer T { get; set; }
/// <summary>
/// Pushes an info message to the notification queue
/// </summary>
/// <param name="message">Message</param>
/// <param name="durable">A value indicating whether the message should be persisted for the next request</param>
protected virtual void NotifyInfo(string message, bool durable = true)
{
_notifier.Value.Information(message, durable);
}
/// <summary>
/// Pushes a warning message to the notification queue
/// </summary>
/// <param name="message">Message</param>
/// <param name="durable">A value indicating whether the message should be persisted for the next request</param>
protected virtual void NotifyWarning(string message, bool durable = true)
{
_notifier.Value.Warning(message, durable);
}
/// <summary>
/// Pushes a success message to the notification queue
/// </summary>
/// <param name="message">Message</param>
/// <param name="durable">A value indicating whether the message should be persisted for the next request</param>
protected virtual void NotifySuccess(string message, bool durable = true)
{
_notifier.Value.Success(message, durable);
}
/// <summary>
/// Pushes an error message to the notification queue
/// </summary>
/// <param name="message">Message</param>
/// <param name="durable">A value indicating whether the message should be persisted for the next request</param>
protected virtual void NotifyError(string message, bool durable = true)
{
_notifier.Value.Error(message, durable);
}
/// <summary>
/// Pushes an error message to the notification queue
/// </summary>
/// <param name="exception">Exception</param>
/// <param name="durable">A value indicating whether a message should be persisted for the next request</param>
/// <param name="logException">A value indicating whether the exception should be logged</param>
protected virtual void NotifyError(Exception exception, bool durable = true, bool logException = true)
{
if (logException)
{
LogException(exception);
}
_notifier.Value.Error(exception.ToAllMessages(), durable);
}
protected virtual ActionResult RedirectToReferrer()
{
if (Request.UrlReferrer != null && Request.UrlReferrer.ToString().HasValue())
{
return Redirect(Request.UrlReferrer.ToString());
}
return RedirectToRoute("HomePage");
}
protected virtual ActionResult RedirectToHomePageWithError(string reason, bool durable = true)
{
string message = T("Common.RequestProcessingFailed", this.RouteData.Values["controller"], this.RouteData.Values["action"], reason.NaIfEmpty());
_notifier.Value.Error(message, durable);
return RedirectToRoute("HomePage");
}
/// <summary>
/// On exception
/// </summary>
/// <param name="filterContext">Filter context</param>
protected override void OnException(ExceptionContext filterContext)
{
if (filterContext.Exception != null)
{
LogException(filterContext.Exception);
}
base.OnException(filterContext);
}
/// <summary>
/// Log exception
/// </summary>
/// <param name="exc">Exception</param>
private void LogException(Exception exc)
{
var workContext = EngineContext.Current.Resolve<IWorkContext>();
var customer = workContext.CurrentCustomer;
Logger.Error(exc.Message, exc, customer);
}
}
}