public async Task <CurrentInnovation> InsertCurrentInnovation(CurrentInnovation currentInnovation, Laboratory laboratory)
        {
            _dbContext.CurrentInnovations.Add(currentInnovation);
            laboratory.CurrentInnovation = currentInnovation;
            await _dbContext.SaveChangesAsync();

            return(currentInnovation);
        }
        public async Task <CurrentInnovation> UpdateCurrentInnovation(CurrentInnovation currentInnovation)
        {
            var oldInnovation = await GetCurrentInnovationAsync(currentInnovation.Id);

            _dbContext.Entry(oldInnovation).CurrentValues.SetValues(currentInnovation);
            await _dbContext.SaveChangesAsync();

            return(currentInnovation);
        }
        public async Task BuyInnovation(int userId, InnovationTypes innovationType)
        {
            var player = await _dbContext.Players
                         .Include(p => p.Stock)
                         .Include(p => p.Laboratory)
                         .ThenInclude(l => l.CurrentInnovation)
                         .Include(p => p.Laboratory)
                         .ThenInclude(l => l.LaboratoryInnovations)
                         .ThenInclude(li => li.Innovation)
                         .Where(p => p.UserId == userId)
                         .SingleOrDefaultAsync();

            var cost = player.Laboratory.LaboratoryInnovations
                       .Where(li => li.Innovation.Type == innovationType)
                       .Select(li => li.Innovation.Cost)
                       .FirstOrDefault();

            var laboratoryInnovation = player.Laboratory.LaboratoryInnovations
                                       .Where(li => li.Innovation.Type == innovationType)
                                       .FirstOrDefault();

            if (player.Laboratory.CurrentInnovation != null)
            {
                throw new GeneralGameException($"Nem tudsz több dolgot egyszerre fejleszteni!");
            }

            if (laboratoryInnovation.Researched)
            {
                throw new GeneralGameException($"{laboratoryInnovation.Innovation.Name} már kifejlesztetted!");
            }

            if (player.Stock.PearlAmount < laboratoryInnovation.Innovation.Cost)
            {
                throw new GeneralGameException($"Nincs elég gyöngyöd a {laboratoryInnovation.Innovation.Name} kifejlesztéséhez!");
            }
            else
            {
                await _stockService.ReducePearl(player.Stock, laboratoryInnovation.Innovation.Cost);
            }

            var currentInnovation = new CurrentInnovation
            {
                InnovationType = innovationType,
                LaboratoryId   = player.Laboratory.Id,
                TurnNeed       = TIME_TO_RESEARCH_INNOVATION
            };

            await InsertCurrentInnovation(currentInnovation, player.Laboratory);
        }
        public async Task UpdateCurrentInnovation(Laboratory laboratory, CurrentInnovation currentInnovation)
        {
            currentInnovation.TurnNeed--;
            if (currentInnovation.TurnNeed > 0)
            {
                await UpdateCurrentInnovation(currentInnovation);
            }
            else
            {
                var laboratoryInnovation = laboratory.LaboratoryInnovations
                                           .Where(li => li.Innovation.Type == currentInnovation.InnovationType)
                                           .SingleOrDefault();

                laboratoryInnovation.Researched = true;
                await _dbContext.SaveChangesAsync();
                await DeleteCurrentInnovation(currentInnovation.Id, laboratory);
            }
        }