Skip to content

Instantly share code, notes, and snippets.

@BryanWilhite
Last active August 29, 2015 14:09
Show Gist options
  • Save BryanWilhite/57cb2ca84d1c3bc4daf8 to your computer and use it in GitHub Desktop.
Save BryanWilhite/57cb2ca84d1c3bc4daf8 to your computer and use it in GitHub Desktop.
C#, Silverlight/Telerik: HandleUserRoleControl
class Sample
{
void HandleUserRoleControl(LightMessage<LightContentForFrameworkElement<UserRoleControl>> message)
{
var control = message.Content.Element;
var data = message.Content.DataOfContext as SystemUser;
Action loadGridView = () =>
{
if (control.GridView.HasItems) control.GridView.Items.Clear();
var set = this._usersRoles.Where(i => i.UserId == data.UserId);
set.ForEachInEnumerable(i => control.GridView.Items.Add(i));
if (this._usersRolesCache != null) return;
var setCopy = set.Select(i => i.GetDeepClone()).ToList();
this._usersRolesCache = new List<SystemUserRole>(setCopy);
control.GridHasChanges = false;
};
if (data == null) return;
loadGridView();
//support insert:
control.GridView.AddingNewDataItem += (s, args) =>
{
args.NewObject = new SystemUserRole { UserId = (int)data.UserId };
};
control.GridView.RowEditEnded += (s, args) =>
{
if (args.EditAction != GridViewEditAction.Commit) return;
if (args.EditOperationType != GridViewEditOperationType.Insert) return;
if (args.NewData == null) return;
var item = args.NewData as SystemUserRole;
this._usersRoles.Add(item);
control.GridHasChanges = true;
};
//support delete:
if (control.GridViewEditCommandsColumn == null) return;
control.GridViewEditCommandsColumn.ActionAfterDelete = rowData =>
{
var item = rowData as SystemUserRole;
if (item == null) return;
this._usersRoles.Remove(item);
control.GridHasChanges = true;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment