Пример #1
0
        public long Insert(News mode)
        {
            if (string.IsNullOrEmpty(mode.MetaTite))
            {
                mode.MetaTite = HepperString.ToUnsignString(mode.Name);
            }
            if (string.IsNullOrEmpty(mode.Title))
            {
                mode.Title = mode.Name;
            }
            mode.ViewCount     = 0;
            mode.PublishedDate = DateTime.Now;
            db.News.Add(mode);
            db.SaveChanges();
            //Xử lý tag
            if (!string.IsNullOrEmpty(mode.Tags))
            {
                string[] tags = mode.Tags.Split(',');
                foreach (var tag in tags)
                {
                    var tagId      = HepperString.ToUnsignString(tag);
                    var existedTag = this.CheckTag(tagId);

                    //insert to to tag table
                    if (!existedTag)
                    {
                        this.InsertTag(tagId, tag);
                    }

                    //insert to content tag
                    this.InsertNewsTag(mode.NewsID, tagId);
                }
            }
            return(mode.NewsID);
        }
Пример #2
0
        public ActionResult Edit(long id)
        {
            NewsDao dbDAO  = new NewsDao();
            News    objNew = null;

            objNew = dbDAO.FindByID(id);
            List <string> cateID = HepperString.GetListByKey(objNew.CategoryID, ",");

            PopulateParentIDDropDownList(HepperString.TolistLong(cateID.ToArray()));

            return(View(objNew));
        }
