示例#1
0
        public ActionResult <Tag> AddTagToComic(int id, Tag tag)
        {
            string description = FormatStringForSql(tag.Description);
            Tag    exists      = tagDAO.GetTagByDescription(description);

            if (exists == null)
            {
                exists = tagDAO.AddTagToDatabase(description);
            }
            if (!tagDAO.IsTagLinkedToComic(id, exists.Id))
            {
                bool isSuccessful = tagDAO.LinkTagToComic(id, exists.Id);
                if (!isSuccessful)
                {
                    return(BadRequest(new { message = "Failed to add tag to comic" }));
                }
                return(Created($"/user/comic/{id}", exists));
            }
            else
            {
                return(BadRequest(new { message = "Comic already has that tag" }));
            }
        }