Skip to content

Commit 933226a

Browse files
committed
adjust for new angular jsonapi module
1 parent 1cb8360 commit 933226a

5 files changed

+861
-857
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
using System;
2-
using System.Data.Entity;
3-
using System.Linq;
4-
using System.Threading;
5-
using System.Threading.Tasks;
6-
using JSONAPI.Documents;
7-
using JSONAPI.Documents.Builders;
8-
using JSONAPI.Http;
9-
using JSONAPI.QueryableTransformers;
10-
11-
namespace JSONAPI.EntityFramework.Documents.Builders
12-
{
13-
/// <summary>
14-
/// Provides a entity framework implementation of an IQueryableResourceCollectionDocumentBuilder
15-
/// </summary>
16-
public class EntityFrameworkQueryableResourceCollectionDocumentBuilder: DefaultQueryableResourceCollectionDocumentBuilder
17-
{
18-
/// <summary>
19-
/// Creates a new EntityFrameworkQueryableResourceCollectionDocumentBuilder
20-
/// </summary>
21-
public EntityFrameworkQueryableResourceCollectionDocumentBuilder(
22-
IResourceCollectionDocumentBuilder resourceCollectionDocumentBuilder,
23-
IQueryableEnumerationTransformer enumerationTransformer,
24-
IQueryableFilteringTransformer filteringTransformer,
25-
IQueryableSortingTransformer sortingTransformer,
26-
IQueryablePaginationTransformer paginationTransformer,
27-
IBaseUrlService baseUrlService) :
28-
base(resourceCollectionDocumentBuilder,
29-
enumerationTransformer,
30-
filteringTransformer,
31-
sortingTransformer,
32-
paginationTransformer,
33-
baseUrlService)
34-
{
35-
}
36-
37-
/// <summary>
38-
/// Returns the metadata that should be sent with this document.
39-
/// </summary>
40-
protected override async Task<IMetadata> GetDocumentMetadata<T>(IQueryable<T> originalQuery, IQueryable<T> filteredQuery, IOrderedQueryable<T> sortedQuery,
41-
IPaginationTransformResult<T> paginationResult, CancellationToken cancellationToken)
42-
{
43-
var metadata = new Metadata();
44-
if (paginationResult.PaginationWasApplied)
45-
{
46-
var count = await filteredQuery.CountAsync(cancellationToken);
47-
metadata.MetaObject.Add("total-pages", (int)Math.Ceiling((decimal) count / paginationResult.PageSize));
48-
metadata.MetaObject.Add("total-count", count);
49-
}
50-
if (metadata.MetaObject.HasValues)
51-
return metadata;
52-
return null;
53-
}
54-
}
55-
}
1+
using System;
2+
using System.Data.Entity;
3+
using System.Linq;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using JSONAPI.Documents;
7+
using JSONAPI.Documents.Builders;
8+
using JSONAPI.Http;
9+
using JSONAPI.QueryableTransformers;
10+
11+
namespace JSONAPI.EntityFramework.Documents.Builders
12+
{
13+
/// <summary>
14+
/// Provides a entity framework implementation of an IQueryableResourceCollectionDocumentBuilder
15+
/// </summary>
16+
public class EntityFrameworkQueryableResourceCollectionDocumentBuilder: DefaultQueryableResourceCollectionDocumentBuilder
17+
{
18+
/// <summary>
19+
/// Creates a new EntityFrameworkQueryableResourceCollectionDocumentBuilder
20+
/// </summary>
21+
public EntityFrameworkQueryableResourceCollectionDocumentBuilder(
22+
IResourceCollectionDocumentBuilder resourceCollectionDocumentBuilder,
23+
IQueryableEnumerationTransformer enumerationTransformer,
24+
IQueryableFilteringTransformer filteringTransformer,
25+
IQueryableSortingTransformer sortingTransformer,
26+
IQueryablePaginationTransformer paginationTransformer,
27+
IBaseUrlService baseUrlService) :
28+
base(resourceCollectionDocumentBuilder,
29+
enumerationTransformer,
30+
filteringTransformer,
31+
sortingTransformer,
32+
paginationTransformer,
33+
baseUrlService)
34+
{
35+
}
36+
37+
/// <summary>
38+
/// Returns the metadata that should be sent with this document.
39+
/// </summary>
40+
protected override async Task<IMetadata> GetDocumentMetadata<T>(IQueryable<T> originalQuery, IQueryable<T> filteredQuery, IOrderedQueryable<T> sortedQuery,
41+
IPaginationTransformResult<T> paginationResult, CancellationToken cancellationToken)
42+
{
43+
var metadata = new Metadata();
44+
if (paginationResult.PaginationWasApplied)
45+
{
46+
var count = await filteredQuery.CountAsync(cancellationToken);
47+
metadata.MetaObject.Add("total-pages", (int)Math.Ceiling((decimal) count / paginationResult.PageSize));
48+
metadata.MetaObject.Add("total-count", count);
49+
metadata.MetaObject.Add("total_resources", count);
50+
}
51+
if (metadata.MetaObject.HasValues)
52+
return metadata;
53+
return null;
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
using System;
2-
using System.Reflection;
3-
using Newtonsoft.Json.Linq;
4-
5-
namespace JSONAPI.Core
6-
{
7-
/// <summary>
8-
/// Implementation of <see cref="IAttributeValueConverter" /> suitable for
9-
/// use converting between DateTime CLR properties and ISO8601 string values.
10-
/// </summary>
11-
public class DateTimeAttributeValueConverter : IAttributeValueConverter
12-
{
13-
private readonly PropertyInfo _property;
14-
private readonly bool _isNullable;
15-
16-
/// <summary>
17-
/// Creates a new DateTimeAttributeValueConverter
18-
/// </summary>
19-
/// <param name="property"></param>
20-
/// <param name="isNullable"></param>
21-
public DateTimeAttributeValueConverter(PropertyInfo property, bool isNullable)
22-
{
23-
_property = property;
24-
_isNullable = isNullable;
25-
}
26-
27-
public JToken GetValue(object resource)
28-
{
29-
var value = _property.GetValue(resource);
30-
if (value != null) return ((DateTime) value).ToString("s");
31-
if (_isNullable) return null;
32-
return "0001-01-01";
33-
}
34-
35-
public void SetValue(object resource, JToken value)
36-
{
37-
if (value == null || value.Type == JTokenType.Null)
38-
{
39-
_property.SetValue(resource, _isNullable ? (DateTime?)null : new DateTime());
40-
}
41-
else
42-
{
43-
var dateTimeValue = value.Value<DateTime>();
44-
if (dateTimeValue.Kind == DateTimeKind.Local) dateTimeValue = dateTimeValue.ToUniversalTime();
45-
_property.SetValue(resource, dateTimeValue);
46-
}
47-
}
48-
}
1+
using System;
2+
using System.Reflection;
3+
using Newtonsoft.Json.Linq;
4+
5+
namespace JSONAPI.Core
6+
{
7+
/// <summary>
8+
/// Implementation of <see cref="IAttributeValueConverter" /> suitable for
9+
/// use converting between DateTime CLR properties and ISO8601 string values.
10+
/// </summary>
11+
public class DateTimeAttributeValueConverter : IAttributeValueConverter
12+
{
13+
private readonly PropertyInfo _property;
14+
private readonly bool _isNullable;
15+
16+
/// <summary>
17+
/// Creates a new DateTimeAttributeValueConverter
18+
/// </summary>
19+
/// <param name="property"></param>
20+
/// <param name="isNullable"></param>
21+
public DateTimeAttributeValueConverter(PropertyInfo property, bool isNullable)
22+
{
23+
_property = property;
24+
_isNullable = isNullable;
25+
}
26+
27+
public JToken GetValue(object resource)
28+
{
29+
var value = _property.GetValue(resource);
30+
if (value != null) return ((DateTime) value).ToString("u");
31+
if (_isNullable) return null;
32+
return "0001-01-01";
33+
}
34+
35+
public void SetValue(object resource, JToken value)
36+
{
37+
if (value == null || value.Type == JTokenType.Null)
38+
{
39+
_property.SetValue(resource, _isNullable ? (DateTime?)null : new DateTime());
40+
}
41+
else
42+
{
43+
var dateTimeValue = value.Value<DateTime>();
44+
if (dateTimeValue.Kind == DateTimeKind.Local) dateTimeValue = dateTimeValue.ToUniversalTime();
45+
_property.SetValue(resource, dateTimeValue);
46+
}
47+
}
48+
}
4949
}

0 commit comments

Comments
 (0)