public ActionResult fetchMaterialPriceHistory(long materialID, [FromQuery] string currency, [FromQuery] string area)
        {
            FetchMaterialPriceHistoryDTO fetchMaterialPriceHistoryDTO = new FetchMaterialPriceHistoryDTO();

            fetchMaterialPriceHistoryDTO.materialID = materialID;
            fetchMaterialPriceHistoryDTO.currency   = currency;
            fetchMaterialPriceHistoryDTO.area       = area;
            try
            {
                GetAllMaterialPriceHistoryModelView materialPriceHistoryModelView = new core.application.PriceTablesController().fetchMaterialPriceHistory(fetchMaterialPriceHistoryDTO, clientFactory);
                return(Ok(materialPriceHistoryModelView));
            }
            catch (ResourceNotFoundException e)
            {
                return(NotFound(new SimpleJSONMessageService(e.Message)));
            }
            catch (ArgumentException e)
            {
                return(BadRequest(new SimpleJSONMessageService(e.Message)));
            }
            catch (Exception)
            {
                return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR)));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Fetches the price history of a material
        /// </summary>
        /// <param name="fetchMaterialFinishPriceHistoryDTO">FetchMaterialPriceHistoryDTO with the information about the fetch</param>
        /// <returns>GetAllMaterialPriceHistoryModelView with the material price history fetch information</returns>
        public GetAllMaterialPriceHistoryModelView fetchMaterialPriceHistory(FetchMaterialPriceHistoryDTO fetchMaterialPriceHistoryDTO, IHttpClientFactory clientFactory)
        {
            IEnumerable <MaterialPriceTableEntry> materialPriceHistory = PersistenceContext.repositories().createMaterialPriceTableRepository().fetchMaterialPriceHistory(fetchMaterialPriceHistoryDTO);

            FetchEnsurance.ensureMaterialPriceHistoryFetchWasSuccessful(materialPriceHistory);
            if (fetchMaterialPriceHistoryDTO.currency != null && fetchMaterialPriceHistoryDTO.area != null)
            {
                CurrenciesService.checkCurrencySupport(fetchMaterialPriceHistoryDTO.currency);
                AreasService.checkAreaSupport(fetchMaterialPriceHistoryDTO.area);
                foreach (MaterialPriceTableEntry materialPriceTableEntry in materialPriceHistory)
                {
                    Task <double> convertedValueTask =
                        new CurrencyPerAreaConversionService(clientFactory)
                        .convertDefaultCurrencyPerAreaToCurrencyPerArea(materialPriceTableEntry.price.value, fetchMaterialPriceHistoryDTO.currency, fetchMaterialPriceHistoryDTO.area);
                    convertedValueTask.Wait();
                    materialPriceTableEntry.price.value = convertedValueTask.Result;
                }
                return(PriceTableModelViewService.fromMaterialCollection(materialPriceHistory, fetchMaterialPriceHistoryDTO.currency, fetchMaterialPriceHistoryDTO.area));
            }
            return(PriceTableModelViewService.fromMaterialCollection(materialPriceHistory, CurrencyPerAreaConversionService.getBaseCurrency(), CurrencyPerAreaConversionService.getBaseArea()));
        }
 /// <summary>
 /// Fetches the price history of a material
 /// </summary>
 /// <param name="fetchMaterialPriceHistoryDTO">FetchMaterialPriceHistoryDTO with the information about the fetch</param>
 /// <returns>IEnumerable with the material price history</returns>
 public IEnumerable <MaterialPriceTableEntry> fetchMaterialPriceHistory(FetchMaterialPriceHistoryDTO fetchMaterialPriceHistoryDTO)
 {
     return(from materialTableEntry in base.dbContext.MaterialPriceTable
            where materialTableEntry.entity.Id == fetchMaterialPriceHistoryDTO.materialID
            select materialTableEntry);
 }