/// <summary> /// Validate the changeset. /// </summary> /// <param name="validationContext">The ValidationContext to use.</param> /// <returns>True if the changeset is valid, false otherwise.</returns> internal bool Validate(ValidationContext validationContext) { bool success = true; foreach (Entity entity in this) { entity.VerifyNotEditing(); bool entityRequiresValidation = entity.MetaType.RequiresValidation; EntityAction customMethod = entity.EntityActions.SingleOrDefault(); if (!entityRequiresValidation && customMethod == null) { continue; } if (entity.EntityState == EntityState.Deleted) { // skip validation for Deleted entities here since the entity is going to be deleted anyway continue; } // first validate the entity List <ValidationResult> validationResults = new List <ValidationResult>(); if (entityRequiresValidation) { ValidationUtilities.TryValidateObject(entity, validationContext, validationResults); } // validate any Custom Method invocations if (customMethod != null) { // validate the method call object[] parameters = customMethod.HasParameters ? customMethod.Parameters.ToArray() : null; ValidationContext customMethodValidationContext = ValidationUtilities.CreateValidationContext(entity, validationContext); ValidationUtilities.TryValidateCustomUpdateMethodCall(customMethod.Name, customMethodValidationContext, parameters, validationResults); } if (validationResults.Count > 0) { // replace the validation errors for the entity IEnumerable <ValidationResult> entityErrors = new ReadOnlyCollection <ValidationResult>(validationResults.Select(err => new ValidationResult(err.ErrorMessage, err.MemberNames)).Distinct(new ValidationResultEqualityComparer()).ToList()); ValidationUtilities.ApplyValidationErrors(entity, entityErrors); success = false; } else { // clear the errors for the entity entity.ValidationErrors.Clear(); } } return(success); }
private EditSession(Entity entity) { this._entity = entity; this._lastState = entity.EntityState; this._customMethodInvocation = entity.CustomMethodInvocation; this._validationErrors = entity.ValidationErrors.ToArray(); this._modifiedProperties = new List<string>(); }
/// <summary> /// Invokes the virtual OnActionStateChanged method as required. /// </summary> /// <param name="prevCustomMethodInvocation">The previous custom method /// invocation.</param> private void UpdateActionState(EntityAction prevCustomMethodInvocation) { if (this._lastCanInvoke == this.CanInvokeAction(null)) { // if the action state hasn't changed, nothing to do return; } // save off any previous invocation this._prevCustomMethodInvocation = prevCustomMethodInvocation; this.OnActionStateChanged(); this._prevCustomMethodInvocation = null; }