public async Task <IActionResult> PutParentWords([FromRoute] int id, [FromBody] ParentWords parentWords)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != parentWords.WordJoinId)
            {
                return(BadRequest());
            }

            _context.Entry(parentWords).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ParentWordsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostParentWords([FromBody] ParentWords parentWords)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ParentWords.Add(parentWords);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetParentWords", new { id = parentWords.WordJoinId }, parentWords));
        }
        public async Task <IActionResult> PostParentWordFromStrings([FromRoute] string parentWord, [FromRoute] string childWord)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var wordLogic = new WordLogic();

            var foundParentWord = wordLogic.GetWordByString(parentWord);

            if (foundParentWord == null)
            {
                foundParentWord = wordLogic.CreateWord(parentWord);
            }

            var mainWordLookup = _context.Words.Where(x => x.WordId == foundParentWord.WordId).FirstOrDefault();

            mainWordLookup.Main = true;

            var foundChildWord = wordLogic.GetWordByString(childWord);

            if (foundChildWord == null)
            {
                foundChildWord = wordLogic.CreateWord(childWord);
            }

            if (mainWordLookup.Weekly < foundChildWord.Weekly)
            {
                mainWordLookup.Weekly = foundChildWord.Weekly;
            }

            if (mainWordLookup.Monthly < foundChildWord.Monthly)
            {
                mainWordLookup.Monthly = foundChildWord.Monthly;
            }

            if (mainWordLookup.Yearly < foundChildWord.Yearly)
            {
                mainWordLookup.Yearly = foundChildWord.Yearly;
            }

            var newParentWord = new ParentWords()
            {
                ParentWordId = foundParentWord.WordId,
                ChildWordId  = foundChildWord.WordId
            };

            _context.ParentWords.Add(newParentWord);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetParentWords", new { id = newParentWord.WordJoinId }, newParentWord));
        }