New Posts New Posts RSS Feed: [SOLVED] Adding a New Entity with Params--The CAB Way
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

[SOLVED] Adding a New Entity with Params--The CAB Way

 Post Reply Post Reply
Author
Linguinut View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 394
Post Options Post Options   Quote Linguinut Quote  Post ReplyReply Direct Link To This Post Topic: [SOLVED] Adding a New Entity with Params--The CAB Way
    Posted: 28-Sep-2007 at 5:00pm

I have the following code in my "old" model of the Contact entity:

public static ContactMaster Create
(
   
PersistenceManager pPersMgr,
   
int pSource,
   
int pMasterIndex,
   
int pAddressIndex,
   
string pLastName,
   
string pFirstName
)
{
    ContactMaster aContact = (ContactMaster)pPersMgr.CreateEntity(typeof(ContactMaster));
    aContact.AddToManager();
    aContact.Sourceindex = pSource;
    aContact.Masterindex = pMasterIndex;
    aContact.Addressindex = pAddressIndex;
    aContact.Lastname = pLastName;
    aContact.Firstname = pFirstName;
   
return aContact;
}

How would I make this call to the create method within the CAB?  At what point would that call happen?  I would think it would occur in the business module at some point.  If so, are there some overrides out there I should be taking advantage of?  Is there an entity creator service or something like that?

I am doing my own investigation, as always, but if anyone can point me in the right direction, then I won't have to retrace a lot of steps.
 
Thanks!
Bill


Edited by Linguinut - 01-Oct-2007 at 2:33pm
Back to Top
Linguinut View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 394
Post Options Post Options   Quote Linguinut Quote  Post ReplyReply Direct Link To This Post Posted: 29-Sep-2007 at 8:06am
Please note that I figured out how to do this within my own control view controller; however, I am not sure how to utilize the same behavior within a summary detail page, and such.  What should I override there in order to make it work?  I will look into this more next week.
Back to Top
Linguinut View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 394
Post Options Post Options   Quote Linguinut Quote  Post ReplyReply Direct Link To This Post Posted: 01-Oct-2007 at 1:32pm
I discovered the following code in the CustomersPageController:
 
/// <summary>
/// Tell the BindingSource how to add new objects.
/// </summary>
/// <remarks>
/// A BindingSource has its own (peculiar) way of managing creation of new objects.
/// Could ignore it and use traditional methods but some controls (e.g., grids)
/// understand the BindingSource protocol and it conveniently adds the new
/// items to its list so we go with it here.
/// </remarks>
protected override void EnableMainBindingSourceAddNew()
{
    //MainBindingSource.AllowNew = CustomerMaster.EntityCreator.AllowCreate;
    //MainBindingSource.AddingNew += BindingSourceAddingNewHandler;
}
 
This seems like the place to go in order to employ the custom Create method of a specific entity.  Should I place my CustomerMaster.Create() call here, or is there another method that needs to be overridden for best results?
 
Thanks,
Bill
 
Back to Top
Linguinut View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 394
Post Options Post Options   Quote Linguinut Quote  Post ReplyReply Direct Link To This Post Posted: 01-Oct-2007 at 2:32pm

Trial and error is a wonderful thing...just really time-consuming!

Here is the solution to my adding a new entity the CAB way--override the CreateEntity method in the page controller, like this:
protected override CustomerMaster CreateEntity(System.ComponentModel.AddingNewEventArgs pArgs)
{
    return CustomerMaster.Create(EntityManager.PersistenceManager, "[CUSTOMER NAME]", 1); ;
}
 
This works like a charm (even when using the PooledNumericIdGenerator!!!).
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down