Repository navigation
Expand file tree
/
Copy pathAdminControllerBase.cs
More file actions
87 lines (82 loc) · 3.27 KB
/
Copy pathAdminControllerBase.cs
File metadata and controls
87 lines (82 loc) · 3.27 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
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Web.Mvc;
using System.Web.Routing;
using SmartStore.Core;
using SmartStore.Core.Infrastructure;
using SmartStore.Services.Localization;
using SmartStore.Web.Framework.Filters;
using SmartStore.Web.Framework.Localization;
using SmartStore.Web.Framework.Security;
using SmartStore.Web.Framework.Theming;
namespace SmartStore.Web.Framework.Controllers
{
[AdminThemed]
[RequireHttpsByConfig(SslRequirement.Yes)]
[AdminValidateIpAddress]
[CustomerLastActivity]
[StoreIpAddress]
public abstract class AdminControllerBase : SmartController
{
/// <summary>
/// Initialize controller
/// </summary>
/// <param name="requestContext">Request context</param>
protected override void Initialize(RequestContext requestContext)
{
var routeData = requestContext.RouteData;
if (routeData != null && !routeData.DataTokens.ContainsKey("ParentActionViewContext"))
{
EngineContext.Current.Resolve<IWorkContext>().IsAdmin = true;
}
base.Initialize(requestContext);
}
/// <summary>
/// Add locales for localizable entities
/// </summary>
/// <typeparam name="TLocalizedModelLocal">Localizable model</typeparam>
/// <param name="languageService">Language service</param>
/// <param name="locales">Locales</param>
protected virtual void AddLocales<TLocalizedModelLocal>(ILanguageService languageService, IList<TLocalizedModelLocal> locales) where TLocalizedModelLocal : ILocalizedModelLocal
{
AddLocales(languageService, locales, null);
}
/// <summary>
/// Add locales for localizable entities
/// </summary>
/// <typeparam name="TLocalizedModelLocal">Localizable model</typeparam>
/// <param name="languageService">Language service</param>
/// <param name="locales">Locales</param>
/// <param name="configure">Configure action</param>
protected virtual void AddLocales<TLocalizedModelLocal>(ILanguageService languageService, IList<TLocalizedModelLocal> locales, Action<TLocalizedModelLocal, int> configure) where TLocalizedModelLocal : ILocalizedModelLocal
{
foreach (var language in languageService.GetAllLanguages(true))
{
var locale = Activator.CreateInstance<TLocalizedModelLocal>();
locale.LanguageId = language.Id;
if (configure != null)
{
configure.Invoke(locale, locale.LanguageId);
}
locales.Add(locale);
}
}
/// <summary>
/// Access denied view
/// </summary>
/// <returns>Access denied view</returns>
[SuppressMessage("ReSharper", "Mvc.AreaNotResolved")]
protected ActionResult AccessDeniedView()
{
return RedirectToAction("AccessDenied", "Security", new { pageUrl = this.Request.RawUrl, area = "Admin" });
}
/// <summary>
/// Renders default access denied view as a partial
/// </summary>
protected ActionResult AccessDeniedPartialView()
{
return PartialView("~/Administration/Views/Security/AccessDenied.cshtml");
}
}
}