public static Dictionary <string, object> ToDictionary (this _ApiEntityType from) => from is null ? null : new Dictionary <string, object> { { nameof(from.Description), from.Description }, { nameof(from.IsArchived), from.IsArchived }, { nameof(from.Title), from.Title }, { nameof(from.GeoJson), from.GeoJson }, };
public static _EntityType ToEntity <TEntity> (this _ApiEntityType from, string id, ClaimsPrincipal currentPrincipal) where TEntity : _EntityType => from is null ? null : new _EntityType { Description = from.Description, Id = id, Title = from.Title, CurrentPrincipal = currentPrincipal, IsArchived = from.IsArchived, GeoJson = from.GeoJson };
public async Task <IActionResult> Update([FromRoute] string id, [FromBody] _ApiEntityUpdateCommandType command) { try { var currentPrincipal = HttpContext.User; var currentUserName = currentPrincipal?.Identity?.Name; using var logScope = Logger.BeginScope("{User}", currentUserName); Logger.LogInformation(ApiLogEvent.ApiRequest, "Geo update command. Id={Id}. Command={Command}", id, command.ToDictionary()); if (command is null || String.IsNullOrWhiteSpace(id)) { Logger.LogWarning(ApiLogEvent.ApiArgumentError, "Geo update empty argument error."); return(BadRequest()); } var appCommand = command.ToEntity <_EntityUpdateCommandType>(id, currentPrincipal); var result = await Mediator.Send(appCommand); if (result is null || !result.Success) { Logger.LogWarning(ApiLogEvent.ApiErrorResponse, "Geo update error response. Error={Error}.", result?.Errors); return(BadRequest()); } return(Ok()); } catch (Exception ex) when(Logger.WriteScopeWhenException (ApiLogEvent.ApiErrorResponse, ex)) { return(BadRequest()); } }