| Author |
Share Topic Topic Search Topic Options
|
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Topic: Process for creating new Base View? Posted: 25-Sep-2007 at 5:23pm |
tx. I am out until next Monday. But I will give it a shot then.
|
 |
Bill Jensen
IdeaBlade
Joined: 31-Jul-2007
Location: United States
Posts: 229
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 5:14pm |
Yeah.
It turns out that in CommonEntity (in IdeaBlade.Common.EntityModel) there are three methods:
AllowCreate()
AllowUpdate()
AllowDelete()
By default the first two return true and the third returns false. You can override these in your entity classes (or in BaseEntity) to control what is allowed and disallowed. In them you could place whatever logic you want to determine if the operation should proceed. Your presenter or controller logic can also invoke them before carrying out an operation.
If you simply override AllowDelete() in your UserRole entity and return true you'll be able to delete.
Sorry not to have this sooner.
Bill J.
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 10:44am |
tx. That worked. A
Any idea about the delete?
|
 |
Bill Jensen
IdeaBlade
Joined: 31-Jul-2007
Location: United States
Posts: 229
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 10:37am |
I think Bill C. is right; it's a problem with the wrong persistence manager.
In my update to the LayoutDemo app posted earlier in this thread, the UserSecurityCode entity has a static Create() method that doesn't accept a persistence manager:
UserSecurityCode newItem = UserSecurityCode.Create(currentUser, selectedRole);
Inside this create method is the line:
UserSecurityCode assoc =
pUser.PersistenceManager.CreateEntity< UserSecurityCode>();
As you can see, it uses the persistence manager it retrieves from the User entity. I suggest you try this.
Within pages whose page controller inherit from PageController<entitytype>, the persistence manager is wrapped in an EntityManager that assists in maintaining synchrony between multiple views without round trips to the persistence server. Again in my earlier post on this thread, I retrieve the initial UserSecurityCodes with:
RdbQuery query = new RdbQuery(typeof(UserSecurityCode), UserSecurityCode.UserIdEntityColumn, EntityQueryOp.EQ, user.Id);
list = EntityManager.PersistenceManager.GetEntities< UserSecurityCode>(query, pStrategy);
It is on this persistence manager that SaveChanges() will be called when Save is selected.
Hope this helps.
Bill J.
|
 |
Linguinut
Senior Member
Joined: 14-Jun-2007
Location: United States
Posts: 394
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 9:52am |
You may have to implement your own save/delete routines for the triple-pane layout that you created. I suppose you could somehow wiggle into the context of the parent layout, but that'll take some work, too. Hopefully, the big guns will weigh in on this again someday.
Edited by Linguinut - 25-Sep-2007 at 9:56am
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 9:47am |
The problem is that I am not controlling the save button. It is in the PageView control.
|
 |
Linguinut
Senior Member
Joined: 14-Jun-2007
Location: United States
Posts: 394
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 9:41am |
|
I don't think there is only one persistence manager involved. I vaguely remember Ward saying something in training one time about a pm per view, or something like that. Is it possible that you are calling the save on a pm that does not have the changes that you made? Just a thought...you probably already checked that, though.
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 8:45am |
My code: And it says nothing to save:
/// <summary>
/// Add a new Role to the Parent User
/// </summary>
public void AddRole()
{
Role mSelectedRole = (Role)ActionViewContext.RolesBindingSource.Current;
User mUser = (User)ActionViewContext.ParentBindingSource.Current;
UserRole newUserRole = UserRole.Create(MainPm.Manager, mUser, mSelectedRole);
ActionViewContext.UserRolesBindingSource.Add(newUserRole);
}
/// <summary>
/// Delete the currently selected UserRole
/// </summary>
public void DeleteRole()
{
UserRole selectedUserRole = ActionViewContext.UserRolesBindingSource.Current as UserRole;
if (selectedUserRole != null)
selectedUserRole.Delete();
}
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 8:27am |
I can now move from one grid to the other. But when I save an added UserRole it says nothing to save, as it did before. Then as you know the delete gives an error.
Why would it be saying nothing to save?
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 7:28am |
|
I meant ActionViewContext
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 25-Sep-2007 at 7:27am |
|
ActionViewPresenter methods are all static correct?
Edited by orcities - 25-Sep-2007 at 7:27am
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 24-Sep-2007 at 5:02pm |
|
When doing the UserSecurityCode.Create() why don't you have to pass then Persistence Manager?
|
 |
