Beispiel #1
0
        // POST: api/BenefitsApi
        /// <summary>
        /// Post performs the calculation.
        /// </summary>
        /// <param name="model">a Family instance</param>
        /// <returns>CalculateResultsModel</returns>
        /// an IEnumerable collection
        public HttpResponseMessage Post([FromBody] Family model)
        {
            try
            {
                var validationResults = _familyValidator.Run(model);

                if (validationResults.IsValid)
                {
                    CalculationResults     results      = _calculator.RunCalculations(model, _appConfig);
                    CalculatedResultsModel resultsModel = _modelMapper.MapToResults(results);

                    return(Request.CreateResponse(HttpStatusCode.OK, resultsModel));
                }

                HttpError err = new HttpError("Invalid input parameter. " + validationResults.Message);
                return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, err));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                //TODO: log the exception
                HttpError err = new HttpError("Exception occurred check server logs");
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, err));
            }
        }