Skip to content

Commit 353524d

Browse files
Merge pull request #106 from davidsonsousa/develop
Develop
2 parents 6d0f159 + b40bc6e commit 353524d

File tree

62 files changed

+1839
-485
lines changed

Some content is hidden

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

62 files changed

+1839
-485
lines changed

.editorconfig

+14-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,19 @@ indent_size = 2
2727
# Sort using and Import directives with System.* appearing first
2828
dotnet_sort_system_directives_first = true
2929

30+
# Async methods to be sufixed with Async
31+
dotnet_naming_rule.async_methods_must_end_with_async.severity = warning
32+
dotnet_naming_rule.async_methods_must_end_with_async.symbols = method_symbols
33+
dotnet_naming_rule.async_methods_must_end_with_async.style = end_in_async_style
34+
35+
dotnet_naming_symbols.method_symbols.applicable_kinds = method
36+
dotnet_naming_symbols.method_symbols.required_modifiers = async
37+
38+
dotnet_naming_style.end_in_async_style.capitalization = pascal_case
39+
dotnet_naming_style.end_in_async_style.required_suffix = Async
40+
3041
# Name all constant fields using PascalCase
31-
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
42+
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning
3243
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
3344
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
3445

@@ -45,7 +56,7 @@ dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_sty
4556
dotnet_naming_symbols.static_fields.applicable_kinds = field
4657
dotnet_naming_symbols.static_fields.required_modifiers = static
4758

48-
dotnet_naming_style.static_prefix_style.required_prefix = s_
59+
#dotnet_naming_style.static_prefix_style.required_prefix = s_
4960
dotnet_naming_style.static_prefix_style.capitalization = camel_case
5061

5162
# Internal and private fields should be _camelCase
@@ -56,7 +67,7 @@ dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_
5667
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
5768
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
5869

59-
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
70+
#dotnet_naming_style.camel_case_underscore_style.required_prefix = _
6071
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
6172

6273
# Avoid "this." and "Me." if not necessary

CmsEngine.Application/Attributes/ShowOnDataTable.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@ namespace CmsEngine.Application.Attributes
88
[AttributeUsage(AttributeTargets.Property)]
99
public sealed class ShowOnDataTable : Attribute
1010
{
11-
private readonly int order;
12-
public int Order
13-
{
14-
get
15-
{
16-
return order;
17-
}
18-
}
11+
public int Order { get; }
1912

20-
public ShowOnDataTable(int Order)
13+
public ShowOnDataTable(int order)
2114
{
22-
order = Order;
15+
Order = order;
2316
}
2417
}
2518
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="2.2.0" />
9-
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
10-
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
11-
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
8+
<PackageReference Include="System.Drawing.Common" Version="5.0.0" />
129
</ItemGroup>
1310

1411
<ItemGroup>
1512
<ProjectReference Include="..\CmsEngine.Data\CmsEngine.Data.csproj" />
1613
</ItemGroup>
1714

15+
<ItemGroup>
16+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
17+
</ItemGroup>
18+
1819
</Project>

CmsEngine.Application/Helpers/Email/EmailSender.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Net.Mail;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using CmsEngine.Core.Exceptions;
67
using Microsoft.Extensions.Logging;
78
using Microsoft.Extensions.Options;
89

@@ -21,19 +22,18 @@ public EmailSender(IOptions<EmailSettings> emailSettings, ILogger<EmailSender> l
2122

2223
public async Task SendEmailAsync(ContactForm contactForm)
2324
{
24-
await Execute(contactForm);
25+
await ExecuteAsync(contactForm);
2526
}
2627

27-
private async Task Execute(ContactForm contactForm)
28+
private async Task ExecuteAsync(ContactForm contactForm)
2829
{
29-
_logger.LogInformation("SendEmailAsync(contactForm: {0})", contactForm.ToString());
30+
_logger.LogDebug("SendEmailAsync(contactForm: {0})", contactForm.ToString());
3031

3132
string from = contactForm.From ?? _emailSettings.Username;
3233
string body = $"From: {from}\r\nTo: {contactForm.To}\r\n-----\r\n\r\n{contactForm.Message}";
3334

3435
try
3536
{
36-
3737
MailMessage message = new MailMessage
3838
{
3939
From = new MailAddress(from),
@@ -67,15 +67,16 @@ private async Task Execute(ContactForm contactForm)
6767
smtp.UseDefaultCredentials = false;
6868
smtp.Credentials = new NetworkCredential(_emailSettings.Username, _emailSettings.Password);
6969

70+
_logger.LogDebug("Message {0}", message.ToString());
7071
await smtp.SendMailAsync(message);
7172
}
7273

73-
_logger.LogInformation("Email sent from {0} to {1}", message.From, message.To[0]);
74+
_logger.LogDebug("Email sent from {0} to {1}", message.From, message.To[0]);
7475
}
7576
catch (Exception ex)
7677
{
7778
_logger.LogError(ex, "Error when sending e-mail");
78-
throw;
79+
throw new EmailException("Error when sending e-mail", ex);
7980
}
8081
}
8182
}

