public ActionResult Edit([Bind(Include = "Id,Name")] BlogTags blogTags)
 {
     if (ModelState.IsValid)
     {
         db.Entry(blogTags).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(blogTags));
 }
        public ActionResult Create([Bind(Include = "Id,Name")] BlogTags blogTags)
        {
            if (ModelState.IsValid)
            {
                db.BlogTags.Add(blogTags);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(blogTags));
        }
        // GET: Admin/BlogTags/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BlogTags blogTags = db.BlogTags.Find(id);

            if (blogTags == null)
            {
                return(HttpNotFound());
            }
            return(View(blogTags));
        }
        // POST: Admin/BlogTags/Delete/5
        public ActionResult DeleteConfirmed(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BlogTags BlogTags = db.BlogTags.Find(id);

            if (BlogTags == null)
            {
                return(RedirectToAction("Error", "Home"));
            }
            db.BlogTags.Remove(BlogTags);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> AddNewTag(int id, string tagTitle)
        {
            var blog = await _db.Blogs.FindAsync(id);

            if (blog != null)
            {
                var tag = new BlogTags();
                tag.Text   = tagTitle;
                tag.BlogId = id;
                await _db.BlogTags.AddAsync(tag);

                await _db.SaveChangesAsync();

                return(ViewComponent(componentName: "BlogTagList", arguments: new { blogId = id }));
            }
            return(Json(false));
        }
        public override Blog GetById(object id)
        {
            var model      = new Blog();
            var entityBlog = (from blog in _context.Blogs
                              join blogtag in _context.BlogsTags on blog.Id equals blogtag.BlogId into BlogTags
                              from b in BlogTags.DefaultIfEmpty()
                              where blog.Id == (Guid)id
                              select new { Blog = blog, Tags = b })
                             .ToLookup(x => x.Blog)
                             .Select(x => new { Blog = x.Key, Tags = x.Select(t => t.Tags).Where(t => t != null).ToList() })
                             .FirstOrDefault();

            model            = _mapper.Map <Blog>(entityBlog.Blog);
            model.BlogTagIds = entityBlog.Tags != null?entityBlog.Tags.Select(x => x.TagId).ToList() : new List <Guid>();

            return(model);
        }
Example #7
0
        private void GetBlogTag(BlogPost model, string tag)
        {
            BlogTags blogTag = new BlogTags();
            blogTag.Blog = model;
            blogTag.Tag = GetTag(tag);
            List<BlogTags> tags = (from data in context.BlogTags.Include("Blog").Include("Tag") where data.Blog.ID == blogTag.Blog.ID && data.Tag.ID == blogTag.Tag.ID select data).ToList();
            if(tags.Count > 0)
            {
                return;
            }
            else
            {
                context.BlogTags.Add(blogTag);
                context.SaveChanges();
                return;

            }
        }
Example #8
0
        // GET: Admin/Blog
        public ActionResult Index()
        {
            List <BlogTagViewModel> tags = new BlogTags().Tags();

            return(View(tags));
        }