Skip to content

Commit d3ad767

Browse files
committed
Web API: added RewardPointsHistory entity
1 parent 4f363b2 commit d3ad767

File tree

8 files changed

+100
-0
lines changed

8 files changed

+100
-0
lines changed

src/Libraries/SmartStore.Core/Domain/Customers/Customer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public virtual ICollection<Order> Orders
247247
/// <summary>
248248
/// Gets or sets reward points history
249249
/// </summary>
250+
[DataMember]
250251
public virtual ICollection<RewardPointsHistory> RewardPointsHistory
251252
{
252253
get => _rewardPointsHistory ?? (_rewardPointsHistory = new HashSet<RewardPointsHistory>());
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,61 @@
11
using System;
2+
using System.Runtime.Serialization;
23
using SmartStore.Core.Domain.Orders;
34

45
namespace SmartStore.Core.Domain.Customers
56
{
67
/// <summary>
78
/// Represents a reward point history entry
89
/// </summary>
10+
[DataContract]
911
public partial class RewardPointsHistory : BaseEntity
1012
{
1113
/// <summary>
1214
/// Gets or sets the customer identifier
1315
/// </summary>
16+
[DataMember]
1417
public int CustomerId { get; set; }
1518

1619
/// <summary>
1720
/// Gets or sets the points redeemed/added
1821
/// </summary>
22+
[DataMember]
1923
public int Points { get; set; }
2024

2125
/// <summary>
2226
/// Gets or sets the points balance
2327
/// </summary>
28+
[DataMember]
2429
public int PointsBalance { get; set; }
2530

2631
/// <summary>
2732
/// Gets or sets the used amount
2833
/// </summary>
34+
[DataMember]
2935
public decimal UsedAmount { get; set; }
3036

3137
/// <summary>
3238
/// Gets or sets the message
3339
/// </summary>
40+
[DataMember]
3441
public string Message { get; set; }
3542

3643
/// <summary>
3744
/// Gets or sets the date and time of instance creation
3845
/// </summary>
46+
[DataMember]
3947
public DateTime CreatedOnUtc { get; set; }
4048

4149
/// <summary>
4250
/// Gets or sets the order for which points were redeemed as a payment
4351
/// </summary>
52+
[DataMember]
4453
public virtual Order UsedWithOrder { get; set; }
4554

4655
/// <summary>
4756
/// Gets or sets the customer
4857
/// </summary>
58+
[DataMember]
4959
public virtual Customer Customer { get; set; }
5060
}
5161
}

src/Libraries/SmartStore.Core/Domain/Orders/Order.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ protected virtual SortedDictionary<decimal, decimal> ParseTaxRates(string taxRat
498498
/// <summary>
499499
/// Gets or sets the reward points history record
500500
/// </summary>
501+
[DataMember]
501502
public virtual RewardPointsHistory RedeemedRewardPointsEntry { get; set; }
502503

503504
/// <summary>

src/Plugins/SmartStore.WebApi/Controllers/OData/CustomersController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ public IHttpActionResult GetCustomerRoleMappings(int key)
215215
return Ok(GetRelatedCollection(key, x => x.CustomerRoleMappings));
216216
}
217217

218+
[WebApiQueryable]
219+
[WebApiAuthenticate(Permission = Permissions.Order.Read)]
220+
public IHttpActionResult GetRewardPointsHistory(int key)
221+
{
222+
return Ok(GetRelatedCollection(key, x => x.RewardPointsHistory));
223+
}
224+
218225
#endregion
219226
}
220227
}

src/Plugins/SmartStore.WebApi/Controllers/OData/OrdersController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ public IHttpActionResult GetOrderItems(int key)
136136
return Ok(GetRelatedCollection(key, x => x.OrderItems));
137137
}
138138

139+
[WebApiQueryable]
140+
[WebApiAuthenticate(Permission = Permissions.Order.Read)]
141+
public IHttpActionResult GetRedeemedRewardPointsEntry(int key)
142+
{
143+
return Ok(GetRelatedEntity(key, x => x.RedeemedRewardPointsEntry));
144+
}
145+
139146
#endregion
140147

