protected virtual string GetOrderStatusDisplayName(OrderItem rawOrder, GetOrderHistoryViewModelParam param) { return(LocalizationProvider.GetLocalizedString(new GetLocalizedParam { Category = "General", Key = $"L_OrderStatus_{rawOrder.OrderStatus}", CultureInfo = param.CultureInfo })); }
/// <summary> /// Builds the compact order view model. /// </summary> /// <param name="rawOrder">The raw order.</param> /// <param name="param"></param> /// <returns></returns> protected virtual LightOrderDetailViewModel BuildLightOrderDetailViewModel(OrderItem rawOrder, GetOrderHistoryViewModelParam param) { var lightOrderVm = new LightOrderDetailViewModel(); var orderInfo = ViewModelMapper.MapTo <OrderDetailInfoViewModel>(rawOrder, param.CultureInfo); var orderId = Guid.Parse(rawOrder.Id); orderInfo.OrderStatus = GetOrderStatusDisplayName(rawOrder, param); orderInfo.OrderStatusRaw = rawOrder.OrderStatus; orderInfo.IsOrderEditable = param.OrderEditingInfos != null && param.OrderEditingInfos.ContainsKey(orderId) && param.OrderEditingInfos[orderId]; CancellationStatus orderCancellationStatusInfo = null; if (param.OrderCancellationStatusInfos != null && param.OrderCancellationStatusInfos.ContainsKey(orderId)) { orderCancellationStatusInfo = param.OrderCancellationStatusInfos[orderId]; } orderInfo.IsOrderCancelable = orderCancellationStatusInfo?.CanCancel ?? false; orderInfo.IsOrderPendingCancellation = orderCancellationStatusInfo?.CancellationPending ?? false; orderInfo.IsBeingEdited = param.CurrentlyEditedOrderId == orderId; orderInfo.HasOwnDraft = HasOwnDraft(param, orderId); var orderDetailUrl = UrlFormatter.AppendQueryString(param.OrderDetailBaseUrl, new NameValueCollection { { "id", rawOrder.OrderNumber } }); lightOrderVm.Url = orderDetailUrl; lightOrderVm.OrderInfos = orderInfo; lightOrderVm.ShipmentSummaries = new List <OrderShipmentSummaryViewModel>(); if (rawOrder.ShipmentItems.Count > 0) { foreach (var shipment in rawOrder.ShipmentItems) { var shipmentSummary = new OrderShipmentSummaryViewModel(); if (shipment.FulfillmentScheduledTimeBeginDate.HasValue) { shipmentSummary.ScheduledShipDate = LocalizationHelper.LocalizedFormat("General", "ShortDateFormat", shipment.FulfillmentScheduledTimeBeginDate.Value, param.CultureInfo); } if (param.ShipmentsTrackingInfos != null && param.ShipmentsTrackingInfos.ContainsKey(shipment.Id)) { var trackingInfo = param.ShipmentsTrackingInfos[shipment.Id]; shipmentSummary.TrackingInfo = trackingInfo; } lightOrderVm.ShipmentSummaries.Add(shipmentSummary); } } return(lightOrderVm); }
protected virtual bool HasOwnDraft(GetOrderHistoryViewModelParam param, Guid orderId) { var orderDraft = param.OrderCartDrafts?.FirstOrDefault(d => Guid.Parse(d.Name) == orderId); if (orderDraft == null) { return(false); } return(orderDraft.IsCurrentApplicationOwner()); }
public void WHEN_orderResult_has_one_order_SHOULD_return_view_model() { //Arrange var factory = _container.CreateInstance <OrderHistoryViewModelFactory>(); var customerId = Guid.NewGuid().ToString(); var orderId = Guid.NewGuid().ToString(); //Act var param = new GetOrderHistoryViewModelParam { CultureInfo = new CultureInfo("en-US"), Page = 1, OrderResult = new OrderQueryResult { Results = new List <OrderItem> { new OrderItem { ShipmentItems = new List <ShipmentItem> { new ShipmentItem() }, CustomerId = customerId, Id = orderId, OrderStatus = "InProgress" } }, TotalCount = 1 }, OrderStatuses = new Dictionary <string, string> { { "InProgress", "In Progress" } }, OrderDetailBaseUrl = GetRandom.String(32), Orders = new List <Overture.ServiceModel.Orders.Order>() { new Overture.ServiceModel.Orders.Order() { CustomerId = customerId, Id = orderId, OrderStatus = "InProgress" } } }; var vm = factory.CreateViewModel(param); //Assert vm.Should().NotBeNull(); vm.Orders.Should().NotBeNull(); var orderVm = vm.Orders.FirstOrDefault(); orderVm.OrderInfos.CustomerId.ShouldBeEquivalentTo(customerId); orderVm.OrderInfos.Id.ShouldBeEquivalentTo(orderId); orderVm.OrderInfos.OrderStatus.Should().NotBeNullOrEmpty(); }
public void WHEN_orderResult_has_n_order_SHOULD_return_right_pagination(int totalOrders, int page, int?expectedPreviousPageNumber, int?expectedNextPageNumber, int expectedPageCount) { //Arrange var factory = _container.CreateInstance <OrderHistoryViewModelFactory>(); var customerId = Guid.NewGuid().ToString(); var orderId = Guid.NewGuid().ToString(); //Act var param = new GetOrderHistoryViewModelParam { CultureInfo = new CultureInfo("en-US"), Page = page, OrderResult = new OrderQueryResult { Results = new List <OrderItem> { new OrderItem { Id = orderId, ShipmentItems = new List <ShipmentItem>(), CustomerId = customerId, OrderStatus = "test" } }, TotalCount = totalOrders }, OrderStatuses = new Dictionary <string, string> { { "test", "test" } }, OrderDetailBaseUrl = GetRandom.String(32), Orders = new List <Overture.ServiceModel.Orders.Order>() { new Overture.ServiceModel.Orders.Order { Id = orderId, CustomerId = customerId, OrderStatus = "test" } } }; var vm = factory.CreateViewModel(param); //Assert vm.Should().NotBeNull(); vm.Pagination.Should().NotBeNull(); vm.Pagination.NextPage.PageNumber.ShouldBeEquivalentTo(expectedNextPageNumber); vm.Pagination.PreviousPage.PageNumber.ShouldBeEquivalentTo(expectedPreviousPageNumber); vm.Pagination.Pages.Count().ShouldBeEquivalentTo(expectedPageCount); vm.Pagination.Pages.FirstOrDefault(x => x.IsCurrentPage).PageNumber.ShouldBeEquivalentTo(page); }
/// <summary> /// Gets the OrderHistory ViewModel, containing a list of Orders. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual async Task <OrderHistoryViewModel> GetOrderHistoryViewModelAsync(GetCustomerOrdersParam param) { if (param == null) { throw new ArgumentNullException("param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo"); } if (param.CustomerId == null) { throw new ArgumentException("param.CustomerId"); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException("param.Scope"); } var orderDetailBaseUrl = OrderUrlProvider.GetOrderDetailsBaseUrl(param.CultureInfo); var orderStatuses = await LookupService.GetLookupDisplayNamesAsync(new GetLookupDisplayNamesParam { CultureInfo = param.CultureInfo, LookupType = LookupType.Order, LookupName = "OrderStatus", }).ConfigureAwait(false); var orderQueryResult = await OrderRepository.GetCustomerOrdersAsync(param).ConfigureAwait(false); var shipmentsTrackingInfos = new Dictionary <Guid, TrackingInfoViewModel>(); if (orderQueryResult != null && orderQueryResult.Results != null && param.OrderTense == OrderTense.CurrentOrders) { shipmentsTrackingInfos = await GetShipmentsTrackingInfoViewModels(orderQueryResult, param).ConfigureAwait(false); } var getOrderHistoryViewModelParam = new GetOrderHistoryViewModelParam { CultureInfo = param.CultureInfo, OrderResult = orderQueryResult, OrderStatuses = orderStatuses, Page = param.Page, OrderDetailBaseUrl = orderDetailBaseUrl, ShipmentsTrackingInfos = shipmentsTrackingInfos }; var viewModel = OrderHistoryViewModelFactory.CreateViewModel(getOrderHistoryViewModelParam); return(viewModel); }
public void WHEN_orderResult_is_null_SHOULD_return_null() { //Arrange var factory = _container.CreateInstance <OrderHistoryViewModelFactory>(); //Act var param = new GetOrderHistoryViewModelParam { CultureInfo = new CultureInfo("en-US"), Page = 1, OrderStatuses = new Dictionary <string, string>(), OrderDetailBaseUrl = GetRandom.String(32) }; var vm = factory.CreateViewModel(param); //Assert vm.Should().BeNull(); }
/// <summary> /// Creates the view model. /// </summary> /// <param name="param">The parameters required to create the view model.</param> /// <returns /> public virtual OrderHistoryViewModel CreateViewModel(GetOrderHistoryViewModelParam param) { if (param == null) { throw new ArgumentNullException("param"); } if (param.CultureInfo == null) { throw new ArgumentException("param.CultureInfo"); } if (param.OrderStatuses == null) { throw new ArgumentException("param.OrderStatuses"); } if (string.IsNullOrWhiteSpace(param.OrderDetailBaseUrl)) { throw new ArgumentException("param.OrderDetailBaseUrl"); } OrderHistoryViewModel viewModel = null; if (param.OrderResult != null && param.OrderResult.Results != null) { viewModel = new OrderHistoryViewModel { Orders = new List <LightOrderDetailViewModel>(), Pagination = BuildOrderHistoryPagination(new OrderHistoryPaginationParam { CultureInfo = param.CultureInfo, CurrentPage = param.Page, TotalNumberOfOrders = param.OrderResult.TotalCount }) }; foreach (var rawOrder in param.OrderResult.Results) { var order = BuildLightOrderDetailViewModel(rawOrder, param); viewModel.Orders.Add(order); } } return(viewModel); }
/// <summary> /// Builds the compact order view model. /// </summary> /// <param name="rawOrder">The raw order.</param> /// <param name="param"></param> /// <returns></returns> protected virtual LightOrderDetailViewModel BuildLightOrderDetailViewModel(OrderItem rawOrder, GetOrderHistoryViewModelParam param) { var lightOrderVm = new LightOrderDetailViewModel(); var orderInfo = ViewModelMapper.MapTo <OrderDetailInfoViewModel>(rawOrder, param.CultureInfo); orderInfo.OrderStatus = GetOrderStatusDisplayName(rawOrder, param); orderInfo.OrderStatusRaw = rawOrder.OrderStatus; var orderDetailUrl = UrlFormatter.AppendQueryString(param.OrderDetailBaseUrl, new NameValueCollection { { "id", rawOrder.OrderNumber } }); lightOrderVm.Url = orderDetailUrl; lightOrderVm.OrderInfos = orderInfo; lightOrderVm.ShipmentSummaries = new List <OrderShipmentSummaryViewModel>(); if (rawOrder.ShipmentItems.Count > 0) { foreach (var shipment in rawOrder.ShipmentItems) { var shipmentSummary = new OrderShipmentSummaryViewModel(); if (shipment.FulfillmentScheduledTimeBeginDate.HasValue) { shipmentSummary.ScheduledShipDate = LocalizationHelper.LocalizedFormat("General", "ShortDateFormat", shipment.FulfillmentScheduledTimeBeginDate.Value, param.CultureInfo); } if (param.ShipmentsTrackingInfos != null && param.ShipmentsTrackingInfos.ContainsKey(shipment.Id)) { var trackingInfo = param.ShipmentsTrackingInfos[shipment.Id]; shipmentSummary.TrackingInfo = trackingInfo; } lightOrderVm.ShipmentSummaries.Add(shipmentSummary); } } return(lightOrderVm); }
/// <summary> /// Gets the OrderHistory ViewModel, containing a list of Orders. /// </summary> /// <param name="param"></param> /// <returns></returns> public virtual async Task <OrderHistoryViewModel> GetOrderHistoryViewModelAsync(GetCustomerOrdersParam param) { if (param == null) { throw new ArgumentNullException(nameof(param)); } if (param.CultureInfo == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param)); } if (param.CustomerId == null) { throw new ArgumentException(GetMessageOfNull(nameof(param.CustomerId)), nameof(param)); } if (string.IsNullOrWhiteSpace(param.Scope)) { throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param)); } var orderQueryResult = await OrderRepository.GetCustomerOrdersAsync(param).ConfigureAwait(false); if (orderQueryResult == null) { return(null); } var orderDetailBaseUrl = OrderUrlProvider.GetOrderDetailsBaseUrl(param.CultureInfo); var orderStatuses = await LookupService.GetLookupDisplayNamesAsync(new GetLookupDisplayNamesParam { CultureInfo = param.CultureInfo, LookupType = LookupType.Order, LookupName = "OrderStatus", }).ConfigureAwait(false); var shipmentsTrackingInfos = new Dictionary <Guid, TrackingInfoViewModel>(); var ordersDetails = new List <Overture.ServiceModel.Orders.Order>(); var orderCartDrafts = new List <CartSummary>(); var orderEditingInfos = new Dictionary <Guid, bool>(); var orderCancellationInfos = new Dictionary <Guid, CancellationStatus>(); if (orderQueryResult.Results != null && param.OrderTense == OrderTense.CurrentOrders) { ordersDetails = await GetOrders(orderQueryResult, param).ConfigureAwait(false); orderCartDrafts = await GetOrderCartDrafts(param.Scope, param.CustomerId, param.CultureInfo).ConfigureAwait(false); orderEditingInfos = await GetOrderEditingInfos(ordersDetails).ConfigureAwait(false); orderCancellationInfos = await GetCancellationStatus(ordersDetails).ConfigureAwait(false); shipmentsTrackingInfos = GetShipmentsTrackingInfoViewModels(ordersDetails, param); } Guid.TryParse(EditingOrderProvider.GetCurrentEditingCartName(), out Guid currentlyEditingOrder); var getOrderHistoryViewModelParam = new GetOrderHistoryViewModelParam { CultureInfo = param.CultureInfo, OrderResult = orderQueryResult, OrderCartDrafts = orderCartDrafts, OrderStatuses = orderStatuses, Page = param.Page, OrderDetailBaseUrl = orderDetailBaseUrl, ShipmentsTrackingInfos = shipmentsTrackingInfos, OrderEditingInfos = orderEditingInfos, Orders = ordersDetails, OrderCancellationStatusInfos = orderCancellationInfos, CurrentlyEditedOrderId = currentlyEditingOrder }; var viewModel = OrderHistoryViewModelFactory.CreateViewModel(getOrderHistoryViewModelParam); return(viewModel); }