コード例 #1
0
        public IHttpActionResult SaveCamperEmergencyContact([FromBody] List <CampEmergencyContactDTO> emergencyContacts, int eventId, int contactId)
        {
            if (!ModelState.IsValid)
            {
                var errors    = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.Exception.Message);
                var dataError = new ApiErrorDto("Camper Emergency Contact data Invalid", new InvalidOperationException("Invalid Camper emergency contact Data" + errors));
                throw new HttpResponseException(dataError.HttpResponseMessage);
            }

            return(Authorized(token =>
            {
                try
                {
                    _campService.SaveCamperEmergencyContactInfo(emergencyContacts, eventId, contactId, token);

                    return Ok();
                }

                catch (Exception e)
                {
                    var apiError = new ApiErrorDto("Save Camp Emergency Contact Info failed", e);
                    throw new HttpResponseException(apiError.HttpResponseMessage);
                }
            }));
        }