using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Media;

using BeWo.ServiceProxy;

using BS.Shared.DataContracts.Compact;

namespace BeWo.View.Search
{
    public class OrganisationSearchView : GenericSearchView<CompactOrganisationDC>
    {
        public OrganisationSearchView()
        {
            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                this.ThemeColor = this.FindResource("OrganisationContentBrush") as Brush;
            }
        }

        protected override void GetAll(Action<List<CompactOrganisationDC>> pCallBack)
        {
            if (this.SearchMode == SearchMode.CostBearer)
            {
                ServiceFacade.DoCustomerServiceAsync(
                    s => s.GetAllCostBearerCompact(), 
                    r =>
                        {
                            r.Sort((x, y) => { return x.Name.CompareTo(y.Name); });

                            pCallBack(r);
                        });
            }
            else
            {
                ServiceFacade.DoCustomerServiceAsync(
                    s => s.GetAllActiveOrganisationsCompact(), 
                    r =>
                        {
                            r.Sort((x, y) => { return x.Name.CompareTo(y.Name); });

                            pCallBack(r);
                        });
            }
        }
    }
}