public static Dictionary <string, object> ToDictionary (this _ApiEntityCreateCommandType from) { if (from is null) { return(null); } return(new Dictionary <string, object> { { nameof(from.Layers), String.Join(',', from.Layers.Select(x => $"{{\"{nameof(x.GeoId)}\"={x.GeoId}," + $"\"{nameof(x.IsHidden)}\"={x.IsHidden}," + $"\"{nameof(x.Order)}\"={x.Order}}}")) }, { nameof(from.Description), from.Description }, { nameof(from.IsArchived), from.IsArchived }, { nameof(from.IsMap), from.IsMap }, { nameof(from.MapParameters), String.Join(',', from.MapParameters.Select(x => $"{{\"{x.Key}\"={x.Value}}}")) }, { nameof(from.MapProvider), from.MapProvider }, { nameof(from.ProjectActorRoles), from.ProjectActorRoles.Select(x => $"{{\"{x.Key}\"={x.Value}}}") }, { nameof(from.ShowMap), from.ShowMap }, { nameof(from.Title), from.Title }, }); }
public static _EntityCreateCommandType ToEntity <TEntity> (this _ApiEntityCreateCommandType from, ClaimsPrincipal currentPrincipal) where TEntity : _EntityCreateCommandType { if (from is null) { return(null); } var to = new _EntityCreateCommandType { Description = from.Description, Title = from.Title, CurrentPrincipal = currentPrincipal, IsArchived = from.IsArchived, IsMap = from.IsMap, MapProvider = from.MapProvider, ShowMap = from.ShowMap }; to.Layers.AddRange(from.Layers); from.MapParameters.ToList().ForEach(x => to.MapParameters.TryAdd(x.Key, x.Value)); var allRoles = EnumerationClass.GetAll <ActorRole>(); foreach (var item in from.ProjectActorRoles) { var actorRole = allRoles.FirstOrDefault(x => x.Id == item.Value); if (actorRole != null) { to.ProjectActorRoles.TryAdd(item.Key, actorRole); } } return(to); }
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 project 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, "Project 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()); } }