Quantcast
Viewing all articles
Browse latest Browse all 764

Parent Child objects

Good day.

i would like to know if what i am doing is the correct way to do this. i have a parent child class: Customer(parent) and Address(children of parent) i would like users to be able to create as many addresses for the customer as needed. i have my parent classes all set up and my address classes. In My customer class i have the following:

 public static PropertyInfo<AddressList> AddressListProperty = RegisterProperty(new PropertyInfo<AddressList>("AddressList", "Address items"));
        public AddressList AddressList
        {
            get
            {
                if (!FieldManager.FieldExists(AddressListProperty))
                    LoadProperty(AddressListProperty, AddressList.NewList());
                return GetProperty(AddressListProperty);
            }
        }

 

i have my address class "Address : BusinessBase<Address>" and my AddressList class ''AddressList : BusinessBindingListBase<AddressList, Address>"

from my UI 'Customer form' i had new address like the following: 

var add = cust.AddressList.AddNew();

and pass the 'add' object to the address form to work with it. once i have finished adding all the fields i do a

add.applyedit()  <--is that the correct way to do it?

and then i load the list into a list view by doing a foreach address in this.cust.AddressList.

i also have this function in my AddressList to remove an address if the user chooses to do so:

public void Remove(Guid id)
        {
            foreach (Address item in this)
            {
                if (item.Id == id)
                {
                    Remove(item);
                    break;
                }
            }
        }

i see that, that removes the item from my addresslist and adds it to the DeletedList, so is that the correct way to remove child objects from the list?

another thing, how would i update the child addresses? in my Customer class i have the following

  public static Customer Update(Customer obj)
        {
            return DataPortal.Update<Customer>(obj);
        }

which calls a method in my customerfactory class, where and how would i call to update my addresslist of children. also how would i go go about doing an ApplyEdit, CancelEdit, on all the children objects?

sorry for all the questions, just trying to wrap my head around it all and do it the correct way the first time.

 

thank you in advance.


Viewing all articles
Browse latest Browse all 764

Trending Articles