/// <summary>
    /// Initializes the target object for the page
    /// </summary>
    /// <remarks>Many pages have "target" objects that the page operates on. For instance, when viewing
    /// an event, the target object is an event. When looking up a directory, that's the target
    /// object. This method is intended to be overriden to initialize the target object for
    /// each page that needs it.</remarks>
    protected override void InitializeTargetObject()
    {
        base.InitializeTargetObject();

        targetRegistrationFee = MultiStepWizards.RegisterForEvent.RegistrationFee;
        targetAdditionalItems = MultiStepWizards.RegisterForEvent.AdditionalLineItems;

        if (MultiStepWizards.RegisterForEvent.Order == null || targetRegistrationFee == null)
        {
            Restart();
            return;
        }

        targetEvent = LoadObjectFromAPI <msEvent>(targetRegistrationFee.Event);

        //Clone the order held in the session
        initializeClonedOrder();

        if (string.IsNullOrWhiteSpace(targetOrder.BillTo) || string.IsNullOrWhiteSpace(targetOrder.ShipTo))
        {
            GoTo(string.Format("~/events/Register_SelectFee.aspx?contextID={0}", ContextID));
            return;
        }

        initializeRegistrationFields();
    }
    /// <summary>
    /// Initializes the target object for the page
    /// </summary>
    /// <remarks>Many pages have "target" objects that the page operates on. For instance, when viewing
    /// an event, the target object is an event. When looking up a directory, that's the target
    /// object. This method is intended to be overriden to initialize the target object for
    /// each page that needs it.</remarks>
    protected override void InitializeTargetObject()
    {
        base.InitializeTargetObject();

        var target = APIExtensions.LoadObjectFromAPI(ContextID);

        if (target == null)
        {
            GoToMissingRecordPage();
            return;
        }

        // If we are starting with a Registration, go to that setup process
        if (target.ClassType == msEventRegistration.CLASS_NAME)
        {
            targetRegistration = target.ConvertTo <msEventRegistration>();
            LoadExistingRegistration();
            return;
        }

        // If this is not a Registration or an Event, then get out of here
        if (target.ClassType != msEvent.CLASS_NAME)
        {
            GoToMissingRecordPage();
            return;
        }

        targetEvent = target.ConvertTo <msEvent>();

        targetOrder           = MultiStepWizards.RegisterForEvent.Order;
        targetRegistrationFee = MultiStepWizards.RegisterForEvent.RegistrationFee;
        MultiStepWizards.RegisterForEvent.IsSessionSwap = false;

        if (targetOrder == null || string.IsNullOrWhiteSpace(targetOrder.BillTo) || string.IsNullOrWhiteSpace(targetOrder.ShipTo) || targetRegistrationFee == null)
        {
            GoTo(string.Format("~/events/Register_SelectFee.aspx?contextID={0}", targetEvent.ID));
            return;
        }

        registrantId = targetOrder.BillTo;
        if (string.IsNullOrEmpty(registrantId))
        {
            GoToMissingRecordPage();
            return;
        }

        loadEventOwners();
    }
    /// <summary>
    /// Initializes the target object for the page
    /// </summary>
    /// <remarks>Many pages have "target" objects that the page operates on. For instance, when viewing
    /// an event, the target object is an event. When looking up a directory, that's the target
    /// object. This method is intended to be overriden to initialize the target object for
    /// each page that needs it.</remarks>
    protected override void InitializeTargetObject()
    {
        base.InitializeTargetObject();

        //Describe a Registration Fee.  We will need this metadata to bind to the acceptable values for certain fields and for creating a new Registration Fee
        using (IConciergeAPIService proxy = GetConciegeAPIProxy())
        {
            registrationFeeClassMetadata = proxy.DescribeObject(msRegistrationFee.CLASS_NAME).ResultValue;
            registrationFeeFieldMetadata = registrationFeeClassMetadata.GenerateFieldDictionary();
        }

        var contextObject = APIExtensions.LoadObjectFromAPI(ContextID);

        if (contextObject.ClassType == msEvent.CLASS_NAME)
        {
            targetEvent           = contextObject.ConvertTo <msEvent>();
            targetRegistrationFee = msRegistrationFee.FromClassMetadata(registrationFeeClassMetadata);
            lblTitleAction.Text   = "Create";
        }
        else
        {
            targetRegistrationFee = contextObject.ConvertTo <msRegistrationFee>();
            targetEvent           = LoadObjectFromAPI <msEvent>(targetRegistrationFee.Event);
            lblTitleAction.Text   = "Edit";
        }

        if (targetEvent == null || targetRegistrationFee == null)
        {
            GoToMissingRecordPage();
            return;
        }

        targetRegistrationFee.Event = targetEvent.ID;

        loadEventOwners();
    }
 protected void unbindAndSave()
 {
     unbindRegistrationFee();
     targetRegistrationFee = SaveObject(targetRegistrationFee).ConvertTo <msRegistrationFee>();
 }
    private void LoadExistingRegistration()
    {
        targetEvent           = LoadObjectFromAPI <msEvent>(targetRegistration.Event);
        targetRegistrationFee = LoadObjectFromAPI <msRegistrationFee>(targetRegistration.Fee);
        registrantId          = targetRegistration.Owner;

        if (targetEvent == null || targetRegistrationFee == null || string.IsNullOrEmpty(registrantId))
        {
            GoToMissingRecordPage();
        }

        if (targetRegistrationFee.IsGuestRegistration)
        {
            QueueBannerError("Cannot set sessions on Guest Registration.");
            GoTo(ReturnToEventURL());
        }

        var sessionSearch = new Search {
            Type = msSessionRegistration.CLASS_NAME
        };

        sessionSearch.AddOutputColumn("Event");
        sessionSearch.AddOutputColumn("Fee");
        sessionSearch.AddOutputColumn("Event.RegistrationMode");
        sessionSearch.AddOutputColumn("OrderLineItemID");
        sessionSearch.AddCriteria(Expr.Equals("Owner", registrantId));
        sessionSearch.AddCriteria(Expr.Equals("Event.ParentEvent", targetEvent.ID));
        sessionSearch.AddCriteria(Expr.IsBlank("CancellationDate"));

        var sessionResult = APIExtensions.GetSearchResult(sessionSearch, 0, null);

        currentSessions = sessionResult.Table;

        currentSessions.Columns.Add(new DataColumn("Price", typeof(decimal)));

        var orderLineItemIDs = currentSessions.Rows.Cast <DataRow>()
                               .Select(currentSession => Convert.ToString(currentSession["OrderLineItemID"]))
                               .Where(itemId => !string.IsNullOrEmpty(itemId)).ToList();

        if (orderLineItemIDs.Count > 0)
        {
            var orderLineItemSearch = new Search {
                Type = msOrderLineItem.CLASS_NAME
            };
            orderLineItemSearch.AddOutputColumn("OrderLineItemID");
            orderLineItemSearch.AddOutputColumn("Total");
            orderLineItemSearch.AddCriteria(Expr.IsOneOfTheFollowing("OrderLineItemID", orderLineItemIDs));
            orderLineItemSearch.AddSortColumn("ID");

            var orderLineItemResult = APIExtensions.GetSearchResult(orderLineItemSearch, 0, null);
            if (orderLineItemResult != null)
            {
                foreach (DataRow dr in orderLineItemResult.Table.Rows)
                {
                    var sessionRow = currentSessions.Select(string.Format("OrderLineItemID = '{0}'", dr["OrderLineItemID"]));
                    if (sessionRow.Length > 0)
                    {
                        sessionRow[0]["Price"] = dr["Total"];
                    }
                }
            }
        }

        loadEventOwners();
    }