public void SaveResource(Resource Resource) { // Preparare validation return data ICollection<ValidationResult> validationResults; // Try to validate given data if (Resource.Validate(out validationResults)) { // If a new Resource should be created if (Resource.ResourceId == 0) { ResourceDAL.InsertResource(Resource); } // Existing Resource should be updated else { // Check that the Resource exists before update if (ResourceDAL.GetResourceById(Resource.ResourceId) == null) { throw new DataBaseEntryNotFoundException(); } // Update Resource ResourceDAL.UpdateResource(Resource); } } // Validation failed else { // Create exception ApplicationException exception = new ApplicationException("Resource object contained invalid values."); // Add validation data to exception. exception.Data.Add("ValidationResults", validationResults); throw exception; } }