/// <summary> /// Fetches a Material from the MaterialRepository given its ID. /// </summary> /// <param name = "materialID">the Material's ID</param> /// <returns>DTO that represents the Material</returns> public MaterialDTO findMaterialByID(long materialID, bool pricedFinishesOnly) { Material material = PersistenceContext.repositories().createMaterialRepository().find(materialID); if (material == null) { throw new ResourceNotFoundException(ERROR_MATERIAL_NOT_FOUND); } if (pricedFinishesOnly) { FinishPriceTableRepository finishPriceTableRepository = PersistenceContext.repositories().createFinishPriceTableRepository(); List <Finish> pricedFinishes = new List <Finish>(); foreach (Finish finish in material.Finishes) { if (finishPriceTableRepository.fetchCurrentMaterialFinishPrice(finish.Id) != null) { pricedFinishes.Add(finish); } } if (pricedFinishes.Count == 0) { throw new ResourceNotFoundException(NO_PRICED_FINISHES); } material.Finishes.Clear(); material.Finishes.AddRange(pricedFinishes); return(material.toDTO()); } return(PersistenceContext.repositories().createMaterialRepository().find(materialID).toDTO()); }
/// <summary> /// Checks if a material finish from a customized product has a current price /// </summary> /// <param name="finishPriceTableRepository">Finish Price Table Repository</param> /// <param name="finishId">Finish's PID</param> /// <returns>FinishPriceTableEntry with the finish's current price</returns> private static FinishPriceTableEntry getCurrentFinishPrice(FinishPriceTableRepository finishPriceTableRepository, long finishId) { FinishPriceTableEntry finishPriceTableEntry = finishPriceTableRepository.fetchCurrentMaterialFinishPrice(finishId); if (finishPriceTableEntry == null) { throw new ResourceNotFoundException ( string.Format(FINISH_HAS_NO_CURRENT_PRICE, finishId) ); } return(finishPriceTableEntry); }