-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
250 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/VirtoCommerce.OrdersModule.Core/Model/Search/ShipmentSearchCriteria.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace VirtoCommerce.OrdersModule.Core.Model.Search | ||
{ | ||
public class ShipmentSearchCriteria : OrderOperationSearchCriteriaBase | ||
{ | ||
/// <summary> | ||
/// It used to limit search within a customer order id | ||
/// </summary> | ||
public string OrderId { get; set; } | ||
/// <summary> | ||
/// It used to limit search within a customer order number | ||
/// </summary> | ||
public string OrderNumber { get; set; } | ||
|
||
public string FulfillmentCenterId { get; set; } | ||
|
||
public string ShipmentMethodCode { get; set; } | ||
|
||
public string ShipmentMethodOption { get; set; } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/VirtoCommerce.OrdersModule.Core/Model/Search/ShipmentSearchResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using VirtoCommerce.Platform.Core.Common; | ||
|
||
namespace VirtoCommerce.OrdersModule.Core.Model.Search | ||
{ | ||
public class ShipmentSearchResult : GenericSearchResult<Shipment> | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/VirtoCommerce.OrdersModule.Core/Services/IShipmentSearchService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using VirtoCommerce.OrdersModule.Core.Model; | ||
using VirtoCommerce.OrdersModule.Core.Model.Search; | ||
using VirtoCommerce.Platform.Core.GenericCrud; | ||
|
||
namespace VirtoCommerce.OrdersModule.Core.Services | ||
{ | ||
public interface IShipmentSearchService : ISearchService<ShipmentSearchCriteria, ShipmentSearchResult, Shipment> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/VirtoCommerce.OrdersModule.Data/Services/ShipmentSearchService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using Microsoft.Extensions.Options; | ||
using VirtoCommerce.OrdersModule.Core.Model; | ||
using VirtoCommerce.OrdersModule.Core.Model.Search; | ||
using VirtoCommerce.OrdersModule.Core.Services; | ||
using VirtoCommerce.OrdersModule.Data.Model; | ||
using VirtoCommerce.OrdersModule.Data.Repositories; | ||
using VirtoCommerce.Platform.Core.Caching; | ||
using VirtoCommerce.Platform.Core.Common; | ||
using VirtoCommerce.Platform.Core.GenericCrud; | ||
using VirtoCommerce.Platform.Data.GenericCrud; | ||
|
||
namespace VirtoCommerce.OrdersModule.Data.Services | ||
{ | ||
public class ShipmentSearchService : SearchService<ShipmentSearchCriteria, ShipmentSearchResult, Shipment, ShipmentEntity>, IShipmentSearchService | ||
{ | ||
public ShipmentSearchService( | ||
Func<IOrderRepository> repositoryFactory, | ||
IPlatformMemoryCache platformMemoryCache, | ||
IShipmentService crudService, | ||
IOptions<CrudOptions> crudOptions) | ||
: base(repositoryFactory, platformMemoryCache, crudService, crudOptions) | ||
{ | ||
} | ||
|
||
|
||
protected override IQueryable<ShipmentEntity> BuildQuery(IRepository repository, ShipmentSearchCriteria criteria) | ||
{ | ||
var query = ((IOrderRepository)repository).Shipments; | ||
|
||
if (!criteria.Ids.IsNullOrEmpty()) | ||
{ | ||
query = query.Where(x => criteria.Ids.Contains(x.Id)); | ||
} | ||
|
||
if (criteria.HasParentOperation != null) | ||
{ | ||
query = query.Where(x => criteria.HasParentOperation.Value ? x.ParentOperationId != null : x.ParentOperationId == null); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(criteria.ParentOperationId)) | ||
{ | ||
query = query.Where(x => x.ParentOperationId == criteria.ParentOperationId); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(criteria.OrderId)) | ||
{ | ||
query = query.Where(x => x.CustomerOrderId == criteria.OrderId); | ||
} | ||
else if (!string.IsNullOrEmpty(criteria.OrderNumber)) | ||
{ | ||
query = query.Where(x => x.CustomerOrder.Number == criteria.OrderNumber); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(criteria.EmployeeId)) | ||
{ | ||
query = query.Where(x => x.CustomerOrder.EmployeeId == criteria.EmployeeId); | ||
} | ||
|
||
if (!criteria.StoreIds.IsNullOrEmpty()) | ||
{ | ||
query = query.Where(x => criteria.StoreIds.Contains(x.CustomerOrder.StoreId)); | ||
} | ||
|
||
if (!criteria.Statuses.IsNullOrEmpty()) | ||
{ | ||
query = query.Where(x => criteria.Statuses.Contains(x.Status)); | ||
} | ||
|
||
if (criteria.StartDate != null) | ||
{ | ||
query = query.Where(x => x.CreatedDate >= criteria.StartDate); | ||
} | ||
|
||
if (criteria.EndDate != null) | ||
{ | ||
query = query.Where(x => x.CreatedDate <= criteria.EndDate); | ||
} | ||
|
||
if (!criteria.Numbers.IsNullOrEmpty()) | ||
{ | ||
query = query.Where(x => criteria.Numbers.Contains(x.Number)); | ||
} | ||
else if (!string.IsNullOrEmpty(criteria.Keyword)) | ||
{ | ||
query = query.Where(GetKeywordPredicate(criteria)); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(criteria.FulfillmentCenterId)) | ||
{ | ||
query = query.Where(x => x.FulfillmentCenterId == criteria.FulfillmentCenterId); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(criteria.ShipmentMethodCode)) | ||
{ | ||
query = query.Where(x => x.ShipmentMethodCode == criteria.ShipmentMethodCode); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(criteria.ShipmentMethodOption)) | ||
{ | ||
query = query.Where(x => x.ShipmentMethodOption == criteria.ShipmentMethodOption); | ||
} | ||
|
||
return query; | ||
} | ||
|
||
protected override IList<SortInfo> BuildSortExpression(ShipmentSearchCriteria criteria) | ||
{ | ||
var sortInfos = criteria.SortInfos; | ||
if (sortInfos.IsNullOrEmpty()) | ||
{ | ||
sortInfos = new[] | ||
{ | ||
new SortInfo | ||
{ | ||
SortColumn = nameof(ShipmentEntity.CreatedDate), | ||
SortDirection = SortDirection.Descending | ||
} | ||
}; | ||
} | ||
return sortInfos; | ||
} | ||
|
||
protected virtual Expression<Func<ShipmentEntity, bool>> GetKeywordPredicate(ShipmentSearchCriteria criteria) | ||
{ | ||
return Shipment => Shipment.Number.Contains(criteria.Keyword); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.