예제 #1
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);
        }
예제 #2
0
        public void WordRepositoryTest_Words_Add_validModel()
        {
            var model = new Word
            {
                WordId        = 0,
                Category      = "Category",
                Original      = "Original",
                Translate     = "Translate",
                Transcription = "Transcription"
            };
            var result = rep.Add(model);

            Assert.AreEqual(true, result, string.Format("result != expected"));
        }
예제 #3
0
        public async Task <IActionResult> CreateWord([FromBody] SaveWordResource wordResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int commasCount   = wordResource.Meaning.ToCharArray().Count(c => c == ',');
            var limitOfCommas = 3;

            if (commasCount > limitOfCommas)
            {
                ModelState.AddModelError("error", "Cannot add a word with more than three commas in meaning");
                return(BadRequest(ModelState));
            }

            var word = mapper.Map <SaveWordResource, Word>(wordResource);

            word.CreatedAt = DateTime.Now;
            word.UpdatedAt = null;

            repository.Add(word);

            await unitOfWork.CompleteAsync();

            word = await repository.GetWord(word.Id);

            var result = mapper.Map <Word, WordResource>(word);

            return(Ok(result));
        }
예제 #4
0
        /// <summary> Deletes word in frontier collection and adds word with deleted tag in word collection </summary>
        /// <returns> A string: id of new word </returns>
        public async Task <string?> DeleteFrontierWord(string projectId, string wordId)
        {
            var wordIsInFrontier = await _wordRepo.DeleteFrontier(projectId, wordId);

            if (!wordIsInFrontier)
            {
                return(null);
            }

            var word = await _wordRepo.GetWord(projectId, wordId);

            if (word is null)
            {
                return(null);
            }

            word.Id            = "";
            word.Modified      = "";
            word.ProjectId     = projectId;
            word.Accessibility = State.Deleted;

            // Keep track of the old word, adding it to the history.
            word.History.Add(wordId);

            var deletedWord = await _wordRepo.Add(word);

            return(deletedWord.Id);
        }
예제 #5
0
 public bool Add(Word word)
 {
     if (!word.Validate(true))
     {
         throw new Exception("Invalid model");
     }
     return(rep.Add(word));
 }
예제 #6
0
 public void Add(Word word)
 {
     //word.AddDate = DateTime.UtcNow;
     //if (word.WordTranslation.Length >= 10)
     //{
     //    word.IsComplicated = true;
     //}
     word.WordColanderID = 1;
     word.Created        = DateTime.UtcNow;
     //_wordRepository.AddColander((int)word.WordColanderID);
     _wordRepository.Add(word);
 }
    public async Task <Unit> Handle(NewTextCommand request, CancellationToken cancellationToken)
    {
        var words = request.Text.Split(" ");

        await _wordRepository.Add(words.Select(w => new Word
        {
            Text     = w,
            ChatId   = request.ChatId,
            AuthorId = request.AuthorId,
        }));

        return(Unit.Value);
    }
예제 #8
0
        public void WordServiceTest_Add_valid()
        {
            var model = new Word
            {
                WordId        = 1,
                Category      = "Category" + 1,
                Original      = "Original" + 1,
                Translate     = "Translate" + 1,
                Transcription = "Transcription" + 1
            };
            var expected = rep.Add(model);
            var actual   = service.Add(model);

            Assert.AreEqual(expected, actual);
        }
        public void AddWord_ShouldAddWordToDictionaryAndReturnTrue()
        {
            RequestedWord = "labas";

            _wordRepository.GetByWord(RequestedWord).ReturnsNull();

            _wordRepository.Add(Arg.Is <WordEntity>(q => q.Word.Equals(RequestedWord))).Returns(1);

            var result = _modificationService.AddWord(RequestedWord);

            result.ShouldBeTrue();

            _wordRepository.Received().Add(Arg.Is <WordEntity>(q => q.Word.Equals(RequestedWord)));
            _wordRepository.Received().GetByWord(RequestedWord);
        }
