public ActionResult fetchMaterialFinishPriceHistory(long materialID, long finishID, [FromQuery] string currency, [FromQuery] string area)
        {
            FetchMaterialFinishPriceHistoryDTO fetchMaterialFinishPriceHistoryDTO = new FetchMaterialFinishPriceHistoryDTO();

            fetchMaterialFinishPriceHistoryDTO.materialID = materialID;
            fetchMaterialFinishPriceHistoryDTO.finishID   = finishID;
            fetchMaterialFinishPriceHistoryDTO.currency   = currency;
            fetchMaterialFinishPriceHistoryDTO.area       = area;
            try
            {
                GetAllMaterialFinishPriceHistoryModelView materialFinishPriceHistoryModelView = new core.application.PriceTablesController().fetchMaterialFinishPriceHistory(fetchMaterialFinishPriceHistoryDTO, clientFactory);
                return(Ok(materialFinishPriceHistoryModelView));
            }
            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)));
            }
        }
        /// <summary>
        /// Fetches the price history of all finishes of a material
        /// </summary>
        /// <param name="fetchMaterialFinishPriceHistoryDTO">FetchMaterialFinishPriceHistoryDTO with the information about the fetch</param>
        /// <returns>IEnumerable with the price history of all finishes of a material</returns>
        public IEnumerable <FinishPriceTableEntry> fetchAllMaterialFinishesPriceHistory(FetchMaterialFinishPriceHistoryDTO fetchMaterialFinishPriceHistoryDTO)
        {
            Material material = dbContext.Material.Where(m => m.Id == fetchMaterialFinishPriceHistoryDTO.materialID).SingleOrDefault();

            return(dbContext.FinishPriceTable.Where(fpte => fpte.materialEID == material.id()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fetches the price history of all finishes of a material
        /// </summary>
        /// <param name="materialFinishPriceHistoryDTO">FetchMaterialFinishPriceHistoryDTO containing the material's PID</param>
        /// <returns>GetAllMaterialFinishPriceHistoryModelView with the price history of all finishes of the material</returns>
        public GetAllMaterialFinishPriceHistoryModelView fetchPriceHistoryOfAllMaterialFinishes(FetchMaterialFinishPriceHistoryDTO materialFinishPriceHistoryDTO, IHttpClientFactory clientFactory)
        {
            IEnumerable <FinishPriceTableEntry> materialFinishPriceHistory = PersistenceContext.repositories().createFinishPriceTableRepository().fetchAllMaterialFinishesPriceHistory(materialFinishPriceHistoryDTO);

            FetchEnsurance.ensureMaterialFinishPriceHistoryFetchWasSuccessful(materialFinishPriceHistory);
            if (materialFinishPriceHistoryDTO.currency != null && materialFinishPriceHistoryDTO.area != null)
            {
                CurrenciesService.checkCurrencySupport(materialFinishPriceHistoryDTO.currency);
                AreasService.checkAreaSupport(materialFinishPriceHistoryDTO.area);
                foreach (FinishPriceTableEntry finishPriceTableEntry in materialFinishPriceHistory)
                {
                    Task <double> convertedValueTask =
                        new CurrencyPerAreaConversionService(clientFactory)
                        .convertDefaultCurrencyPerAreaToCurrencyPerArea(finishPriceTableEntry.price.value, materialFinishPriceHistoryDTO.currency, materialFinishPriceHistoryDTO.area);
                    convertedValueTask.Wait();
                    finishPriceTableEntry.price.value = convertedValueTask.Result;
                }
                return(PriceTableModelViewService.fromMaterialFinishCollection(materialFinishPriceHistory, materialFinishPriceHistoryDTO.currency, materialFinishPriceHistoryDTO.area));
            }
            return(PriceTableModelViewService.fromMaterialFinishCollection(materialFinishPriceHistory, CurrencyPerAreaConversionService.getBaseCurrency(), CurrencyPerAreaConversionService.getBaseArea()));
        }
 /// <summary>
 /// Fetches the price history of a material finish
 /// </summary>
 /// <param name="fetchMaterialFinishPriceHistoryDTO">FetchMaterialFinishPriceHistoryDTO with the information about the fetch</param>
 /// <returns>IEnumerable with the material finish price history</returns>
 public IEnumerable <FinishPriceTableEntry> fetchMaterialFinishPriceHistory(FetchMaterialFinishPriceHistoryDTO fetchMaterialFinishPriceHistoryDTO)
 {
     return(from finishPriceTableEntry in base.dbContext.FinishPriceTable
            where finishPriceTableEntry.entity.Id == fetchMaterialFinishPriceHistoryDTO.finishID
            select finishPriceTableEntry);
 }