예제 #1
0
        public async Task AddGame(CreateGameModel createGameModel)
        {
            var game      = _mapper.Map <CreateGameModel, Game>(createGameModel);
            var developer = await _developerService.GetDeveloperByNameAsync(createGameModel.DeveloperName);

            var publisher = await _publisherService.GetPublisherByNameAsync(createGameModel.PublisherName);

            if (developer == null)
            {
                developer = new Developer()
                {
                    Name = createGameModel.DeveloperName, Description = "No description yet.", Location = "No location yet.", LogoUrl = "https://images.app.goo.gl/piYLgvJBbpcKbT9A7"
                };
                await _businessLogicDevelopers.AddDeveloper(developer);
            }

            if (publisher == null)
            {
                publisher = new Publisher()
                {
                    Name = createGameModel.PublisherName, Description = "No description yet.", Location = "No location yet.", LogoUrl = "https://images.app.goo.gl/piYLgvJBbpcKbT9A7"
                };
                await _businessLogicPublisher.AddPublsherAsync(publisher);
            }

            await _businessLogicDevelopers.SaveChangesAsync();

            await _businessLogicPublisher.SaveChangesAsync();

            developer = await _businessLogicDevelopers.GetDeveloperByNameAsync(createGameModel.DeveloperName);

            publisher = await _businessLogicPublisher.GetPublisherByNameAsync(createGameModel.PublisherName);

            game.DeveloperId = developer.Id;
            game.PublisherId = publisher.Id;
            game.Genre       = createGameModel.Genres.First(genre => decimal.Parse(genre.Value) == game.GenreId)?.Text;
            await _businessLogicGames.AddGame(game);

            await _businessLogicGames.SaveChangesAsync();
        }
 public async Task <Publisher> GetPublisherByNameAsync(string name)
 {
     return(await _businessLogicPublishers.GetPublisherByNameAsync(name));
 }