CmsEngine.Application/Services/CategoryService.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ public IEnumerable<Category> FilterForDataTable(string searchValue, IEnumerable<
8080

8181
public async Task<IEnumerable<CategoryViewModel>> GetCategoriesWithPost()
8282
{
83-
logger.LogInformation("CategoryService > GetCategoriesWithPost()");
83+
logger.LogDebug("CategoryService > GetCategoriesWithPost()");
8484
var items = await _unitOfWork.Categories.GetCategoriesWithPostOrderedByName();
85-
logger.LogInformation("Categories loaded: {0}", items.Count());
85+
logger.LogDebug("Categories loaded: {0}", items.Count());
8686
return items.MapToViewModelWithPost();
8787
}
8888

8989
public async Task<IEnumerable<CategoryViewModel>> GetCategoriesWithPostCount()
9090
{
91-
logger.LogInformation("CategoryService > GetCategoriesWithPostCount()");
91+
logger.LogDebug("CategoryService > GetCategoriesWithPostCount()");
9292
var items = await _unitOfWork.Categories.GetCategoriesWithPostCountOrderedByName();
93-
logger.LogInformation("Categories loaded: {0}", items.Count());
93+
logger.LogDebug("Categories loaded: {0}", items.Count());
9494
return items.MapToViewModelWithPostCount();
9595
}
9696

@@ -139,31 +139,31 @@ public IEnumerable<Category> OrderForDataTable(int column, string direction, IEn
139139

140140
public async Task<ReturnValue> Save(CategoryEditModel categoryEditModel)
141141
{
142-
logger.LogInformation("CmsService > Save(CategoryEditModel: {0})", categoryEditModel.ToString());
142+
logger.LogDebug("CmsService > Save(CategoryEditModel: {0})", categoryEditModel.ToString());
143143

144144
var returnValue = new ReturnValue($"Category '{categoryEditModel.Name}' saved.");
145145

146146
try
147147
{
148148
if (categoryEditModel.IsNew)
149149
{
150-
logger.LogInformation("New category");
150+
logger.LogDebug("New category");
151151
var category = categoryEditModel.MapToModel();
152152
category.WebsiteId = Instance.Id;
153153

154154
await unitOfWork.Categories.Insert(category);
155155
}
156156
else
157157
{
158-
logger.LogInformation("Update category");
158+
logger.LogDebug("Update category");
159159
var category = categoryEditModel.MapToModel(await unitOfWork.Categories.GetByIdAsync(categoryEditModel.VanityId));
160160
category.WebsiteId = Instance.Id;
161161

162162
_unitOfWork.Categories.Update(category);
163163
}
164164

165165
await _unitOfWork.Save();
166-
logger.LogInformation("Category saved");
166+
logger.LogDebug("Category saved");
167167
}
168168
catch (Exception ex)
169169
{
@@ -176,15 +176,15 @@ public async Task<ReturnValue> Save(CategoryEditModel categoryEditModel)
176176

177177
public CategoryEditModel SetupEditModel()
178178
{
179-
logger.LogInformation("CmsService > SetupEditModel()");
179+
logger.LogDebug("CmsService > SetupEditModel()");
180180
return new CategoryEditModel();
181181
}
182182

183183
public async Task<CategoryEditModel> SetupEditModel(Guid id)
184184
{
185-
logger.LogInformation("CmsService > SetupCategoryEditModel(id: {0})", id);
185+
logger.LogDebug("CmsService > SetupCategoryEditModel(id: {0})", id);
186186
var item = await _unitOfWork.Categories.GetByIdAsync(id);
187-
logger.LogInformation("Category: {0}", item.ToString());
187+
logger.LogDebug("Category: {0}", item.ToString());
188188

189189
return item?.MapToEditModel();
190190
}

CmsEngine.Application/Services/EmailService.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,28 @@ public EmailService(IUnitOfWork uow, IHttpContextAccessor hca, ILoggerFactory lo
2424

2525
public async Task<IEnumerable<ContactForm>> GetOrderedByDate()
2626
{
27-
logger.LogInformation("EmailService > GetOrderedByDate()");
27+
logger.LogDebug("EmailService > GetOrderedByDate()");
2828
var items = await _unitOfWork.Emails.GetOrderedByDate();
29-
logger.LogInformation("E-mails loaded: {0}", items.Count());
29+
logger.LogDebug("E-mails loaded: {0}", items.Count());
3030
return items.MapToViewModel();
3131
}
3232

3333
public async Task<ReturnValue> Save(ContactForm contactForm)
3434
{
35-
logger.LogInformation("CmsService > Save(contactForm: {0})", contactForm.ToString());
35+
logger.LogDebug("CmsService > Save(contactForm: {0})", contactForm.ToString());
3636

3737
var returnValue = new ReturnValue($"E-mail saved.");
3838

3939
try
4040
{
41-
logger.LogInformation("New e-mail");
41+
logger.LogDebug("New e-mail");
4242
var message = contactForm.MapToModel();
4343
message.DateReceived = DateTime.Now;
4444

4545
await _unitOfWork.Emails.Insert(message);
4646

4747
await _unitOfWork.Save();
48-
logger.LogInformation("E-mail saved");
48+
logger.LogDebug("E-mail saved");
4949
}
5050
catch (Exception ex)
5151
{

CmsEngine.Application/Services/PageService.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ public IEnumerable<Page> FilterForDataTable(string searchValue, IEnumerable<Page
7979

8080
public async Task<IEnumerable<PageViewModel>> GetAllPublished()
8181
{
82-
logger.LogInformation("PageService > GetPagesByStatusReadOnly()");
82+
logger.LogDebug("PageService > GetPagesByStatusReadOnly()");
8383
var items = await _unitOfWork.Pages.GetByStatusOrderByDescending(DocumentStatus.Published);
84-
logger.LogInformation("Pages loaded: {0}", items.Count());
84+
logger.LogDebug("Pages loaded: {0}", items.Count());
8585
return items.MapToViewModel();
8686
}
8787

8888
public async Task<PageViewModel> GetBySlug(string slug)
8989
{
90-
logger.LogInformation($"PageService > GetBySlug({slug})");
90+
logger.LogDebug($"PageService > GetBySlug({slug})");
9191
var item = await _unitOfWork.Pages.GetBySlug(slug);
9292
return item?.MapToViewModel();
9393
}
@@ -143,34 +143,34 @@ public IEnumerable<Page> OrderForDataTable(int column, string direction, IEnumer
143143

144144
public async Task<ReturnValue> Save(PageEditModel pageEditModel)
145145
{
146-
logger.LogInformation("PageService > Save(PageEditModel: {0})", pageEditModel.ToString());
146+
logger.LogDebug("PageService > Save(PageEditModel: {0})", pageEditModel.ToString());
147147

148148
var returnValue = new ReturnValue($"Page '{pageEditModel.Title}' saved.");
149149

150150
try
151151
{
152152
if (pageEditModel.IsNew)
153153
{
154-
logger.LogInformation("New page");
154+
logger.LogDebug("New page");
155155
var page = pageEditModel.MapToModel();
156156
page.WebsiteId = Instance.Id;
157157

158-
await PrepareRelatedProperties(page);
158+
await PrepareRelatedPropertiesAsync(page);
159159
await unitOfWork.Pages.Insert(page);
160160
}
161161
else
162162
{
163-
logger.LogInformation("Update page");
163+
logger.LogDebug("Update page");
164164
var page = pageEditModel.MapToModel(await unitOfWork.Pages.GetForSavingById(pageEditModel.VanityId));
165165
page.WebsiteId = Instance.Id;
166166

167167
_unitOfWork.Pages.RemoveRelatedItems(page);
168-
await PrepareRelatedProperties(page);
168+
await PrepareRelatedPropertiesAsync(page);
169169
_unitOfWork.Pages.Update(page);
170170
}
171171

172172
await _unitOfWork.Save();
173-
logger.LogInformation("Page saved");
173+
logger.LogDebug("Page saved");
174174
}
175175
catch (Exception ex)
176176
{
@@ -183,19 +183,19 @@ public async Task<ReturnValue> Save(PageEditModel pageEditModel)
183183

184184
public PageEditModel SetupEditModel()
185185
{
186-
logger.LogInformation("PageService > SetupEditModel()");
186+
logger.LogDebug("PageService > SetupEditModel()");
187187
return new PageEditModel();
188188
}
189189

190190
public async Task<PageEditModel> SetupEditModel(Guid id)
191191
{
192-
logger.LogInformation("PageService > SetupPageEditModel(id: {0})", id);
192+
logger.LogDebug("PageService > SetupPageEditModel(id: {0})", id);
193193
var item = await _unitOfWork.Pages.GetByIdAsync(id);
194-
logger.LogInformation("Page: {0}", item.ToString());
194+
logger.LogDebug("Page: {0}", item.ToString());
195195
return item?.MapToEditModel();
196196
}
197197

198-
private async Task PrepareRelatedProperties(Page page)
198+
private async Task PrepareRelatedPropertiesAsync(Page page)
199199
{
200200
var user = await GetCurrentUserAsync();
201201
page.PageApplicationUsers.Clear();

0 commit comments

Comments
 (0)