using System;
using System.Linq;
using EspaceClient.FrontOffice.Domaine;
using EspaceClient.FrontOffice.Business.Depots;

namespace EspaceClient.FrontOffice.Data.Depots
{
    public partial class DepotConfigurationPage : IDepotConfigurationPage
    {
        public ConfigurationPage GetConfigurationPageByEspacePageCodeAndNaturePageCode(string espacePageCode, string naturePageCode, long langueId)
        {
            var today = DateTime.Today;

            var query = from conf in DbContext.ConfigurationPages
                        where conf.EspacePage.Code == espacePageCode
                        where conf.NaturePage.Code == naturePageCode
                        where conf.DateDebut <= today && today <= conf.DateFin
                        where conf.LangueID == langueId
                        orderby conf.DateDebut descending
                        select conf;

            return query.FirstOrDefault();
        }
    }
}
