本文整理汇总了C#中Order.AddLineItem方法的典型用法代码示例。如果您正苦于以下问题:C# Order.AddLineItem方法的具体用法?C# Order.AddLineItem怎么用?C# Order.AddLineItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Order
的用法示例。
在下文中一共展示了Order.AddLineItem方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Duplicate
/// <summary>
/// Duplicates the given order info a new order, one that doesn't include the splits, approvals, or history of the given order
/// </summary>
/// <remarks>
/// //TODO: should a duplicate order retain the same splits?
/// //TODO: should approvals/create events be called automatically?
/// </remarks>
public Order Duplicate(Order order)
{
var newOrder = new Order
{
Address = order.Address,
AllowBackorder = order.AllowBackorder,
DateNeeded = order.DateNeeded,
EstimatedTax = order.EstimatedTax,
OrderType = order.OrderType,
Organization = order.Organization,
ReferenceNumber = order.ReferenceNumber,
ShippingAmount = order.ShippingAmount,
ShippingType = order.ShippingType,
Vendor = order.Vendor,
Workgroup = order.Workgroup
};
//Now add in the line items
foreach (var lineItem in order.LineItems)
{
var newLineItem = new LineItem
{
CatalogNumber = lineItem.CatalogNumber,
Commodity = lineItem.Commodity,
Description = lineItem.Description,
Notes = lineItem.Notes,
Quantity = lineItem.Quantity,
Unit = lineItem.Unit,
UnitPrice = lineItem.UnitPrice,
Url = lineItem.Url
};
newOrder.AddLineItem(newLineItem);
}
return newOrder;
}
示例2: Example
public void Example()
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Order, OrderDto>();
cfg.CreateMap<OrderLine, OrderLineDto>();
});
var order = new Order();
order.AddLineItem(new OrderLine { Quantity = 5 });
order.AddLineItem(new OrderLine { Quantity = 15 });
order.AddLineItem(new OrderLine { Quantity = 25 });
var orderDto = config.CreateMapper().Map<Order, OrderDto>(order);
orderDto.LineItems.Length.ShouldEqual(3);
orderDto.LineItems[0].Quantity.ShouldEqual(5);
orderDto.LineItems[1].Quantity.ShouldEqual(15);
orderDto.LineItems[2].Quantity.ShouldEqual(25);
}
示例3: Example
public void Example()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<Order, OrderDto>();
cfg.CreateMap<OrderLine, OrderLineDto>();
});
var order = new Order();
order.AddLineItem(new OrderLine { Quantity = 5 });
order.AddLineItem(new OrderLine { Quantity = 15 });
order.AddLineItem(new OrderLine { Quantity = 25 });
var orderDto = Mapper.Map<Order, OrderDto>(order);
orderDto.LineItems.Length.ShouldEqual(3);
orderDto.LineItems[0].Quantity.ShouldEqual(5);
orderDto.LineItems[1].Quantity.ShouldEqual(15);
orderDto.LineItems[2].Quantity.ShouldEqual(25);
}
示例4: GenderateRandomOrder
/// <summary>
/// Generate Random orders
/// </summary>
/// <param name="users">List of users to select from</param>
/// <param name="vendors">List of vendors to select from</param>
/// <param name="statusCode">Status code to set the order approved through</param>
/// <returns></returns>
private static Order GenderateRandomOrder(Workgroup workgroup, OrderStatusCode statusCode, ISession session, WorkgroupPermission user = null, WorkgroupPermission excludeUser = null )
{
var randomizedPerms = workgroup.Permissions.Select(a => new {Permission = a, Key = Guid.NewGuid()});
var requester = user ?? (excludeUser == null ?
randomizedPerms.Where(a=>a.Permission.Role.Id == "RQ").OrderBy(a => a.Key).Select(a => a.Permission).FirstOrDefault()
: randomizedPerms.Where(a=>a.Permission.Role.Id == "RQ" && a.Permission != excludeUser).OrderBy(a => a.Key).Select(a => a.Permission).FirstOrDefault());
var approver = randomizedPerms.Where(a => a.Permission.Role.Id == "AP" && a.Permission.User.Id !="zoidberg").OrderBy(a => a.Key).Select(a => a.Permission).FirstOrDefault();
var conditionalApprover = session.Load<User>("zoidberg"); //workgroup.Permissions.Where(a => a.User.Id == "zoidberg").FirstOrDefault();
var accountmgr = randomizedPerms.Where(a => a.Permission.Role.Id == "AM").OrderBy(a => a.Key).Select(a => a.Permission).FirstOrDefault();
var purchaser = randomizedPerms.Where(a => a.Permission.Role.Id == "PR").OrderBy(a => a.Key).Select(a => a.Permission).FirstOrDefault();
var order = new Order()
{
Justification = _justifications.Skip(_random.Next() % 5).Take(1).FirstOrDefault(),
OrderType = session.Load<OrderType>("OR"),
Workgroup = workgroup,
Organization = workgroup.PrimaryOrganization,
Vendor = workgroup.Vendors.Skip(_random.Next() % workgroup.Vendors.Count).Take(1).FirstOrDefault(),
Address = workgroup.Addresses.Skip(_random.Next() % workgroup.Addresses.Count).Take(1).FirstOrDefault(),
ShippingType = session.QueryOver<ShippingType>().Skip(_random.Next() % 3).Take(1).SingleOrDefault(),
DeliverTo = "Mr. Smith",
DateNeeded = DateTime.Now.AddDays(_random.Next() % 30),
AllowBackorder = _random.Next() % 2 == 1,
EstimatedTax = 8.89m,
CreatedBy = requester.User,
StatusCode = statusCode
};
order.GenerateRequestNumber();
// add the tracking
order.AddApproval(new Approval() { StatusCode = session.Load<OrderStatusCode>("RQ"), Completed = true, User = requester.User });
order.AddApproval(new Approval() { StatusCode = session.Load<OrderStatusCode>("AP"), Completed = statusCode.Level > 2 , User = approver.User });
order.AddApproval(new Approval() { StatusCode = session.Load<OrderStatusCode>("AM"), Completed = statusCode.Level > 3 , User = accountmgr.User });
order.AddApproval(new Approval() { StatusCode = session.Load<OrderStatusCode>("PR"), Completed = statusCode.Level > 4 , User = purchaser.User });
// add the approvals
var daysBack = ((-1)*(_random.Next()%10)) - 10;
order.AddTracking(new OrderTracking() { User = requester.User, DateCreated = DateTime.Now.AddDays(daysBack), Description = "Order submitted by " + requester.User.FullName, StatusCode = session.Load<OrderStatusCode>("RQ") });
if (statusCode.Level > 2)
{
order.AddTracking(new OrderTracking() { User = approver.User, DateCreated = DateTime.Now.AddDays(daysBack + 1), Description = "Order reviewed by " + approver.User.FullName, StatusCode = session.Load<OrderStatusCode>("AP") });
}
if (statusCode.Level > 3)
{
order.AddTracking(new OrderTracking() { User = accountmgr.User, DateCreated = DateTime.Now.AddDays(daysBack + 3), Description = "Order reviewed by " + accountmgr.User.FullName, StatusCode = session.Load<OrderStatusCode>("AM") });
}
if (statusCode.Level > 4)
{
order.AddTracking(new OrderTracking() { User = purchaser.User, DateCreated = DateTime.Now.AddDays(daysBack + (_random.Next() % 4)+3), Description = "Order reviewed by " + purchaser.User.FullName, StatusCode = session.Load<OrderStatusCode>("PR") });
order.AddTracking(new OrderTracking() { User = purchaser.User, DateCreated = DateTime.Now.AddDays(daysBack + (_random.Next() % 4)+8), Description = "Order marked complete by " + purchaser.User.FullName, StatusCode = session.Load<OrderStatusCode>("CN") });
}
// add the conditional stuff if we feel like it
if (_random.Next() % 2 == 1)
{
order.AddApproval(new Approval() { StatusCode = session.Load<OrderStatusCode>("CA"), Completed = statusCode.Level > 2 , User = conditionalApprover });
if (statusCode.Level > 2)
{
order.AddTracking(new OrderTracking() { User = conditionalApprover, DateCreated = DateTime.Now.AddDays(daysBack + 2), Description = "Order reviewed by " + conditionalApprover.FullName, StatusCode = session.Load<OrderStatusCode>("AP") });
}
}
// add the line items
var numLineItems = (_random.Next()%5) + 1; // minimum of 1 line item
for (var i = 0; i < numLineItems; i++)
{
var item = _items.Skip(_random.Next()%_items.Count()).Take(1).FirstOrDefault();
order.AddLineItem(new LineItem() { Quantity = _random.Next() % 10, UnitPrice = item.Value + (item.Value * ((_random.Next() % 10)+1 / 10)), Unit = "each", Description = item.Key });
}
// account information
var splitType = _random.Next()%2;
if (splitType == 1) {
var numSplits = _random.Next()%2;
var skip = _random.Next()%18;
var accounts = session.QueryOver<Account>().Skip(skip+numSplits>=18 ? 18-numSplits : skip).Take(numSplits);
foreach (var act in accounts.List())
{
order.AddSplit(new Split(){Account = act.Id, Amount = order.Total()/numSplits});
}
}
// set shipping
//.........这里部分代码省略.........
示例5: BindOrderModel
//.........这里部分代码省略.........
EndUser = model.Restricted.Users,
StorageSite = model.Restricted.StorageSite,
Use = model.Restricted.Use,
PharmaceuticalGrade = model.Restricted.PharmaceuticalGrade
};
order.SetAuthorizationInfo(restricted);
}
else
{
order.ClearAuthorizationInfo();
}
if (includeLineItemsAndSplits)
{
_bugTrackingService.CheckForClearedOutSubAccounts(order, model.Splits, model);
decimal number;
order.EstimatedTax = decimal.TryParse(model.Tax != null ? model.Tax.TrimEnd('%') : null, out number) ? number : order.EstimatedTax;
order.ShippingAmount = decimal.TryParse(model.Shipping != null ? model.Shipping.TrimStart('$') : null, out number) ? number : order.ShippingAmount;
order.FreightAmount = decimal.TryParse(model.Freight != null ? model.Freight.TrimStart('$') : null, out number) ? number : order.FreightAmount;
order.LineItems.Clear(); //replace line items and splits
order.Splits.Clear();
//Add in line items
foreach (var lineItem in model.Items)
{
if (lineItem.IsValid())
{
Commodity commodity = null;
if (!string.IsNullOrWhiteSpace(lineItem.CommodityCode))
{
commodity = _repositoryFactory.CommodityRepository.Queryable.SingleOrDefault(a => a.Id == lineItem.CommodityCode && a.IsActive);
}
//TODO: could use automapper later, but need to do validation
var orderLineItem = new LineItem
{
CatalogNumber = lineItem.CatalogNumber,
Commodity = commodity,
Description = lineItem.Description,
Notes = lineItem.Notes,
Quantity = decimal.Parse(lineItem.Quantity),
Unit = lineItem.Units,//TODO: shouldn't this link to UOM?
UnitPrice = decimal.Parse(lineItem.Price),
Url = lineItem.Url
};
order.AddLineItem(orderLineItem);
if (model.SplitType == OrderViewModel.SplitTypes.Line)
{
var lineItemId = lineItem.Id;
//Go through each split created for this line item
foreach (var split in model.Splits.Where(x => x.LineItemId == lineItemId))
{
if (split.IsValid())
{
order.AddSplit(new Split
{
Account = split.Account,
Amount = decimal.Parse(split.Amount),
LineItem = orderLineItem,
SubAccount = split.SubAccount,
Project = split.Project
});
}
}
}
}
}
//TODO: note that I am not checking an order split actually has valid splits, or that they add to the total.
if (model.SplitType == OrderViewModel.SplitTypes.Order)
{
foreach (var split in model.Splits)
{
if (split.IsValid())
{
order.AddSplit(new Split
{
Account = split.Account,
Amount = decimal.Parse(split.Amount),
SubAccount = split.SubAccount,
Project = split.Project
});
}
}
}
else if (model.SplitType == OrderViewModel.SplitTypes.None)
{
order.AddSplit(new Split { Amount = order.Total(), Account = model.Account, SubAccount = model.SubAccount, Project = model.Project }); //Order with "no" splits get one split for the full amount
}
order.TotalFromDb = order.Total();
order.LineItemSummary = order.GenerateLineItemSummary();
}
}
示例6: ProcessOrder
public void ProcessOrder(List<OrderViewModel> orderViewModelList)
{
ValidationResultInfo vri = orderViewModelList.BasicValidation();
foreach (OrderViewModel ovm in orderViewModelList)
{
Order order = new Order(Guid.NewGuid());
// Order ord = _documentRepository.GetAll().OfType<Order>().FirstOrDefault(n => n.DocumentReference == ovm.documentReference);
// if (ord == null)
if (IfExistsOrderReference(ovm.documentReference) == false)
{
if (ovm.distributorCode != null || ovm.salesManCode != null || ovm.outletCode != null)
{
var costCentreList = _costCentreRepository.GetAll().Where(p => p.CostCentreCode != null).ToList();
Distributor distributor = costCentreList.Where(n => n.CostCentreCode.ToLower() == ovm.distributorCode.ToString().ToLower()).ToList().FirstOrDefault() as Distributor;
if (distributor == null)
throw new DomainValidationException(vri, "Distributor Not Found\nPlease Check Distributor Code");
Outlet outlet = costCentreList.Where(n => n.CostCentreCode == ovm.outletCode).FirstOrDefault() as Outlet;//.FirstOrDefault (n => n.CostCentreCode.ToLower() == ovm.outletCode.ToLower());
if (outlet == null)
throw new DomainValidationException(vri, "Outlet Not Found\nPlease Check Outlet Code");
ProductPricingTier pricingTier = (outlet as Outlet).OutletProductPricingTier;// _productPricingTierRepository.GetAll().FirstOrDefault(s=>s.);
VATClass vatClass = (outlet as Outlet).VatClass;// _vatClassRepository.GetAll().First();
DistributorSalesman salesman = costCentreList.Where(n => n.CostCentreCode == ovm.salesManCode).FirstOrDefault() as DistributorSalesman;
if (salesman == null)
throw new DomainValidationException(vri, "Salesman not found\nPlease Check DistributorSalesman Code");
User docIssuerUser = _userRepository.GetAll().FirstOrDefault(n => n.CostCentre == salesman.Id);
if (docIssuerUser == null)
throw new DomainValidationException(vri, "User not found\nPlease Check DistributorSalesman Code");
// order = new Order(Guid.NewGuid(),true,ovm.documentReference,salesman,DateTime.Now,outlet,0,docIssuerUser,DateTime.Now,outlet,DocumentStatus.Confirmed,OrderType.OutletToDistributor);// _documentFactory.CreateDocument(Guid.NewGuid(), DocumentType.Order, outlet, distributor, docIssuerUser, Guid.NewGuid().ToString()) as Order;
order = new Order(Guid.NewGuid(), true, ovm.documentReference, outlet, DateTime.Now, salesman, Guid.Empty, docIssuerUser, DateTime.Now, distributor, DocumentStatus.Confirmed, OrderType.OutletToDistributor, 0);
foreach (OrderViewModel.OrderLineItemViewModel orderLineItemsViewModel in ovm.orderViewModelLineItemVm)
{
_summarizeProduct.ClearBuffer();
Product product = _productRepository.GetAll().FirstOrDefault(n => n.ProductCode.ToLower() == orderLineItemsViewModel.productCode.ToLower());
if (product == null)
throw new DomainValidationException(vri, "Product not found");
SummarizeProduct(product.Id, orderLineItemsViewModel.quantity, true, false);
List<PackagingSummary> summary = _summarizeProduct.GetProductSummary();
foreach (PackagingSummary item in summary)
{
var unitpricediscount = _discountProcessorService.GetUnitPrice(item.Product.Id, outlet.Id);
var vat = _discountProcessorService.GetVATRate(item.Product, outlet);
order.AddLineItem(new OrderLineItem(Guid.NewGuid())
{
Product = _productRepository.GetById(item.Product.Id),
//Description = ovm.Description,
LineItemSequenceNo = 1,
Qty = item.Quantity,// orderLineItemsViewModel.quantity,
LineItemVatValue = vat * unitpricediscount.UnitPrice,//vatClass != null ? vatClass.CurrentRate : 0,// orderLineItemsViewModel.LineItemVatTotal,
Value = unitpricediscount.UnitPrice,//pricingTier!=null?item.Product.ProductPrice(pricingTier):0,// orderLineItemsViewModel.LineItemTotal,
ProductDiscount = unitpricediscount.Discount,
LineItemType = (OrderLineItemType)Enum.Parse(typeof(OrderLineItemType), orderLineItemsViewModel.LineItemType)
});
}
}
//var orderitems = order.LineItems;
//foreach (var item in orderitems)
//{
// List<ProductAsDiscount> productAsDiscounts = _discountProcessorService.GetFOCCertainProduct(item.Product.Id, item.Qty);
// if(productAsDiscounts!=null&& productAsDiscounts.Count>0)
// {
// var discount = productAsDiscounts.FirstOrDefault();
// order._SetLineItems( AddLineItem(order.LineItems, discount.ProductId, discount.Quantity, 0, 0, 0, OrderLineItemType.Discount, discount.DiscountType));
// }
//}
//decimal amount = order.LineItems.Sum(p => (p.Qty*(p.Value + p.LineItemVatValue)));
//ProductAsDiscount productAsDiscount = _discountProcessorService.GetFOCCertainValue(amount);
// order._SetLineItems( AddLineItem(order.LineItems, productAsDiscount.ProductId, productAsDiscount.Quantity, 0, 0, 0, OrderLineItemType.Discount, productAsDiscount.DiscountType));
SubmitOrder(order);
_summarizeProduct.ClearBuffer();
}
}
else
{
Unproc.Add(ovm);
}
}
}