Skip to content

Commit 84ae1cd

Browse files
Merge pull request #102 from davidsonsousa/develop
Develop
2 parents 8ead5bf + 218477e commit 84ae1cd

Some content is hidden

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

45 files changed

+1085
-184
lines changed

CmsEngine.Application/CmsEngine.Application.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

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

77
<ItemGroup>
88
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="2.2.0" />
99
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
1010
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
11-
<PackageReference Include="System.Drawing.Common" Version="4.6.0" />
11+
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

CmsEngine.Application/Extensions/Mapper/PageExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static IEnumerable<PageTableViewModel> MapToTableViewModel(this IEnumerab
119119
Slug = item.Slug,
120120
PublishedOn = item.PublishedOn.ToString(),
121121
Status = item.Status,
122-
Author = item.ApplicationUsers.MapToViewModelSimple().SingleOrDefault()
122+
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
123123
});
124124
}
125125

@@ -142,7 +142,7 @@ public static PageViewModel MapToViewModel(this Page item)
142142
DocumentContent = item.DocumentContent,
143143
HeaderImage = item.HeaderImage,
144144
PublishedOn = item.PublishedOn.ToShortDateString(),
145-
Author = item.ApplicationUsers.MapToViewModelSimple().SingleOrDefault()
145+
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
146146
};
147147
}
148148

CmsEngine.Application/Extensions/Mapper/PostExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static IEnumerable<PostTableViewModel> MapToTableViewModel(this IEnumerab
121121
Slug = item.Slug,
122122
PublishedOn = item.PublishedOn.ToString(),
123123
Status = item.Status,
124-
Author = item.ApplicationUsers.MapToViewModelSimple().SingleOrDefault()
124+
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
125125
});
126126
}
127127

@@ -145,7 +145,7 @@ public static PostViewModel MapToViewModel(this Post item)
145145
HeaderImage = item.HeaderImage,
146146
PublishedOn = item.PublishedOn.ToShortDateString(),
147147
Categories = item.Categories.MapToViewModelSimple(),
148-
Author = item.ApplicationUsers.MapToViewModelSimple().SingleOrDefault()
148+
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
149149
};
150150
}
151151

@@ -255,7 +255,7 @@ public static IEnumerable<PostViewModel> MapToViewModelForPartialView(this IEnum
255255
HeaderImage = item.HeaderImage,
256256
PublishedOn = item.PublishedOn.ToShortDateString(),
257257
Categories = item.Categories.MapToViewModelSimple(),
258-
Author = item.ApplicationUsers.MapToViewModelSimple().SingleOrDefault()
258+
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
259259
});
260260
}
261261

@@ -283,7 +283,7 @@ public static IEnumerable<PostViewModel> MapToViewModelForPartialViewForTags(thi
283283
PublishedOn = item.PublishedOn.ToShortDateString(),
284284
Categories = item.Categories.MapToViewModelSimple(),
285285
Tags = item.Tags.MapToViewModelSimple(),
286-
Author = item.ApplicationUsers.MapToViewModelSimple().SingleOrDefault()
286+
Author = item.ApplicationUsers.MapToViewModelSimple().Single()
287287
});
288288
}
289289

CmsEngine.Application/Services/EmailService.cs

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public async Task<ReturnValue> Save(ContactForm contactForm)
4040
{
4141
logger.LogInformation("New e-mail");
4242
var message = contactForm.MapToModel();
43+
message.DateReceived = DateTime.Now;
44+
4345
await _unitOfWork.Emails.Insert(message);
4446

4547
await _unitOfWork.Save();

CmsEngine.Application/Services/PageService.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public async Task<ReturnValue> Save(PageEditModel pageEditModel)
154154
logger.LogInformation("New page");
155155
var page = pageEditModel.MapToModel();
156156
page.WebsiteId = Instance.Id;
157+
157158
await PrepareRelatedProperties(page);
158159
await unitOfWork.Pages.Insert(page);
159160
}
@@ -162,6 +163,8 @@ public async Task<ReturnValue> Save(PageEditModel pageEditModel)
162163
logger.LogInformation("Update page");
163164
var page = pageEditModel.MapToModel(await unitOfWork.Pages.GetForSavingById(pageEditModel.VanityId));
164165
page.WebsiteId = Instance.Id;
166+
167+
_unitOfWork.Pages.RemoveRelatedItems(page);
165168
await PrepareRelatedProperties(page);
166169
_unitOfWork.Pages.Update(page);
167170
}
@@ -194,14 +197,13 @@ public async Task<PageEditModel> SetupEditModel(Guid id)
194197

