public Task <int> InsertGlossaryItem(GlossaryItemModel item)
        {
            string sql = @$ "INSERT INTO glossary (term, definition)
                        SELECT @Term, @Definition
                        WHERE
                        NOT EXISTS (
                        SELECT term FROM glossary WHERE term = @Term
                        );";

            return(_db.SaveData(sql, item));
        }
        private void OpenEditModal(GlossaryItemModel entry)
        {
            newGlossaryItem = new GlossaryItemModel
            {
                Term       = entry.Term,
                Definition = entry.Definition
            };

            editModal.Open();

            StateHasChanged();
        }
        public async Task <ActionResult> Delete(GlossaryItemModel glossaryItem)
        {
            var rowsDeleted = await _db.DeleteGlossaryItemByTerm(glossaryItem.Term);

            if (rowsDeleted == 0)
            {
                return(BadRequest());
            }
            else
            {
                return(Accepted(glossaryItem));
            }
        }
        private async void DeleteGlossaryItem(GlossaryItemModel item)
        {
            Console.WriteLine($"Delete {item.Term}");

            var itemDeleted = await Http.Delete <GlossaryItemModel>("api/glossary", item);

            if (itemDeleted.Term != null)
            {
                glossary.RemoveAll(x => x.Term == itemDeleted.Term);
            }

            StateHasChanged();
        }
        public async Task <ActionResult> Post(GlossaryItemModel glossaryItem)
        {
            var rowsChanged = await _db.InsertGlossaryItem(glossaryItem);

            if (rowsChanged == 0)
            {
                return(Conflict("Cannot create the term because it already exists."));
            }
            else
            {
                var resourceUrl = Path.Combine(Request.Path.ToString(), Uri.EscapeUriString(glossaryItem.Term));
                return(Created(resourceUrl, glossaryItem));
            }
        }
        private async void InsertGlossaryItem()
        {
            GlossaryItemModel item = new GlossaryItemModel
            {
                Term       = newGlossaryItem.Term,
                Definition = newGlossaryItem.Definition
            };

            var returnedItem = await Http.Post <GlossaryItemModel>("api/glossary", item);

            if (returnedItem.Term != null)
            {
                glossary.Add(returnedItem);
            }

            // clear our form
            newGlossaryItem = new GlossaryItemModel();

            modal.Close();

            StateHasChanged();
        }