コード例 #1
0
		private void RemoveLineItemFromShipment(Shipment shipment, string lineItemId)
		{
			var links = shipment.ShipmentItems.Where(link => link.LineItemId == lineItemId).ToList();

			foreach (var link in links)
			{
				shipment.ShipmentItems.Remove(link);
			}
		}
コード例 #2
0
		private void SplitForm(OrderForm form)
		{
			foreach (var item in form.LineItems)
			{
				Shipment itemShipment = null;

				// Find appropriate shipment for item
				foreach (var shipment in form.Shipments)
				{
					if (shipment.ShippingMethodId == item.ShippingMethodId
						&& string.CompareOrdinal(shipment.ShippingAddressId, item.ShippingAddressId) == 0
						&& string.Compare(shipment.FulfillmentCenterId, item.FulfillmentCenterId, StringComparison.OrdinalIgnoreCase) == 0)
					{
						// we found out match, exit
						itemShipment = shipment;
						//break;
					}
					else
					{
						// if shipment contains current LineItem, remove it from the shipment
						RemoveLineItemFromShipment(shipment, item.LineItemId);
					}
				}

				// did we find any shipment?
				if (itemShipment == null)
				{
					itemShipment = new Shipment
						{
							ShippingAddressId = item.ShippingAddressId,
							ShippingMethodId = item.ShippingMethodId,
							ShippingMethodName = item.ShippingMethodName,
							FulfillmentCenterId = item.FulfillmentCenterId,
							OrderForm = form
						};
					form.Shipments.Add(itemShipment);
				}

				// Add item to the shipment
				//if (item.LineItemId == 0)
				//    throw new ArgumentNullException("LineItemId = 0");

				RemoveLineItemFromShipment(itemShipment, item.LineItemId);

				var link = new ShipmentItem
					{
						LineItemId = item.LineItemId,
						LineItem = item,
						Quantity = item.Quantity,
						ShipmentId = itemShipment.ShipmentId
					};
				itemShipment.ShipmentItems.Add(link);
			}
		}
コード例 #3
0
        public Shipment(model.Shipment item = null)
        {
            if (item != null)
            {
                this.InjectFrom(item);

                var propInfo = item.GetType().FindPropertiesWithAttribute(typeof(KeyAttribute)).First();
                ShipmentId = propInfo.GetValue(item) as string ?? Guid.NewGuid().ToString();

                Address = item.OrderForm != null?item.OrderForm.OrderGroup.OrderAddresses.Where(address => address.Name == "Shipping").FirstOrDefault().ToString() : string.Empty;

                Customer      = item.OrderForm != null ? item.OrderForm.OrderGroup.CustomerName : string.Empty;
                ShipmentItems = new ObservableCollection <ShipmentItem>();
                item.ShipmentItems.ToList().ForEach(shipItem => this.ShipmentItems.Add(new ShipmentItem(shipItem)));
            }
        }
コード例 #4
0
		public ShipmentViewModel(OrderClient client, IViewModelsFactory<ISplitShipmentViewModel> splitVmFactory, IViewModelsFactory<ILineItemAddViewModel> wizardLineItemVmFactory, IViewModelsFactory<ILineItemViewModel> lineItemVmFactory, OrderViewModel orderViewModel, Shipment shipmentItem, IOrderEntityFactory entityFactory, IRepositoryFactory<IPricelistRepository> repositoryFactory, PriceListClient priceListClient)
		{
			_orderClient = client;
			ParentViewModel = orderViewModel;
			_currentOrder = orderViewModel._innerModel;
			CurrentShipment = shipmentItem;
			_entityFactory = entityFactory;
			_repositoryFactory = repositoryFactory;
			_priceListClient = priceListClient;
			_lineItemVmFactory = lineItemVmFactory;
			_wizardLineItemVmFactory = wizardLineItemVmFactory;
			_splitVmFactory = splitVmFactory;

			CommonShipmentConfirmRequest = orderViewModel.CommonOrderCommandConfirmRequest;

			ReleaseShipmentCommand = new DelegateCommand(RaiseReleaseShipmentInteractionRequest, () => CurrentShipment.IsReleaseable(_currentOrder.InnerItem, client));
			CompleteShipmentCommand = new DelegateCommand(RaiseCompleteShipmentInteractionRequest, () => CurrentShipment.IsCompletable(_currentOrder.InnerItem, client));
			CancelShipmentCommand = new DelegateCommand(RaiseCancelShipmentInteractionRequest, () => CurrentShipment.IsCancellable(_currentOrder.InnerItem, client));
			AddLineItemCommand = new DelegateCommand(RaiseAddLineItemInteractionRequest, () => CurrentShipment.IsModifyable(_currentOrder.InnerItem));
			MoveLineItemCommand = new DelegateCommand<ShipmentItem>(RaiseMoveLineItemInteractionRequest, x => x != null && CurrentShipment.IsModifyable(_currentOrder.InnerItem));
			RemoveLineItemCommand = new DelegateCommand<ShipmentItem>(RaiseRemoveLineItemInteractionRequest, x => x != null && CurrentShipment.IsModifyable(_currentOrder.InnerItem));
			ViewLineItemDetailsCommand = new DelegateCommand<object>(RaiseViewLineItemDetailsInteractionRequest, x => x != null);
		}
