protected virtual async Task <object> PerformPost(TEditorModel model, TKey id = default(TKey)) { if (Throttled && !ThrottlingService.CanAccess(User, Request)) { return(StatusCode(429, ThrottleService.Message)); } if (!ModelState.IsValid) { var errors = ModelState.ConcatErrors(); return(BadRequest(errors)); } id = DefaultIfUnspecified(id, model.Id); if (!CanPost(id)) { return(Unauthorized()); } if (!IsUnspecified(id)) { var entities = FetchEntities(id); var single = entities.SingleOrDefault(); if (single != null) { return(await CreateOrUpdate(model, single)); } } return(await CreateOrUpdate(model)); }
public async Task <IActionResult> Get(long?date = null) { if (Throttled && !ThrottlingService.CanAccess(User, Request, Request.Path, Timeout)) { return(StatusCode(429, ThrottleService.Message)); } var found = DbContext.CacheSets.Where(x => x.Type == Type); if (date.HasValue) { var dateTime = date.Value.FromUnixEpochDate(); found = found.Where(x => x.EditedDate > dateTime); } var data = await found.SingleOrDefaultAsync(); if (data != null) { var result = new CacheResults { Timestamp = data.EditedDate, Items = data.JSON }; return(Ok(result)); } return(Ok(null)); }
public async Task <IActionResult> Get() { if (Throttled && !ThrottlingService.CanAccess(User, Request, Request.Path)) { return(StatusCode(429, ThrottleService.Message)); } var id = User.GetId(); if (String.IsNullOrWhiteSpace(User.GetId())) { return(Unauthorized()); } var notifications = await DbContext.Notifications .Where(x => x.UserId == id) .OrderBy(x => x.Id) .ProjectTo <NotificationModel>(AutoMapper.ConfigurationProvider) .ToListAsync(); return(Ok(notifications)); }
public override void OnActionExecuting(ActionExecutingContext context) { var controller = context.Controller as Controller; if (controller != null) { if (!_service.CanAccess(null, controller.Request, null, 0.5, 10, "filter")) { var userString = controller.User?.GetId(); _logger.LogWarning($"User {(!String.IsNullOrWhiteSpace(userString) ? $"'{userString}'" : "")}" + $" from '{context.HttpContext.Connection.RemoteIpAddress}' was throttled when" + $"trying to access '{controller.Request.Path}'"); context.Result = new StatusCodeResult(429); } } base.OnActionExecuting(context); }