public async Task <PackageBindingModel> ModelToBindingModel(Package package, string currency) { var price = await _pricingService.ConvertCurrency("USD", currency, package.UsdPrice); return(new PackageBindingModel { Id = package.Id, Name = package.Name, Description = package.Description, Products = package.Products.Split(','), Price = Math.Round(price / 100, 2) }); }
private async Task <Package> PreparePackage(PackageBindingModel packageBindingModel, string currency) { var areValidProductIds = await _productService.AreValidProductIds(packageBindingModel.Products); if (!areValidProductIds) { throw new InvalidProductsException(); } var products = (await _productService.GetAllProducts()) .Where(p => packageBindingModel.Products.Contains(p.Id)); var package = _packageMapper.BindingModelToModel(packageBindingModel); package.UsdPrice = await _pricingService.ConvertCurrency(currency, "USD", products.Sum(p => p.UsdPrice)); return(package); }