public async Task <SurchargeRateCreateResponseDto> CreateSurchargeRateAsync(SurchargeRateCreateRequestDto request) { var isProductIdExists = await _productTypeService.IsProductTypeIdExistsAsync(request.ProductTypeId); if (!isProductIdExists) { var message = $"ProductTypeId[{request.ProductTypeId}] is not found."; _logger.LogError(message); throw new SurchargeRateProductTypeNotFoundException(message); } var productTypeSurchargeRate = new ProductTypeSurchargeRate() { ProductTypeId = request.ProductTypeId, SurchargeRates = request.SurchareRates.Select(r => new SurchargeRate() { Rate = r }).ToList() }; var surchargeRate = await _surchargeRateManager.CreateSurchargeRateAsync(productTypeSurchargeRate); return(new SurchargeRateCreateResponseDto() { SurchareRates = surchargeRate.SurchargeRates.Select(r => r.Rate).ToList(), ProductTypeId = surchargeRate.ProductTypeId }); }
public async Task <ProductTypeSurchargeRate> AddSurchargeRateAsync(ProductTypeSurchargeRate productTypeSurchargeRate) { var productTypeId = productTypeSurchargeRate.ProductTypeId; var isAssigned = await Task.Run(() => { if (_productTypeSurchargeRate.ContainsKey(productTypeId)) { throw new ProductTypeAlreadyHasSurchargeRateException($"ProductTypeId[{productTypeId}] has already its Surcharge rates added"); } var isAdded = _productTypeSurchargeRate.TryAdd(productTypeId, productTypeSurchargeRate.SurchargeRates); return(isAdded); }); if (!isAssigned) { throw new CreateSurchareRateException($"Failed to Add surcharge rates to product type id [{productTypeId}]."); } return(productTypeSurchargeRate); }
public async Task <ProductTypeSurchargeRate> CreateSurchargeRateAsync(ProductTypeSurchargeRate productTypeSurchargeRate) { var surchargeRate = await _surchargeRateRepository.AddSurchargeRateAsync(productTypeSurchargeRate); return(surchargeRate); }