Esempio n. 1
0
 public Tag AddTag([FromBody] Tag newTag)
 {
     if (ModelState.IsValid)
     {
         return(_db.AddTag(newTag));
     }
     return(null);
 }
Esempio n. 2
0
        public async Task <ActionResult <Tag> > PostTag(Tag tag)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var dbTag = await _repo.AddTag(tag);

            return(CreatedAtAction("GetTag", new { id = dbTag.Id }, dbTag));
        }
Esempio n. 3
0
        public void TagsAreClearedCorrectly()
        {
            var dbContextProvider = MockedDbContextFactory.GetMock();

            var tagRepository = new TagRepository(dbContextProvider.Object);

            tagRepository.AddTag("URL", "NAME", "VALUE", 1);
            tagRepository.AddTag("URL", "NAME", "VALUE2", 1);
            tagRepository.AddTag("URL", "NAME", "VALUE3", 1);
            tagRepository.AddTag("URL", "NAME", "VALUE4", 1);

            tagRepository.Clear("URL");

            using (var context = dbContextProvider.Object.GetContext())
            {
                Assert.Equal(1, context.Sites.Count());
                Assert.Equal(0, context.Tags.Count());
            }
        }
        public Tag AddTag([FromBody] Tag newTag, int id)
        {
            newTag.Name.Replace(" ", "+");
            var user = HttpContext.User.Identity.Name;

            if (ModelState.IsValid)
            {
                return(_db.AddTag(newTag, user, id));
            }
            return(null);
        }
Esempio n. 5
0
 public ActionResult Create(Tag tag)
 {
     try
     {
         _tagRepository.AddTag(tag);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Esempio n. 6
0
 public ActionResult Create(Tag model)
 {
     try
     {
         TagRepository repo = new TagRepository();
         repo.AddTag(model);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(model));
     }
 }
        public ActionResult Create(Tag tag)
        {
            try
            {
                // TODO: Add insert logic here
                _tagRepository.AddTag(tag);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(tag));
            }
        }
Esempio n. 8
0
        public void AddingTagCreatesTagAndSiteInDatabase()
        {
            var dbContextProvider = MockedDbContextFactory.GetMock();

            var tagRepository = new TagRepository(dbContextProvider.Object);

            tagRepository.AddTag("URL", "NAME", "VALUE", 1);

            using (var context = dbContextProvider.Object.GetContext())
            {
                Assert.Equal(1, context.Sites.Count());
                Assert.Equal(1, context.Tags.Count());

                Assert.Equal("URL", context.Sites.First().Url);
                Assert.Equal("NAME", context.Tags.First().Name);
                Assert.Equal("VALUE", context.Tags.First().Value);
                Assert.Equal("URL", context.Tags.Include(x => x.Site).First().Site.Url);
            }
        }
Esempio n. 9
0
 public void AddTag(Tag tag)
 {
     _tagRepository.AddTag(tag);
     Tags.Add(tag);
     SortTags();
 }