Пример #1
0
        /// <summary>
        /// Converts the value from a unit to another unit.
        /// </summary>
        /// <param name="convertUnitMV">ConvertUnitModelView containing unit conversion data.</param>
        /// <returns>ConvertUnitModelView with converted value.</returns>
        public ConvertUnitModelView convertValue(ConvertUnitModelView convertUnitMV)
        {
            double valueInMM = MeasurementUnitService.convertFromUnit(convertUnitMV.value, convertUnitMV.fromUnit);

            double newValue = MeasurementUnitService.convertToUnit(valueInMM, convertUnitMV.toUnit);

            convertUnitMV.value = newValue;

            return(convertUnitMV);
        }
        public ActionResult convertValue([FromQuery] string to, [FromQuery] string from, [FromQuery] double value)
        {
            ConvertUnitModelView convertMV = new ConvertUnitModelView();

            convertMV.toUnit   = to;
            convertMV.fromUnit = from;
            convertMV.value    = value;

            try
            {
                ConvertUnitModelView convertedUnitMV = new core.application.UnitConversionController().convertValue(convertMV);
                return(Ok(convertedUnitMV));
            }
            catch (ArgumentException e)
            {
                return(BadRequest(new SimpleJSONMessageService(e.Message)));
            }
            catch (Exception)
            {
                return(StatusCode(500, new SimpleJSONMessageService(UNEXPECTED_ERROR)));
            }
        }