public async Task Invoke(HttpContext context, IAuthenticatedService authenticatedService, ISqlService sqlService) { var token = authenticatedService.Token(); var uri = context.Request.Path.ToUriComponent(); var path = "/users"; Validate(token, uri, path); var paths = uri.Replace(path, string.Empty).Split('/', StringSplitOptions.RemoveEmptyEntries); var parameter = string.Empty; if (paths.Length > 0) { parameter = paths[0]; } if (Int32.TryParse(parameter, out int value)) { await Authorize(value, token, sqlService); } await _next(context); }
public async Task <Pagination <Servico> > ListAsync(int offset, int limit) { this._logger.LogDebug("Starting ListAsync"); this._logger.LogDebug("Validating pagination parameters"); if (limit - offset > 100) { this._validationService.Throw("Limit", "Too much items for pagination", limit, Validation.PaginationExceedsLimits); } this._logger.LogDebug("Retriving paginated list of Servicos"); var list = await _sqlService.ListAsync <Servico>(ServicosQuery.PAGINATE, new { Offset = offset, Limit = limit }); this._logger.LogDebug("Retriving the number of Servicos"); var total = await _sqlService.CountAsync(ServicosQuery.TOTAL, new { CreatedBy = _authenticatedService.Token().Subject }); this._logger.LogDebug("Retriving the number of servicos"); var pagination = new Pagination <Servico>() { Offset = offset, Limit = limit, Items = list, Total = total }; this._logger.LogDebug("Ending ListAsync"); return(pagination); }