public async Task <LearningList> HandleGeneration(Dictionary dictionary)
        {
            var items = await _context.Items
                        .Where(i => i.DictionaryId == dictionary.Id)
                        .ToListAsync();

            if (items.Count < 10)
            {
                throw new RestException(HttpStatusCode.BadRequest, ErrorType.NotEnoughItemsForLearningListGeneration);
            }

            var list = LearningListGenerator.Generate(items, dictionary.PreferredLearningListSize);

            var learningList = new LearningList
            {
                DictionaryId = dictionary.Id,

                Size         = list.Count,
                CreationDate = DateTime.Now,

                CorrectAnswersToItemCompletion = dictionary.CorrectAnswersToItemCompletion,
                IsHardModeEnabled = dictionary.IsHardModeEnabled,

                LearningItems = list
            };

            return(learningList);
        }
 public void Delete(LearningModel l)
 {
     LearningList.Remove(l);
     for (int i = 0; i < LearningList.Count; i++)
     {
         LearningList[i].Number = i + 1;
     }
 }
Beispiel #3
0
        public static bool IsLearningListOutdated(LearningList learningList)
        {
            var creationDate = learningList.CreationDate;
            var now          = DateTime.Now;

            if (creationDate.Day == now.Day)
            {
                return(false);
            }
            return(true);
        }
Beispiel #4
0
        public async Task Remove(LearningList learningList)
        {
            _context.LearningItems.RemoveRange(learningList.LearningItems);
            _context.LearningLists.Remove(learningList);

            var success = await _context.SaveChangesAsync() > 0;

            if (!success)
            {
                throw new RestException(HttpStatusCode.InternalServerError, ErrorType.SavingChangesError);
            }
        }
 public void Add(LearningModel l)
 {
     LearningList.Add(l);
     l.Number = LearningList.Count;
 }
Beispiel #6
0
        public static void ProcessItemAnswer(Dictionary dictionary, LearningList list, LearningItem learningItem,
                                             bool isAnswerCorrect)
        {
            var item = learningItem.Item;

            item.TotalRepeatsCount++;

            if (isAnswerCorrect)
            {
                item.CorrectAnswersCount++;

                if (item.IsLearned)
                {
                    item.LastLearnedRepeatDate = DateTime.Now;
                    item.LearnedRepeatsCount++;
                    return;
                }

                if (item.CorrectAnswersToCompletionCount != list.CorrectAnswersToItemCompletion &&
                    list.TimesCompleted != 1)
                {
                    item.CorrectAnswersToCompletionCount++;
                }

                if (item.CorrectAnswersToCompletionCount == list.CorrectAnswersToItemCompletion)
                {
                    if (item.IsStarred)
                    {
                        dictionary.StarredItemsCount--;
                    }
                    item.IsLearned      = true;
                    item.IsStarred      = false;
                    item.GoesForNextDay = false;

                    item.LastLearnedRepeatDate = DateTime.Now;
                    item.LearnedRepeatsCount++;

                    if (item.Type == ItemType.Word)
                    {
                        dictionary.LearnedWordsCount++;
                    }
                    else
                    {
                        dictionary.LearnedPhrasesCount++;
                    }
                }
            }
            else
            {
                item.GoesForNextDay = true;
                item.IsLearned      = false;

                item.LastLearnedRepeatDate = null;
                item.LearnedRepeatsCount   = 0;

                if (list.IsHardModeEnabled)
                {
                    item.CorrectAnswersToCompletionCount = 0;
                }
                else
                {
                    item.CorrectAnswersToCompletionCount--;
                }
            }
        }