Last active
August 21, 2020 08:40
-
-
Save mattbrailsford/a9cc7768756ec87e30fa4494820bec27 to your computer and use it in GitHub Desktop.
Vendr extension to get all orders for a customer
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Vendr.Core; | |
using Vendr.Core.Api; | |
using Vendr.Core.Models; | |
using Vendr.Core.Services; | |
namespace VendrExt | |
{ | |
public static class OrderServiceExtensions | |
{ | |
public static IEnumerable<OrderReadOnly> GetAllOrdersForCustomer(this IOrderService orderService, Guid storeId, string customerReference) | |
{ | |
var orders = new List<OrderReadOnly>(); | |
try | |
{ | |
using (var uow = VendrApi.Instance.Uow.Create() as IDatabaseUnitOfWork) | |
{ | |
var orderIds = uow.Database.Fetch<Guid>($"SELECT id FROM {Constants.DatabaseSchema.Tables.Order} WHERE storeId = @0 AND customerReference = @1", storeId, customerReference); | |
orders = orderService.GetOrders(orderIds.ToArray()).ToList(); | |
uow.Complete(); | |
} | |
} | |
catch (Exception ex) | |
{ | |
VendrApi.Instance.Log.Error<IOrderService>(ex, "Error fetching all orders for customer {CustomerReference}", customerReference); | |
} | |
return orders; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment