public static void RequiresAccessToken(this CarterModule module) { module.Before += ctx => { if (ctx.Request.GetAccessToken() != null) { return(Task.FromResult(true)); } throw new LinnApiException(HttpStatusCode.Unauthorized); }; }
public static void RequiresIftttServiceKey(this CarterModule module) { module.Before = ctx => { if (ctx.Request.Headers.TryGetValue("IFTTT-Service-Key", out var serviceKey) && serviceKey == ConfigurationManager.Configuration["iftttServiceKey"]) { return(Task.FromResult(true)); } throw new InvalidServiceKeyException(); }; }
public static T GetById <T>(this CarterModule Module, int Id, IBaseFinder <T> Finder) where T : Entity { T entity = Finder.GetById(Id); if (entity == null) { throw new HttpException(HttpStatusCode.BadRequest, $"Element with Id = {Id.ToString()} not found"); } else { return(entity); } }