Repository navigation
Expand file tree
/
Copy pathProfileController.cs
More file actions
253 lines (221 loc) · 8.73 KB
/
Copy pathProfileController.cs
File metadata and controls
253 lines (221 loc) · 8.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using SmartStore.Core.Domain.Customers;
using SmartStore.Core.Domain.Forums;
using SmartStore.Core.Domain.Media;
using SmartStore.Services.Common;
using SmartStore.Services.Customers;
using SmartStore.Services.Directory;
using SmartStore.Services.Forums;
using SmartStore.Services.Helpers;
using SmartStore.Services.Localization;
using SmartStore.Services.Media;
using SmartStore.Services.Seo;
using SmartStore.Web.Framework;
using SmartStore.Web.Framework.Security;
using SmartStore.Web.Models.Common;
using SmartStore.Web.Models.Profile;
using SmartStore.Web.Framework.Controllers;
namespace SmartStore.Web.Controllers
{
[RequireHttpsByConfigAttribute(SslRequirement.No)]
public partial class ProfileController : PublicControllerBase
{
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 ForumSettings _forumSettings;
private readonly CustomerSettings _customerSettings;
private readonly MediaSettings _mediaSettings;
public ProfileController(IForumService forumService,
ILocalizationService localizationService,
IPictureService pictureService,
ICountryService countryService,
ICustomerService customerService,
IDateTimeHelper dateTimeHelper,
ForumSettings forumSettings,
CustomerSettings customerSettings,
MediaSettings mediaSettings)
{
this._forumService = forumService;
this._localizationService = localizationService;
this._pictureService = pictureService;
this._countryService = countryService;
this._customerService = customerService;
this._dateTimeHelper = dateTimeHelper;
this._forumSettings = forumSettings;
this._customerSettings = customerSettings;
this._mediaSettings = mediaSettings;
}
public ActionResult Index(int? id, int? page)
{
var customerId = 0;
if (id.HasValue)
{
customerId = id.Value;
}
var customer = _customerService.GetCustomerById(customerId);
if (!_customerSettings.AllowViewingProfiles || (customer == null || customer.IsGuest()))
{
return HttpNotFound();
}
bool pagingPosts = false;
int postsPage = 0;
if (page.HasValue)
{
postsPage = page.Value;
pagingPosts = true;
}
var name = customer.FormatUserName();
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
};
return View(model);
}
//profile info tab
[ChildActionOnly]
public ActionResult Info(int customerProfileId)
{
var customer = _customerService.GetCustomerById(customerProfileId);
if (customer == null)
{
return HttpNotFound();
}
//avatar
bool avatarEnabled = false;
string avatarUrl = _pictureService.GetDefaultPictureUrl(_mediaSettings.AvatarPictureSize, PictureType.Avatar);
if (_customerSettings.AllowCustomersToUploadAvatars)
{
avatarEnabled = true;
var customerAvatarId = customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId);
if (customerAvatarId != 0)
{
avatarUrl = _pictureService.GetPictureUrl(customerAvatarId, _mediaSettings.AvatarPictureSize, false);
}
else
{
if (!_customerSettings.DefaultAvatarEnabled)
{
avatarEnabled = false;
}
}
}
//location
bool locationEnabled = false;
string location = string.Empty;
if (_customerSettings.ShowCustomersLocation)
{
locationEnabled = true;
var countryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId);
var country = _countryService.GetCountryById(countryId);
if (country != null)
{
location = country.GetLocalized(x => x.Name);
}
else
{
locationEnabled = false;
}
}
//private message
bool pmEnabled = _forumSettings.AllowPrivateMessages && !customer.IsGuest();
//total forum posts
bool totalPostsEnabled = false;
int totalPosts = 0;
if (_forumSettings.ForumsEnabled && _forumSettings.ShowCustomersPostCount)
{
totalPostsEnabled = true;
totalPosts = customer.GetAttribute<int>(SystemCustomerAttributeNames.ForumPostCount);
}
//registration date
bool joinDateEnabled = false;
string joinDate = string.Empty;
if (_customerSettings.ShowCustomersJoinDate)
{
joinDateEnabled = true;
joinDate = _dateTimeHelper.ConvertToUserTime(customer.CreatedOnUtc, DateTimeKind.Utc).ToString("f");
}
//birth date
bool dateOfBirthEnabled = false;
string dateOfBirth = string.Empty;
if (_customerSettings.DateOfBirthEnabled)
{
var dob = customer.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth);
if (dob.HasValue)
{
dateOfBirthEnabled = true;
dateOfBirth = dob.Value.ToString("D");
}
}
var model = new ProfileInfoModel()
{
CustomerProfileId = customer.Id,
AvatarEnabled = avatarEnabled,
AvatarUrl = avatarUrl,
LocationEnabled = locationEnabled,
Location = location,
PMEnabled = pmEnabled,
TotalPostsEnabled = totalPostsEnabled,
TotalPosts = totalPosts.ToString(),
JoinDateEnabled = joinDateEnabled,
JoinDate = joinDate,
DateOfBirthEnabled = dateOfBirthEnabled,
DateOfBirth = dateOfBirth,
};
return PartialView(model);
}
//latest posts tab
[ChildActionOnly]
public ActionResult Posts(int customerProfileId, int page)
{
var customer = _customerService.GetCustomerById(customerProfileId);
if (customer == null)
{
return HttpNotFound();
}
if (page > 0)
{
page -= 1;
}
var pageSize = _forumSettings.LatestCustomerPostsPageSize;
var list = _forumService.GetAllPosts(0, customer.Id, string.Empty, false, page, pageSize);
var latestPosts = new List<PostsModel>();
foreach (var forumPost in list)
{
var posted = string.Empty;
if (_forumSettings.RelativeDateTimeFormattingEnabled)
{
posted = forumPost.CreatedOnUtc.RelativeFormat(true, "f");
}
else
{
posted = _dateTimeHelper.ConvertToUserTime(forumPost.CreatedOnUtc, DateTimeKind.Utc).ToString("f");
}
latestPosts.Add(new PostsModel()
{
ForumTopicId = forumPost.TopicId,
ForumTopicTitle = forumPost.ForumTopic.Subject,
ForumTopicSlug = forumPost.ForumTopic.GetSeName(),
ForumPostText = forumPost.FormatPostText(),
Posted = posted
});
}
ViewData["PagerRouteValues"] = new RouteValues { page = page, id = customerProfileId };
var model = new ProfilePostsModel(list)
{
Posts = latestPosts,
};
return PartialView(model);
}
}
}