Example #1
0
        public Task <IWord> GetWordInfo(string language, string word)
        {
            // Lock to prevent concurrent requests of the same word to the Dictionary API
            // If the word has no description, when the lock is over it should already have it.
            // next call in queue will not get an empty description on wordRepository.Get
            lock (padLock)
            {
                var getWordTask = wordRepository.Get(language, word);
                getWordTask.Wait();
                var result = getWordTask.Result;
                if (result == null)
                {
                    return(null);
                }

                if (string.IsNullOrEmpty(result.Description))
                {
                    var newWord = dictionaryApiFactory.UpdateDescription(result);
                    logger.Info($"Aquired new word from API: [{newWord.Name}] = [{newWord.Description}]");

                    Task.WaitAll(wordRepository.Update(newWord));
                    result = newWord;
                }
                return(Task.FromResult(result));
            }
        }
        public IActionResult Get(Guid id)
        {
            _log.LogInformation($"Get word with id {id}");
            var word = _wordRepository.Get(id, UserId);
            if (word == null)
            {
                _log.LogWarning($"Word with id {id} not found. User: {UserId}");
                return NotFound();
            }

            return Ok(new WordViewModel(word));
        }
Example #3
0
        public void WordServiceTest_GetById_valid()
        {
            var expected = rep.Get(1);
            var actual   = service.Get(1);

            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public ActionResult Get(int id)
        {
            var word = _wordReposirory.Get(id);

            if (word == null)
            {
                return(NotFound());
            }

            var wordDTO = _mapper.Map <Word, WordDTO>(word);

            wordDTO.Links.Add(new LinkDTO("self", Url.Link("Get", new { id = id }), "GET"));
            wordDTO.Links.Add(new LinkDTO("update", Url.Link("Update", new { id = id }), "PUT"));
            wordDTO.Links.Add(new LinkDTO("delete", Url.Link("Delete", new { id = id }), "DELETE"));

            return(Ok(wordDTO));
        }
Example #5
0
 public Word Get(int id)
 {
     if (!id.Validate())
     {
         throw new Exception("Invalid model");
     }
     return(rep.Get(id));
 }
Example #6
0
 public void Perform()
 {
     imageSettings.UpdateSettings();
     tagGenerator.GetTags(wordsRepository.Get())
     .Then(tags => new TagCloudVisualizer(imageBox, imageSettings, tags))
     .Then(tagCloud => tagCloud.GetTagCloudImage())
     .RefineError("Failed, trying to get a Tag Cloud image")
     .OnFail(exceptionHandler.HandleException);
 }
 void AddWord()
 {
     if (txtWord.TextLength == 0)
     {
         MessageBox.Show("Kelime / Cümle Giriniz.");
     }
     else if (_wordRepository.Get(txtWord.Text.Trim()) != null)
     {
         MessageBox.Show("Kelime / Cümle Daha Önceden Tanımlanmış.");
     }
     else
     {
         _wordRepository.Add(new Word()
         {
             SetId    = _setId,
             WordText = txtWord.Text.Trim()
         });
         MessageBox.Show("Kelime / Cümle Eklendi.");
     }
 }
Example #8
0
        public async Task Add_NewWord_CheckHasInserted()
        {
            var result = await hubRepository.Add(new WordEntity
            {
                originalword = "apology",
                description  = "özür"
            });

            var newEntity = await hubRepository.Get(result._id.ToString());

            Assert.Equal(result._id, newEntity._id);
        }
        public void FinishTraining(Guid userId, TrainingResultViewModel result)
        {
            var word = _wordRepository.Get(result.WordId, userId);

            if (word == null)
            {
                throw new NotFoundException();
            }

            word.TrainingHistories.Add(new TrainingHistory
            {
                Score     = 100f,
                IsCorrect = result.IsCorrect,
                Date      = DateTime.Now,
                Type      = result.TrainingType
            });

            _wordRepository.Update(word);
        }
 public TestController(ILogger logger, IWordRepository wordRepository)
 {
     logger.Error("test");
     Word word = wordRepository.Get(1);
 }
Example #11
0
 public async Task <IEnumerable <Word> > GetWords()
 {
     // when this method is invoked, asp.net will convert word object to json
     // before returning it to the caller
     return(await _wordRepository.Get());
 }
Example #12
0
 public ActionResult Edit(long id)
 {
     return(View(_wordRepository.Get(id)));
 }
        public Word Get(int id)
        {
            var result = _repository.Get(id);

            return(result);
        }