public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (context.ActionArguments.ContainsKey("key")) { var key = (string)context.ActionArguments["key"]; var s = await _service.GetByKeyAsync(key); if (s != OperationStatus.OK) { var data = _keyService.DeconstructFilmKey(key); context.Result = new NotFoundObjectResult($"There is no film {data.title}({data.year})"); return; } } await next(); }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (context.ActionArguments.ContainsKey("key")) { var key = (string)context.ActionArguments["key"]; var data = _keyService.DeconstructFilmKey(key); if (data.title == FilmConstants.BADKEY) { context.Result = new BadRequestObjectResult(key); return; } else { var f = ((IFilmRepository)_repository).GetByTitleAndYear(data.title, data.year).value; if (f == null) { context.Result = new NotFoundObjectResult(key); return; } } } await next(); }