public void ValidateItem(ContentRepresentationBase postedItem, TPersisted content) { if (postedItem == null) { throw new ArgumentNullException("postedItem"); } if (content == null) { throw new ArgumentNullException("content"); } //now do each validation step if (ValidateProperties(postedItem, content) == false) { return; } if (ValidatePropertyData(postedItem.Properties, content) == false) { return; } }
/// <summary> /// Ensure all of properties exist /// </summary> /// <param name="postedItem"></param> /// <param name="content"></param> /// <returns></returns> protected bool ValidateProperties(ContentRepresentationBase postedItem, TPersisted content) { var hasErrors = false; if (postedItem.Properties != null) { foreach (var p in postedItem.Properties) { if (!content.HasProperty(p.Key)) { //TODO: Do we return errors here ? If someone deletes a property whilst their editing then should we just //save the property data that remains? Or inform them they need to reload... not sure. This problem exists currently too i think. var message = string.Format("property with alias: {0} was not found", p.Key); _modelState.AddModelError(string.Format("content.properties.{0}", p.Key), message); hasErrors = true; } } } return(!hasErrors); }