Beispiel #1
0
        public IHttpActionResult SaveCampReservation([FromBody] CampReservationDTO campReservation, int eventId)
        {
            if (!ModelState.IsValid)
            {
                var errors    = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.Exception.Message);
                var dataError = new ApiErrorDto("Camper Application data Invalid", new InvalidOperationException("Invalid Camper Application Data" + errors));
                throw new HttpResponseException(dataError.HttpResponseMessage);
            }

            return(Authorized(token =>
            {
                try
                {
                    var newCamperInfo = _campService.SaveCampReservation(campReservation, eventId, token);
                    return Ok(newCamperInfo);
                }
                catch (ApplicationException e)
                {
                    throw new HttpResponseException(HttpStatusCode.PreconditionFailed);
                }
                catch (Exception e)
                {
                    var apiError = new ApiErrorDto("Camp Reservation failed", e);
                    throw new HttpResponseException(apiError.HttpResponseMessage);
                }
            }));
        }