141148
#region Actions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Net;
2+
using System.Web.Http;
3+
using SmartStore.Core.Domain.Customers;
4+
using SmartStore.Core.Security;
5+
using SmartStore.Services.Customers;
6+
using SmartStore.Web.Framework.WebApi.OData;
7+
using SmartStore.Web.Framework.WebApi.Security;
8+
9+
namespace SmartStore.WebApi.Controllers.OData
10+
{
11+
[IEEE754Compatible]
12+
public class RewardPointsHistoryController : WebApiEntityController<RewardPointsHistory, ICustomerService>
13+
{
14+
[WebApiQueryable]
15+
[WebApiAuthenticate(Permission = Permissions.Customer.Read)]
16+
public IHttpActionResult Get()
17+
{
18+
return Ok(GetEntitySet());
19+
}
20+
21+
[WebApiQueryable]
22+
[WebApiAuthenticate(Permission = Permissions.Customer.Read)]
23+
public IHttpActionResult Get(int key)
24+
{
25+
return Ok(GetByKey(key));
26+
}
27+
28+
[WebApiAuthenticate(Permission = Permissions.Customer.Read)]
29+
public IHttpActionResult GetProperty(int key, string propertyName)
30+
{
31+
return GetPropertyValue(key, propertyName);
32+
}
33+
34+
public IHttpActionResult Post()
35+
{
36+
return StatusCode(HttpStatusCode.Forbidden);
37+
}
38+
39+
public IHttpActionResult Put()
40+
{
41+
return StatusCode(HttpStatusCode.Forbidden);
42+
}
43+
44+
public IHttpActionResult Patch()
45+
{
46+
return StatusCode(HttpStatusCode.Forbidden);
47+
}
48+
49+
public IHttpActionResult Delete()
50+
{
51+
return StatusCode(HttpStatusCode.Forbidden);
52+
}
53+
54+
#region Navigation properties
55+
56+
[WebApiQueryable]
57+
[WebApiAuthenticate(Permission = Permissions.Customer.Read)]
58+
public IHttpActionResult GetUsedWithOrder(int key)
59+
{
60+
return Ok(GetRelatedEntity(key, x => x.UsedWithOrder));
61+
}
62+
63+
[WebApiQueryable]
64+
[WebApiAuthenticate(Permission = Permissions.Customer.Read)]
65+
public IHttpActionResult GetCustomer(int key)
66+
{
67+
return Ok(GetRelatedEntity(key, x => x.Customer));
68+
}
69+
70+
#endregion
71+
}
72+
}

src/Plugins/SmartStore.WebApi/SmartStore.WebApi.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
<Compile Include="Controllers\OData\ProductVariantAttributesController.cs" />
265265
<Compile Include="Controllers\OData\QuantityUnitsController.cs" />
266266
<Compile Include="Controllers\OData\PaymentMethodsController.cs" />
267+
<Compile Include="Controllers\OData\RewardPointsHistoryController.cs" />
267268
<Compile Include="Controllers\OData\ShipmentItemsController.cs" />
268269
<Compile Include="Controllers\OData\TaxCategoriesController.cs" />
269270
<Compile Include="Controllers\OData\SyncMappingsController.cs" />

src/Plugins/SmartStore.WebApi/WebApiConfigurationProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void Configure(WebApiConfigurationBroadcaster configData)
8080
m.EntitySet<QuantityUnit>("QuantityUnits");
8181
m.EntitySet<RelatedProduct>("RelatedProducts");
8282
m.EntitySet<ReturnRequest>("ReturnRequests");
83+
m.EntitySet<RewardPointsHistory>("RewardPointsHistory");
8384
m.EntitySet<Setting>("Settings");
8485
m.EntitySet<Shipment>("Shipments");
8586
m.EntitySet<ShipmentItem>("ShipmentItems");

0 commit comments

Comments
 (0)