Esempio n. 1
0
 public async Task <IEnumerable <Guid> > GetCardsIdFromBoxAsync(MemorizationBoxes box, Guid uId)
 {
     return(await Task.Run(() => context.Trainings
                           .Where(x => x.Box == box)
                           .Where(u => u.UserId == uId)
                           .Select(t => t.CardId)));
 }
Esempio n. 2
0
 public async Task <int> GetCardsFromBoxAsync(MemorizationBoxes box, Guid uId)
 {
     return(await Task.Run(() => repository.GetTrainingsFromBox(box)
                           .Where(u => u.UserId == uId)
                           .Select(t => t.CardId)
                           .Count()));
 }
Esempio n. 3
0
        public async Task <IEnumerable <Guid> > GetCardsIdFromBoxAsync(MemorizationBoxes box, Guid userId)
        {
            if (userId == Guid.Empty)
            {
                throw new AppException(nameof(userId) + " is required");
            }

            return(await Task.Run(() => repository.GetTrainingsFromBox(box)
                                  .Where(u => u.UserId == userId)
                                  .Select(u => u.CardId)));
        }
Esempio n. 4
0
        public async Task <IActionResult> GetNumberOfCardsInBox(MemorizationBoxes box, CancellationToken cancellationToken)
        {
            try
            {
                Guid.TryParse(HttpContext.User.Identity.Name, out var uId);
                var cardNumber = await trainingService.GetCardsFromBoxAsync(box, uId);

                return(Ok(cardNumber));
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Esempio n. 5
0
        private int GetDaysCountFromBox(MemorizationBoxes box)
        {
            switch (box)
            {
            case MemorizationBoxes.NotLearned:
                return(1);

            case MemorizationBoxes.PartlyLearned:
                return(3);

            case MemorizationBoxes.FullyLearned:
                return(5);
            }

            throw new AppException("Unknown card box");
        }
Esempio n. 6
0
        public Training CreateTraining(Guid userId, Guid cardId, MemorizationBoxes box)
        {
            if (userId == Guid.Empty || cardId == Guid.Empty)
            {
                throw new AppException("ID is empty");
            }

            var training = new Training
            {
                CardId      = cardId,
                UserId      = userId,
                Box         = box,
                CompletedAt = DateTime.Now
            };

            return(training);
        }
Esempio n. 7
0
        private bool CardLearned(Guid cardId, MemorizationBoxes level)
        {
            var cardTrainings = trainingRepository.GetCardTrainingsAsync(cardId).Result;

            if (cardTrainings.Count() == 0)
            {
                return(false);
            }

            var lastCardTrainingDate = cardTrainings.Max(t => t.CompletedAt);
            var lastСardTraining     = cardTrainings.First(t => t.CompletedAt == lastCardTrainingDate);

            if (lastСardTraining == null)
            {
                return(false);
            }

            if (lastСardTraining.Box == level)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
 public Training UpdateTraining(Training training, MemorizationBoxes box)
 {
     training.CompletedAt = DateTime.Now;
     training.Box         = box;
     return(training);
 }
Esempio n. 9
0
 public List <Training> GetTrainingsFromBox(MemorizationBoxes box)
 {
     return(context.Trainings
            .Where(x => x.Box == box).ToList());
 }