195198
private async Task PrepareRelatedProperties(Page page)
196199
{
197-
page.PageApplicationUsers = new List<PageApplicationUser>
200+
var user = await GetCurrentUserAsync();
201+
page.PageApplicationUsers.Clear();
202+
page.PageApplicationUsers.Add(new PageApplicationUser
198203
{
199-
new PageApplicationUser
200-
{
201-
Page = page,
202-
ApplicationUser = await GetCurrentUserAsync()
203-
}
204-
};
204+
PageId = page.Id,
205+
ApplicationUserId = user.Id
206+
});
205207
}
206208
}
207209
}

CmsEngine.Application/Services/PostService.cs

+19-17
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public async Task<ReturnValue> Save(PostEditModel postEditModel)
189189
logger.LogInformation("New post");
190190
var post = postEditModel.MapToModel();
191191
post.WebsiteId = Instance.Id;
192+
192193
await PrepareRelatedProperties(postEditModel, post);
193194
await unitOfWork.Posts.Insert(post);
194195
}
@@ -197,6 +198,8 @@ public async Task<ReturnValue> Save(PostEditModel postEditModel)
197198
logger.LogInformation("Update post");
198199
var post = postEditModel.MapToModel(await unitOfWork.Posts.GetForSavingById(postEditModel.VanityId));
199200
post.WebsiteId = Instance.Id;
201+
202+
_unitOfWork.Posts.RemoveRelatedItems(post);
200203
await PrepareRelatedProperties(postEditModel, post);
201204
_unitOfWork.Posts.Update(post);
202205
}
@@ -237,37 +240,36 @@ public async Task<PostEditModel> SetupEditModel(Guid id)
237240

238241
private async Task PrepareRelatedProperties(PostEditModel postEditModel, Post post)
239242
{
240-
var categories = await _unitOfWork.Categories.GetByMultipleIdsAsync(postEditModel.SelectedCategories.ToList().ConvertAll(Guid.Parse));
241-
var tags = await _unitOfWork.Tags.GetByMultipleIdsAsync(postEditModel.SelectedTags.ToList().ConvertAll(Guid.Parse));
243+
var categoryIds = await _unitOfWork.Categories.GetIdsByMultipleGuidsAsync(postEditModel.SelectedCategories.ToList().ConvertAll(Guid.Parse));
244+
var tagIds = await _unitOfWork.Tags.GetIdsByMultipleGuidsAsync(postEditModel.SelectedTags.ToList().ConvertAll(Guid.Parse));
242245

243-
post.PostCategories = new List<PostCategory>();
244-
foreach (var category in categories)
246+
post.PostCategories.Clear();
247+
foreach (int categoryId in categoryIds)
245248
{
246249
post.PostCategories.Add(new PostCategory
247250
{
248-
Post = post,
249-
Category = category
251+
PostId = post.Id,
252+
CategoryId = categoryId
250253
});
251254
}
252255

253-
post.PostTags = new List<PostTag>();
254-
foreach (var tag in tags)
256+
post.PostTags.Clear();
257+
foreach (int tagId in tagIds)
255258
{
256259
post.PostTags.Add(new PostTag
257260
{
258-
Post = post,
259-
Tag = tag
261+
PostId = post.Id,
262+
TagId = tagId
260263
});
261264
}
262265

263-
post.PostApplicationUsers = new List<PostApplicationUser>
266+
var user = await GetCurrentUserAsync();
267+
post.PostApplicationUsers.Clear();
268+
post.PostApplicationUsers.Add(new PostApplicationUser
264269
{
265-
new PostApplicationUser
266-
{
267-
Post = post,
268-
ApplicationUser = await GetCurrentUserAsync()
269-
}
270-
};
270+
PostId = post.Id,
271+
ApplicationUserId = user.Id
272+
});
271273
}
272274
}
273275
}