예제 #10
0
        public IActionResult Add(int collectionId, Word word)
        {
            // Get current User
            var firebaseUser = _utils.GetCurrentUser(User);

            // Ensure an unauthorized user (anonymous account) can not add a collection
            if (firebaseUser == null)
            {
                return(NotFound());
            }

            // Ensure the userId on the incoming word matches the person making the request
            if (word.UserId != firebaseUser.Id)
            {
                return(BadRequest());
            }

            // Ensure the incoming collectionId matches the incoming word.CollectionId
            if (collectionId != word.CollectionId)
            {
                return(BadRequest());
            }

            // Get all of this user's words in this word
            var allWordsInCollection = _wordRepo.GetByCollectionId(collectionId);

            // see if the MwWordId of the incoming word is in the db
            var wordWithThatMwId = allWordsInCollection.Find(w => w.MwWordId == word.MwWordId);

            // if there is a returned collection, we can't add because name isn't unique for this user
            if (wordWithThatMwId != null)
            {
                return(BadRequest());
            }

            // Need to add the default requirements for the word here
            word.LastViewed = DateTime.Now;

            try
            {
                _wordRepo.Add(word);
                return(Ok(word));
            }
            catch (DbUpdateException e)
            {
                return(NotFound());
            }
        }
예제 #11
0
        public async Task <IActionResult> Add([FromBody] WordRequestEntity word)
        {
            var result = await hubRepository.Add(new WordEntity
            {
                _id            = ObjectId.GenerateNewId(),
                originalword   = word.word,
                description    = word.description,
                userId         = word.userId,
                packageId      = word.packageId,
                synonym        = word.synonym,
                lexialCategory = word.lexialCategory,
                definition     = word.definition,
                ownSentence    = word.ownSentence
            });

            return(Ok(result));
        }
        public bool AddWord(string word)
        {
            WordEntity wordEntity = _wordRepository.GetByWord(word);

            if (wordEntity != null)
            {
                return(false);
            }

            wordEntity = new WordEntity()
            {
                Word       = word,
                SortedWord = string.Concat(word.ToLower().OrderBy(x => x))
            };
            _wordRepository.Add(wordEntity);

            return(true);
        }
예제 #13
0
        public void MergeWords()
        {
            // The parent word is inherently correct as it is calculated by the frontend as the desired result of the
            // merge
            var parentChildMergeObject = new MergeWords
            {
                Parent = RandomWord(), Time = Util.RandString(), ChildrenWords = new List <MergeSourceWord>()
            };

            // Set the child info
            var childWords = new List <Word> {
                RandomWord(), RandomWord(), RandomWord()
            };

            foreach (var child in childWords)
            {
                // Generate mergeSourceWord with new child Id and desired child state list
                var newGenChild = new MergeSourceWord
                {
                    SrcWordId   = _repo.Add(child).Result.Id,
                    SenseStates = new List <State> {
                        State.Duplicate, State.Sense, State.Separate
                    }
                };
                parentChildMergeObject.ChildrenWords.Add(newGenChild);
            }

            var newWordList = _wordService.Merge(_projId, parentChildMergeObject).Result;

            // Check for parent is in the db
            var dbParent = newWordList.FirstOrDefault();

            Assert.IsNotNull(dbParent);
            Assert.AreEqual(dbParent.Senses.Count, 3);
            Assert.AreEqual(dbParent.History.Count, 3);

            // Check the separarte words were made
            Assert.AreEqual(newWordList.Count, 4);

            foreach (var word in newWordList)
            {
                Assert.Contains(_repo.GetWord(_projId, word.Id).Result, _repo.GetAllWords(_projId).Result);
            }
        }
예제 #14
0
 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.");
     }
 }
예제 #15
0
        private void BrnSetImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();

            file.Filter      = "Si Dosyası |*.si";
            file.FilterIndex = 1;
            file.ShowDialog();

            var json   = System.IO.File.ReadAllText(file.FileName);
            var set    = Newtonsoft.Json.JsonConvert.DeserializeObject <SetExportModel>(json);
            var newSet = new Set()
            {
                Name = set.Name + " " + DateTime.Now.ToString()
            };

            Repository.Add(newSet);

            foreach (var item in set.Words)
            {
                var newWord = new Word()
                {
                    SetId    = newSet.ID,
                    WordText = item.WordText
                };
                _wordRepository.Add(newWord);

                var meanings = set.Meanings.Where(x => x.WordId == item.ID).ToList();
                foreach (var mItem in meanings)
                {
                    var newMeaning = new Meaning()
                    {
                        MeaningWord = mItem.MeaningWord,
                        WordId      = newWord.ID
                    };
                    _meaningRepository.Add(newMeaning);
                }
            }
            MessageBox.Show("Set İçeri Aktarıldı.");
        }
