using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Address
/// </summary>
namespace TerritorySite.BL.CMS
{
    public partial class Address
    {


        public static AddressSearchCollection Search(string streetName, int cityId, int houseNumber, string apartmentNumber)
        {
            AddressSearchCollection collection = new AddressSearchCollection();
            if (cityId > 0)
            {
                SubSonic.Query query = AddressSearch.CreateQuery();
                query.AddWhere(Columns.CityId, cityId);
                query.AddWhere(Columns.TerritoryId, CurrentUser.TerritoryId);
                bool addWhere = false;
                if (houseNumber > 0)
                {
                    query.AND(Columns.HouseNumber, houseNumber);

                }
                if (streetName != null & streetName != string.Empty)
                {

                    query.AND(Columns.StreetName, streetName);

                }
                if (apartmentNumber != null & apartmentNumber != string.Empty)
                {

                    query.AND(Columns.ApartmentNumber, apartmentNumber);

                }
                

                collection.LoadAndCloseReader(AddressSearch.FetchByQuery(query));
            }
            return collection;
        }


        

        //public static AddressSearchCollection GetByTerritoryId(int territoryId, int languageId)
        //{
        //    var collection = GetByTerritoryId(territoryId);
        //    AddressSearchCollection collectionFiltered = new AddressSearchCollection();
        //    foreach (var address in collection)
        //    {
        //        if (address.LanguageId == languageId)
        //        {
        //            collectionFiltered.Add(address);
        //        }
        //    }
        //    return collectionFiltered;
        //}


    }

}