Ejemplo n.º 1
0
        public async Task <IActionResult> AddTagToEntry(int id, [FromBody] Models.Tag tag, [FromServices] ApplicationDbContext db)
        {
            var entry = await db.Entries.SingleOrDefaultAsync(i => i.Id == id);

            if (entry == null)
            {
                return(NotFound("Entry not found"));
            }
            var dbTag = await db.Tags.SingleOrDefaultAsync(i => i.Name.Equals(tag.Name, StringComparison.InvariantCultureIgnoreCase));

            if (dbTag == null)
            {
                dbTag = new Data.Tag()
                {
                    Name = tag.Name
                };
                db.Tags.Add(dbTag);
            }
            var ec = await db.EntryTags.SingleOrDefaultAsync(e => e.TagId == dbTag.Id && e.EntryId == entry.Id);

            if (ec == null)
            {
                ec = new EntryTag()
                {
                    Tag = dbTag, Entry = entry
                };
                db.EntryTags.AddRange(ec);
                await db.SaveChangesAsync();
            }

            return(Created("", dbTag));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            EntryTag entryTag = db.EntryTags.Find(id);

            db.EntryTags.Remove(entryTag);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <TagViewModel> > AddTag([FromQuery] string tagName)
        {
            var tag = new EntryTag(tagName);

            tag = _repository.AddOrUpdate(tag);
            await _unitOfWork.CompleteAsync();

            return(_mapper.Map <EntryTag, TagViewModel>(tag));
        }
Ejemplo n.º 4
0
 public ActionResult Edit(EntryTag tag)
 {
     using (var db = new BlogContext())
     {
         db.Tags.Find(tag.TagId).Name = tag.Name;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
 public ActionResult Edit([Bind(Include = "Id,TagName")] EntryTag entryTag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(entryTag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(entryTag));
 }
        public ActionResult CreateEducation([Bind(Include = "TagName")] EntryTag entryTag)
        {
            EducationTag aTag = new EducationTag();

            aTag.TagName = entryTag.TagName;

            db.EducationTag.Add(aTag);
            db.SaveChanges();
            return(RedirectToAction("CreateEducation", "EntryInformative"));

            //return View(entryTag);
        }
        public ActionResult Create([Bind(Include = "TagName")] EntryTag entryTag)
        {
            EntryTag aTag = new EntryTag();

            aTag.TagName = entryTag.TagName;

            db.EntryTags.Add(aTag);
            db.SaveChanges();
            return(RedirectToAction("CreateTest", "Entries"));

            //return View(entryTag);
        }
        // GET: EntryTags/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EntryTag entryTag = db.EntryTags.Find(id);

            if (entryTag == null)
            {
                return(HttpNotFound());
            }
            return(View(entryTag));
        }
Ejemplo n.º 9
0
 private void HandleTags(BlogContext db, BlogEntry entry, string collectedTags)
 {
     if (!string.IsNullOrEmpty(collectedTags))
     {
         var tagArray = collectedTags.Split(' ').Distinct();
         foreach (var tag in tagArray)
         {
             if (!db.Tags.Any(t => t.Name.Equals(tag)))
             {
                 var tagStruct = new EntryTag
                 {
                     Name = tag
                 };
                 db.Tags.Add(tagStruct);
             }
         }
         db.SaveChanges(); // save tags, because entry won't get linked to tags if they are not in db
         entry.Tags = db.Tags.Where(t => tagArray.Contains(t.Name)).ToList();
     }
 }