public async Task <IActionResult> Patch([FromRoute] string id, [FromBody] ApiPatchCommand <ApiGeoTask> patch) { try { var currentPrincipal = HttpContext.User; var currentUserName = currentPrincipal?.Identity?.Name; using var logScope = Logger.BeginScope("{User}", currentUserName); Logger.LogInformation(ApiLogEvent.ApiRequest, "Task patch command. Id={Id}. Command={Command}", id, patch.ToDictionary()); if (patch?.Patch is null || String.IsNullOrWhiteSpace(id)) { Logger.LogWarning(ApiLogEvent.ApiArgumentError, "Patch task empty argument."); return(BadRequest()); } var getQuery = new EntityQuery <GeoTask>(id, currentPrincipal); var getResult = await Mediator.Send(getQuery); if (getResult is null || !getResult.Success) { Logger.LogWarning(ApiLogEvent.ApiErrorResponse, "Get task error response. Error={Error}.", getResult?.Errors); return(BadRequest()); } var apiGeoTask = getResult.Entity.ToApiGeoTask(); patch.Patch.ApplyTo(apiGeoTask); var command = apiGeoTask.ToGeoTaskUpdateCommand(id, currentPrincipal, patch.MessageTitle, patch.MessageDescription); var result = await Mediator.Send(command); if (result is null || !result.Success) { Logger.LogWarning(ApiLogEvent.ApiErrorResponse, "Task update error response. Error={Error}.", result?.Errors); return(BadRequest()); } return(Ok()); } catch (Exception ex) when(Logger.WriteScopeWhenException (ApiLogEvent.ApiErrorResponse, ex)) { return(BadRequest()); } }