Exemplo n.º 1
0
 public ActionResult <CreateWordFormDTO> Edit(CreateWordFormDTO word)
 {
     if (_serviceWrapper.UserWords.TryEditCreatedWord(word))
     {
         return(Ok(word));
     }
     return(Ok(false));
 }
Exemplo n.º 2
0
 public ActionResult <CreateWordFormDTO> Create(CreateWordFormDTO word)
 {
     if (_serviceWrapper.UserWords.TryCreateWord(word))
     {
         return(Created("", word));
     }
     return(Ok(false));
 }
Exemplo n.º 3
0
 public bool TryCreateWord(CreateWordFormDTO wordDto)
 {
     if (_currentUser != null)
     {
         if (wordDto?.Name == null || wordDto.Definition == null)
         {
             return(false);
         }
         CreateWord(wordDto);
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
        public void CreateWord(CreateWordFormDTO wordDto)
        {
            Word word = new Word {
                Definition = wordDto?.Definition, Image = wordDto.Image, Example = wordDto.Example, Name = wordDto.Name, AuthorId = _currentUser.Id
            };

            _repoWrapper.Word.Create(word);

            foreach (string tagName in wordDto.Tags.Distinct())
            {
                CreateTag(tagName, word);
            }

            _repoWrapper.Save();
        }
Exemplo n.º 5
0
        public bool TryEditCreatedWord(CreateWordFormDTO wordDto)
        {
            if (_currentUser != null)
            {
                if (wordDto?.Name == null || wordDto.Definition == null)
                {
                    return(false);
                }

                Word word = _repoWrapper.Word.FindByCondition(w => w.Id.Equals(wordDto.Id) && w.AuthorId == _currentUser.Id).FirstOrDefault();
                if (word != null)
                {
                    word.Image        = wordDto.Image;
                    word.Name         = wordDto.Name;
                    word.Definition   = wordDto.Definition;
                    word.Example      = wordDto.Example;
                    word.CreationDate = DateTime.Now;
                    word.WordStatus   = WordStatus.OnModeration;

                    _repoWrapper.Word.Update(word);

                    Dictionary <string, Tag> oldTags = _repoWrapper.Tag.FindByCondition(t => t.WordTags.Any(w => w.WordId.Equals(word.Id)))
                                                       .ToDictionary(t => t.Name, t => t);

                    foreach (string tagName in wordDto.Tags.Distinct())
                    {
                        if (!oldTags.Keys.Contains(tagName))
                        {
                            CreateTag(tagName, word);
                        }
                        else
                        {
                            oldTags.Remove(tagName);
                        }
                    }
                    foreach (Tag tag in oldTags.Values)
                    {
                        WordTag wordTag = _repoWrapper.WordTag.FindByCondition(wt => wt.TagId.Equals(tag.Id) && wt.WordId.Equals(word.Id)).FirstOrDefault();
                        _repoWrapper.WordTag.Delete(wordTag);
                    }

                    _repoWrapper.Save();
                    return(true);
                }
            }
            return(false);
        }