Example #1
0
        public void UpdateTinTuc(TIN_TUC tintuc)
        {
            var query = (from c in _dataContext.TIN_TUCs
                         where c.MaTinTuc == tintuc.MaTinTuc
                         select c).Single();

            query.HinhAnh      = tintuc.HinhAnh;
            query.MaAdminDuyet = tintuc.MaAdminDuyet;
            query.NoiDung      = tintuc.NoiDung;
            query.NgayDang     = tintuc.NgayDang;
            query.TieuDe       = tintuc.TieuDe;
            query.TomTat       = tintuc.TomTat;

            _dataContext.SubmitChanges();
        }
Example #2
0
        public bool Save(TIN_TUC tintuc)
        {
            var model = db.TIN_TUC.FirstOrDefault(n => n.MaTinTuc == tintuc.MaTinTuc);

            try
            {
                if (model != null)
                {
                    if (Session["fileUpload"] != null)
                    {
                        fileUpload = (HttpPostedFileBase)Session["fileUpload"];
                        if (fileUpload != null && fileUpload.ContentLength > 0)
                        {
                            fileUpload = (HttpPostedFileBase)Session["fileUpload"];
                            string path = Path.Combine(Server.MapPath("~/Images/ImagesNews"), fileUpload.FileName);
                            fileUpload.SaveAs(path);
                            //xóa ảnh trong csdl
                            model.HinhAnh = "";
                            db.SaveChanges();

                            //thay ảnh mới
                            model.MaTinTuc  = tintuc.MaTinTuc;
                            model.TenTinTuc = tintuc.TenTinTuc;
                            model.NoiDung   = tintuc.NoiDung;
                            model.TacGia    = tintuc.TacGia;
                            model.HinhAnh   = fileUpload.FileName;
                            model.NgayTao   = tintuc.NgayTao;
                            model.IsDeleted = tintuc.IsDeleted;
                            db.SaveChanges();
                        }
                    }
                    else// nếu k thực thiện thay đỏi ảnh đại diện thì vào đây
                    {
                        model.MaTinTuc  = tintuc.MaTinTuc;
                        model.TenTinTuc = tintuc.TenTinTuc;
                        model.NoiDung   = tintuc.NoiDung;
                        model.TacGia    = tintuc.TacGia;
                        model.NgayTao   = tintuc.NgayTao;
                        model.IsDeleted = tintuc.IsDeleted;
                        db.SaveChanges();
                    }
                }
                else
                {
                    TIN_TUC model2 = new TIN_TUC();
                    if (Session["fileUpload"] != null)
                    {
                        fileUpload = (HttpPostedFileBase)Session["fileUpload"];
                        if (fileUpload != null && fileUpload.ContentLength > 0)
                        {
                            string path = Path.Combine(Server.MapPath("~/Images/ImagesNews"), fileUpload.FileName);
                            fileUpload.SaveAs(path);
                            model2.MaTinTuc  = tintuc.MaTinTuc;
                            model2.TenTinTuc = tintuc.TenTinTuc;
                            model2.NoiDung   = tintuc.NoiDung;
                            model2.TacGia    = tintuc.TacGia;
                            model2.HinhAnh   = fileUpload.FileName;
                            model2.NgayTao   = DateTime.Now;
                            model2.IsDeleted = false;
                            db.TIN_TUC.Add(model2);
                            db.SaveChanges();
                        }
                    }
                }
                Session["fileUpload"] = null;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Example #3
0
 public void UpdateTinTuc(TIN_TUC tintuc)
 {
     _tintucDao.UpdateTinTuc(tintuc);
 }
Example #4
0
 public void InsertTinTuc(TIN_TUC tintuc)
 {
     _dataContext.TIN_TUCs.InsertOnSubmit(tintuc);
     _dataContext.SubmitChanges();
 }
Example #5
0
 public void InsertTinTuc(TIN_TUC tintuc)
 {
     _tintucDao.InsertTinTuc(tintuc);
 }