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))); }
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())); }
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))); }
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 })); } }
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"); }
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); }
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); }
public Training UpdateTraining(Training training, MemorizationBoxes box) { training.CompletedAt = DateTime.Now; training.Box = box; return(training); }
public List <Training> GetTrainingsFromBox(MemorizationBoxes box) { return(context.Trainings .Where(x => x.Box == box).ToList()); }