public ActionResult fetchCurrentMaterialFinishPrice(long materialId, long finishId, [FromQuery] string currency, [FromQuery] string area)
        {
            GetCurrentMaterialFinishPriceModelView fetchCurrentMaterialFinishPrice = new GetCurrentMaterialFinishPriceModelView();

            fetchCurrentMaterialFinishPrice.finish                = new GetMaterialFinishModelView();
            fetchCurrentMaterialFinishPrice.currentPrice          = new PriceModelView();
            fetchCurrentMaterialFinishPrice.finish.materialId     = materialId;
            fetchCurrentMaterialFinishPrice.finish.id             = finishId;
            fetchCurrentMaterialFinishPrice.currentPrice.currency = currency;
            fetchCurrentMaterialFinishPrice.currentPrice.area     = area;
            try
            {
                GetCurrentMaterialFinishPriceModelView currentMaterialFinishPrice = new core.application.PriceTablesController().fetchCurrentMaterialFinishPrice(fetchCurrentMaterialFinishPrice, clientFactory);
                return(Ok(currentMaterialFinishPrice));
            }
            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)));
            }
        }
        public static GetCurrentMaterialFinishPriceModelView fromMaterialFinish(GetCurrentMaterialFinishPriceModelView modelView, IHttpClientFactory clientFactory)
        {
            Material material = PersistenceContext.repositories().createMaterialRepository().find(modelView.finish.materialId);

            if (material == null)
            {
                throw new ResourceNotFoundException(string.Format(MATERIAL_NOT_FOUND, modelView.finish.materialId));
            }

            MaterialPriceTableEntry currentMaterialPrice = PersistenceContext.repositories().createMaterialPriceTableRepository().fetchCurrentMaterialPrice(modelView.finish.materialId);

            if (currentMaterialPrice == null)
            {
                throw new ResourceNotFoundException(string.Format(NO_CURRENT_MATERIAL_PRICE, modelView.finish.materialId));
            }

            foreach (Finish finish in material.Finishes)
            {
                if (finish.Id == modelView.finish.id)
                {
                    FinishPriceTableEntry currentMaterialFinishPrice = PersistenceContext.repositories().createFinishPriceTableRepository().fetchCurrentMaterialFinishPrice(modelView.finish.id);

                    if (currentMaterialFinishPrice == null)
                    {
                        throw new ResourceNotFoundException(string.Format(NO_CURRENT_FINISH_PRICE, modelView.finish.id, modelView.finish.materialId));
                    }

                    GetCurrentMaterialFinishPriceModelView currentMaterialFinishPriceModelView = new GetCurrentMaterialFinishPriceModelView();
                    currentMaterialFinishPriceModelView.finish                  = new GetMaterialFinishModelView();
                    currentMaterialFinishPriceModelView.currentPrice            = new PriceModelView();
                    currentMaterialFinishPriceModelView.timePeriod              = new TimePeriodModelView();
                    currentMaterialFinishPriceModelView.tableEntryId            = currentMaterialFinishPrice.Id;
                    currentMaterialFinishPriceModelView.finish.materialId       = material.Id;
                    currentMaterialFinishPriceModelView.finish.id               = finish.Id;
                    currentMaterialFinishPriceModelView.finish.description      = finish.description;
                    currentMaterialFinishPriceModelView.finish.shininess        = finish.shininess;
                    currentMaterialFinishPriceModelView.timePeriod.startingDate = LocalDateTimePattern.GeneralIso.Format(currentMaterialFinishPrice.timePeriod.startingDate);
                    currentMaterialFinishPriceModelView.timePeriod.endingDate   = LocalDateTimePattern.GeneralIso.Format(currentMaterialFinishPrice.timePeriod.endingDate);
                    if (modelView.currentPrice.currency == null || modelView.currentPrice.area == null)
                    {
                        currentMaterialFinishPriceModelView.currentPrice.value    = currentMaterialFinishPrice.price.value;
                        currentMaterialFinishPriceModelView.currentPrice.area     = CurrencyPerAreaConversionService.getBaseArea();
                        currentMaterialFinishPriceModelView.currentPrice.currency = CurrencyPerAreaConversionService.getBaseCurrency();
                    }
                    else
                    {
                        Task <double> convertedValueTask =
                            new CurrencyPerAreaConversionService(clientFactory)
                            .convertDefaultCurrencyPerAreaToCurrencyPerArea(currentMaterialFinishPrice.price.value, modelView.currentPrice.currency, modelView.currentPrice.area);
                        convertedValueTask.Wait();
                        currentMaterialFinishPriceModelView.currentPrice.value    = convertedValueTask.Result;
                        currentMaterialFinishPriceModelView.currentPrice.currency = modelView.currentPrice.currency;
                        currentMaterialFinishPriceModelView.currentPrice.area     = modelView.currentPrice.area;
                    }
                    return(currentMaterialFinishPriceModelView);
                }
            }
            throw new ResourceNotFoundException(string.Format(FINISH_NOT_FOUND, modelView.finish.id, modelView.finish.materialId));
        }
Beispiel #3
0
 /// <summary>
 /// Fetches the current price of a material finish
 /// </summary>
 /// <param name="modelView">GetCurrentMaterialFinishPriceModelView with info to fetch the current price</param>
 /// <returns>GetCurrentMaterialFinishPriceModelView with the material's finish current price</returns>
 public GetCurrentMaterialFinishPriceModelView fetchCurrentMaterialFinishPrice(GetCurrentMaterialFinishPriceModelView modelView, IHttpClientFactory clientFactory)
 {
     return(CurrentPriceService.fromMaterialFinish(modelView, clientFactory));
 }