/// <summary> /// Converts an instance of CustomizedMaterial into an instance of GetCustomizedMaterialModelView. /// </summary> /// <param name="customizedMaterial">Instance of CustomizedMaterial being converted.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">Thrown when the provided instance of CustomizedMaterial is null.</exception> public static GetCustomizedMaterialModelView fromEntity(CustomizedMaterial customizedMaterial) { if (customizedMaterial == null) { throw new System.ArgumentNullException(nameof(customizedMaterial)); } GetCustomizedMaterialModelView customizedMaterialModelView = new GetCustomizedMaterialModelView(); customizedMaterialModelView.customizedMaterialId = customizedMaterial.Id; customizedMaterialModelView.materialId = customizedMaterial.material.Id; if (customizedMaterial.finish != null) { customizedMaterialModelView.finish = FinishModelViewService.fromEntity(customizedMaterial.finish); } if (customizedMaterial.color != null) { customizedMaterialModelView.color = ColorModelViewService.fromEntity(customizedMaterial.color); } return(customizedMaterialModelView); }
/// <summary> /// Builds a CustomizedProductPriceModelView out of a Customized Product /// </summary> /// <param name="customizedProduct">Customized Product to build the model view out of</param> /// <param name="fetchCustomizedProductPriceModelView">ModelView to know if currency/area conversion is needed</param> /// <returns>CustomizedProductPriceModelView</returns> private static async Task <CustomizedProductPriceModelView> buildCustomizedProductPriceModelView(CustomizedProduct customizedProduct, FetchCustomizedProductPriceModelView fetchCustomizedProductPriceModelView, MaterialPriceTableEntry materialPriceTableEntry, FinishPriceTableEntry finishPriceTableEntry, IHttpClientFactory clientFactory) { CustomizedProductPriceModelView customizedProductPriceModelView = new CustomizedProductPriceModelView(); string defaultCurrency = CurrencyPerAreaConversionService.getBaseCurrency(); string defaultArea = CurrencyPerAreaConversionService.getBaseArea(); bool convertCurrencyPerArea = fetchCustomizedProductPriceModelView.currency != null && fetchCustomizedProductPriceModelView.area != null; customizedProductPriceModelView.customizedProductId = customizedProduct.Id; customizedProductPriceModelView.reference = customizedProduct.reference; customizedProductPriceModelView.productId = customizedProduct.product.Id; string requestedMeasurementUnit = null; if (convertCurrencyPerArea) { requestedMeasurementUnit = new String(fetchCustomizedProductPriceModelView.area.Where(c => Char.IsLetter(c)).ToArray()); } else { requestedMeasurementUnit = new String(CurrencyPerAreaConversionService.getBaseArea().Where(c => Char.IsLetter(c)).ToArray()); } customizedProductPriceModelView.customizedDimensions = new GetCustomizedDimensionsModelView(); customizedProductPriceModelView.customizedDimensions.unit = requestedMeasurementUnit; customizedProductPriceModelView.customizedDimensions.width = MeasurementUnitService.convertToUnit(customizedProduct.customizedDimensions.width, requestedMeasurementUnit); customizedProductPriceModelView.customizedDimensions.height = MeasurementUnitService.convertToUnit(customizedProduct.customizedDimensions.height, requestedMeasurementUnit); customizedProductPriceModelView.customizedDimensions.depth = MeasurementUnitService.convertToUnit(customizedProduct.customizedDimensions.depth, requestedMeasurementUnit); customizedProductPriceModelView.customizedMaterial = new CustomizedMaterialPriceModelView(); customizedProductPriceModelView.customizedMaterial.customizedMaterialId = customizedProduct.customizedMaterial.Id; customizedProductPriceModelView.customizedMaterial.materialId = customizedProduct.customizedMaterial.material.Id; if (customizedProduct.customizedMaterial.finish != null) { customizedProductPriceModelView.customizedMaterial.finish = new FinishPriceModelView(); customizedProductPriceModelView.customizedMaterial.finish.finishId = customizedProduct.customizedMaterial.finish.Id; customizedProductPriceModelView.customizedMaterial.finish.description = customizedProduct.customizedMaterial.finish.description; customizedProductPriceModelView.customizedMaterial.finish.shininess = customizedProduct.customizedMaterial.finish.shininess; customizedProductPriceModelView.customizedMaterial.finish.price = new PriceModelView(); if (convertCurrencyPerArea) { customizedProductPriceModelView.customizedMaterial.finish.price.currency = fetchCustomizedProductPriceModelView.currency; customizedProductPriceModelView.customizedMaterial.finish.price.area = fetchCustomizedProductPriceModelView.area; customizedProductPriceModelView.customizedMaterial.finish.price.value = await convertPriceValue( finishPriceTableEntry.price.value, fetchCustomizedProductPriceModelView.currency, fetchCustomizedProductPriceModelView.area, clientFactory ); } else { customizedProductPriceModelView.customizedMaterial.finish.price.currency = defaultCurrency; customizedProductPriceModelView.customizedMaterial.finish.price.area = defaultArea; customizedProductPriceModelView.customizedMaterial.finish.price.value = finishPriceTableEntry.price.value; } } if (customizedProduct.customizedMaterial.color != null) { customizedProductPriceModelView.customizedMaterial.color = ColorModelViewService.fromEntity(customizedProduct.customizedMaterial.color); } customizedProductPriceModelView.customizedMaterial.price = new PriceModelView(); if (convertCurrencyPerArea) { customizedProductPriceModelView.customizedMaterial.price.currency = fetchCustomizedProductPriceModelView.currency; customizedProductPriceModelView.customizedMaterial.price.area = fetchCustomizedProductPriceModelView.area; customizedProductPriceModelView.customizedMaterial.price.value = await convertPriceValue( materialPriceTableEntry.price.value, fetchCustomizedProductPriceModelView.currency, fetchCustomizedProductPriceModelView.area, clientFactory ); } else { customizedProductPriceModelView.customizedMaterial.price.currency = defaultCurrency; customizedProductPriceModelView.customizedMaterial.price.area = defaultArea; customizedProductPriceModelView.customizedMaterial.price.value = materialPriceTableEntry.price.value; } customizedProductPriceModelView.price = new PriceModelView(); customizedProductPriceModelView.totalArea = new AreaModelView(); if (convertCurrencyPerArea) { customizedProductPriceModelView.price.currency = fetchCustomizedProductPriceModelView.currency; customizedProductPriceModelView.totalArea.area = fetchCustomizedProductPriceModelView.area; } else { customizedProductPriceModelView.price.currency = defaultCurrency; customizedProductPriceModelView.totalArea.area = defaultArea; } calculateTotalAreaAndPriceOfCustomizedMaterial(customizedProductPriceModelView, customizedProduct); return(customizedProductPriceModelView); }