예제 #16
0
        public IActionResult Create([FromBody]WordViewModel word)
        {
            _log.LogInformation($"Add word {word.Word} translated to {word.Translation}");
            var translationModel = word.Translation.ToModel();
            var wordModel = new Word
            {
                UserId = UserId,
                Original = word.Word.Text,
                LanguageId = word.Word.Language,
                Translation = translationModel,
                AddedDateTime = DateTime.Now,
                Context = word.Context
            };

            if (word.AdditionalTranslations != null && word.AdditionalTranslations.Count > 0)
            {
                wordModel.AdditionalTranslations = word.AdditionalTranslations
                    .Select(x => new WordAdditionalTranslation { WordId = wordModel.Id, Translation = x.ToModel() }).ToList();
            }
            
            _wordRepository.Add(wordModel);
            return Created("/api/word/" + wordModel.Id);
        }
 public IActionResult Post([FromBody] Word word)
 {
     _repository.Add(word.Value);
     return(Ok());
 }
예제 #18
0
 public int AddWord(Word word)
 {
     return(_repository.Add(word));
 }
 public void Add(string wordValue)
 {
     _repository.Add(wordValue);
     CleanCache();
 }
예제 #20
0
        /// <summary> Makes a parent from merging other words and some number of separate words </summary>
        /// <returns> List of words added: Parent first, followed by separate words in order added </returns>
        public async Task <List <Word> > Merge(string projectId, MergeWords mergeWords)
        {
            var newWordsList = new List <Word>();

            var addParent = mergeWords.Parent.Clone();

            addParent.History = new List <string>();

            // Generate new child words form child word field
            foreach (var newChildWordState in mergeWords.ChildrenWords)
            {
                // Get child word
                var currentChildWord = await _repo.GetWord(projectId, newChildWordState.SrcWordId);

                // Remove child from frontier
                await _repo.DeleteFrontier(projectId, currentChildWord.Id);

                // Iterate through senses of that word and change to corresponding state in mergewords
                if (currentChildWord.Senses.Count != newChildWordState.SenseStates.Count)
                {
                    throw new FormatException("Sense counts don't match");
                }
                for (var i = 0; i < currentChildWord.Senses.Count; i++)
                {
                    currentChildWord.Senses[i].Accessibility = (int)newChildWordState.SenseStates[i];
                }

                // Change the child word's history to its previous self
                currentChildWord.History = new List <string>()
                {
                    newChildWordState.SrcWordId
                };

                // Add child word to the database
                currentChildWord.Id = "";
                var newChildWord = await _repo.Add(currentChildWord);

                // Handle different states
                var separateWord = currentChildWord.Clone();
                separateWord.Senses = new List <Sense>();
                separateWord.Id     = "";
                for (var i = 0; i < currentChildWord.Senses.Count; i++)
                {
                    switch (newChildWordState.SenseStates[i])
                    {
                    // Add the word to the parent's history
                    case State.Sense:
                    case State.Duplicate:
                        if (!addParent.History.Contains(currentChildWord.Id))
                        {
                            addParent.History.Add(currentChildWord.Id);
                        }
                        break;

                    // Add the sense to a separate word and the word to its history
                    case State.Separate:
                        currentChildWord.Senses[i].Accessibility = (int)State.Active;
                        separateWord.Senses.Add(currentChildWord.Senses[i]);
                        if (!separateWord.History.Contains(currentChildWord.Id))
                        {
                            separateWord.History.Add(currentChildWord.Id);
                        }
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }

                // Add a new word to the database with all of the senses with separate tags from this word
                if (separateWord.Senses.Count != 0)
                {
                    separateWord.ProjectId = projectId;
                    var newSeparate = await _repo.Create(separateWord);

                    newWordsList.Add(newSeparate);
                }
            }

            // Add parent with child history to the database
            addParent.ProjectId = projectId;
            var newParent = await _repo.Create(addParent);

            newWordsList.Insert(0, newParent);
            return(newWordsList);
        }