Пример #3
0
        public bool Update(Category mode)
        {
            try
            {
                var bd = db.Categories.Find(mode.CategoryID);
                if (string.IsNullOrEmpty(mode.MetaTite))
                {
                    bd.MetaTite = HepperString.ToUnsignString(mode.Name);
                }
                else
                {
                    bd.MetaTite = mode.MetaTite;
                }
                if (string.IsNullOrEmpty(mode.SeoTite))
                {
                    bd.SeoTite = mode.Name;
                }
                else
                {
                    bd.SeoTite = mode.SeoTite;
                }
                // bd.CategoryID = mode.CategoryID;
                //bd.CreateBy = mode.CreateBy;
                //bd.CreateDate = mode.CreateDate;
                bd.Description  = mode.Description;
                bd.DisplayOrder = mode.DisplayOrder;
                bd.Image        = mode.Image;

                bd.LanguageID      = mode.LanguageID;
                bd.MetaDescription = mode.MetaDescription;
                bd.MetakeyWords    = mode.MetakeyWords;

                bd.ModifiedBy   = mode.ModifiedBy;
                bd.ModifiedDate = mode.ModifiedDate;
                bd.ParentID     = mode.ParentID;
                bd.Position     = mode.Position;

                bd.ShowOnHome = mode.ShowOnHome;
                bd.Status     = mode.Status;
                bd.Name       = mode.Name;


                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #4
0
        public bool Update(About mode)
        {
            try
            {
                var bd = db.Abouts.Find(mode.AboutID);
                if (string.IsNullOrEmpty(mode.MetaTite))
                {
                    bd.MetaTite = HepperString.ToUnsignString(mode.Name);
                }
                else
                {
                    bd.MetaTite = mode.MetaTite;
                }

                // bd.AboutID = mode.AboutID;
                //bd.CreateBy = mode.CreateBy;
                //bd.CreateDate = mode.CreateDate;
                bd.Description = mode.Description;
                bd.Phone       = mode.Phone;
                bd.Twitter     = mode.Twitter;
                bd.Video       = mode.Video;
                bd.Address     = mode.Address;
                bd.Detail      = mode.Detail;
                bd.Email       = mode.Email;
                bd.Facebook    = mode.Facebook;
                bd.Googleplus  = mode.Googleplus;

                bd.Image = mode.Image;

                bd.LanguageID      = mode.LanguageID;
                bd.MetaDescription = mode.MetaDescription;
                bd.MetakeyWords    = mode.MetakeyWords;

                bd.ModifiedBy   = mode.ModifiedBy;
                bd.ModifiedDate = mode.ModifiedDate;

                bd.Status = mode.Status;
                bd.Name   = mode.Name;


                db.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #5
0
        public ActionResult Publicer(long id)
        {
            NewsDao dbDAO  = new NewsDao();
            News    objNew = null;

            //SetParentIDViewBag();
            try
            {
                objNew = dbDAO.FindByID(id);
                List <string> cateID = HepperString.GetListByKey(objNew.CategoryID, ",");
                PopulateParentIDDropDownList(HepperString.TolistLong(cateID.ToArray()));
            }
            catch
            {
                ModelState.AddModelError("", Resources.ResourceAdmin.ErrorGetRecordMessage);
            }
            return(View(objNew));
        }
Пример #6
0
        public bool Insert(About mode)
        {
            try
            {
                if (string.IsNullOrEmpty(mode.MetaTite))
                {
                    mode.MetaTite = HepperString.ToUnsignString(mode.Name);
                }

                db.Abouts.Add(mode);
                db.SaveChanges();
                return(true);
            }

            catch
            {
                return(false);
            }
        }
Пример #7
0
        public bool Insert(Category mode)
        {
            try
            {
                if (string.IsNullOrEmpty(mode.MetaTite))
                {
                    mode.MetaTite = HepperString.ToUnsignString(mode.Name);
                }
                if (string.IsNullOrEmpty(mode.SeoTite))
                {
                    mode.SeoTite = mode.Name;
                }
                db.Categories.Add(mode);
                db.SaveChanges();
                return(true);
            }

            catch
            {
                return(false);
            }
        }
Пример #8
0
        public long Update(News mode)
        {
            var bd = db.News.Find(mode.NewsID);

            if (string.IsNullOrEmpty(mode.MetaTite))
            {
                bd.MetaTite = HepperString.ToUnsignString(mode.Name);
            }
            else
            {
                bd.MetaTite = mode.MetaTite;
            }
            if (string.IsNullOrEmpty(mode.Title))
            {
                bd.MetaTite = mode.Name;
            }
            else
            {
                bd.MetaTite = mode.MetaTite;
            }

            //bd.NewsID = mode.NewsID;
            //bd.CreateBy = mode.CreateBy;
            //bd.CreateDate = mode.CreateDate;

            bd.CategoryID    = mode.CategoryID;
            bd.ContentHtml   = mode.ContentHtml;
            bd.Description   = mode.Description;
            bd.Name          = mode.Name;
            bd.PublishedDate = mode.PublishedDate;
            if (string.IsNullOrEmpty(mode.RelatedNewses))
            {
                bd.RelatedNewses = "";
            }
            else
            {
                bd.RelatedNewses = mode.RelatedNewses;
            }

            bd.ShowConment     = mode.ShowConment;
            bd.ShowShare       = mode.ShowShare;
            bd.UpTopHot        = mode.UpTopHot;
            bd.UpTopNew        = mode.UpTopNew;
            bd.ViewCount       = mode.ViewCount;
            bd.Image           = mode.Image;
            bd.LanguageID      = mode.LanguageID;
            bd.MetaDescription = mode.MetaDescription;
            bd.MetakeyWords    = mode.MetakeyWords;

            bd.ModifiedBy   = mode.ModifiedBy;
            bd.ModifiedDate = mode.ModifiedDate;

            bd.Status = mode.Status;

            bd.Source = mode.Source;


            db.SaveChanges();
            //Xử lý tag
            if (!string.IsNullOrEmpty(mode.Tags))
            {
                this.RemoveAllContentTag(mode.NewsID);
                string[] tags = mode.Tags.Split(',');
                foreach (var tag in tags)
                {
                    var tagId      = HepperString.ToUnsignString(tag);
                    var existedTag = this.CheckTag(tagId);

                    //insert to to tag table
                    if (!existedTag)
                    {
                        this.InsertTag(tagId, tag);
                    }

                    //insert to content tag
                    this.InsertNewsTag(mode.NewsID, tagId);
                }
            }
            return(mode.NewsID);
        }
Пример #9
0
        public ActionResult Create(FormCollection data)
        {
            ViewBag.UpTopNew = data["UpTopNew"].ToString();
            ViewBag.UpTopHot = data["UpTopHot"].ToString();

            PopulateParentIDDropDownList(HepperString.TolistLong(data.GetValues("CategoryID")));
            try
            {
                News    objNews = new News();
                NewsDao bdDao   = new NewsDao();

                UserLogin us = (UserLogin)Session[SystemConsts.USER_SESSION];


                objNews.Name            = data["Name"].ToString();
                objNews.Title           = data["Title"].ToString();
                objNews.MetaTite        = data["MetaTite"].ToString();
                objNews.MetakeyWords    = data["MetakeyWords"].ToString();
                objNews.MetaDescription = data["MetaDescription"].ToString();
                objNews.Description     = data["Description"].ToString();
                objNews.ContentHtml     = data["ContentHtml"].ToString();
                objNews.Image           = data["Image"].ToString();
                objNews.UpTopNew        = Convert.ToDateTime(ViewBag.UpTopNew);
                objNews.UpTopHot        = Convert.ToDateTime(ViewBag.UpTopHot);
                bool ShowShare = true;
                if (data.GetValues("ShowShare").Equals("false"))
                {
                    ShowShare = false;
                }
                bool ShowConment = true;
                if (data.GetValues("ShowConment").Equals("false"))
                {
                    ShowConment = false;
                }
                objNews.ShowShare    = ShowShare;
                objNews.ShowConment  = ShowConment;
                objNews.Source       = data["Source"].ToString();
                objNews.Status       = 0;
                objNews.CreateDate   = Hepper.GetDateServer();
                objNews.CreateBy     = us.UserName;
                objNews.ModifiedBy   = us.UserName;
                objNews.Tags         = data["Tags"].ToString();
                objNews.ModifiedDate = Hepper.GetDateServer();
                objNews.LanguageID   = "vi";
                string[] cateIDs = data.GetValues("CategoryID");
                string   sCatID  = "";
                foreach (var sID in cateIDs)
                {
                    sCatID += sID + ",";
                }
                if (sCatID.Length > 0)
                {
                    sCatID = sCatID.Remove(sCatID.Length - 1, 1);
                }
                objNews.CategoryID = sCatID;
                //collection.CreateBy = us.UserName;
                //collection.ModifiedBy = us.UserName;
                if (bdDao.Insert(objNews) > 0)
                {
                    SetAlert(@Resources.ResourceAdmin.AdminCreateRecordSuccess, "success");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    SetAlert(@Resources.ResourceAdmin.AdminCreateRecordFailed, "danger");
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                SetAlert(@Resources.ResourceAdmin.AdminCreateRecordFailed, "danger");
                return(View());
            }
        }