//-----------------------------------------------------------------------
// <copyright file="AdresarDomainContext.cs" company="CÍGLER SOFTWARE,a.s.">
//     All rights are reserved. Reproduction or transmission in whole or
//     in part, in any form or by any means, electronic, mechanical or
//     otherwise, is prohibited without the prior written consent of the 
//     copyright owner.
// </copyright>
// <summary>
//     Definition of the AdresarDomainContext class.
// </summary>
//-----------------------------------------------------------------------

namespace ComboBoxDemo.Web
{
    using System;
    using System.ServiceModel.DomainServices.Client;
    using System.ComponentModel;

    public partial class AdresarDomainContext
    {       
        public override LoadOperation Load(EntityQuery query, LoadBehavior loadBehavior, Action<LoadOperation> callback, object userState)
        {
            this.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(MyDomainContext_PropertyChanged);
            this.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(MyDomainContext_PropertyChanged);

            return base.Load(query, loadBehavior, callback, userState);
        }

        private void MyDomainContext_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "IsLoading" && this.IsLoading == true)
            {
                if (IsBusy != null)
                { 
                    IsBusy(this, new IsBusyEventArgs(true));
                }
            }
            else if (e.PropertyName == "IsLoading" && this.IsLoading == false)
            {
                if (IsBusy != null)
                { 
                    IsBusy(this, new IsBusyEventArgs(false));
                }
            }
            else if (e.PropertyName == "IsSubmitting" && this.IsSubmitting == true)
            {
                if (IsBusy != null)
                {
                    IsBusy(this, new IsBusyEventArgs(true));
                }
            }
            else if (e.PropertyName == "IsSubmitting" && this.IsSubmitting == false)
            {
                if (IsBusy != null)
                {
                    IsBusy(this, new IsBusyEventArgs(false));
                }
            }
        }

        public event EventHandler<IsBusyEventArgs> IsBusy;
    }
}
