Skip to content

Commit 63d5f1f

Browse files
Minor code improvements (#119)
* Features/upgrate to dotnet 6 (#108) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Features/fix email bugs (#110) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Fixed e-mail issues * Features/fix email bugs (#112) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Fixed e-mail issues * Feature/fix email send issues (#114) * Removed development files * Updated .gitignore * Added MailKit library * Implemented e-mail sender with MailKit * Feature/minor changes (#116) * Updated nuget packages * Improved HtmlHelperExtensions logic and added possibility to use with slugs * Added "About me" menu item * Feature/code improvements (#117) * Add possibility to use global.json * Add global.json file with targeting SDK 6.0.403 * Removed warnings * Add exclusion of generated code * Exclude Identity pages from null check * Update packages; Add ardalis.GuardClauses * Remove warnings * Remove null warnings; Minor code improvements * Fixed post not being saved * Fixed post not being saved * Add filter to prevent articles to appear before publishing time * Add filter to prevent articles to appear before publishing time * Add about me and subscribe; Reorder menu * Add Author partial view * Change DateTime format * Add SASS package * Reduce padding; Add max-height of 100% * Minor improvements (#118) * Develop (#113) * Features/upgrate to dotnet 6 (#108) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Features/fix email bugs (#110) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Fixed e-mail issues * Features/fix email bugs (#112) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Fixed e-mail issues * Bugfix for e-mail sending (#115) * Features/upgrate to dotnet 6 (#108) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Features/fix email bugs (#110) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Fixed e-mail issues * Features/fix email bugs (#112) * Moved files to src; Adapted C# code to a more modern approach; Minor refactoring everywhere * Removed old project folders/files * Removed temporary old solution * Refactored code; Set some members to nullable * Changed usage on TryUpdateModelAsync * Fixed e-mail issues * Feature/fix email send issues (#114) * Removed development files * Updated .gitignore * Added MailKit library * Implemented e-mail sender with MailKit
1 parent 6ae61af commit 63d5f1f

File tree

127 files changed

+916
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+916
-630
lines changed

.editorconfig

+16-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# There already existed an .editorconfig file in this directory. Copy rules from this .editorconfig.inferred file to the existing .editorconfig file as desired to have them take effect at this location.
33
# You can modify the rules from these initially generated values to suit your own policies
44
# You can learn more about editorconfig here: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
5+
6+
[/src/CmsEngine.{Data/Migrations,Ui/Areas/Identity/Pages}/**]
7+
generated_code = true
8+
dotnet_analyzer_diagnostic.severity = none
9+
510
[*.cs]
611

712
csharp_style_namespace_declarations = file_scoped:warning
@@ -188,29 +193,29 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
188193

189194
dotnet_naming_symbols.interface.applicable_kinds = interface
190195
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
191-
dotnet_naming_symbols.interface.required_modifiers =
196+
dotnet_naming_symbols.interface.required_modifiers =
192197

193198
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
194199
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
195-
dotnet_naming_symbols.types.required_modifiers =
200+
dotnet_naming_symbols.types.required_modifiers =
196201

197202
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
198203
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
199-
dotnet_naming_symbols.non_field_members.required_modifiers =
204+
dotnet_naming_symbols.non_field_members.required_modifiers =
200205

201206
# Naming styles
202207

203208
dotnet_naming_style.begins_with_i.required_prefix = I
204-
dotnet_naming_style.begins_with_i.required_suffix =
205-
dotnet_naming_style.begins_with_i.word_separator =
209+
dotnet_naming_style.begins_with_i.required_suffix =
210+
dotnet_naming_style.begins_with_i.word_separator =
206211
dotnet_naming_style.begins_with_i.capitalization = pascal_case
207212

208-
dotnet_naming_style.pascal_case.required_prefix =
209-
dotnet_naming_style.pascal_case.required_suffix =
210-
dotnet_naming_style.pascal_case.word_separator =
213+
dotnet_naming_style.pascal_case.required_prefix =
214+
dotnet_naming_style.pascal_case.required_suffix =
215+
dotnet_naming_style.pascal_case.word_separator =
211216
dotnet_naming_style.pascal_case.capitalization = pascal_case
212217

213-
dotnet_naming_style.pascal_case.required_prefix =
214-
dotnet_naming_style.pascal_case.required_suffix =
215-
dotnet_naming_style.pascal_case.word_separator =
218+
dotnet_naming_style.pascal_case.required_prefix =
219+
dotnet_naming_style.pascal_case.required_suffix =
220+
dotnet_naming_style.pascal_case.word_separator =
216221
dotnet_naming_style.pascal_case.capitalization = pascal_case

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,4 @@ package-lock.json
260260
*.Development.json
261261
[Rr]eadme.md
262262
CmsEngine.Ui/_logs
263-
global.json
263+
global.json

CmsEngine.sln

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution files", "Solution
77
ProjectSection(SolutionItems) = preProject
88
.editorconfig = .editorconfig
99
.gitignore = .gitignore
10+
global.json = global.json
1011
LICENSE = LICENSE
1112
README.md = README.md
1213
EndProjectSection
1314
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CmsEngine.Core", "src\CmsEngine.Core\CmsEngine.Core.csproj", "{0DCFFE7F-6BF0-40F5-B8ED-B0A213B415C4}"
15+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CmsEngine.Core", "src\CmsEngine.Core\CmsEngine.Core.csproj", "{0DCFFE7F-6BF0-40F5-B8ED-B0A213B415C4}"
1516
EndProject
16-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CmsEngine.Data", "src\CmsEngine.Data\CmsEngine.Data.csproj", "{9D472F52-7D5D-4956-9DE2-DB5546262DAB}"
17+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CmsEngine.Data", "src\CmsEngine.Data\CmsEngine.Data.csproj", "{9D472F52-7D5D-4956-9DE2-DB5546262DAB}"
1718
EndProject
18-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CmsEngine.Application", "src\CmsEngine.Application\CmsEngine.Application.csproj", "{081C9102-37CB-4873-97D2-0A5063FFA4A3}"
19+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CmsEngine.Application", "src\CmsEngine.Application\CmsEngine.Application.csproj", "{081C9102-37CB-4873-97D2-0A5063FFA4A3}"
1920
EndProject
20-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CmsEngine.Ui", "src\CmsEngine.Ui\CmsEngine.Ui.csproj", "{AEED8BDE-0C8A-43BC-91B8-77B967511921}"
21+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CmsEngine.Ui", "src\CmsEngine.Ui\CmsEngine.Ui.csproj", "{AEED8BDE-0C8A-43BC-91B8-77B967511921}"
2122
EndProject
2223
Global
2324
GlobalSection(SolutionConfigurationPlatforms) = preSolution

global.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "6.0.403"
4+
}
5+
}

src/CmsEngine.Application/CmsEngine.Application.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="MailKit" Version="3.1.1" />
10+
<PackageReference Include="Ardalis.GuardClauses" Version="4.0.1" />
11+
<PackageReference Include="MailKit" Version="3.4.3" />
1112
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="2.2.0" />
1213
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
1314
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />

src/CmsEngine.Application/Extensions/EnumerableExtensions.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace CmsEngine.Application.Extensions;
22

33
public static class EnumerableExtensions
44
{
5-
public static Expression<Func<T, bool>> GetSearchExpression<T>(this IEnumerable<T> element, string searchValue, IEnumerable<PropertyInfo> properties)
5+
public static Expression<Func<T, bool>>? GetSearchExpression<T>(this IEnumerable<T> element, string searchValue, IEnumerable<PropertyInfo> properties)
66
{
77
var expressionFilter = new List<ExpressionFilter>();
88

@@ -19,22 +19,22 @@ public static Expression<Func<T, bool>> GetSearchExpression<T>(this IEnumerable<
1919
return ExpressionBuilder.GetExpression<T>(expressionFilter, LogicalOperator.Or);
2020
}
2121

22-
public static IEnumerable<SelectListItem> PopulateSelectList<T>(this IEnumerable<T> items, IEnumerable<string> selectedItems = null) where T : BaseViewModel
22+
public static IEnumerable<SelectListItem> PopulateSelectList<T>(this IEnumerable<T> items, IEnumerable<string>? selectedItems = null) where T : BaseViewModel
2323
{
2424
return items.Select(x => new SelectListItem
2525
{
26-
Text = x.GetType().GetProperty("Name").GetValue(x).ToString(),
26+
Text = x.GetType().GetProperty("Name")?.GetValue(x)?.ToString() ?? string.Empty,
2727
Value = x.VanityId.ToString(),
2828
Disabled = false,
2929
Selected = selectedItems?.Contains(x.VanityId.ToString()) ?? false
3030
}).OrderBy(o => o.Text);
3131
}
3232

33-
public static IEnumerable<CheckboxEditModel> PopulateCheckboxList<T>(this IEnumerable<T> items, IEnumerable<string> selectedItems = null) where T : BaseViewModel
33+
public static IEnumerable<CheckboxEditModel> PopulateCheckboxList<T>(this IEnumerable<T> items, IEnumerable<string>? selectedItems = null) where T : BaseViewModel
3434
{
3535
return items.Select(x => new CheckboxEditModel
3636
{
37-
Label = x.GetType().GetProperty("Name").GetValue(x).ToString(),
37+
Label = x.GetType().GetProperty("Name")?.GetValue(x)?.ToString() ?? string.Empty,
3838
Value = x.VanityId.ToString(),
3939
Enabled = true,
4040
Selected = selectedItems?.Contains(x.VanityId.ToString()) ?? false

src/CmsEngine.Application/Extensions/Mapper/CategoryExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static IEnumerable<CategoryTableViewModel> MapToTableViewModel(this IEnum
8282
/// </summary>
8383
/// <param name="categories"></param>
8484
/// <returns></returns>
85-
public static IEnumerable<CategoryViewModel> MapToViewModel(this IEnumerable<Category> categories)
85+
public static IEnumerable<CategoryViewModel> MapToViewModel(this IEnumerable<Category> categories, string dateFormat)
8686
{
8787
var viewModel = new List<CategoryViewModel>();
8888

@@ -95,7 +95,7 @@ public static IEnumerable<CategoryViewModel> MapToViewModel(this IEnumerable<Cat
9595
Name = item.Name,
9696
Description = item.Description,
9797
Slug = item.Slug,
98-
Posts = item.PostCategories.Select(x => x.Post).MapToViewModel()
98+
Posts = item.PostCategories?.Select(x => x.Post).MapToViewModel(dateFormat)
9999
});
100100
}
101101

@@ -152,7 +152,7 @@ public static IEnumerable<CategoryViewModel> MapToViewModelWithPostCount(this IE
152152
/// </summary>
153153
/// <param name="categories"></param>
154154
/// <returns></returns>
155-
public static IEnumerable<CategoryViewModel> MapToViewModelWithPost(this IEnumerable<Category> categories)
155+
public static IEnumerable<CategoryViewModel> MapToViewModelWithPost(this IEnumerable<Category> categories, string dateFormat)
156156
{
157157
var viewModel = new List<CategoryViewModel>();
158158

@@ -169,7 +169,7 @@ public static IEnumerable<CategoryViewModel> MapToViewModelWithPost(this IEnumer
169169
Title = p.Title,
170170
Description = p.Description,
171171
Slug = p.Slug,
172-
PublishedOn = p.PublishedOn.ToShortDateString()
172+
PublishedOn = p.PublishedOn.ToString(dateFormat)
173173
})
174174
});
175175
}

src/CmsEngine.Application/Extensions/Mapper/PageExtensions.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static IEnumerable<PageTableViewModel> MapToTableViewModel(this IEnumerab
110110
Title = item.Title,
111111
Description = item.Description,
112112
Slug = item.Slug,
113-
PublishedOn = item.PublishedOn.ToString(),
113+
PublishedOn = item.PublishedOn.ToString("yyyy-MM-dd HH:mm:ss"),
114114
Status = item.Status,
115115
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
116116
});
@@ -124,7 +124,7 @@ public static IEnumerable<PageTableViewModel> MapToTableViewModel(this IEnumerab
124124
/// </summary>
125125
/// <param name="item"></param>
126126
/// <returns></returns>
127-
public static PageViewModel MapToViewModel(this Page item)
127+
public static PageViewModel MapToViewModel(this Page item, string dateFormat)
128128
{
129129
return new PageViewModel
130130
{
@@ -134,7 +134,7 @@ public static PageViewModel MapToViewModel(this Page item)
134134
Description = item.Description,
135135
DocumentContent = item.DocumentContent,
136136
HeaderImage = item.HeaderImage,
137-
PublishedOn = item.PublishedOn.ToShortDateString(),
137+
PublishedOn = item.PublishedOn.ToString(dateFormat),
138138
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
139139
};
140140
}
@@ -144,7 +144,7 @@ public static PageViewModel MapToViewModel(this Page item)
144144
/// </summary>
145145
/// <param name="pages"></param>
146146
/// <returns></returns>
147-
public static IEnumerable<PageViewModel> MapToViewModel(this IEnumerable<Page> pages)
147+
public static IEnumerable<PageViewModel> MapToViewModel(this IEnumerable<Page> pages, string dateFormat)
148148
{
149149
var editModels = new List<PageViewModel>();
150150

@@ -159,7 +159,7 @@ public static IEnumerable<PageViewModel> MapToViewModel(this IEnumerable<Page> p
159159
Description = item.Description,
160160
DocumentContent = item.DocumentContent,
161161
HeaderImage = item.HeaderImage,
162-
PublishedOn = item.PublishedOn.ToShortDateString(),
162+
PublishedOn = item.PublishedOn.ToString(dateFormat),
163163
Status = item.Status
164164
});
165165
}

src/CmsEngine.Application/Extensions/Mapper/PostExtensions.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static IEnumerable<PostTableViewModel> MapToTableViewModel(this IEnumerab
112112
Title = item.Title,
113113
Description = item.Description,
114114
Slug = item.Slug,
115-
PublishedOn = item.PublishedOn.ToString(),
115+
PublishedOn = item.PublishedOn.ToString("yyyy-MM-dd HH:mm:ss"),
116116
Status = item.Status,
117117
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
118118
});
@@ -126,7 +126,7 @@ public static IEnumerable<PostTableViewModel> MapToTableViewModel(this IEnumerab
126126
/// </summary>
127127
/// <param name="item"></param>
128128
/// <returns></returns>
129-
public static PostViewModel MapToViewModel(this Post item)
129+
public static PostViewModel MapToViewModel(this Post item, string dateFormat)
130130
{
131131
return new PostViewModel
132132
{
@@ -136,7 +136,7 @@ public static PostViewModel MapToViewModel(this Post item)
136136
Description = item.Description,
137137
DocumentContent = item.DocumentContent,
138138
HeaderImage = item.HeaderImage,
139-
PublishedOn = item.PublishedOn.ToShortDateString(),
139+
PublishedOn = item.PublishedOn.ToString(dateFormat),
140140
Categories = item.Categories.MapToViewModelSimple(),
141141
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
142142
};
@@ -147,7 +147,7 @@ public static PostViewModel MapToViewModel(this Post item)
147147
/// </summary>
148148
/// <param name="item"></param>
149149
/// <returns></returns>
150-
public static IEnumerable<PostViewModel> MapToViewModel(this IEnumerable<Post> posts)
150+
public static IEnumerable<PostViewModel> MapToViewModel(this IEnumerable<Post> posts, string dateFormat)
151151
{
152152
var viewModels = new List<PostViewModel>();
153153

@@ -162,7 +162,7 @@ public static IEnumerable<PostViewModel> MapToViewModel(this IEnumerable<Post> p
162162
Description = item.Description,
163163
DocumentContent = item.DocumentContent,
164164
HeaderImage = item.HeaderImage,
165-
PublishedOn = item.PublishedOn.ToShortDateString(),
165+
PublishedOn = item.PublishedOn.ToString(dateFormat),
166166
Status = item.Status
167167
});
168168
}
@@ -175,7 +175,7 @@ public static IEnumerable<PostViewModel> MapToViewModel(this IEnumerable<Post> p
175175
/// </summary>
176176
/// <param name="item"></param>
177177
/// <returns></returns>
178-
public static IEnumerable<PostViewModel> MapToViewModelWithCategories(this IEnumerable<Post> posts)
178+
public static IEnumerable<PostViewModel> MapToViewModelWithCategories(this IEnumerable<Post> posts, string dateFormat)
179179
{
180180
var viewModels = new List<PostViewModel>();
181181

@@ -190,9 +190,9 @@ public static IEnumerable<PostViewModel> MapToViewModelWithCategories(this IEnum
190190
Description = item.Description,
191191
DocumentContent = item.DocumentContent,
192192
HeaderImage = item.HeaderImage,
193-
PublishedOn = item.PublishedOn.ToShortDateString(),
193+
PublishedOn = item.PublishedOn.ToString(dateFormat),
194194
Status = item.Status,
195-
Categories = item.PostCategories.Select(x => x.Category).MapToViewModel()
195+
Categories = item.PostCategories.Select(x => x.Category).MapToViewModel(dateFormat)
196196
});
197197
}
198198

@@ -204,7 +204,7 @@ public static IEnumerable<PostViewModel> MapToViewModelWithCategories(this IEnum
204204
/// </summary>
205205
/// <param name="item"></param>
206206
/// <returns></returns>
207-
public static IEnumerable<PostViewModel> MapToViewModelWithTags(this IEnumerable<Post> posts)
207+
public static IEnumerable<PostViewModel> MapToViewModelWithTags(this IEnumerable<Post> posts, string dateFormat)
208208
{
209209
var viewModels = new List<PostViewModel>();
210210

@@ -219,7 +219,7 @@ public static IEnumerable<PostViewModel> MapToViewModelWithTags(this IEnumerable
219219
Description = item.Description,
220220
DocumentContent = item.DocumentContent,
221221
HeaderImage = item.HeaderImage,
222-
PublishedOn = item.PublishedOn.ToShortDateString(),
222+
PublishedOn = item.PublishedOn.ToString(dateFormat),
223223
Status = item.Status,
224224
Tags = item.PostTags.Select(x => x.Tag).MapToViewModel()
225225
});
@@ -233,7 +233,7 @@ public static IEnumerable<PostViewModel> MapToViewModelWithTags(this IEnumerable
233233
/// </summary>
234234
/// <param name="item"></param>
235235
/// <returns></returns>
236-
public static IEnumerable<PostViewModel> MapToViewModelForPartialView(this IEnumerable<Post> posts)
236+
public static IEnumerable<PostViewModel> MapToViewModelForPartialView(this IEnumerable<Post> posts, string dateFormat)
237237
{
238238
var viewModels = new List<PostViewModel>();
239239

@@ -246,7 +246,7 @@ public static IEnumerable<PostViewModel> MapToViewModelForPartialView(this IEnum
246246
Slug = item.Slug,
247247
Description = item.Description,
248248
HeaderImage = item.HeaderImage,
249-
PublishedOn = item.PublishedOn.ToShortDateString(),
249+
PublishedOn = item.PublishedOn.ToString(dateFormat),
250250
Categories = item.Categories.MapToViewModelSimple(),
251251
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
252252
});
@@ -260,7 +260,7 @@ public static IEnumerable<PostViewModel> MapToViewModelForPartialView(this IEnum
260260
/// </summary>
261261
/// <param name="item"></param>
262262
/// <returns></returns>
263-
public static IEnumerable<PostViewModel> MapToViewModelForPartialViewForTags(this IEnumerable<Post> posts)
263+
public static IEnumerable<PostViewModel> MapToViewModelForPartialViewForTags(this IEnumerable<Post> posts, string dateFormat)
264264
{
265265
var viewModels = new List<PostViewModel>();
266266

@@ -273,7 +273,7 @@ public static IEnumerable<PostViewModel> MapToViewModelForPartialViewForTags(thi
273273
Slug = item.Slug,
274274
Description = item.Description,
275275
HeaderImage = item.HeaderImage,
276-
PublishedOn = item.PublishedOn.ToShortDateString(),
276+
PublishedOn = item.PublishedOn.ToString(dateFormat),
277277
Categories = item.Categories.MapToViewModelSimple(),
278278
Tags = item.Tags.MapToViewModelSimple(),
279279
Author = item.ApplicationUsers.MapToViewModelSimple().Single()

src/CmsEngine.Application/GlobalUsings.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
global using System.Drawing.Imaging;
55
global using System.Globalization;
66
global using System.Linq.Expressions;
7-
global using System.Net;
87
global using System.Reflection;
8+
global using System.Runtime.Versioning;
99
global using System.Text.Encodings.Web;
1010
global using System.Xml.Linq;
11+
global using Ardalis.GuardClauses;
1112
global using CmsEngine.Application.Attributes;
1213
global using CmsEngine.Application.Extensions;
1314
global using CmsEngine.Application.Extensions.Mapper;

src/CmsEngine.Application/Helpers/DataTableHelper.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ public static DataTableViewModel BuildDataTable(IEnumerable<IViewModel> listItem
4141
private static string PrepareProperty(IViewModel item, PropertyInfo property)
4242
{
4343
GeneralStatus generalStatus;
44-
var value = item.GetType().GetProperty(property.Name).GetValue(item);
44+
var value = item.GetType().GetProperty(property.Name)?.GetValue(item);
45+
46+
if (value == null)
47+
{
48+
return string.Empty;
49+
}
4550

4651
switch (property.PropertyType.Name)
4752
{
@@ -63,12 +68,12 @@ private static string PrepareProperty(IViewModel item, PropertyInfo property)
6368
return $"<span class=\"badge badge-{generalStatus.ToString().ToLowerInvariant()}\">{documentStatus.ToEnum<DocumentStatus>().GetName()}</status-label>";
6469
case "UserViewModel":
6570
var author = (UserViewModel)value;
66-
return HtmlEncoder.Default.Encode(author?.FullName ?? "");
71+
return HtmlEncoder.Default.Encode(author?.FullName ?? string.Empty);
6772
case "Boolean":
6873
generalStatus = (bool)value ? GeneralStatus.Success : GeneralStatus.Danger;
6974
return $"<span class=\"badge badge-{generalStatus.ToString().ToLowerInvariant()}\">{((bool)value).ToYesNo().ToUpper()}</status-label>";
7075
default:
71-
return HtmlEncoder.Default.Encode(value?.ToString() ?? "");
76+
return HtmlEncoder.Default.Encode(value?.ToString() ?? string.Empty);
7277
}
7378
}
7479
}

0 commit comments

Comments
 (0)