public void Save(Order order) { if (order.Id == 0) { order.Id = _random.Next(); // assign random Id if a new order } order.TotalPrice = _pricingService.GetPrice(order); _orders.Add(order.Id, order); }
public IActionResult Post([FromBody] List <InventoryModel> values) { long totalPrice = 0; var totalLoyaltyPoints = 0; var builder = new StringBuilder(); builder.AppendLine(" Your Rental Invoice "); builder.AppendLine(); builder.AppendLine("Rent details:"); foreach (var value in values) { var price = _pricingService.GetPrice(value); builder.AppendLine($"{value.Name}: {price} {_settings.Value.Currency}"); totalPrice += price; totalLoyaltyPoints += GetLoyaltyPoint(value.Type); } builder.AppendLine(); builder.AppendLine($"Total price: {totalPrice}{_settings.Value.Currency}"); builder.AppendLine(); builder.AppendLine($"Number of bonus points earned: {totalLoyaltyPoints}"); // convert string to stream var byteArray = Encoding.ASCII.GetBytes(builder.ToString()); return(File(byteArray, "application/txt", "invoice.txt")); }
private ProductTileViewModel CreateProductViewModelForEntry(EntryContentBase entry) { var originalPrice = _pricingService.GetPrice(entry.Code); var image = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? ""; return(new ProductTileViewModel { Code = entry.Code, DisplayName = entry.DisplayName, PlacedPrice = originalPrice?.UnitPrice ?? _pricingService.GetMoney(0), DiscountedPrice = GetDiscountPrice(entry), ImageUrl = image, Url = entry.GetUrl(), IsAvailable = originalPrice != null }); }
public void SetCartCurrency(ICart cart, Currency currency) { if (currency.IsEmpty || currency == cart.Currency) { return; } cart.Currency = currency; foreach (var lineItem in cart.GetAllLineItems()) { // If there is an item which has no price in the new currency, a NullReference exception will be thrown. // Mixing currencies in cart is not allowed. // It's up to site's managers to ensure that all items have prices in allowed currency. lineItem.PlacedPrice = _pricingService.GetPrice(lineItem.Code, cart.MarketId, currency).UnitPrice.Amount; } ValidateCart(cart); }
private void GetPriceAssertion(InventoryType inventoryType, int rentalDays, int expectedPrice) { var actualPrice = _pricingService.GetPrice(new InventoryModel { Type = inventoryType, RentalDays = rentalDays }); Assert.Equal(expectedPrice, actualPrice); }
public async Task <IActionResult> Submit([FromBody] Submission submission) { var submissionPrice = await _pricingService.GetPrice(CreatePriceRequest(submission)); submission.SubmissionPrice = submissionPrice; await _submissionService.SaveSubmission(submission); raiseSubmissionEvent(submission); return(Ok()); }
public int Total() { int total = 0; var itemGroups = from i in _items group i by i into counts select new { Count = counts.Count(), Group = counts.Key }; foreach (var item in itemGroups) { total += _pricingService.GetPrice(item.Group, item.Count); } return(total); }
private void UpdateRecommendation(RecommendationData recommendation, EntryContentBase entry) { var imageUrl = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? ""; var originalPrice = _pricingService.GetPrice(entry.Code); var salePrice = _pricingService.GetDiscountPrice(entry.Code); if (recommendation.Attributes == null) { recommendation.Attributes = new Dictionary <string, string>(); } recommendation.Attributes.Add(Title, entry.DisplayName); recommendation.Attributes.Add(Url, entry.GetUrl(recommendation.Lang)); recommendation.Attributes.Add(Image, imageUrl); recommendation.Attributes.Add(UnitPrice, originalPrice?.UnitPrice.ToString()); recommendation.Attributes.Add(SalePrice, salePrice?.UnitPrice.ToString()); }
public virtual CartItemViewModel CreateCartItemViewModel(ICart cart, ILineItem lineItem, EntryContentBase entry) { var viewModel = new CartItemViewModel { Code = lineItem.Code, DisplayName = entry.DisplayName, ImageUrl = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "", DiscountedPrice = GetDiscountedPrice(cart, lineItem), PlacedPrice = _pricingService.GetMoney(lineItem.PlacedPrice), Quantity = lineItem.Quantity, Url = entry.GetUrl(_relationRepository, _urlResolver), Entry = entry, IsAvailable = _pricingService.GetPrice(entry.Code) != null, DiscountedUnitPrice = GetDiscountedUnitPrice(cart, lineItem), IsGift = lineItem.IsGift }; var productLink = entry is VariationContent? entry.GetParentProducts(_relationRepository).FirstOrDefault() : entry.ContentLink; FashionProduct product; if (_contentLoader.TryGet(productLink, out product)) { viewModel.Brand = GetBrand(product); } var variant = entry as FashionVariant; if (variant != null) { viewModel.AvailableSizes = GetAvailableSizes(product, variant); } return(viewModel); }
public AddToCartResult AddToCart(ICart cart, string code, string warehouseCode, decimal quantity) { var result = new AddToCartResult(); var contentLink = _referenceConverter.GetContentLink(code); var entryContent = _contentLoader.Get <EntryContentBase>(contentLink); if (entryContent is BundleContent) { foreach (var relation in _relationRepository.GetChildren <BundleEntry>(contentLink)) { var entry = _contentLoader.Get <EntryContentBase>(relation.Child); var recursiveResult = AddToCart(cart, entry.Code, warehouseCode, relation.Quantity ?? 1); if (recursiveResult.EntriesAddedToCart) { result.EntriesAddedToCart = true; } foreach (var message in recursiveResult.ValidationMessages) { result.ValidationMessages.Add(message); } } return(result); } ILineItem lineItem = null; if (!string.IsNullOrEmpty(warehouseCode)) { IShipment shipment = null; if (cart.GetFirstForm().Shipments.Count == 1 && string.IsNullOrEmpty(cart.GetFirstForm().Shipments.First().WarehouseCode)) { shipment = cart.GetFirstForm().Shipments.First(); shipment.WarehouseCode = warehouseCode; } else { shipment = cart.GetFirstForm().Shipments.FirstOrDefault(s => s.WarehouseCode.Equals(warehouseCode, StringComparison.CurrentCultureIgnoreCase)); } if (shipment == null) { shipment = cart.CreateShipment(_orderGroupFactory); shipment.WarehouseCode = warehouseCode; cart.AddShipment(shipment); } lineItem = shipment.LineItems.FirstOrDefault(x => x.Code == code && !x.IsGift); if (lineItem == null) { //this is just like AddNewLineItem but doesn't add there - adds to shipment instead lineItem = cart.CreateLineItem(code, _orderGroupFactory); lineItem.Quantity = quantity; lineItem.DisplayName = entryContent.DisplayName; //cart.AddLineItem(newLineItem, _orderGroupFactory); var price = _pricingService.GetPrice(code); if (price != null) { lineItem.PlacedPrice = price.UnitPrice.Amount; } cart.AddLineItem(shipment, lineItem); } else { cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } } else { lineItem = cart.GetAllLineItems().FirstOrDefault(x => x.Code == code && !x.IsGift); if (lineItem == null) { lineItem = AddNewLineItem(cart, code, quantity, entryContent.DisplayName); } else { var shipment = cart.GetFirstShipment(); cart.UpdateLineItemQuantity(shipment, lineItem, lineItem.Quantity + quantity); } } var validationIssues = ValidateCart(cart); AddValidationMessagesToResult(result, lineItem, validationIssues); return(result); }