Bill Jensen
IdeaBlade
Joined: 31-Jul-2007
Location: United States
Posts: 229
|
Post Options
Quote Reply
Posted: 24-Sep-2007 at 3:35pm |
First:
In my LayoutDemo application, I populated the UserRolesBindingManager with:
IList list = pParent.GetChildren<UserSecurityCode>(EntityRelations.User_UserSecurityCode, pStrategy);
You'll note that GetChildren() returns an array of UserSecurityCode objects--a fixed length list. Instead, we need to perform a query:
EntityQuery query = new EntityQuery(typeof(UserSecurityCode), UserSecurityCode.UserIdEntityColumn, EntityQueryOp.EQ, user.Id);
list = EntityManager.PersistenceManager.GetEntities< UserSecurityCode>(query, pStrategy);
to get a managed EntityList.
Second:
In the Add() method of the ActionViewPresenter, I tried to add the selected Role directly to the UserRole BindingList. That won't work, since they're of different entity types. We need to create a new UserRole ("UserSecurityCode" in the LayoutDemo model) entity using its Create() method and add THAT to the binding source:
UserSecurityCode newItem = UserSecurityCode.Create(currentUser, selectedRole);
mUserRolesBindingSource.Add(newItem);
The "selectedRole" is just the current item in the RolesBindingManager.
The current user is the current item in the parent binding manager but unfortunately, the parent binding manager isn't available in the ActionViewPresenter. You could either pass it in via the ActionViewContext, or move the Add and Remove logic out to the UserRolesTabViewController and pass a reference to IT in the ActionViewContext.
In Remove() we need to actually remove the UserSecurityCode entity from the PM:
UserSecurityCode selectedUserRole = mUserRolesBindingSource.Current as UserSecurityCode;
if (selectedUserRole != null)
{
selectedUserRole.Delete();
}
That updates the UserRolesBindingSource and the grid automatically.
In my version I can save additions of user roles OK, but I also get the "Validation Issue" message when I try to save a deletion. I'll investigate that further.
Hope this helps.
Bill J.
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 24-Sep-2007 at 9:12am |
**Please read edits to previous post
|
 |
orcities
Senior Member
Joined: 28-Aug-2007
Location: United States
Posts: 454
|
Post Options
Quote Reply
Posted: 24-Sep-2007 at 8:03am |
Updates in Red
I appreciate your help. That worked.
But I am still having one issue. When I go to add. It does not add the UserRole to the grid. UserRole.Create(MainPm.Manager, User, Role))
Update: I understand this adds it to the cache. Since it didn't show I tried to add it to the BindingSource as well and I get the following error: Collection was of fixed size.
When I go to delete it the action seems to work, but the grid is not updated. ((UserRole)UserRoleBindingSource.Current).Delete();
Then when I save after deleting it tells me I can't "You are not allowed to delete LOC.CEMS.Model.UserRole.
When I try and save after an add it says there is nothing to save.
But when I hit add a second time on the same role it gives me a foreign key conflict error.
It doesn't seem to hit the Refresh for the TabController after an action has take place.
Edited by orcities - 24-Sep-2007 at 9:11am
|
 |
Bill Jensen
IdeaBlade
Joined: 31-Jul-2007
Location: United States
Posts: 229
|
Post Options
Quote Reply
Posted: 21-Sep-2007 at 2:08pm |
Try this (terminology is from my LayoutDemo app):
Add fields to the ActionViewContext for the RoleBindingSource and UserRoleBindingSource. Set these in the UserRolesTabViewController (be sure both binding sources are created before creating the ActionViewContext).
Then you'll have access to them in the ActionViewPresenter (from the Context property). [You can override OnContextSet() so you know when the context is available].
EntityBindingSources expose a Current property that is the current selected item. They also expose a CurrentItemChanged event. With these and the events from the Add and Remove buttons in the view, the ActionViewPresenter should be able to implement the functionality you need.
Bill J.
|
 |