public Tag DoesTagExist(string tagname, int postId)
        {
            var tagToReturn = new Tag();
            var newtag = new Tag();
            var oldTags = Getall();

            for (int i = 0; i < oldTags.Count; i++)
            {
                //foreach (var tag in oldTags)
                //{

                if (tagname == oldTags[i].TagName)
                {

                    tagToReturn = oldTags[i];
                    break;
                }
            }
            if (tagToReturn.TagName == null)
            {

                newtag.TagName = tagname;
                newtag.TagID = oldTags.Max(t => t.TagID) + 1;
                add(newtag);
            }

            tagToReturn = newtag;

            return tagToReturn;
        }
Exemple #2
0
        public void add(Tag tag)
        {
            using (SqlConnection cn = new SqlConnection(_connectionString))
            {
                var c = new DynamicParameters();

                c.Add("TagID", tag.TagID);
                c.Add("TagName", tag.TagName);

                cn.Execute("AddTag", c,
                    commandType: CommandType.StoredProcedure);
            }
        }
Exemple #3
0
        public void CanAddTag()
        {
            var manager =  new AdminManager();
            var toAdd = new Tag();
            var tagCount = manager.GetAllTags().Count;

            toAdd.TagID = tagCount + 1;
            toAdd.TagName = "TestTag";

            manager.AddTag(toAdd);

            var secondCount = manager.GetAllTags().Count;
            Assert.AreEqual(tagCount + 1, secondCount);
        }
Exemple #4
0
        public Tag DoesTagExist(string tagname, int postId)
        {
            var tagtoreturn = new Tag();
            var newtag = new Tag();
            var allTags = Getall();
            var tagCheck = new Tag();

            // Check if tag exists
            for (int i = 0; i < allTags.Count; i++)
            {
                if (allTags[i].TagName == tagname)
                {
                    tagtoreturn = allTags[i];
                }

            }
            // if tag does not already exist, create it
            if (tagtoreturn.TagName == null)
            {
                newtag.TagName = tagname;
                if (allTags.Count == 0)
                {
                    newtag.TagID = 1;
                }
                else
                {
                    newtag.TagID = allTags.Max(t => t.TagID) + 1;
                }
                add(newtag);

                tagtoreturn = newtag;
            }

            // Add post tags
            AddPostTag(tagtoreturn.TagID, postId);

            return tagtoreturn;
        }
Exemple #5
0
        public void AddTag(Tag newTag)
        {
            if (GetAllTags().Count != 0)
            {
                newTag.TagID = GetAllTags().LastOrDefault().TagID + 1;
            }
            else
            {
                newTag.TagID = 1;
            }

            _tagRepo.add(newTag);
        }
Exemple #6
0
 public void EditTag(Tag tag)
 {
     _tagRepo.Update(tag);
 }
Exemple #7
0
 public ActionResult EditTag(Tag editedTag)
 {
     var manager = new AdminManager();
     manager.EditTag(editedTag);
     return RedirectToAction("TagIndex", "Tag");
 }
Exemple #8
0
 public ActionResult DeleteTag(Tag tag)
 {
     var manager = new AdminManager();
     manager.DeleteTag(tag.TagID);
     return RedirectToAction("TagIndex", "Tag");
 }
Exemple #9
0
 public ActionResult CreateTag(Tag newTag)
 {
     var manager = new AdminManager();
     manager.AddTag(newTag);
     return RedirectToAction("TagIndex","Tag");
 }
 public void add(Tag tag)
 {
     _tags.Add(tag);
 }
 public void Update(Tag tag)
 {
     var selectedTag = _tags.FirstOrDefault(t => t.TagID == tag.TagID);
     selectedTag.TagID = tag.TagID;
     selectedTag.TagName = tag.TagName;
 }