public async override Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { int id = (int)context.ActionArguments.Values.FirstOrDefault(); var prodct = await _IproductServis.GetByIdAsync(id); //Prodct null değilse yani böyle bir ürün var ise if (prodct != null) { // gelen requesti bir sonraki adıma atıyor. await next(); } else { ErrorDto rrdto = new ErrorDto(); rrdto.status = 404; //dolar işaretini kullandık içinde değişken var rrdto.Errors.Add($"id'si{id} olan ürün veri tabanında bulunamadı"); context.Result = new NotFoundObjectResult(rrdto); } }
public async Task <IActionResult> GetById(int Id) { var product = await _productServis.GetByIdAsync(Id); return(Ok(_mapper.Map <ProductDto>(product))); }