Created
September 15, 2012 13:55
-
-
Save davybrion/3728058 to your computer and use it in GitHub Desktop.
code snippets for "MVP In Silverlight/WPF: Implementing The Overview UserControl" post, part II
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IUserGroupsView : IView | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void Initialize() | |
{ | |
var requestDispatcher = RequestDispatcherFactory.CreateAsyncRequestDispatcher(); | |
requestDispatcher.Add(new CheckPermissionsRequest { PermissionsToCheck = new[] { Permissions.CreateUserGroup } }); | |
requestDispatcher.Add(new GetAllUserGroupsRequest()); | |
requestDispatcher.ProcessRequests(ResponsesReceived, PublishRemoteException); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ResponsesReceived(ReceivedResponses receivedResponses) | |
{ | |
if (receivedResponses.HasResponse<GetAllUserGroupsResponse>()) | |
{ | |
BindingModel.PopulateFrom(receivedResponses.Get<GetAllUserGroupsResponse>().UserGroups); | |
View.ExpandTreeView(); | |
} | |
if (receivedResponses.HasResponse<CheckPermissionsResponse>() && | |
!receivedResponses.Get<CheckPermissionsResponse>().AuthorizationResults[Permissions.CreateUserGroup]) | |
{ | |
View.HideAddNewButton(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IUserGroupsView : IView | |
{ | |
void ExpandTreeView(); | |
void HideAddNewButton(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void DealWithSelectedUserGroup(HierarchicalUserGroupBindingModel selectedUserGroup) | |
{ | |
EventAggregator.Publish(new UserGroupSelectedEvent(selectedUserGroup.Id)); | |
} | |
public void PrepareUserGroupCreation() | |
{ | |
EventAggregator.Publish(new UserGroupNeedsToBeCreatedEvent()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserGroupChangedEvent : Event | |
{ | |
public Guid Id { get; set; } | |
public string Name { get; set; } | |
public Guid? ParentId { get; set; } | |
public bool IsNew { get; set; } | |
} | |
public class UserGroupDeletedEvent : Event | |
{ | |
public UserGroupDeletedEvent(Guid userGroupId) | |
{ | |
UserGroupId = userGroupId; | |
} | |
public Guid UserGroupId { get; private set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserGroupsPresenter : Presenter<IUserGroupsView, UserGroupsBindingModel>, | |
IListenTo<UserGroupChangedEvent>, IListenTo<UserGroupDeletedEvent> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EventAggregator.Subscribe(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Handle(UserGroupChangedEvent receivedEvent) | |
{ | |
if (receivedEvent.IsNew) | |
{ | |
View.SelectItemInTreeView(BindingModel.AddUserGroup(receivedEvent.Id, receivedEvent.Name, receivedEvent.ParentId)); | |
} | |
else | |
{ | |
BindingModel.UpdateUserGroup(receivedEvent.Id, receivedEvent.Name, receivedEvent.ParentId); | |
} | |
} | |
public void Handle(UserGroupDeletedEvent receivedEvent) | |
{ | |
BindingModel.RemoveUserGroup(receivedEvent.UserGroupId); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment