protected void ucIDetail_ChildListInstanceRowDeleting(object sender, InstanceRowDeletingEventArgs e)
        {
            using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey))
            {
                switch ((InstanceTypes)Enum.Parse(typeof(InstanceTypes), e.InstanceType))
                {
                case InstanceTypes.Contact:
                    ContactFacade facade = new ContactFacade(uow);
                    IFacadeUpdateResult <ContactData> result = facade.DeleteContact(e.Instance.Id);
                    e.IsSuccessful = result.IsSuccessful;

                    if (result.IsSuccessful)
                    {
                        // Refresh data in session
                        CurrentInstance.Contacts = facade.RetrieveContactsByCustomer(CurrentInstance.Id, new ContactConverter());
                    }
                    else
                    {
                        // Deal with Update result
                        ProcUpdateResult(result.ValidationResult, result.Exception);
                    }
                    break;

                case InstanceTypes.ScheduleEvent:
                    ScheduleEventFacade facade2 = new ScheduleEventFacade(uow);
                    // Delete data
                    IFacadeUpdateResult <ScheduleEventData> result2 = facade2.DeleteScheduleEvent(e.Instance.Id);
                    e.IsSuccessful = result2.IsSuccessful;
                    if (result2.IsSuccessful)
                    {
                        // Refresh data in session
                        CurrentInstance.ScheduleEvents = facade2.RetrieveScheduleEventsByCustomer(CurrentInstance.Id, new ScheduleEventConverter());
                    }
                    else
                    {
                        ProcUpdateResult(result2.ValidationResult, result2.Exception);
                    }
                    break;

                case InstanceTypes.ShipTo:
                    ShipToFacade facade3 = new ShipToFacade(uow);
                    // Delete data
                    IFacadeUpdateResult <ShipToData> result3 = facade3.DeleteShipTo(e.Instance.Id);
                    e.IsSuccessful = result3.IsSuccessful;
                    if (result3.IsSuccessful)
                    {
                        // Refresh data in session
                        CurrentInstance.ShipTos = facade3.RetrieveShipTosByCustomer(CurrentInstance.Id, new ShipToConverter());
                    }
                    else
                    {
                        ProcUpdateResult(result3.ValidationResult, result3.Exception);
                    }
                    break;
                }
            }
        }
        protected void ucIDetail_ChildListInstanceRowSaving(object sender, InstanceRowSavingEventArgs e)
        {
            using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey))
            {
                switch ((InstanceTypes)Enum.Parse(typeof(InstanceTypes), e.InstanceType))
                {
                case InstanceTypes.Contact:
                    ContactFacade facade     = new ContactFacade(uow);
                    ContactDto    contactDto = e.Instance as ContactDto;
                    contactDto.CustomerId = CurrentInstance.Id;
                    // Save data
                    IFacadeUpdateResult <ContactData> result = facade.SaveContact(contactDto);
                    e.IsSuccessful = result.IsSuccessful;
                    if (result.IsSuccessful)
                    {
                        // Refresh data in session
                        CurrentInstance.Contacts = facade.RetrieveContactsByCustomer(CurrentInstance.Id, new ContactConverter());
                    }
                    else
                    {
                        ProcUpdateResult(result.ValidationResult, result.Exception);
                    }
                    break;

                case InstanceTypes.ScheduleEvent:
                    ScheduleEventFacade facade2  = new ScheduleEventFacade(uow);
                    ScheduleEventDto    eventDto = e.Instance as ScheduleEventDto;
                    eventDto.ObjectId     = CurrentInstance.Id;
                    eventDto.ObjectTypeId = (int)EventObjectTypes.Customer;
                    // Save data
                    IFacadeUpdateResult <ScheduleEventData> result2 = facade2.SaveScheduleEvent(eventDto);
                    e.IsSuccessful = result2.IsSuccessful;
                    if (result2.IsSuccessful)
                    {
                        // Refresh data in session
                        CurrentInstance.ScheduleEvents = facade2.RetrieveScheduleEventsByCustomer(CurrentInstance.Id, new ScheduleEventConverter());
                    }
                    else
                    {
                        ProcUpdateResult(result2.ValidationResult, result2.Exception);
                    }
                    break;

                case InstanceTypes.ShipTo:
                    ShipToFacade facade3   = new ShipToFacade(uow);
                    ShipToDto    shipToDto = e.Instance as ShipToDto;
                    shipToDto.CustomerId = CurrentInstance.Id;
                    // Save data
                    IFacadeUpdateResult <ShipToData> result3 = facade3.SaveShipTo(shipToDto);
                    e.IsSuccessful = result3.IsSuccessful;
                    if (result3.IsSuccessful)
                    {
                        // Refresh data in session
                        CurrentInstance.ShipTos = facade3.RetrieveShipTosByCustomer(CurrentInstance.Id, new ShipToConverter());
                    }
                    else
                    {
                        ProcUpdateResult(result3.ValidationResult, result3.Exception);
                    }
                    break;
                }
            }
        }