示例#1
0
        public void WordServiceTest_Get_count()
        {
            var expected = rep.GetAll().Count();
            var actual   = service.GetAll().Count();

            Assert.AreEqual(expected, actual);
        }
        public Word Next(Guid userId)
        {
            var allWords = _wordRepository.GetAll(userId);

            if (allWords == null)
            {
                return(null);
            }

            var      stacks = allWords.GroupBy(x => x.TrainingHistories.Count(y => y.IsCorrect)).OrderBy(x => x.Key);
            Word     wordReadyForTraining = null;
            DateTime olderDate            = DateTime.MaxValue;

            foreach (var stack in stacks)
            {
                foreach (var word in stack)
                {
                    if (IsReadyForTraining(word, stack.Key))
                    {
                        if ((word.LastTraining == null && word.AddedDateTime < olderDate))
                        {
                            wordReadyForTraining = word;
                            olderDate            = word.AddedDateTime;
                        }
                        else if (word.LastTraining != null && word.LastTraining < olderDate)
                        {
                            wordReadyForTraining = word;
                            olderDate            = word.LastTraining.Value;
                        }
                    }
                }
            }

            return(wordReadyForTraining);
        }
示例#3
0
        public void WordRepositoryTest_Words_count()
        {
            var count     = context.Object.Words.Count();
            var rep_count = rep.GetAll().Count();

            Assert.AreEqual(count, rep_count, string.Format(count + " != " + rep_count));
        }
        public IActionResult GetAll([FromQuery] WordQueryUrl query)
        {
            var item = _repository.GetAll(query);

            if (item.Results.Count == 0)
            {
                return(StatusCode(404));
            }

            PaginationList <WordDTO> List = CreateLinksListWordDTO(query, item);

            return(Ok(List));
        }
示例#5
0
        //
        // GET: /Words/

        public ViewResult Index(int page = 1, string like = "")
        {
            if (!UserHelper.GetCurrent().IsAdmin)
            {
                return(View("AccesoDenegdo"));
            }
            IList <Word> list  = _wordRepository.GetAll().Where(x => x.Name.StartsWith(like)).ToList();
            var          model = new CrudViewModel <Word>(list, page, 20);

            model.Filter = like;

            return(View(model));
        }
示例#6
0
        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());
        }
示例#7
0
 public IQueryable <Word> GetAll()
 {
     return(rep.GetAll());
 }
 public List <Word> GetAllWords()
 {
     return(_wordRepository.GetAll());
 }
示例#9
0
        public async Task <IActionResult> StartGame(Room room)
        {
            var wordCount = await _wordRepository.CountAll();

            Random rnd        = new Random();
            var    randomWord = rnd.Next(0, wordCount);
            var    data       = await _wordRepository.GetAll();

            var           word      = data.ToList()[randomWord];
            StringBuilder firstHint = new StringBuilder();

            for (int i = 0; i < word.WordName.Length; i++)
            {
                firstHint.Append("_");
            }

            var           secondHintNumber = rnd.Next(0, word.WordName.Length);
            StringBuilder secondHint       = new StringBuilder();

            for (int i = 0; i < word.WordName.Length; i++)
            {
                if (i != secondHintNumber)
                {
                    secondHint.Append("_");
                }
                else
                {
                    secondHint.Append($"{word.WordName[secondHintNumber]} ");
                }
            }

            var thirdHintNumber = rnd.Next(0, word.WordName.Length);
            var thirdHint       = secondHint.ToString();

            if (thirdHint.ToString()[thirdHintNumber] != '_')
            {
                thirdHint.Remove(thirdHintNumber, 1);
                thirdHint.Insert(thirdHintNumber, word.WordName[thirdHintNumber].ToString());
            }
            else
            {//PROBLEM
                thirdHintNumber = rnd.Next(0, word.WordName.Length);
                thirdHint.Remove(thirdHintNumber, 1);
                thirdHint.Insert(thirdHintNumber, word.WordName[thirdHintNumber].ToString());
            }

            var roomPlayerList = JsonConvert.DeserializeObject <List <ConnectedUser> >(await _redisHandler.GetFromCache("Userlist:ConnectedUser")).Where(x => x.ConnectedRoomName == room.roomName).ToList();
            var shuffledList   = ShuffleList(roomPlayerList);

            await _redisHandler.AddToCache($"Room:StartedGame:{room.roomName}", TimeSpan.FromMinutes(10), JsonConvert.SerializeObject(new StartedGame
            {
                word       = word,
                firstHint  = firstHint.ToString(),
                secondHint = secondHint.ToString(),
                thirdHint  = thirdHint,
                userList   = shuffledList,
                point      = 30,
                turn       = 1
            }));

            await _hubContext.Clients.Group(room.roomName).SendAsync("GameTurn", new { wordName = word.WordName, turn = 1, firstHint = firstHint.ToString(), secondHint = secondHint.ToString() });

            await _hubContext.Clients.Client(shuffledList[0].ConnectionId).SendAsync("YourTurn", true);

            await _hubContext.Clients.Group(room.roomName).SendAsync("StartTurnTimer", true);

            return(await Task.FromResult(Ok()));
        }
示例#10
0
 // GET: Word
 public ActionResult Index()
 {
     return(View(_wordRepository.GetAll()));
 }
示例#11
0
 public IActionResult GetAll()
 {
     _log.LogInformation("Get all words");
     return Ok(_wordRepository.GetAll(UserId).Select(x => new WordViewModel(x)));
 }
示例#12
0
        public ICollection <Word> GetAll()
        {
            var results = _repository.GetAll();

            return(results);
        }