コード例 #1
0
 public void ChangeIsHot(Tbl_News input)
 {
     using (var Db = new ProjectWebEntities())
     {
         try
         {
             var model = Db.Tbl_News.Find(input.Id);
             model.IsHot           = input.IsHot;
             Db.Entry(model).State = EntityState.Modified;
             Db.SaveChanges();
             if (input.IsHot)
             {
                 Db.pr_LogSystem_save("Thay đổi trạng thái của (" + model.Title + ") thành NỔI BẬT", "Cập nhật", "Dự án", User.Identity.Name);
             }
             else
             {
                 Db.pr_LogSystem_save("Thay đổi trạng thái của (" + model.Title + ") thành KHÔNG NỔI BẬT", "Cập nhật", "Dự án", User.Identity.Name);
             }
             //Xóa cache
             CacheHelper.ClearAllOutputCache();
         }
         catch (Exception ex)
         {
             logger.Error("An Error Happened! ", ex);
         }
     }
 }
コード例 #2
0
        public ActionResult Create(Tbl_News model)
        {
            using (var Db = new ProjectWebEntities())
            {
                try
                {
                    model.DateCreate = DateTime.Now;
                    model.NewsTypeId = 2;
                    // create new
                    if (model.Id == 0)
                    {
                        Db.Tbl_News.Add(model);
                        Db.SaveChanges();
                        Db.pr_LogSystem_save("Thêm mới dữ liệu(ID = " + model.Id + ")", "Thêm mới", "Tin tức", User.Identity.Name);

                        //Repository.ClearCache(); // clear cache
                    }
                    else // update current
                    {
                        Db.Entry(model).State = EntityState.Modified;
                        Db.SaveChanges();
                        Db.pr_LogSystem_save("Cập nhật dữ liệu(ID = " + model.Id + ")", "Cập nhật", "Tin tức", User.Identity.Name);
                    }
                    //Xóa cache
                    CacheHelper.ClearAllOutputCache();
                }
                catch (Exception ex)
                {
                    logger.Error("An Error Happened! ", ex);
                }
                return(RedirectToAction("Index", "Project"));
            }
        }
コード例 #3
0
 public void ChangeIsDisable(Tbl_News input)
 {
     using (var db = new ProjectWebEntities())
     {
         try
         {
             var model = db.Tbl_News.Find(input.Id);
             model.IsDisable       = input.IsDisable;
             db.Entry(model).State = EntityState.Modified;
             db.SaveChanges();
             db.pr_LogSystem_save("Cập nhật trạng thái sử dụng(" + model.Title + ")", "Cập nhật", "News", User.Identity.Name);
             //Xóa cache
             CacheHelper.ClearAllOutputCache();
         }
         catch (Exception ex)
         {
             logger.Error("An Error Happened! ", ex);
         }
     }
 }
コード例 #4
0
        public ActionResult SaveAbout(Tbl_News model)
        {
            using (var Db = new ProjectWebEntities())
            {
                try
                {
                    var news = Db.Tbl_News.Find(1);
                    news.Content         = model.Content;
                    Db.Entry(news).State = EntityState.Modified;
                    Db.SaveChanges();
                    Db.pr_LogSystem_save("Cập nhật dữ liệu(ID = " + model.Id + ")", "Cập nhật", "Giới thiệu", User.Identity.Name);
                    TempData["success"] = "Cập nhật thành công !!";
                }
                catch (Exception ex)
                {
                    _logger.Error("An Error Happened! ", ex);
                }

                return(RedirectToAction("Index", "About"));
            }
        }
コード例 #5
0
 public void Double(int id)
 {
     using (var Db = new ProjectWebEntities())
     {
         try
         {
             var model    = Db.Tbl_News.Find(id);
             var newModel = new Tbl_News
             {
                 Title       = model.Title,
                 Description = model.Description,
                 ImagePath   = model.ImagePath,
                 DateCreate  = DateTime.Now,
                 NewsTypeId  = model.NewsTypeId
             };
             Db.Tbl_News.Add(newModel);
             Db.SaveChanges();
         }
         catch (Exception ex)
         {
             logger.Error("An Error Happened! ", ex);
         }
     }
 }
コード例 #6
0
 public ActionResult destroyNews([DataSourceRequest] DataSourceRequest request, Tbl_News model)
 {
     using (var Db = new ProjectWebEntities())
     {
         try
         {
             var m = Db.Tbl_News.Find(model.Id);
             if (model != null)
             {
                 try
                 {
                     Db.Tbl_News.Remove(m);
                     Db.SaveChanges();
                     // Write log system---------
                     Db.pr_LogSystem_save("Xóa dữ liệu(ID = " + model.Id + ")", "Xóa", "News", User.Identity.Name);
                 }
                 catch (Exception ex)
                 {
                     // Write log system---------
                     Db.pr_LogSystem_save("Xóa dữ liệu(ID = " + model.Id + ")", "Xóa", "News", User.Identity.Name);
                     logger.Error("An Error Happened! ", ex);
                 }
             }
             //Xóa cache
             CacheHelper.ClearAllOutputCache();
         }
         catch (Exception ex)
         {
             logger.Error("An Error Happened! ", ex);
         }
         return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
     }
 }
コード例 #7
0
        public ActionResult Create(Tbl_News model)
        {
            using (var db = new ProjectWebEntities())
            {
                try
                {
                    if (!string.IsNullOrEmpty(Request.Form["fileName"]))
                    {
                        model.ImagePath = Request.Form["fileName"].ToString();
                    }
                    else
                    {
                        model.ImagePath = null;
                    }


                    if (Request.Form["ParentId"] != null && Request.Form["ParentId"] != "")
                    {
                        string[] parList = Request.Form["ParentId"].Split(',');
                        for (int i = parList.Count() - 1; i >= 0; i--)
                        {
                            if (parList[i] != "")
                            {
                                if (int.Parse(parList[i]) > 0)
                                {
                                    model.NewsTypeId = int.Parse(parList[i]);
                                    break;
                                }
                            }
                        }
                    }
                    model.Url = "/trang-don/" + Util.GenerateUrl(model.Title);
                    if (model != null)
                    {
                        model.DateCreate       = DateTime.Now;
                        model.IsIndividualPage = true;

                        // create new
                        if (model.Id == 0)
                        {
                            db.Tbl_News.Add(model);
                            db.SaveChanges();
                            db.pr_LogSystem_save("Thêm mới dữ liệu(ID = " + model.Id + ")", "Thêm mới", "Tin tức", User.Identity.Name);

                            //Repository.ClearCache(); // clear cache
                        }
                        else // update current
                        {
                            var menu = db.Tbl_MenuMultiLevel.FirstOrDefault(p => p.PageChildId == model.Id && p.PageId == GlobalVariables.MenuTrangdon);
                            if (menu != null)
                            {
                                menu.Url             = db.Tbl_MenuLink.Find(GlobalVariables.MenuTrangdon).Url + model.Url + "-" + model.Id;
                                db.Entry(menu).State = EntityState.Modified;
                            }
                            db.Entry(model).State = EntityState.Modified;
                            db.SaveChanges();
                            db.pr_LogSystem_save("Cập nhật dữ liệu(ID = " + model.Id + ")", "Cập nhật", "Tin tức", User.Identity.Name);
                        }
                        //Xóa cache
                        CacheHelper.ClearAllOutputCache();
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("An Error Happened! ", ex);
                }
                return(RedirectToAction("Index", "IndividualPage"));
            }
        }