private static string formatAlignRawLineItem(LineItemModel lineItem) { var formatArgs = "{0}"; string lineItemAdjust = lineItem.Text; if (lineItem.Width.HasValue) { if (lineItem.Align == StringAlignment.Center) { if (lineItem.Text.Length < lineItem.Width) { lineItemAdjust = lineItem.Text.CenterString(lineItem.Width.Value); } } if (lineItem.Align == StringAlignment.Near) { formatArgs = "{0,-" + lineItem.Width.Value.ToString() + "}"; } if (lineItem.Align == StringAlignment.Far) { formatArgs = "{0," + lineItem.Width.Value.ToString() + "}"; } } var formatString = string.Format(formatArgs, lineItemAdjust); return(formatString); }
protected bool AddDiscount(OrderModel order, string lookupCode) { try { var discount = _api.Get <IEnumerable <ItemModel> >($"/merchants/{MerchantID}/items") .FirstOrDefault(x => x.ItemTypeID == (int)ItemTypeEnums.Discount && x.LookupCode == lookupCode); if (discount != null) { var amount = 0M; switch (discount.PriceTypeID) { case (int)PriceTypeEnums.Fixed: amount = discount.Price ?? 0; break; case (int)PriceTypeEnums.Variable: var lineItems = _api.Get <IEnumerable <LineItemModel> >("/lineitems").Where(x => x.OrderID == order.ID); amount = lineItems.Sum(x => x.ItemAmount) * discount.Percentage.Value; break; } var lineItem = new LineItemModel { ItemAmount = amount > 0 ? amount * -1 : amount, ItemID = discount.ID, OrderID = order.ID }; _api.Post("/lineitems", lineItem); return(true); } } catch { } return(false); }
public static LineItemDto ToLineItemsDTO(this LineItemModel lineItem) { var isValid = Enum.TryParse(typeof(ProductType), lineItem.ProductType, out object productType); if (!isValid) { throw new OrderException($"Product type {lineItem.ProductType} is not valid."); } var lineItemDto = new LineItemDto { ProductID = lineItem.ProductID, Category = lineItem.Category, Notes = lineItem.Notes, ProductName = lineItem.ProductName, ProductType = (ProductType)productType }; switch (lineItemDto.ProductType) { case ProductType.Website: lineItemDto.WebsiteDetails = new WebsiteDetailsDto { TemplateId = lineItem.WebsiteDetails.TemplateId, WebsiteAddressLine1 = lineItem.WebsiteDetails.WebsiteAddressLine1, WebsiteAddressLine2 = lineItem.WebsiteDetails.WebsiteAddressLine2, WebsiteBusinessName = lineItem.WebsiteDetails.WebsiteBusinessName, WebsiteCity = lineItem.WebsiteDetails.WebsiteCity, WebsiteEmail = lineItem.WebsiteDetails.WebsiteEmail, WebsiteMobile = lineItem.WebsiteDetails.WebsiteMobile, WebsitePhone = lineItem.WebsiteDetails.WebsitePhone, WebsitePostCode = lineItem.WebsiteDetails.WebsitePostCode, WebsiteState = lineItem.WebsiteDetails.WebsiteState, }; break; case ProductType.PaidSearch: lineItemDto.AdWordCampaign = new AdWordCampaignDto { CampaignName = lineItem.AdWordCampaign.CampaignName, CampaignAddressLine1 = lineItem.AdWordCampaign.CampaignAddressLine1, CampaignPostCode = lineItem.AdWordCampaign.CampaignPostCode, CampaignRadius = lineItem.AdWordCampaign.CampaignRadius, LeadPhoneNumber = lineItem.AdWordCampaign.LeadPhoneNumber, SMSPhoneNumber = lineItem.AdWordCampaign.SMSPhoneNumber, UniqueSellingPoint1 = lineItem.AdWordCampaign.UniqueSellingPoint1, UniqueSellingPoint2 = lineItem.AdWordCampaign.UniqueSellingPoint2, UniqueSellingPoint3 = lineItem.AdWordCampaign.UniqueSellingPoint3, Offer = lineItem.AdWordCampaign.Offer, DestinationURL = lineItem.AdWordCampaign.DestinationURL }; break; default: throw new OrderException($"Product type {lineItem.ProductType} is not valid."); } return(lineItemDto); }
private void AssertOrder(LineItemModel lineItem, LineItemDto lineItemDto) { Assert.Equal(lineItemDto.Category, lineItem.Category); Assert.Equal(lineItemDto.Notes, lineItem.Notes); Assert.Equal(lineItemDto.ProductName, lineItem.ProductName); Assert.Equal(lineItemDto.ProductID, lineItem.ProductID); Assert.Equal(lineItemDto.ProductType.ToString(), lineItem.ProductType); }
/// <summary> /// line item section /// </summary> public LineItems ParseLineItem(LineItemModel lineItem) { return(new LineItems() { Order = lineItem.OrderID, Product = lineItem.ProductID, Quantity = lineItem.Quantity }); }
public async Task <LineItemModel> AddAsync(LineItemModel model) { var lineItem = _mapper.Map <LineItem>(model); _unitOfWork.LineItemRepository.Add(lineItem); await _unitOfWork.SaveAsync(); return(_mapper.Map <LineItemModel>(lineItem)); }
public CustomerCartItemModel(LineItemModel lineItem, int qty) { ID = lineItem.ID; ItemAmount = lineItem.ItemAmount; ItemID = lineItem.ItemID; OrderID = lineItem.OrderID; ItemName = lineItem.ItemName; ItemMaxAllowed = lineItem.ItemMaxAllowed; CurrentQuantity = qty; }
/////////////////////////////////////////////////////////// // Event Functions /////////////////////////////////////////////////////////// private void CreditOrDebitView_CurrentChanged(object sender, EventArgs e) { ListCollectionView view = (ListCollectionView)sender; LineItemModel lineModel = (LineItemModel)view.CurrentItem; this.currentLineItem = lineModel; this.reportPropertyChangedWithName("EnvelopeLinesView"); this.reportPropertyChangedWithName("IsCurrentLineError"); this.reportPropertyChangedWithName("CurrentEnvelopeLineSum"); }
public async Task <ActionResult <LineItemModel> > Post(LineItemModel model) { try { return(Ok(await BLL.LineItems.AddAsync(model))); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public void canCalculateSalesTax() { //arrange LineItemModel lim = new LineItemModel(); lim.Quantity = 1; lim.Price = 47.5M; lim.ImportDutyRate = 5.0M; lim.SalesTaxRate = 10.0M; //assert Assert.AreEqual(7.15M, lim.calculateTaxes()); }
// LTI Outcomes reverse the relationship between Tool Consumers and Tool Providers. The Tool // Provider becomes a consumer of the Outcomes service hosted by the Tool Consumer. In this // sample, the Tool Provider and tell the Tool Consumer to save, read, and delete scores. #region Outcomes V2 (scores) /// <summary> /// Display the Outcomes V2 settings and provide buttons to exercise the three actions. /// </summary> public ActionResult Outcomes(string lineItemServiceUrl, string lineItemsServiceUrl, string contextId, string consumerKey, string consumerSecret) { var model = new LineItemModel { LineItemServiceUrl = lineItemServiceUrl, LineItemsServiceUrl = lineItemsServiceUrl, ConsumerKey = consumerKey, ConsumerSecret = consumerSecret, ContextId = contextId }; return(View(model)); }
private bool DebitsFilter(object item) { LineItemModel lineRow = (LineItemModel)item; if (lineRow.Polarity == PolarityCON.DEBIT) { return(true); } else { return(false); } }
public IActionResult AddLineItem(LineItemModel lineItem) { try { ordersService.AddToOrder(lineItem); int id = lineItem.ID; return(CreatedAtAction("AddLineItem", lineItem)); } catch (Exception) { return(BadRequest()); } }
/// <summary> /// Creates the compare model. /// </summary> /// <param name="cartHelper">The cart helper.</param> /// <returns>CompareListModel.</returns> public static CompareListModel CreateCompareModel(this CartHelper cartHelper) { var lineItemModels = new LineItemModel[0]; var items = CartHelper.CatalogClient.GetItems(cartHelper.LineItems.Select(li => li.CatalogItemId).ToArray()); if (items != null) { lineItemModels = cartHelper.LineItems.Join(items, li => li.CatalogItemId, i => i.ItemId, (li, item) => new LineItemModel(li, item, CartHelper.CatalogClient.GetItem(li.ParentCatalogItemId), cartHelper.Cart.BillingCurrency)).ToArray(); } return(new CompareListModel(lineItemModels)); }
protected bool AddLineItem(ItemModel item, OrderModel order) { if (item?.ID > 0) { var lineItem = new LineItemModel { ItemAmount = item.Price ?? 0M, ItemID = item.ID, }; lineItem.OrderID = order.ID; _api.Post("/lineitems", lineItem); return(true); } return(false); }
public async Task <LineItemModel> UpdateAsync(LineItemModel model) { var lineItem = await _unitOfWork .LineItemRepository .GetAsync(x => x.ID == model.ID); if (lineItem == null) { return(null); } _mapper.Map(model, lineItem); _unitOfWork.LineItemRepository.Update(lineItem); await _unitOfWork.SaveAsync(); return(_mapper.Map <LineItemModel>(lineItem)); }
protected bool UpdateDiscounts(OrderModel order) { try { var discounts = _api.Get <IEnumerable <ItemModel> >("/items") .Where(x => x.ItemTypeID == (int)ItemTypeEnums.Discount && x.MerchantID == MerchantID); foreach (var discount in discounts) { var lineItemDiscount = _api.Get <ItemModel>($"/items/{discount.ID}"); if (lineItemDiscount?.ID > 0) { var amount = 0M; switch (discount.PriceTypeID) { case (int)PriceTypeEnums.Fixed: //fixed amount = discount.Price ?? 0; break; case (int)PriceTypeEnums.Variable: //variable var lineItems = _api.Get <IEnumerable <LineItemModel> >("/lineitems").Where(x => x.OrderID == order.ID && x.ID != lineItemDiscount.ID); amount = lineItems.Sum(x => x.ItemAmount) * discount.Percentage ?? 0; break; } _api.Delete($"/lineitems/{lineItemDiscount.ID}"); if (amount != 0) { var lineItem = new LineItemModel { ItemAmount = amount > 0 ? amount * -1 : amount, ItemID = discount.ID, OrderID = order.ID }; _api.Post("/lineitems", lineItem); } } } return(true); } catch (Exception) { return(false); } }
private static LineItemModel ToLineItemModel(this LineItem lineItem, Address shipFrom, Address shipTo, string exemptionNo) { var line = new LineItemModel() { amount = lineItem.LineTotal, quantity = lineItem.Quantity, taxCode = lineItem.Product.xp.Tax.Code, itemCode = lineItem.ProductID, customerUsageType = null, number = lineItem.ID, addresses = ToAddressesModel(shipFrom, shipTo) }; var isResaleProduct = (bool)lineItem.Product.xp.IsResale; if (isResaleProduct && exemptionNo != null) { line.exemptionCode = exemptionNo; } return(line); }
private static LineItemModel ToLineItemModel(this LineItem lineItem, Address shipFrom, Address shipTo, string exemptionNo) { var line = new LineItemModel() { amount = lineItem.LineTotal, // Total after line-item level promotions have been applied quantity = lineItem.Quantity, taxCode = lineItem.Product.xp.Tax.Code, itemCode = lineItem.ProductID, discounted = true, // Assumption that all products are eligible for order-level promotions customerUsageType = null, number = lineItem.ID, addresses = ToAddressesModel(shipFrom, shipTo) }; var isResaleProduct = (bool)lineItem.Product.xp?.IsResale; if (isResaleProduct && exemptionNo != null) { line.exemptionCode = exemptionNo; } return(line); }
public async Task <ActionResult <LineItemModel> > Put(int id, LineItemModel model) { if (id != model.ID) { return(BadRequest()); } try { var lineItem = await BLL.LineItems.UpdateAsync(model); if (lineItem == null) { return(NotFound()); } return(Ok(lineItem)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
/// <summary> /// Map LineItemModel to LineItem /// </summary> /// <param name="lineItemModel"></param> /// <returns></returns> public static LineItem MapToLineItem(LineItemModel lineItemModel) { TypeAdapterConfig <LineItemModel, LineItem> .NewConfig(); return(lineItemModel.Adapt <LineItem>()); }
public async Task <ActionResult> Outcomes(LineItemModel model, string submit) { switch (submit) { case "Delete LineItem": var deleteLineItemResponse = await OutcomesClient.DeleteLineItem( model.LineItemServiceUrl, model.ConsumerKey, model.ConsumerSecret); model.HttpRequest = deleteLineItemResponse.HttpRequest; model.HttpResponse = deleteLineItemResponse.HttpResponse; switch (deleteLineItemResponse.StatusCode) { case HttpStatusCode.OK: model.LineItem = null; ModelState.Clear(); ViewBag.Message = "200 LineItem deleted"; break; case HttpStatusCode.Unauthorized: ViewBag.Message = "401 Not authorized"; break; case HttpStatusCode.NotFound: ViewBag.Message = "404 Not found"; break; case HttpStatusCode.InternalServerError: ViewBag.Message = "500 Internal server error"; break; default: ViewBag.Message = Convert.ToInt32(deleteLineItemResponse.StatusCode) + " " + deleteLineItemResponse.StatusCode; break; } break; case "Get LineItem": var getLineItemResponse = await OutcomesClient.GetLineItem( model.LineItemServiceUrl, model.ConsumerKey, model.ConsumerSecret); model.HttpRequest = getLineItemResponse.HttpRequest; model.HttpResponse = getLineItemResponse.HttpResponse; switch (getLineItemResponse.StatusCode) { case HttpStatusCode.OK: model.LineItem = getLineItemResponse.Outcome; ModelState.Clear(); ViewBag.Message = "200 LineItem received"; break; case HttpStatusCode.Unauthorized: ViewBag.Message = "401 Not authorized"; break; case HttpStatusCode.NotFound: ViewBag.Message = "404 Not found"; break; case HttpStatusCode.InternalServerError: ViewBag.Message = "500 Internal server error"; break; default: ViewBag.Message = Convert.ToInt32(getLineItemResponse.StatusCode) + " " + getLineItemResponse.StatusCode; break; } break; case "Get LineItems": var getLineItemsResponse = await OutcomesClient.GetLineItemPage( model.LineItemsServiceUrl, model.ConsumerKey, model.ConsumerSecret); model.HttpRequest = getLineItemsResponse.HttpRequest; model.HttpResponse = getLineItemsResponse.HttpResponse; switch (getLineItemsResponse.StatusCode) { case HttpStatusCode.OK: ViewBag.Message = "200 LineItems received"; break; case HttpStatusCode.Unauthorized: ViewBag.Message = "401 Not authorized"; break; case HttpStatusCode.NotFound: ViewBag.Message = "404 Not found"; break; case HttpStatusCode.InternalServerError: ViewBag.Message = "500 Internal server error"; break; default: ViewBag.Message = Convert.ToInt32(getLineItemsResponse.StatusCode) + " " + getLineItemsResponse.StatusCode; break; } break; case "Post LineItem": var postLineItem = new LineItem { ReportingMethod = "res:totalScore", LineItemOf = new Context { ContextId = model.ContextId }, AssignedActivity = new Activity { ActivityId = model.LineItem.AssignedActivity.ActivityId }, ScoreContraints = new NumericLimits { NormalMaximum = 100, ExtraCreditMaximum = 10, TotalMaximum = 110 } }; var postLineItemResponse = await OutcomesClient.PostLineItem( postLineItem, model.LineItemsServiceUrl, model.ConsumerKey, model.ConsumerSecret); model.HttpRequest = postLineItemResponse.HttpRequest; model.HttpResponse = postLineItemResponse.HttpResponse; switch (postLineItemResponse.StatusCode) { case HttpStatusCode.Created: model.LineItem = postLineItemResponse.Outcome; ModelState.Clear(); ViewBag.Message = "201 LineItem added"; break; case HttpStatusCode.BadRequest: ViewBag.Message = "400 Bad Request"; break; case HttpStatusCode.Unauthorized: ViewBag.Message = "401 Not authorized"; break; case HttpStatusCode.InternalServerError: ViewBag.Message = "500 Internal server error"; break; default: ViewBag.Message = Convert.ToInt32(postLineItemResponse.StatusCode) + " " + postLineItemResponse.StatusCode; break; } break; case "Put LineItem": var putLineItem = new LineItem { Id = model.LineItem.Id, ReportingMethod = "res:totalScore", LineItemOf = new Context { ContextId = model.ContextId }, AssignedActivity = new Activity { ActivityId = model.LineItem.AssignedActivity.ActivityId }, ScoreContraints = new NumericLimits { NormalMaximum = 100, ExtraCreditMaximum = 10, TotalMaximum = 110 }, Results = model.LineItem.Results }; var putLineItemResponse = await OutcomesClient.PutLineItem( putLineItem, model.LineItemsServiceUrl, model.ConsumerKey, model.ConsumerSecret); model.HttpRequest = putLineItemResponse.HttpRequest; model.HttpResponse = putLineItemResponse.HttpResponse; switch (putLineItemResponse.StatusCode) { case HttpStatusCode.OK: ViewBag.Message = "200 LineItem updated"; break; case HttpStatusCode.Unauthorized: ViewBag.Message = "401 Not authorized"; break; case HttpStatusCode.NotFound: ViewBag.Message = "404 Not found"; break; case HttpStatusCode.InternalServerError: ViewBag.Message = "500 Internal server error"; break; default: ViewBag.Message = Convert.ToInt32(putLineItemResponse.StatusCode) + " " + putLineItemResponse.StatusCode; break; } break; } return(View(model)); }
public LineItemModel AddToOrder(LineItemModel cartItem) { context.LineItems.Add(mapper.ParseLineItem(cartItem)); context.SaveChanges(); return(null); }
/// <summary> /// Converts domain model to object to be consumed by TaxjarApi.TaxForOrder /// </summary> private object OrderModelToApiParameters(OrderModel model) { if (model == null) { return(null); } int nexusAddressesCount = model.NexusAddresses?.Count ?? 0; int lineItemsCount = model.LineItems?.Count ?? 0; object[] nexusAddresses = new object[nexusAddressesCount]; object[] lineItems = new object[lineItemsCount]; for (int i = 0; i < nexusAddressesCount; i++) { LocationModel locationModel = model.NexusAddresses[i]; if (locationModel == null) { continue; } nexusAddresses[i] = new { id = locationModel.Id ?? string.Empty, country = locationModel.Country ?? string.Empty, zip = locationModel.Zip ?? string.Empty, state = locationModel.State ?? string.Empty, city = locationModel.City ?? string.Empty, street = locationModel.Street ?? string.Empty }; } for (int i = 0; i < lineItemsCount; i++) { LineItemModel lineItemModel = model.LineItems[i]; if (lineItemModel == null) { continue; } lineItems[i] = new { id = lineItemModel.Id ?? string.Empty, quantity = lineItemModel.Quantity, product_tax_code = lineItemModel.ProductTaxCode ?? string.Empty, unit_price = lineItemModel.UnitPrice, discount = lineItemModel.Discount }; } return(new { from_country = model.FromLocation.Country ?? string.Empty, from_zip = model.FromLocation.Zip ?? string.Empty, from_state = model.FromLocation.State ?? string.Empty, from_city = model.FromLocation.City ?? string.Empty, from_street = model.FromLocation.Street ?? string.Empty, to_country = model.ToLocation.Country ?? string.Empty, to_zip = model.ToLocation.Zip ?? string.Empty, to_state = model.ToLocation.State ?? string.Empty, to_city = model.ToLocation.City ?? string.Empty, to_street = model.ToLocation.Street ?? string.Empty, amount = model.Amount, shipping = model.Shipping, customer_id = model.CustomerId, nexus_addresses = nexusAddresses, line_items = lineItems }); }
public static CustomerOrderModel PrepareCustomerOrderModel(this Order order) { var priceFormatter = EngineContext.Current.Resolve <IPriceFormatter>(); var model = new CustomerOrderModel { Id = order.Id, OrderTotal = priceFormatter.FormatValue(order.GrandTotal, order.CurrencyCode), CreatedOn = order.OrderPlaced.Value, OrderStatusCode = order.StatusCode, OrderStatus = order.OrderStatus }; // To avoid customer frustration, ON HOLD will be changed to ORDER PLACED if (model.OrderStatusCode == OrderStatusCode.ON_HOLD) { var orderService = EngineContext.Current.Resolve <IOrderService>(); model.OrderStatusCode = OrderStatusCode.ORDER_PLACED; model.OrderStatus = orderService.GetOrderStatusByCode(OrderStatusCode.ORDER_PLACED); } var orderItems = order.LineItemCollection.Where(x => ValidLineStatus.VALID_LINE_STATUSES.Contains(x.StatusCode)).ToList(); foreach (var item in orderItems) { var itemModel = new LineItemModel { Name = item.Name, Option = item.Option, Quantity = item.Quantity, UnitPrice = priceFormatter.FormatValue(item.PriceInclTax * item.ExchangeRate, item.CurrencyCode), Subtotal = priceFormatter.FormatValue(item.PriceInclTax * item.Quantity * item.ExchangeRate, item.CurrencyCode) }; model.Items.Add(itemModel); } model.Totals.Subtotal = priceFormatter.FormatValue(orderItems.Select(x => (x.PriceInclTax * x.Quantity * x.ExchangeRate)).Sum(), order.CurrencyCode); model.Totals.Discount = order.DiscountAmount > 0M ? priceFormatter.FormatValue(order.DiscountAmount, order.CurrencyCode) : null; model.Totals.UsedPointsAmount = order.AllocatedPoint > 0 ? priceFormatter.FormatValue(order.AllocatedPoint / 100M * order.ExchangeRate, order.CurrencyCode) : null; model.Totals.UsedPoints = order.AllocatedPoint; model.Totals.ShippingCost = priceFormatter.FormatValue(order.ShippingCost * order.ExchangeRate, order.CurrencyCode); model.Totals.VAT = priceFormatter.FormatValue(orderItems.Select(x => ((x.PriceInclTax - x.PriceExclTax) * x.Quantity * x.ExchangeRate)).Sum(), order.CurrencyCode); model.Totals.VATMessage = order.ShippingCountry.IsEC ? "included" : "discount"; // Some orders may not have billing address if (order.Country != null) { model.Billing = new AddressModel { Name = order.BillTo, AddressLine1 = order.AddressLine1, AddressLine2 = order.AddressLine2, City = order.City, CountryName = order.Country.Name, PostCode = order.PostCode }; } if (order.ShippingCountry != null) { model.Shipping = new AddressModel { Name = order.ShipTo, AddressLine1 = order.ShippingAddressLine1, AddressLine2 = order.ShippingAddressLine2, City = order.ShippingCity, CountryName = order.ShippingCountry.Name, PostCode = order.ShippingPostCode }; } // Check if the order is valid for invoice download model.IsAllowedToDownloadInvoice = ValidOrderStatus.VALID_STATUSES.Contains(order.StatusCode); return(model); }
public void AddToOrder(LineItemModel lineItem) { dBRepo.AddToOrder(lineItem); }