Skip to content

Commit

Permalink
Fixed async bug for posts.
Browse files Browse the repository at this point in the history
  • Loading branch information
tidyui committed Feb 17, 2020
1 parent ff25c60 commit 8ee9a2f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions data/Piranha.Data.EF/Repositories/PageRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task<T> GetStartpage<T>(Guid siteId) where T : Models.PageBase

if (page != null)
{
return await _contentService.TransformAsync<T>(page, App.PageTypes.GetById(page.PageTypeId), Process);
return await _contentService.TransformAsync<T>(page, App.PageTypes.GetById(page.PageTypeId), ProcessAsync);
}
return null;
}
Expand All @@ -147,7 +147,7 @@ public async Task<T> GetById<T>(Guid id) where T : Models.PageBase

if (page != null)
{
return await _contentService.TransformAsync<T>(page, App.PageTypes.GetById(page.PageTypeId), Process);
return await _contentService.TransformAsync<T>(page, App.PageTypes.GetById(page.PageTypeId), ProcessAsync);
}
return null;
}
Expand All @@ -167,7 +167,7 @@ public async Task<T> GetBySlug<T>(string slug, Guid siteId) where T : Models.Pag

if (page != null)
{
return await _contentService.TransformAsync<T>(page, App.PageTypes.GetById(page.PageTypeId), Process);
return await _contentService.TransformAsync<T>(page, App.PageTypes.GetById(page.PageTypeId), ProcessAsync);
}
return null;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public async Task<T> GetDraftById<T>(Guid id) where T : Models.PageBase
// Transform data model
var page = JsonConvert.DeserializeObject<Page>(draft.Data);

return await _contentService.TransformAsync<T>(page, App.PageTypes.GetById(page.PageTypeId), Process);
return await _contentService.TransformAsync<T>(page, App.PageTypes.GetById(page.PageTypeId), ProcessAsync);
}
}
return null;
Expand Down Expand Up @@ -898,7 +898,7 @@ private IQueryable<Page> GetQuery<T>()
/// </summary>
/// <param name="page">The source page</param>
/// <param name="model">The targe model</param>
private async void Process<T>(Data.Page page, T model) where T : Models.PageBase
private async Task ProcessAsync<T>(Data.Page page, T model) where T : Models.PageBase
{
// Permissions
foreach (var permission in page.Permissions)
Expand Down
8 changes: 4 additions & 4 deletions data/Piranha.Data.EF/Repositories/PostRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public async Task<T> GetById<T>(Guid id) where T : Models.PostBase

if (post != null)
{
return await _contentService.TransformAsync<T>(post, App.PostTypes.GetById(post.PostTypeId), Process);
return await _contentService.TransformAsync<T>(post, App.PostTypes.GetById(post.PostTypeId), ProcessAsync);
}
return null;
}
Expand All @@ -205,7 +205,7 @@ public async Task<T> GetBySlug<T>(Guid blogId, string slug) where T : Models.Pos

if (post != null)
{
return await _contentService.TransformAsync<T>(post, App.PostTypes.GetById(post.PostTypeId), Process);
return await _contentService.TransformAsync<T>(post, App.PostTypes.GetById(post.PostTypeId), ProcessAsync);
}
return null;
}
Expand Down Expand Up @@ -235,7 +235,7 @@ public async Task<T> GetDraftById<T>(Guid id) where T : Models.PostBase
// Transform data model
var post = JsonConvert.DeserializeObject<Post>(draft.Data);

return await _contentService.TransformAsync<T>(post, App.PostTypes.GetById(post.PostTypeId), Process);
return await _contentService.TransformAsync<T>(post, App.PostTypes.GetById(post.PostTypeId), ProcessAsync);
}
}
return null;
Expand Down Expand Up @@ -1051,7 +1051,7 @@ private IQueryable<Post> GetQuery<T>()
/// </summary>
/// <param name="post">The source post</param>
/// <param name="model">The targe model</param>
private async void Process<T>(Data.Post post, T model) where T : Models.PostBase
private async Task ProcessAsync<T>(Data.Post post, T model) where T : Models.PostBase
{
// Permissions
foreach (var permission in post.Permissions)
Expand Down
4 changes: 2 additions & 2 deletions data/Piranha.Data.EF/Services/ContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ContentService(IContentFactory factory, IMapper mapper)
/// <param name="content">The content entity</param>
/// <param name="type">The content type</param>
/// <returns>The page model</returns>
public async Task<T> TransformAsync<T>(TContent content, Models.ContentType type, Action<TContent, T> process = null)
public async Task<T> TransformAsync<T>(TContent content, Models.ContentType type, Func<TContent, T, Task> process = null)
where T : Models.Content, TModelBase
{
if (type != null)
Expand Down Expand Up @@ -129,7 +129,7 @@ public async Task<T> TransformAsync<T>(TContent content, Models.ContentType type
}
}
}
process?.Invoke(content, model);
await process?.Invoke(content, model);

return model;
}
Expand Down
2 changes: 1 addition & 1 deletion data/Piranha.Data.EF/Services/IContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface IContentService<TContent, TField, TModelBase>
/// <param name="content">The content entity</param>
/// <param name="type">The content type</param>
/// <returns>The page model</returns>
Task<T> TransformAsync<T>(TContent content, Models.ContentType type, Action<TContent, T> process = null)
Task<T> TransformAsync<T>(TContent content, Models.ContentType type, Func<TContent, T, Task> process = null)
where T : Models.Content, TModelBase;

/// <summary>
Expand Down

0 comments on commit 8ee9a2f

Please sign in to comment.