CmsEngine.Core/CmsEngine.Core.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

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

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.0.0" />
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
10-
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
8+
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.3" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
10+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
1111
</ItemGroup>
1212

1313
</Project>

CmsEngine.Data/CmsEngine.Data.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

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

77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
9-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
11-
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
8+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.3" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.3" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
11+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

CmsEngine.Data/CmsEngineContext.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ public class CmsEngineContext : IdentityDbContext<ApplicationUser>
2020
public CmsEngineContext(DbContextOptions<CmsEngineContext> options) : base(options)
2121
{
2222
//Database.SetInitializer(new CmsEngineInitializer());
23+
24+
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
2325
}
2426

2527
protected override void OnModelCreating(ModelBuilder builder)
2628
{
2729
//modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
2830

29-
// Forces the database to use the type datetime2
30-
//modelBuilder.Properties<DateTime>().Configure(c => c.HasColumnType("datetime2").HasPrecision(0));
31-
3231
// Model configuration
3332
builder.Entity<Website>(ModelConfiguration.ConfigureWebsite);
3433
builder.Entity<Page>(ModelConfiguration.ConfigurePage);
@@ -49,17 +48,20 @@ protected override void OnModelCreating(ModelBuilder builder)
4948

5049
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
5150
{
52-
var saveTime = DateTime.Now;
51+
ChangeTracker.DetectChanges();
52+
53+
var timeStamp = DateTime.Now;
5354
var entries = ChangeTracker.Entries().Where(e => e.Entity is BaseEntity && (e.State == EntityState.Added || e.State == EntityState.Modified));
5455
string currentUsername = "";//HttpContext.Current?.User?.Identity?.Name;
5556
foreach (var entry in entries)
5657
{
5758
if (entry.State == EntityState.Added)
5859
{
59-
entry.Property("DateCreated").CurrentValue = saveTime;
60+
entry.Property("DateCreated").CurrentValue = timeStamp;
6061
entry.Property("UserCreated").CurrentValue = currentUsername;
6162
}
62-
entry.Property("DateModified").CurrentValue = saveTime;
63+
64+
entry.Property("DateModified").CurrentValue = timeStamp;
6365
entry.Property("UserModified").CurrentValue = currentUsername;
6466
}
6567

CmsEngine.Data/Entities/BaseEntity.cs

-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ public bool IsNew
2323

2424
public Guid VanityId { get; set; }
2525

26-
public DateTime DateCreated { get; set; }
27-
public DateTime DateModified { get; set; }
28-
29-
public string UserCreated { get; set; }
30-
public string UserModified { get; set; }
31-
3226
public override string ToString()
3327
{
3428
var jsonResult = new JObject(

CmsEngine.Data/Entities/Category.cs

+5
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ public override string ToString()
3232
);
3333
return jsonResult.ToString();
3434
}
35+
36+
public Category()
37+
{
38+
Posts = new List<Post>();
39+
}
3540
}
3641
}

CmsEngine.Data/Entities/Email.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Newtonsoft.Json.Linq;
23

34
namespace CmsEngine.Data.Entities
@@ -7,6 +8,7 @@ public class Email : BaseEntity
78
public string From { get; set; }
89
public string Subject { get; set; }
910
public string Message { get; set; }
11+
public DateTime DateReceived { get; set; }
1012

1113
public override string ToString()
1214
{

0 commit comments

Comments
 (0)