コード例 #5
0
		public TestOrderBuilder WithShipmentCount(int count, decimal cost)
		{
			for (var i = 0; i < count; i++)
			{
				var shipment = new Shipment
					{
						ShippingMethodName = "Any localized test text",
						ShippingAddressId = _order.OrderAddresses[0].OrderAddressId,
						ShippingCost = 0m,
						Subtotal = cost,
						ShippingMethodId = "FreeShipping"
					};

				_order.OrderForms[0].Shipments.Add(shipment);
			}

			return this;
		}
コード例 #6
0
		private static decimal CalculateShipmentItemSubtotal(OrderForm form, Shipment shipment)
		{
			var retVal = (from shipItem in shipment.ShipmentItems where shipItem.Quantity > 0 
						  from lineItem in form.LineItems where lineItem.LineItemId == shipItem.LineItemId 
						  select lineItem.ExtendedPrice/lineItem.Quantity*shipItem.Quantity).Sum();

			return Math.Floor(retVal * 100) * 0.01m;
		}
コード例 #7
0
		private void RaiseRemoveLineItemInteractionRequest(ShipmentItem removingItem)
		{
			var itemVM = _lineItemVmFactory.GetViewModelInstance();
			itemVM.Initialize(removingItem);

			CommonShipmentConfirmRequest.Raise(
				new ConditionalConfirmation { Title = "Item removal details", Content = itemVM },
				(x) =>
				{
					if (x.Confirmed)
					{
						// removing is moving item to fake shipment
						var fakeShipment = new Shipment { OrderForm = CurrentShipment.OrderForm };
						_currentOrder.MoveShippingItem(removingItem, itemVM.Quantity, fakeShipment, CurrentShipment);

						// update LineItem Quantity or remove it completely
						var lineItem = removingItem.LineItem;
						if (lineItem.Quantity > itemVM.Quantity)
						{
							lineItem.Quantity -= itemVM.Quantity;
						}
						else
						{
							_currentOrder.OrderForms[0].LineItems.Remove(lineItem);
						}

						ParentViewModel.Recalculate();
					}
				});
		}
コード例 #8
0
		public void MoveShippingItem(ShipmentItem item, decimal quantity, Shipment targetShipment, Shipment sourceShipment)
		{
			if (item == null)
			{
				throw new ArgumentNullException("item");
			}
			if (targetShipment == null)
			{
				throw new ArgumentNullException("targetShipment");
			}

			// prevent removing last Shipment
			if (item.Quantity == quantity
				&& sourceShipment.ShipmentItems.Count == 1
				&& _innerItem.OrderForms[0].Shipments.Count == 1)
			{
				throw new OperationCanceledException("Can't remove last item. Update Shipment instead");
			}

			item.Quantity -= quantity;
			if (item.Quantity <= 0)
			{
				// remove empty ShipmentItem, Shipment
				sourceShipment.ShipmentItems.Remove(item);

				if (sourceShipment.ShipmentItems.Count == 0)
				{
					_innerItem.OrderForms[0].Shipments.Remove(sourceShipment);
				}
			}

			var targetShipmentItem = targetShipment.ShipmentItems.FirstOrDefault(x => x.LineItemId == item.LineItemId);
			if (targetShipmentItem == null)
			{
				targetShipmentItem = _entityFactory.CreateEntityForType(typeof(ShipmentItem)) as ShipmentItem;
				targetShipmentItem.LineItemId = item.LineItemId;
				targetShipmentItem.LineItem = item.LineItem;
				targetShipmentItem.ShipmentId = targetShipment.ShipmentId;
				//targetShipmentItem.Shipment = targetShipment;
				targetShipment.ShipmentItems.Add(targetShipmentItem);
			}

			targetShipmentItem.Quantity += quantity;
		}
コード例 #9
0
		public bool CanChangeStatus(Shipment shipment, string newStatus)
		{
			return CanChangeStatus(shipment.Status, newStatus, _stateController.ShipmentStateMachine);
		}
