using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication1.ActionFilers {
  public class HorairesDAccesAttribute : FilterAttribute, IAuthorizationFilter {
    public TimeSpan Debut { get; }
    public TimeSpan Fin { get; }
    public HorairesDAccesAttribute( string debut, string fin ) {
      Debut = TimeSpan.Parse( debut );
      Fin = TimeSpan.Parse( fin );
    }
    public void OnAuthorization( AuthorizationContext filterContext ) {
      var now = DateTime.Now.TimeOfDay;
      if( !(Debut <= now && now <= Fin) )
        filterContext.Result = new ContentResult() { Content = $"Utilisable seulement dans la plage horaire {Debut}-{Fin}" };
    }
  }
}