fix services
This commit is contained in:
@@ -23,9 +23,9 @@ public class GameProfile : Profile
|
|||||||
.ForMember(d => d.Properties, o => o.MapFrom(s => s.GameProperties.Select(p => p.Property)))
|
.ForMember(d => d.Properties, o => o.MapFrom(s => s.GameProperties.Select(p => p.Property)))
|
||||||
.ForMember(d => d.Tags, o => o.MapFrom(s => s.GameTags.Select(t => t.Tag)))
|
.ForMember(d => d.Tags, o => o.MapFrom(s => s.GameTags.Select(t => t.Tag)))
|
||||||
.ForMember(d => d.Publisher, o => o.MapFrom(s => s.Publisher))
|
.ForMember(d => d.Publisher, o => o.MapFrom(s => s.Publisher))
|
||||||
.ForMember(d => d.Publisher!.Id, o => o.MapFrom(s => s.PublisherId))
|
.ForPath(d => d.Publisher!.Id, o => o.MapFrom(s => s.PublisherId))
|
||||||
.ForMember(d => d.Developer, o => o.MapFrom(s => s.Developer))
|
.ForMember(d => d.Developer, o => o.MapFrom(s => s.Developer))
|
||||||
.ForMember(d => d.Developer!.Id, o => o.MapFrom(s => s.DeveloperId))
|
.ForPath(d => d.Developer!.Id, o => o.MapFrom(s => s.DeveloperId))
|
||||||
.ReverseMap();
|
.ReverseMap();
|
||||||
|
|
||||||
CreateMap<Game, GameDto>()
|
CreateMap<Game, GameDto>()
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
|||||||
{
|
{
|
||||||
var gameToCreate = mapper.Map<Game>(gameDto);
|
var gameToCreate = mapper.Map<Game>(gameDto);
|
||||||
|
|
||||||
await HandlePublisherCreation(gameDto.Publisher);
|
HandleDeveloperPublisherCreation(gameToCreate);
|
||||||
await HandleDeveloperCreation(gameDto.Developer);
|
|
||||||
|
|
||||||
await context.Games.AddAsync(gameToCreate);
|
await context.Games.AddAsync(gameToCreate);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -38,9 +36,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
|||||||
|
|
||||||
var gameToUpdate = mapper.Map<Game>(gameDto);
|
var gameToUpdate = mapper.Map<Game>(gameDto);
|
||||||
|
|
||||||
await HandlePublisherCreation(gameDto.Publisher);
|
HandleDeveloperPublisherCreation(gameToUpdate);
|
||||||
await HandleDeveloperCreation(gameDto.Developer);
|
|
||||||
|
|
||||||
await HandlePlatformsCreation(gameDto.Platforms, gameToUpdate.Id);
|
await HandlePlatformsCreation(gameDto.Platforms, gameToUpdate.Id);
|
||||||
await HandlePropertiesCreation(gameDto.Properties, gameToUpdate.Id);
|
await HandlePropertiesCreation(gameDto.Properties, gameToUpdate.Id);
|
||||||
await HandleTagsCreation(gameDto.Tags, gameToUpdate.Id);
|
await HandleTagsCreation(gameDto.Tags, gameToUpdate.Id);
|
||||||
@@ -109,23 +105,16 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandlePublisherCreation(PublisherDto? categoriesToCreate)
|
private void HandleDeveloperPublisherCreation(Game? game)
|
||||||
{
|
{
|
||||||
if (categoriesToCreate != null)
|
if (game?.Publisher != null)
|
||||||
{
|
{
|
||||||
var pub = mapper.Map<Publisher>(categoriesToCreate);
|
context.Publishers.Attach(game.Publisher);
|
||||||
context.Publishers.Attach(pub);
|
|
||||||
await context.Publishers.AddAsync(pub);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleDeveloperCreation(DeveloperDto? categoriesToCreate)
|
if (game?.Developer != null)
|
||||||
{
|
{
|
||||||
if (categoriesToCreate != null)
|
context.Developers.Attach(game.Developer);
|
||||||
{
|
|
||||||
var dev = mapper.Map<Developer>(categoriesToCreate);
|
|
||||||
context.Developers.Attach(dev);
|
|
||||||
await context.Developers.AddAsync(dev);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user