public IHttpActionResult Put(string id, ACT_INFO activity) { if (!ModelState.IsValid) { string errors = ""; foreach (var modelstate in ModelState.Values) { foreach (var error in modelstate.Errors) { errors += "|" + error.ErrorMessage + "|" + error.Exception; } } throw new BadInputException() { ExceptionMessage = errors }; } var result = _activityService.Update(id, activity); if (result == null) { return(NotFound()); } return(Ok(result)); }
// Helper method to validate an activity info post. Throws an exception that gets caught later if something is not valid. // Returns true if all is well. The return value is not really used though. This could be of type void. private bool validateActivityInfo(ACT_INFO activity) { var activityExists = _unitOfWork.ActivityInfoRepository.Where(x => x.ACT_CDE == activity.ACT_CDE).Count() > 0; if (!activityExists) { throw new ResourceNotFoundException() { ExceptionMessage = "The Activity was not found." } } ; return(true); }
/// <summary> /// Updates the Activity Info /// </summary> /// <param name="activity">The activity info resource with the updated information</param> /// <param name="id">The id of the activity info to be updated</param> /// <returns>The updated activity info resource</returns> public ACT_INFO Update(string id, ACT_INFO activity) { var original = _unitOfWork.ActivityInfoRepository.GetById(id); if (original == null) { throw new ResourceNotFoundException() { ExceptionMessage = "The Activity Info was not found." }; } validateActivityInfo(activity); // One can only update certain fields within a membrship original.ACT_BLURB = activity.ACT_BLURB; original.ACT_URL = activity.ACT_URL; original.ACT_JOIN_INFO = activity.ACT_JOIN_INFO; _unitOfWork.Save(); return(original); }