public ModelResult <Role> EditRole(Role role, RoleInput roleInput) { ValidationStateDictionary validationState = new ValidationStateDictionary(); validationState.Add(typeof(RoleInput), validator.Validate(roleInput)); if (!validationState.IsValid) { return(new ModelResult <Role>(validationState)); } Role originalRole = role; Role newRole; using (TransactionScope transaction = new TransactionScope()) { newRole = originalRole.Apply(roleInput); validateRole(newRole, originalRole, validationState); if (!validationState.IsValid) { return(new ModelResult <Role>(validationState)); } newRole = repository.Save(newRole); transaction.Complete(); } pluginEngine.ExecuteAll("RoleSaved", new { context, role = new RoleReadOnly(newRole) }); pluginEngine.ExecuteAll("RoleEdited", new { context, role = new RoleReadOnly(newRole), roleOriginal = new RoleReadOnly(originalRole) }); return(new ModelResult <Role>(newRole, validationState)); }