public void Add(Word word)
        {
            _db.Translations.Add(word.Translation);
            foreach (var wordAdditionalTranslation in word.AdditionalTranslations)
            {
                _db.Translations.Add(wordAdditionalTranslation.Translation);
            }

            _db.Words.Add(word);
        }
        private IList<WordViewModel> GetRandomWords(Word except, int amount)
        {
            var allWords = _wordRepository.GetAll(except.UserId).Except(new List<Word>
            {
                except
            }).ToList();

            if (allWords.Count <= amount)
            {
                return allWords.Select(x => new WordViewModel(x)).ToList();
            }

            return allWords.Shuffle().Take(amount).Select(x => new WordViewModel(x)).ToList();
        }
 public TrainingViewModel Create(Word rightWord)
 {
     var stackIndex = rightWord.TrainingHistories.Count(x => x.IsCorrect);
     var rightWordViewModel = new WordViewModel(rightWord);
     switch (stackIndex)
     {
         case 0:
         {
             return new OneRightTrainingViewModel(OneRight.RepeatTranslation, rightWordViewModel);
         }
         case 1:
         {
             return new OneRightManyWrongViewModel(
                 OneRightManyWrong.ChooseTranslation,
                 rightWordViewModel,
                 GetRandomWords(except: rightWord, amount: 5));
         }
         case 2:
         {
             return new OneRightManyWrongViewModel(
                 OneRightManyWrong.ChooseOriginal,
                 rightWordViewModel,
                 GetRandomWords(except: rightWord, amount: 5));
         }
         case 3:
         {
             var words = GetRandomWords(except: rightWord, amount: 4);
             words.Add(rightWordViewModel);
             return new ManyRightTrainingViewModel(ManyRight.MatchWords, words);
         }
         case 4:
         {
             return new OneRightTrainingViewModel(OneRight.ComposeOriginal, rightWordViewModel);
         }
         case 5:
         {
             return new OneRightTrainingViewModel(OneRight.TypeTranslation, rightWordViewModel);
         }
         case 6:
         {
             return new OneRightTrainingViewModel(OneRight.TypeOriginal, rightWordViewModel);
         }
         default:
         {
             return new OneRightTrainingViewModel(OneRight.TypeOriginal, rightWordViewModel);
         }
     }
 }
        private bool IsReadyForTraining(Word word, int stack)
        {
            // if word was trained more then amount of stacks, threat it as word from last stack
            if (stack >= TrainingIntervals.Count)
            {
                stack = TrainingIntervals.Count - 1;
            }

            var freezInStackInteval = TrainingIntervals[stack];

            if (stack == 0)
            {
                if (word.LastTraining != null)
                {
                    if (_dateTimeService.Now - word.LastTraining >= RetrainWrongInterval)
                    {
                        return true;
                    }
                }

                if (_dateTimeService.Now - word.AddedDateTime >= freezInStackInteval)
                {
                    return true;
                }
            }

            if (word.LastCorrectTraining != word.LastTraining)
            {
                if (_dateTimeService.Now - word.LastCorrectTraining > RetrainWrongInterval)
                {
                    return true;
                }
            }

            if (_dateTimeService.Now - word.LastCorrectTraining > freezInStackInteval)
            {
                return true;
            }

            return false;
        }
        public IActionResult Create([FromBody]WordViewModel word)
        {
            _log.LogInformation($"Add word {word.Word} translated to {word.Translation}");
            var translationModel = word.Translation.ToModel();
            var wordModel = new Word
            {
                UserId = UserId,
                Original = word.Word.Text,
                LanguageId = word.Word.Language,
                Translation = translationModel,
                AddedDateTime = DateTime.Now,
                Context = word.Context
            };

            if (word.AdditionalTranslations != null && word.AdditionalTranslations.Count > 0)
            {
                wordModel.AdditionalTranslations = word.AdditionalTranslations
                    .Select(x => new WordAdditionalTranslation { WordId = wordModel.Id, Translation = x.ToModel() }).ToList();
            }

            _wordRepository.Add(wordModel);
            return Created("/api/word/" + wordModel.Id);
        }
 public void Update(Word word)
 {
 }
 public void Delete(Word word)
 {
     _db.Words.Remove(word);
 }