示例#1
0
        public int Create(Model.EntityFramework.Content content)
        {
            var db = DataAccess.Db;

            if (string.IsNullOrEmpty(content.MetaTitle))
            {
                content.MetaTitle = StringHelper.ToUnsignString(content.Name);
            }

            db.Contents.Add(content);
            db.SaveChanges();

            //lay danh sach tag
            if (!string.IsNullOrEmpty(content.Tags))
            {
                string[] tags = content.Tags.Split(',');
                foreach (var tag in tags)
                {
                    var tagId      = StringHelper.ToUnsignString(tag);
                    var existedTag = CheckTag(tagId);
                    if (!existedTag)
                    {
                        this.InsertTag(tagId, tag);
                    }
                    this.InsertContentTag((int)content.ID, tagId);
                }
            }
            return((int)content.ID);
        }
示例#2
0
        public int Update(Model.EntityFramework.Content model)
        {
            var db  = DataAccess.Db;
            var old = db.Contents.Find(model.ID);

            if (string.IsNullOrEmpty(model.MetaTitle))
            {
                model.MetaTitle = StringHelper.ToUnsignString(model.Name);
            }

            model.ModifiedDate = DateTime.Now;
            model.ModifiedBy   = HttpContext.Current.User.Identity.Name.ToString();
            db.Entry(old).CurrentValues.SetValues(model);
            DataAccess.Db.SaveChanges();

            this.RemoveAllContentTag(model.ID);

            //lay danh sach tag
            if (!string.IsNullOrEmpty(model.Tags))
            {
                string[] tags = model.Tags.Split(',');
                foreach (var tag in tags)
                {
                    var tagId      = StringHelper.ToUnsignString(tag);
                    var existedTag = CheckTag(tagId);
                    if (!existedTag)
                    {
                        this.InsertTag(tagId, tag);
                    }
                    this.InsertContentTag((int)model.ID, tagId);
                }
            }

            return(1);
        }
示例#3
0
        public ActionResult Edit(Model.EntityFramework.Content content)
        {
            if (ModelState.IsValid)
            {
                var dao    = new ContentDAO();
                int result = dao.Update(content);
                if (result > 0)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Có lỗi xảy ra thử lại sau.");
                }
            }

            SetViewBag((int)content.CategoryID);
            return(View(content));
        }