Skip to content

Commit

Permalink
Create CustomerOrderSearchCriteria with AbstractTypeFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev committed Dec 15, 2017
1 parent ec16ce1 commit e3fe51c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ public IHttpActionResult Search(CustomerOrderSearchCriteria criteria)
[ResponseType(typeof(CustomerOrder))]
public IHttpActionResult GetByNumber(string number)
{
var result = _searchService.SearchCustomerOrders(new CustomerOrderSearchCriteria { Number = number, ResponseGroup = CustomerOrderResponseGroup.Full.ToString() });
var searchCriteria = AbstractTypeFactory<CustomerOrderSearchCriteria>.TryCreateInstance();
searchCriteria.Number = number;
searchCriteria.ResponseGroup = CustomerOrderResponseGroup.Full.ToString();

var result = _searchService.SearchCustomerOrders(searchCriteria);

var retVal = result.Results.FirstOrDefault();
if (retVal != null)
Expand Down Expand Up @@ -172,8 +176,16 @@ public IHttpActionResult CalculateTotals(CustomerOrder order)
[ResponseType(typeof(ProcessPaymentResult))]
public IHttpActionResult ProcessOrderPayments(string orderId, string paymentId, [SwaggerOptional] BankCardInfo bankCardInfo)
{
var order = _customerOrderService.GetByIds(new[] { orderId }, CustomerOrderResponseGroup.Full.ToString()).FirstOrDefault()
?? _searchService.SearchCustomerOrders(new CustomerOrderSearchCriteria { Number = orderId, ResponseGroup = CustomerOrderResponseGroup.Full.ToString() }).Results.FirstOrDefault();
var order = _customerOrderService.GetByIds(new[] { orderId }, CustomerOrderResponseGroup.Full.ToString()).FirstOrDefault();

if (order == null)
{
var searchCriteria = AbstractTypeFactory<CustomerOrderSearchCriteria>.TryCreateInstance();
searchCriteria.Number = orderId;
searchCriteria.ResponseGroup = CustomerOrderResponseGroup.Full.ToString();

order = _searchService.SearchCustomerOrders(searchCriteria).Results.FirstOrDefault();
}

if (order == null)
{
Expand Down Expand Up @@ -388,11 +400,14 @@ public IHttpActionResult PostProcessPayment(webModel.PaymentCallbackParameters c
if (callback?.Parameters != null && callback.Parameters.Any(param => param.Key.EqualsInvariant("orderid")))
{
var orderId = callback.Parameters.First(param => param.Key.EqualsInvariant("orderid")).Value;

//some payment method require customer number to be passed and returned. First search customer order by number
var searchCriteria = new CustomerOrderSearchCriteria { Number = orderId, ResponseGroup = CustomerOrderResponseGroup.Full.ToString() };
var order = _searchService.SearchCustomerOrders(searchCriteria).Results.FirstOrDefault() ?? _customerOrderService.GetByIds(new[] { orderId }, CustomerOrderResponseGroup.Full.ToString()).FirstOrDefault();
var searchCriteria = AbstractTypeFactory<CustomerOrderSearchCriteria>.TryCreateInstance();
searchCriteria.Number = orderId;
searchCriteria.ResponseGroup = CustomerOrderResponseGroup.Full.ToString();

//if order not found by order number search by order id
var order = _searchService.SearchCustomerOrders(searchCriteria).Results.FirstOrDefault() ?? _customerOrderService.GetByIds(new[] { orderId }, CustomerOrderResponseGroup.Full.ToString()).FirstOrDefault();

if (order == null)
{
Expand Down Expand Up @@ -445,13 +460,11 @@ public IHttpActionResult PostProcessPayment(webModel.PaymentCallbackParameters c
[SwaggerFileResponse]
public IHttpActionResult GetInvoicePdf(string orderNumber)
{
var oderSearchResult = _searchService.SearchCustomerOrders(new CustomerOrderSearchCriteria
{
Number = orderNumber,
Take = 1
});
var searchCriteria = AbstractTypeFactory<CustomerOrderSearchCriteria>.TryCreateInstance();
searchCriteria.Number = orderNumber;
searchCriteria.Take = 1;

var order = oderSearchResult.Results.FirstOrDefault();
var order = _searchService.SearchCustomerOrders(searchCriteria).Results.FirstOrDefault();

if (order == null)
{
Expand Down
13 changes: 11 additions & 2 deletions VirtoCommerce.OrderModule.Web/ExportImport/OrderExportImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,22 @@ private BackupObject GetBackupObject(Action<ExportImportProgressInfo> progressCa
var retVal = new BackupObject();
var progressInfo = new ExportImportProgressInfo();

var searchCriteria = AbstractTypeFactory<CustomerOrderSearchCriteria>.TryCreateInstance();
searchCriteria.ResponseGroup = CustomerOrderResponseGroup.Default.ToString();
searchCriteria.Take = 0;

var searchResponse = _customerOrderSearchService.SearchCustomerOrders(new CustomerOrderSearchCriteria { Take = 0, ResponseGroup = CustomerOrderResponseGroup.Default.ToString() });
var searchResponse = _customerOrderSearchService.SearchCustomerOrders(searchCriteria);

const int take = 20;
for (var skip = 0; skip < searchResponse.TotalCount; skip += take)
{
searchResponse = _customerOrderSearchService.SearchCustomerOrders(new CustomerOrderSearchCriteria { Skip = skip, Take = take, WithPrototypes = true, ResponseGroup = CustomerOrderResponseGroup.Full.ToString() });
searchCriteria = AbstractTypeFactory<CustomerOrderSearchCriteria>.TryCreateInstance();
searchCriteria.ResponseGroup = CustomerOrderResponseGroup.Full.ToString();
searchCriteria.WithPrototypes = true;
searchCriteria.Skip = skip;
searchCriteria.Take = take;

searchResponse = _customerOrderSearchService.SearchCustomerOrders(searchCriteria);

progressInfo.Description = string.Format(CultureInfo.InvariantCulture, "{0} of {1} orders loading", Math.Min(skip + take, searchResponse.TotalCount), searchResponse.TotalCount);
progressCallback(progressInfo);
Expand Down

0 comments on commit e3fe51c

Please sign in to comment.