public async Task <IActionResult> Delete(int id) { _logger.LogInformation($"User trying to delete advertisement with identificator {id}"); var entity = await _advertisements.FindAdvertisementAsync(id); var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); if (entity == default(Advertisement)) { _logger.LogWarning($"User requested not existing advertisement"); return(NotFound()); } if (entity.AuthorId.ToString() != userId) { _logger.LogWarning($"User is tried to delete not his own advertisement"); return(Forbid()); } await _advertisements.DeleteAdvertisementAsync(entity); _logger.LogInformation($"Advertisement with identificator {entity.Id} was deleted"); return(NoContent()); }