forked from grandnode/grandnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileController.cs
More file actions
101 lines (90 loc) · 3.73 KB
/
Copy pathProfileController.cs
File metadata and controls
101 lines (90 loc) · 3.73 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
using Grand.Core.Domain.Customers;
using Grand.Core.Domain.Forums;
using Grand.Core.Domain.Media;
using Grand.Services.Customers;
using Grand.Services.Directory;
using Grand.Services.Forums;
using Grand.Services.Helpers;
using Grand.Services.Localization;
using Grand.Services.Media;
using Grand.Services.Security;
using Grand.Web.Models.Profile;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
namespace Grand.Web.Controllers
{
public partial class ProfileController : BasePublicController
{
private readonly IForumService _forumService;
private readonly ILocalizationService _localizationService;
private readonly IPictureService _pictureService;
private readonly ICountryService _countryService;
private readonly ICustomerService _customerService;
private readonly IDateTimeHelper _dateTimeHelper;
private readonly IPermissionService _permissionService;
private readonly ForumSettings _forumSettings;
private readonly CustomerSettings _customerSettings;
private readonly MediaSettings _mediaSettings;
public ProfileController(IForumService forumService,
ILocalizationService localizationService,
IPictureService pictureService,
ICountryService countryService,
ICustomerService customerService,
IDateTimeHelper dateTimeHelper,
IPermissionService permissionService,
ForumSettings forumSettings,
CustomerSettings customerSettings,
MediaSettings mediaSettings)
{
this._forumService = forumService;
this._localizationService = localizationService;
this._pictureService = pictureService;
this._countryService = countryService;
this._customerService = customerService;
this._permissionService = permissionService;
this._dateTimeHelper = dateTimeHelper;
this._forumSettings = forumSettings;
this._customerSettings = customerSettings;
this._mediaSettings = mediaSettings;
}
public virtual async Task<IActionResult> Index(string id, int? pageNumber)
{
if (!_customerSettings.AllowViewingProfiles)
{
return RedirectToRoute("HomePage");
}
var customerId = "";
if (!String.IsNullOrEmpty(id))
{
customerId = id;
}
var customer = await _customerService.GetCustomerById(customerId);
if (customer == null || customer.IsGuest())
{
return RedirectToRoute("HomePage");
}
bool pagingPosts = false;
int postsPage = 0;
if (pageNumber.HasValue)
{
postsPage = pageNumber.Value;
pagingPosts = true;
}
var name = customer.FormatUserName(_customerSettings.CustomerNameFormat);
var title = string.Format(_localizationService.GetResource("Profile.ProfileOf"), name);
var model = new ProfileIndexModel
{
ProfileTitle = title,
PostsPage = postsPage,
PagingPosts = pagingPosts,
CustomerProfileId = customer.Id,
ForumsEnabled = _forumSettings.ForumsEnabled
};
//display "edit" (manage) link
if (await _permissionService.Authorize(StandardPermissionProvider.AccessAdminPanel) && await _permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
DisplayEditLink(Url.Action("Edit", "Customer", new { id = customer.Id, area = "Admin" }));
return View(model);
}
}
}