public bool AddNewNews(News newNews)
        {
            bool ret = false;
            try
            {
                newNews.CreatedDate = DateTime.Now;
                newNews.Title = newNews.Title == null ? "" : newNews.Title;

                newNews.Title2 = newNews.Title2 == null ? "" : newNews.Title2;

                newNews.Description = newNews.Description == null ? "" : newNews.Description;
                newNews.Description2 = newNews.Description2 == null ? "" : newNews.Description2;

                newNews.MainContent = newNews.MainContent == null ? "" : newNews.MainContent;

                newNews.MainContent2 = newNews.MainContent2 == null ? "" : newNews.MainContent2;

                newNews.KeySearch = newNews.KeySearch == null ? "" : newNews.KeySearch;
                newNews.ItemImageURL = newNews.ItemImageURL == null ? "" : newNews.ItemImageURL;

                newNews.Active = newNews.Active == null ? "" : newNews.Active;

                _context.News.Add(newNews);
                if (_context.SaveChanges() > 0)
                {
                    ret = true;
                }

            }
            catch (Exception e)
            {
                ErrorHandle.WriteError("GetAllCategory", e.Message);
            }
            return ret;
        }
        public News LoadNewsByNewsID(int sNewsID)
        {
            News ret = new News();
            try
            {
                ret = (from ite in _context.News
                       where ite.NewsID == sNewsID
                       select ite).FirstOrDefault();

            }
            catch (Exception e)
            {
                ErrorHandle.WriteError("GetAllCategory", e.Message);
            }
            return ret;
        }
        public News LoadNewsAndRelativeOfIt(string sNewsID, int numberOfRecordRelative, ref List<News> listNewsAndRelative)
        {
            News ret = new News();

            try
            {
                int sNewsIDTem = 1;
                int.TryParse(sNewsID, out sNewsIDTem);
                var _ret = (from ite in _context.News
                            where ite.NewsID == sNewsIDTem
                            select ite).FirstOrDefault();

                if (_ret != null)
                {
                    ret = _ret;
                    var _retList = (from ite in _context.News
                                    where ite.CreatedDate <= _ret.CreatedDate && ite.NewsID != _ret.NewsID
                                    select ite).Take(numberOfRecordRelative).OrderByDescending(p => p.CreatedDate).ToList();

                    if (_retList != null)
                    {
                        listNewsAndRelative = _retList;
                    }

                }

            }
            catch (Exception e)
            {
                ErrorHandle.WriteError("GetAllCategory", e.Message);
            }
            return ret;
        }
        public bool EditNews(News editNews)
        {
            bool ret = false;
            try
            {
                News oldItem = (from ite in _context.News
                                where ite.NewsID == editNews.NewsID
                                select ite).FirstOrDefault();

                if (oldItem != null)
                {
                    oldItem.Title = editNews.Title == null ? "" : editNews.Title;

                    oldItem.Title2 = editNews.Title2 == null ? "" : editNews.Title2;

                    oldItem.Title2 = editNews.Title2 == null ? "" : editNews.Title2;

                    oldItem.Description = editNews.Description == null ? "" : editNews.Description;
                    oldItem.Description2 = editNews.Description2 == null ? "" : editNews.Description2;

                    oldItem.MainContent = editNews.MainContent == null ? "" : editNews.MainContent;

                    oldItem.MainContent2 = editNews.MainContent2 == null ? "" : editNews.MainContent2;

                    oldItem.KeySearch = editNews.KeySearch == null ? "" : editNews.KeySearch;

                    oldItem.Active = editNews.Active == null ? "" : editNews.Active;

                    if (editNews.ItemImageURL != null && editNews.ItemImageURL != "")
                    {
                        oldItem.ItemImageURL = editNews.ItemImageURL;
                    }

                    if (_context.SaveChanges() > 0)
                    {
                        ret = true;
                    }
                    ret = true;
                }

            }
            catch (Exception e)
            {
                ErrorHandle.WriteError("GetAllCategory", e.Message);
            }
            return ret;
        }
        public JsonResult EditNews(News newsInfor)
        {
            JsonResult jResult = new JsonResult();
            try
            {
                
                string message = "File upload failed";
                if (TempData["HttpPostedFileBase"] != null)
                {

                    HttpPostedFileBase file = (HttpPostedFileBase)TempData["HttpPostedFileBase"];
                    string pathForSaving = Server.MapPath(Var.UrlUploadCompanyNewsImage);
                    if (this.CreateFolderIfNeeded(pathForSaving))
                    {
                        try
                        {
                            file.SaveAs(Path.Combine(pathForSaving, file.FileName));
                           
                            message = "File uploaded successfully!";
                            newsInfor.ItemImageURL = "/" + file.FileName;
                            TempData["HttpPostedFileBase"] = null;
                        }
                        catch (Exception ex)
                        {
                            message = string.Format("File upload failed: {0}", ex.Message);
                        }
                    }
                }

                bool ret = adminPageProvider.EditNews(newsInfor);
                if (ret)
                {
                    return LoadAllNews(allStatus, 0);
                }
                else
                {
                    jResult = Json(new { success = false }, JsonRequestBehavior.AllowGet);
                }
                 
            }
            catch (Exception)
            {


            }

            return jResult;
        }
        public ActionResult NewsDetail()
        {
            var id = RouteData.Values["id"];

            ViewBag.ListNewsAndRelative = new List<News>();
            List<News> ListNewsAndRelative = new List<News>();
            News NewsDetail = new News();
            if (id != null)
            {

                NewsDetail = adminPageProvider.LoadNewsAndRelativeOfIt(id.ToString(), 5, ref ListNewsAndRelative);
                ViewBag.ListNewsAndRelative = ListNewsAndRelative;

            }
            return View(NewsDetail);
        }