public ActionResult Edit(ModelTopic modelTopic)
        {
            String baoloi = "";

            if (ModelState.IsValid)
            {
                try
                {
                    if (modelTopic.ParentId == null)
                    {
                        modelTopic.ParentId = 0;
                    }
                    modelTopic.Update_At       = DateTime.Now;
                    modelTopic.Update_By       = (int?)Session["UserIdAdmin"];
                    db.Entry(modelTopic).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    baoloi += "Không Thành Công";
                }
            }
            ViewBag.Error = baoloi;
            return(View(modelTopic));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ModelTopic modelTopic = db.Topic.Find(id);

            db.Topic.Remove(modelTopic);
            db.SaveChanges();
            return(RedirectToAction("Trash", "Topics"));
        }
        public ActionResult Restore(int id)
        {
            ModelTopic modelTopic = db.Topic.Find(id);

            if (modelTopic != null)
            {
                modelTopic.Status          = 1;
                db.Entry(modelTopic).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("Trash", "Topics"));
        }
        public ActionResult Status(int id)
        {
            ModelTopic modelTopic = db.Topic.Find(id);

            if (modelTopic != null)
            {
                modelTopic.Status          = (modelTopic.Status == 1) ? 2 : 1;
                db.Entry(modelTopic).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "Topics"));
        }
        // GET: Admin/Topics/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ModelTopic modelTopic = db.Topic.Find(id);

            if (modelTopic == null)
            {
                return(HttpNotFound());
            }
            return(View(modelTopic));
        }
        // GET: Admin/Topics/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ModelTopic modelTopic = db.Topic.Find(id);

            if (modelTopic == null)
            {
                return(HttpNotFound());
            }
            ViewBag.listParent = new SelectList(db.Topic.Where(m => m.Status != 0 && m.ParentId == 0).ToList(), "Id", "Name", 0);
            return(View(modelTopic));
        }
        public ActionResult Create(ModelTopic modelTopic)
        {
            ViewBag.listParent = new SelectList(db.Topic.Where(m => m.Status != 0 && m.ParentId == 0).ToList(), "Id", "Name", 0);
            String baoloi = "";

            if (ModelState.IsValid)
            {
                try
                {
                    if (modelTopic.ParentId == null)
                    {
                        modelTopic.ParentId = 0;
                    }
                    string slug = Mystring.str_slug(modelTopic.Name);
                    modelTopic.Slug       = slug;
                    modelTopic.Created_At = DateTime.Now;
                    modelTopic.Created_By = (int?)Session["UserIdAdmin"];
                    db.Topic.Add(modelTopic);
                    //them du lieu bang link
                    ModelLink modelLink = new ModelLink();
                    modelLink.Name    = modelTopic.Name;
                    modelLink.Slug    = modelTopic.Slug;
                    modelLink.TableId = modelTopic.Id;
                    modelLink.Type    = "topic";
                    db.Links.Add(modelLink);

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    baoloi += "Thêm Không Thành Công";
                }
            }
            ViewBag.Error = baoloi;
            return(View(modelTopic));
        }