/// <summary> /// Creates a <see cref="IShipment"/> without persisting it to the database. /// </summary> /// <param name="shipmentStatus"> /// The shipment status. /// </param> /// <param name="origin"> /// The origin. /// </param> /// <param name="destination"> /// The destination. /// </param> /// <param name="items"> /// The items. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> /// <returns> /// The <see cref="IShipment"/>. /// </returns> public IShipment CreateShipment(IShipmentStatus shipmentStatus, IAddress origin, IAddress destination, LineItemCollection items, bool raiseEvents = true) { Mandate.ParameterNotNull(shipmentStatus, "shipmentStatus"); Mandate.ParameterNotNull(origin, "origin"); Mandate.ParameterNotNull(destination, "destination"); Mandate.ParameterNotNull(items, "items"); // Use the visitor to filter out and validate shippable line items var visitor = new ShippableProductVisitor(); items.Accept(visitor); var lineItemCollection = new LineItemCollection(); foreach (var item in visitor.ShippableItems) { lineItemCollection.Add(item); } var shipment = new Shipment(shipmentStatus, origin, destination, lineItemCollection) { VersionKey = Guid.NewGuid() }; if (!raiseEvents) { return(shipment); } Creating.RaiseEvent(new Events.NewEventArgs <IShipment>(shipment), this); return(shipment); }
internal static IOrder ToOrder(this OrderDisplay orderDisplay, IOrder destination) { if (orderDisplay.Key != Guid.Empty) { destination.Key = orderDisplay.Key; } destination.OrderNumberPrefix = orderDisplay.OrderNumberPrefix; destination.OrderDate = orderDisplay.OrderDate; destination.OrderStatus = orderDisplay.OrderStatus.ToOrderStatus(); destination.VersionKey = orderDisplay.VersionKey; destination.Exported = orderDisplay.Exported; // TODO remove existing line items from destination not present in orderDisplay var items = destination.Items.Where(x => orderDisplay.Items.Any(display => display.Key == x.Key)); var collection = new LineItemCollection(); foreach (var item in items) { collection.Add(item); } ((Order)destination).Items = collection; return(destination); }
public static LineItemCollection Select(string WhereClause, string OrderByClause) { string Sql = string.Format("SELECT * from [lineItem] WHERE ({0}) ORDER BY {1}", WhereClause, OrderByClause); //string ConnStr = @"Server=STUDENT05;Database=prs;Trusted_Connection=True;"; SqlCommand Cmd = CreateConnection(ConnStr, Sql, "Connection didn't open"); SqlDataReader Reader = Cmd.ExecuteReader(); //if (!Reader.HasRows) { // throw new ApplicationException("Result set has no rows!"); //} LineItemCollection lineItems = new LineItemCollection(); while (Reader.Read()) { int id = Reader.GetInt32(Reader.GetOrdinal("Id")); int purchaseRequestId = Reader.GetInt32(Reader.GetOrdinal("PurchaseRequestId")); int productId = Reader.GetInt32(Reader.GetOrdinal("ProductId")); int quantity = Reader.GetInt32(Reader.GetOrdinal("Quantity")); LineItem lineItem = new LineItem(); lineItem.Id = id; lineItem.PurchaseRequestId = purchaseRequestId; lineItem.ProductId = productId; lineItem.Quantity = quantity; // get the PurchaseRequest lineItem.PurchaseRequest = PurchaseRequest.Select(lineItem.PurchaseRequestId); // get the Product lineItem.Product = Product.Select(lineItem.ProductId); lineItems.Add(lineItem); } Cmd.Connection.Close(); return(lineItems); }
/// <summary> /// The get line item collection. /// </summary> /// <param name="invoiceKey"> /// The invoice key. /// </param> /// <returns> /// The <see cref="LineItemCollection"/>. /// </returns> private LineItemCollection GetLineItemCollection(Guid invoiceKey) { var sql = new Sql(); sql.Select("*").From <InvoiceItemDto>(SqlSyntax).Where <InvoiceItemDto>(x => x.ContainerKey == invoiceKey); var dtos = Database.Fetch <InvoiceItemDto>(sql); var factory = new LineItemFactory(); var collection = new LineItemCollection(); foreach (var dto in dtos) { collection.Add(factory.BuildEntity(dto)); } return(collection); }
/// <summary> /// Creates an instance of <see cref="LineItemCollection"/> from a serialized collection in the ExtendedDataCollection /// </summary> /// <typeparam name="T">The type of the <see cref="ILineItem"/></typeparam> /// <param name="extendedData">The extended data collection</param> /// <returns><see cref="LineItemCollection"/></returns> public static LineItemCollection GetLineItemCollection <T>(this ExtendedDataCollection extendedData) where T : LineItemBase { if (!extendedData.ContainsKey(Constants.ExtendedDataKeys.LineItemCollection)) { return(null); } var xdoc = XDocument.Parse(extendedData.GetValue(Constants.ExtendedDataKeys.LineItemCollection)); var lineItemCollection = new LineItemCollection(); foreach (var element in xdoc.Descendants(Constants.ExtendedDataKeys.LineItem)) { var dictionary = GetLineItemXmlValues(element.ToString()); var extendData = new ExtendedDataCollection(dictionary[Constants.ExtendedDataKeys.ExtendedData]); var ctrValues = new object[] { new Guid(dictionary[Constants.ExtendedDataKeys.LineItemTfKey]), dictionary[Constants.ExtendedDataKeys.Name], dictionary[Constants.ExtendedDataKeys.Sku], int.Parse(dictionary[Constants.ExtendedDataKeys.Quantity]), decimal.Parse(dictionary[Constants.ExtendedDataKeys.Price], NumberStyles.Any, CultureInfo.InvariantCulture), new ExtendedDataCollection(dictionary[Constants.ExtendedDataKeys.ExtendedData]) }; var attempt = ActivatorHelper.CreateInstance <LineItemBase>(typeof(T).FullName, ctrValues); if (!attempt.Success) { MultiLogHelper.Error <LineItemCollection>("Failed to instantiate a LineItemCollection from ExtendedData", attempt.Exception); throw attempt.Exception; } attempt.Result.ContainerKey = new Guid(dictionary[Constants.ExtendedDataKeys.ContainerKey]); lineItemCollection.Add(attempt.Result); } return(lineItemCollection); }
/// <summary> /// Clones a shipment /// </summary> /// <param name="org"> /// The org. /// </param> /// <returns> /// The <see cref="IShipment"/>. /// </returns> /// <remarks> /// http://issues.merchello.com/youtrack/issue/M-458 /// </remarks> internal static IShipment Clone(this IShipment org) { var lineItemCollection = new LineItemCollection(); foreach (var li in org.Items) { lineItemCollection.Add(li.AsLineItemOf <OrderLineItem>()); } return(new Shipment(org.ShipmentStatus, org.GetOriginAddress(), org.GetDestinationAddress(), lineItemCollection) { ShipmentNumberPrefix = org.ShipmentNumberPrefix, ShipmentNumber = org.ShipmentNumber, ShippedDate = org.ShippedDate, TrackingCode = org.TrackingCode, Carrier = org.Carrier, ShipMethodKey = org.ShipMethodKey, Phone = org.Phone, Email = org.Email }); }
private LineItemCollection GetLineItemCollection(Guid itemCacheKey) { var sql = new Sql(); sql.Select("*") .From <ItemCacheItemDto>() .Where <ItemCacheItemDto>(x => x.ContainerKey == itemCacheKey); var dtos = Database.Fetch <ItemCacheItemDto>(sql); //var lineItems = _lineItemRepository.GetByContainerId(itemCacheId); var factory = new LineItemFactory(); var collection = new LineItemCollection(); foreach (var dto in dtos) { collection.Add(factory.BuildEntity(dto)); } return(collection); }
//Select public static LineItemCollection Select(string whereClause, string orderByClause) { string Sql = string.Format("SELECT * from [LineItem] WHERE {0} ORDER BY {1}", whereClause, orderByClause); string ConnStr = @"Server=STUDENT05;Database=prs;Trusted_Connection=True;"; SqlConnection Conn = new SqlConnection(ConnStr); Conn.Open(); if (Conn.State != System.Data.ConnectionState.Open) { throw new ApplicationException("Connection didn't open"); } SqlCommand Cmd = new SqlCommand(Sql, Conn); SqlDataReader Reader = Cmd.ExecuteReader(); if (!Reader.HasRows) { throw new ApplicationException("Result set has no rows!"); } LineItemCollection lineitems = new LineItemCollection(); while (Reader.Read()) { int id = Reader.GetInt32(Reader.GetOrdinal("id")); int purchaseRequestId = Reader.GetInt32(Reader.GetOrdinal("PurchaseRequestId")); int productId = Reader.GetInt32(Reader.GetOrdinal("ProductID")); int quantity = Reader.GetInt32(Reader.GetOrdinal("Quantity")); LineItem lineitem = new LineItem(); lineitem.Id = id; lineitem.PurchaseRequestID = purchaseRequestId; lineitem.ProductID = productId; lineitem.quantity = quantity; lineitems.Add(lineitem); } return(lineitems); }
internal static IOrder ToOrder(this OrderDisplay orderDisplay, IOrder destination) { if (orderDisplay.Key != Guid.Empty) destination.Key = orderDisplay.Key; destination.OrderNumberPrefix = orderDisplay.OrderNumberPrefix; destination.OrderDate = orderDisplay.OrderDate; destination.OrderStatus = orderDisplay.OrderStatus.ToOrderStatus(); destination.VersionKey = orderDisplay.VersionKey; destination.Exported = orderDisplay.Exported; // TODO remove existing line items from destination not present in orderDisplay var items = destination.Items.Where(x => orderDisplay.Items.Any(display => display.Key == x.Key)); var collection = new LineItemCollection(); foreach (var item in items) { collection.Add(item); } ((Order)destination).Items = collection; return destination; }
/// <summary> /// Creates a <see cref="IShipment"/> without persisting it to the database. /// </summary> /// <param name="shipmentStatus"> /// The shipment status. /// </param> /// <param name="origin"> /// The origin. /// </param> /// <param name="destination"> /// The destination. /// </param> /// <param name="items"> /// The items. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> /// <returns> /// The <see cref="IShipment"/>. /// </returns> public IShipment CreateShipment(IShipmentStatus shipmentStatus, IAddress origin, IAddress destination, LineItemCollection items, bool raiseEvents = true) { Mandate.ParameterNotNull(shipmentStatus, "shipmentStatus"); Mandate.ParameterNotNull(origin, "origin"); Mandate.ParameterNotNull(destination, "destination"); Mandate.ParameterNotNull(items, "items"); // Use the visitor to filter out and validate shippable line items var visitor = new ShippableProductVisitor(); items.Accept(visitor); var lineItemCollection = new LineItemCollection(); foreach (var item in visitor.ShippableItems) { lineItemCollection.Add(item); } var shipment = new Shipment(shipmentStatus, origin, destination, lineItemCollection) { VersionKey = Guid.NewGuid() }; if (!raiseEvents) { return shipment; } Creating.RaiseEvent(new Events.NewEventArgs<IShipment>(shipment), this); return shipment; }
/// <summary> /// Clones a shipment /// </summary> /// <param name="org"> /// The org. /// </param> /// <returns> /// The <see cref="IShipment"/>. /// </returns> /// <remarks> /// http://issues.merchello.com/youtrack/issue/M-458 /// </remarks> internal static IShipment Clone(this IShipment org) { var lineItemCollection = new LineItemCollection(); foreach (var li in org.Items) { lineItemCollection.Add(li.AsLineItemOf<OrderLineItem>()); } return new Shipment(org.ShipmentStatus, org.GetOriginAddress(), org.GetDestinationAddress(), lineItemCollection) { ShipmentNumberPrefix = org.ShipmentNumberPrefix, ShipmentNumber = org.ShipmentNumber, ShippedDate = org.ShippedDate, TrackingCode = org.TrackingCode, Carrier = org.Carrier, ShipMethodKey = org.ShipMethodKey, Phone = org.Phone, Email = org.Email }; }