/// <summary> /// Helper for reducing duplicate code /// </summary> /// <param name="id"></param> /// <param name="newState"></param> /// <returns></returns> private IActionResult ChangeIdeationState(int id, bool newState) { try { _unitOfWorkManager.StartUnitOfWork(); Ideation updatedIdeation = _ideationManager.ChangeIdeationState(id, newState); _unitOfWorkManager.EndUnitOfWork(); if (updatedIdeation == null) { return(BadRequest("Something went wrong while updating the ideation state.")); } return(Ok(_mapper.Map <IdeationDto>(updatedIdeation))); } catch (ValidationException ve) { return(UnprocessableEntity($"Invalid input data: {ve.ValidationResult.ErrorMessage}")); } catch (ArgumentException e) { switch (e.ParamName) { case "id": return(NotFound(e.Message)); default: return(BadRequest(e.Message)); } } }