コード例 #10
0
		//[RepositoryTheory(Skip = "One or both of the ends of the relationship is in the added state.")]
		/// <summary>
		/// problem while creating the second ShipmentItem in a new Shipment.
		/// </summary>
		public void Can_create_shipment_with_2shipmentitems()
		{
			var order = TestOrderBuilder.BuildOrder()
				.WithAddresess()
				.WithShipment()
				.WithLineItemsCount(2).GetOrder();

			var repository = GetRepository();
			repository.Add(order);
			repository.UnitOfWork.Commit();

			RefreshRepository(ref repository);
			order = repository.Orders.ExpandAll()
				.Where(x => x.OrderGroupId == order.OrderGroupId)
				.ExpandAll()
				.Expand("RmaRequests/RmaReturnItems/RmaLineItems/LineItem")
				.Expand("RmaRequests/Order")
				.Expand("OrderForms/OrderGroup")
				.Expand("OrderForms/Shipments/ShipmentItems/LineItem")
				.SingleOrDefault();

			//adding new Shipment
			var targetShipment = new Shipment();

			//adding new ShipmentItem 1
			var movingShipmentItem = order.OrderForms[0].Shipments[0].ShipmentItems[0];
			movingShipmentItem.Quantity--;

			var targetShipmentItem = new ShipmentItem();
			targetShipmentItem.Quantity = 1;
			targetShipmentItem.LineItemId = movingShipmentItem.LineItemId;
			targetShipmentItem.LineItem = movingShipmentItem.LineItem;
			targetShipmentItem.ShipmentId = targetShipment.ShipmentId;
			targetShipment.ShipmentItems.Add(targetShipmentItem);

			targetShipment.ShipmentId = targetShipment.GenerateNewKey();
			targetShipment.OrderFormId = order.OrderForms[0].OrderFormId;
			order.OrderForms[0].Shipments.Add(targetShipment);

			//adding new ShipmentItem 2
			movingShipmentItem = order.OrderForms[0].Shipments[0].ShipmentItems[1];
			movingShipmentItem.Quantity--;

			targetShipmentItem = new ShipmentItem();
			targetShipmentItem.Quantity = 1;
			targetShipmentItem.LineItemId = movingShipmentItem.LineItemId;
			targetShipmentItem.LineItem = movingShipmentItem.LineItem; // commenting out this single line makes the test to pass
			targetShipmentItem.ShipmentId = targetShipment.ShipmentId;
			targetShipment.ShipmentItems.Add(targetShipmentItem);

			repository.UnitOfWork.Commit();

			RefreshRepository(ref repository);
			order = repository.Orders.ExpandAll()
				.Where(x => x.OrderGroupId == order.OrderGroupId)
				.ExpandAll()
				.Expand("RmaRequests/RmaReturnItems/RmaLineItems/LineItem")
				.Expand("RmaRequests/Order")
				.Expand("OrderForms/OrderGroup")
				.Expand("OrderForms/Shipments/ShipmentItems/LineItem")
				.SingleOrDefault();
			Assert.NotNull(order);
			Assert.Equal(2, order.OrderForms[0].Shipments.Count);
			Assert.Equal(2, order.OrderForms[0].Shipments[0].ShipmentItems.Count);
			Assert.Equal(2, order.OrderForms[0].Shipments[1].ShipmentItems.Count);
		}
コード例 #11
0
		public void Can_add_collection_item_without_parentid()
		{
			var order = TestOrderBuilder.BuildOrder().WithLineItemsCount(1).GetOrder();

			var repository = GetRepository();
			repository.Add(order);
			repository.UnitOfWork.Commit();

			order = repository.Orders.ExpandAll().FirstOrDefault();

			// adding new Shipment
			var newShipment = new Shipment();
			order.OrderForms[0].Shipments.Add(newShipment);

			repository.UnitOfWork.Commit();

			RefreshRepository(ref repository);
			order = repository.Orders.ExpandAll().FirstOrDefault();
			var savedShipment = order.OrderForms[0].Shipments.FirstOrDefault(x => x.ShipmentId == newShipment.ShipmentId);

			Assert.NotNull(savedShipment);
			Assert.Equal(order.OrderForms[0].OrderFormId, savedShipment.OrderFormId);
		}
コード例 #12
0
		public void Can_add_collection_item_items()
		{
			var order = TestOrderBuilder.BuildOrder().WithLineItemsCount(1).GetOrder();

			var repository = GetRepository();
			repository.Add(order);
			repository.UnitOfWork.Commit();

			order = repository.Orders.ExpandAll().FirstOrDefault();

			// adding new ShipmentItem
			var item = new ShipmentItem();
			item.Quantity = 1;
			item.LineItem = order.OrderForms[0].LineItems[0];

			// adding new Shipment
			var newShipment = new Shipment();
			newShipment.ShipmentItems.Add(item);
			order.OrderForms[0].Shipments.Add(newShipment);

			repository.UnitOfWork.Commit();
		}
コード例 #13
0
		/// <summary>
		/// Gets the line items with quantities that are included in the shipment.
		/// </summary>
		/// <param name="shipment">The shipment.</param>
		/// <returns></returns>
		private IEnumerable<LineItem> GetLineItems(Shipment shipment)
		{
			var lineItems = new List<LineItem>();
			foreach (var shipItem in shipment.ShipmentItems)
			{
				if (shipItem.LineItem == null)
					continue;

				var lineItem = shipItem.LineItem.DeepClone(new OrderEntityFactory());
				lineItem.Quantity = shipItem.Quantity;
				lineItem.ExtendedPrice = lineItem.ExtendedPrice / lineItem.Quantity * shipItem.Quantity;
				lineItems.Add(lineItem);
			}

			return lineItems.ToArray();
		}