public static Dictionary <string, object> ToDictionary (this _ApiEntityCreateCommandType 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 }, { nameof(from.ProjectId), from.ProjectId } };
public static _EntityCreateCommandType ToEntity <TEntity> (this _ApiEntityCreateCommandType from, ClaimsPrincipal currentPrincipal) where TEntity : _EntityCreateCommandType => from is null ? null : new _EntityCreateCommandType { Description = from.Description, Title = from.Title, CurrentPrincipal = currentPrincipal, IsArchived = from.IsArchived, GeoJson = from.GeoJson, ProjectId = from.ProjectId };
public async Task <IActionResult> Create ([FromBody] _ApiEntityCreateCommandType command) { try { var currentPrincipal = HttpContext.User; var currentUserName = currentPrincipal?.Identity?.Name; using var logScope = Logger.BeginScope("{User}", currentUserName); Logger.LogInformation(ApiLogEvent.ApiRequest, "Get create geo command {Command}", command.ToDictionary()); var query = command .ToEntity <_EntityCreateCommandType>(currentPrincipal); var result = await Mediator.Send(query).ConfigureAwait(false); if (result is null || !result.Success) { Logger.LogWarning(ApiLogEvent.ApiErrorResponse, "Geo create error response. Error={Error}.", result?.Errors); return(BadRequest()); } return(CreatedAtAction(nameof(Get), new { id = result.Id }, result.Id)); } catch (Exception ex) when(Logger.WriteScopeWhenException (ApiLogEvent.ApiErrorResponse, ex)) { return(BadRequest()); } }