public ActionResult LayTinTuc(int matin)
        {
            if (Session["MaTKAdmin"] == null)
            {
                return(RedirectToAction("Login", "Admin"));
            }
            else
            {
                try
                {
                    ShopEntities           shop = new ShopEntities();
                    JsonSerializerSettings jss  = new JsonSerializerSettings {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    };

                    TinTuc tt     = shop.TinTucs.Single(t => t.MaTinTuc == matin);
                    var    result = JsonConvert.SerializeObject(tt, Formatting.Indented, jss);
                    return(this.Json(result, JsonRequestBehavior.AllowGet));;
                }
                catch (Exception)
                {
                    return(RedirectToAction("Index"));
                }
            }
        }
Exemple #2
0
        public async Task <IActionResult> Create(TinTucCreateViewModel model)
        {
            ViewBag.ListNgonNgu = ListNgonNgu;
            ViewBag.ListLoaiTin = ListLoaiTin;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var dbItem = new TinTuc();

            dbItem.FkNgonNgu      = model.TenLoaiId;
            dbItem.FkLoaiTin      = model.NgonNguId;
            dbItem.TieuDe         = model.TieuDe;
            dbItem.GioiThieu      = model.GioiThieu;
            dbItem.NoiDung        = model.NoiDung;
            dbItem.HinhAnhMinhHoa = model.HinhAnh;
            dbItem.Author         = model.TacGia;

            dbItem.NgayTao        = DateTime.Now;
            dbItem.FkUserNguoiTao = "admin";
            dbItem.NgaySua        = dbItem.NgayTao;
            dbItem.FkUserNguoiSua = "admin";

            InitParam.Db.TinTuc.Add(dbItem);
            await InitParam.Db.SaveChangesAsync();

            return(RedirectToAction(nameof(Edit), new { id = dbItem.Id }));
        }
Exemple #3
0
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (txtTitle.Text == "")
     {
         showMessage("Tiêu đề không để trống");
     }
     else
     {
         TinTuc t = new TinTuc();
         t.id     = dbc.TinTucs.OrderByDescending(p => p.id).First().id + 1;
         t.title  = txtTitle.Text;
         t.tomTat = txtTomTat.Text;
         if (imgUp.HasFile)
         {
             string filename = "Tin/images/" + t.id + imgUp.FileName;
             string filePath = MapPath(filename);
             imgUp.SaveAs(filePath);
             t.cover = filename;
         }
         t.noiDung = Request["area2"];
         int  userid = (int)Session["userid"];
         User us     = dbc.Users.Where(u => u.id == userid).FirstOrDefault();
         t.id_User   = us.id;
         t.ngayDang  = DateTime.Now;
         t.luotXem   = 0;
         t.doUuTien  = 0;
         t.idLoai    = int.Parse(cbLoai.SelectedValue);
         t.idGiaiDau = int.Parse(cbDanhMuc.SelectedValue);
         dbc.TinTuc_Insert(t.id, t.title, t.tomTat, t.cover, t.noiDung, t.id_User, t.ngayDang, t.idLoai, t.idGiaiDau, 0);
         showMessage("Đăng bài thành công!");
         Response.Redirect("danhsachbaidang.aspx");
     }
 }
Exemple #4
0
 public ActionResult Edit(TinTuc collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             // TODO: Add insert logic here
             var dao    = new TinTucDao();
             var result = dao.Update(collection);
             if (result)
             {
                 SetAlert("Sửa thành công", "success");
                 return(RedirectToAction("Index", "TinTuc"));
             }
             else
             {
                 ModelState.AddModelError("", "Cập nhật không thành công");
             }
         }
         return(View(collection));
     }
     catch
     {
         return(View("Index"));
     }
 }
Exemple #5
0
        public List <TinTuc> TinTuc_GetByTop(string Top, string Where, string Order)
        {
            List <TinTuc> list = new List <TinTuc>();

            using (SqlCommand dbCmd = new SqlCommand("sp_TinTuc_getByTop", openConnection()))
            {
                TinTuc obj = new TinTuc();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                dr.Close();
                dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.TinTucIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return(list);
        }
 public async Task <IActionResult> Edit(int id, [Bind("MaTt,NoiDung,NgayTao,MaNv,LoaiTt,TrangThai,TieuDe")] TinTuc tinTuc)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(tinTuc);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!TinTucExists(tinTuc.MaTt))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["LoaiTt"] = new SelectList(_context.LoaiTinTuc, "LoaiTt", "LoaiTt", tinTuc.LoaiTt);
     ViewData["MaNv"]   = new SelectList(_context.NhanVien, "MaNv", "Email", tinTuc.MaNv);
     return(View(tinTuc));
 }
Exemple #7
0
        public ActionResult SaveNew(TinTuc model)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();

            try
            {
                if (model.NewCategoryID == 0)
                {
                    if (!ModelState.IsValid)
                    {
                        string fail = "Có lỗi xảy ra. Vui lòng kiểm tra lại!";

                        return(Json(new { status = false, failReason = js.Serialize(fail) }));
                    }
                    model.NgayTao = DateTime.Now;
                    newRepository.SaveNew(model);
                    string addSuccess = "Thêm mới Tin Tức thành công!";
                    return(Json(new { status = true, success = js.Serialize(addSuccess) }));
                }
                if (!ModelState.IsValid)
                {
                    string fail = "Có lỗi xảy ra. Vui lòng kiểm tra lại!";
                    return(Json(new { status = false, failReason = js.Serialize(fail) }));
                }
                newRepository.SaveNew(model);
                string updateSuccess = "Cập nhật  Tin Tức thành công!";
                return(Json(new { status = true, success = js.Serialize(updateSuccess) }));
            }
            catch (Exception ex)
            {
                string fail = ex.Message;
                return(Json(new { status = false, failReason = js.Serialize(fail) }));
            }
        }
        public ActionResult Create(TinTucViewModel viewModel, HttpPostedFileBase chonHinh)
        {
            if (chonHinh != null)
            {
                string fileName   = Path.GetFileNameWithoutExtension(chonHinh.FileName);
                string extensions = Path.GetExtension(chonHinh.FileName);
                fileName       = fileName + DateTime.Now.ToString("yymmssfff") + extensions;
                viewModel.Hinh = "~/Content/images/" + fileName;
                chonHinh.SaveAs(Path.Combine(Server.MapPath("~/Content/images/"), fileName));
            }
            TinTuc tintuc = new TinTuc
            {
                TieuDe       = viewModel.TieuDe,
                NoiDung      = viewModel.NoiDung,
                ThoiGianDang = viewModel.ThoiGianDang,
                Hinh         = viewModel.Hinh,
                LoaiTinTucId = viewModel.LoaiTinTuc,
                NhanVienId   = User.Identity.GetUserId(),
                TrangThai    = true
            };

            _dbContext.TinTucs.Add(tintuc);
            _dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult SuaTintuc(TinTuc tintuc, HttpPostedFileBase fileUpload)
        {
            //Dua du lieu vao dropdownload

            //Kiem tra duong dan file
            if (fileUpload == null)
            {
                ViewBag.Thongbao = "Vui lòng chọn ảnh bìa";
                return(View());
            }
            //Them vao CSDL
            else
            {
                if (ModelState.IsValid)
                {
                    var fileName = Path.GetFileName(fileUpload.FileName);
                    //Luu duong dan cua file
                    var path = Path.Combine(Server.MapPath("~/img/slider/slider-2/"), fileName);

                    fileUpload.SaveAs(path);

                    TinTuc tt = db.TinTucs.SingleOrDefault(n => n.MaTin == tintuc.MaTin);
                    tt.TieuDe      = tintuc.TieuDe;
                    tt.TomTat      = tintuc.TomTat;
                    tt.Anhtintuc   = fileName;
                    tt.NoiDung     = tintuc.NoiDung;
                    tt.NgayCapNhat = tintuc.NgayCapNhat;


                    UpdateModel(tintuc);
                    db.SubmitChanges();
                }
                return(RedirectToAction("Laptop"));
            }
        }
Exemple #10
0
        public ActionResult XoaBinhLuan_ajax(string matin, string macha)
        {
            try
            {
                int      iLuotComment = 1;
                int      iMaTin       = int.Parse(matin);
                int      iMaCha       = int.Parse(macha);
                BinhLuan xoaBL        = db.BinhLuans.SingleOrDefault(n => n.Id == iMaCha);

                IEnumerable <BinhLuan> lstxoaBL = db.BinhLuans.Where(n => n.MaBinhLuanCha == iMaCha);

                if (lstxoaBL.Count() > 0)
                {
                    iLuotComment += lstxoaBL.Count();
                    db.BinhLuans.RemoveRange(lstxoaBL);
                }

                TinTuc tin = db.TinTucs.SingleOrDefault(n => n.MaTinTuc == iMaTin);
                tin.LuotBinhLuan -= iLuotComment;

                db.BinhLuans.Remove(xoaBL);
                db.SaveChanges();
            }
            catch
            {
                return(Content("0"));
            }
            return(Content("1"));
        }
Exemple #11
0
        public ActionResult Index()
        {
            TinTuc tintuc = db.TinTucs.Find(db.TinTucs.ToList()[db.TinTucs.ToList().Count - 1].MaTinTuc);

            ViewBag.listTT = db.TinTucs.ToList();
            return(View(tintuc));
        }
Exemple #12
0
        public ActionResult Detail(int id)
        {
            TinTuc tintuc = db.TinTucs.Find(id);

            ViewBag.listTT = db.TinTucs.ToList();
            return(View(tintuc));
        }
Exemple #13
0
        public string SuaTinTuc(TinTuc t)
        {
            string st = "Update TinTuc SET TieuDe=N'" + t.TieuDe + "', HinhAnh='" + t.HinhAnh + "', NoiDung=N'" +
                        t.NoiDung + "',NgayDang='" + t.NgayDang + "', TrangThai='" + t.TrangThai + "' where ID='" + t.ID + "'";

            return(dc.ExcuteNonQuery(st));
        }
Exemple #14
0
        public string ThemTinTuc(TinTuc t)
        {
            string sql = "INSERT into TinTuc values(N'" + t.TieuDe + "','" + t.HinhAnh + "',N'" +
                         t.NoiDung + "','" + t.NgayDang + "','" + t.TrangThai + "')";

            return(dc.ExcuteNonQuery(sql));
        }
        public async Task <IActionResult> PutTinTuc(int id, TinTuc tinTuc)
        {
            if (id != tinTuc.Id)
            {
                return(BadRequest());
            }

            _context.Entry(tinTuc).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TinTucExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public JsonResult Add_Edit()
        {
            var inputCount = Request.Form.Count;
            var rID        = Request.Form["id"];
            var tt         = new TinTuc();

            if (rID != "-1")
            {
                var rId = int.Parse(rID);
                tt = db.TinTucs.Single(z => z.ID == rId);
            }
            tt.TieuDe    = Request.Form["tieude"];
            tt.TomTat    = Request.Form["tomtat"];
            tt.TrangThai = Request.Form["trangthai"] == "true" ? true : false;
            var noidungRaw = Request.Form["noidung"];
            var noidung    = HttpUtility.UrlDecode(noidungRaw);

            tt.NoiDung   = noidung;
            tt.MetaTitle = MetaTitle(tt.TieuDe);
            try
            {
                if (rID == "-1")
                {
                    db.TinTucs.Add(tt);
                }
                db.SaveChanges();
                return(Json(new { data = true }));
            }
            catch
            {
                return(Json(new { data = false }));
            }
        }
Exemple #17
0
        public bool Update(TinTuc entity)
        {
            try
            {
                var dao = db.TinTucs.Find(entity.TinTucID);
                dao.TinTucID        = entity.TinTucID;
                dao.DanhMucTinTucID = entity.DanhMucTinTucID;
                dao.TieuDe          = entity.TieuDe;
                dao.TieuDeSeo       = entity.TieuDeSeo;
                dao.NoiDung         = entity.NoiDung;
                dao.NgayTao         = DateTime.Now;
                dao.Ten             = entity.Ten;

                //if (!string.IsNullOrEmpty())
                //{
                //}
                dao.NguoiTao = entity.NguoiTao;

                dao.Video     = entity.Video;
                dao.TrangThai = entity.TrangThai;
                dao.Tag       = entity.Tag;
                dao.MoTa      = entity.MoTa;
                dao.HinhAnh   = entity.HinhAnh;


                db.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #18
0
        public ActionResult AddNews(TinTuc tin, HttpPostedFileBase file)
        {
            if (String.IsNullOrEmpty(tin.TieuDe))
            {
                @ViewData["tieude"] = "Không được trống!";
            }
            if (String.IsNullOrEmpty(tin.NoiDung))
            {
                @ViewData["noidung"] = "Không được trống!";
            }
            if (file == null)
            {
                @ViewData["anh"] = "Chưa chọn ảnh!";
            }

            if (String.IsNullOrEmpty(tin.NoiDung) || String.IsNullOrEmpty(tin.TieuDe) || file == null)
            {
                return(this.AddNews());
            }
            else
            {
                var fileName = System.IO.Path.GetFileName(file.FileName);
                var path     = Server.MapPath("~/Images/" + fileName);
                file.SaveAs(path);
                tin.LinkAnh = "Images/" + fileName;
                db.TinTucs.InsertOnSubmit(tin);
                db.SubmitChanges();
                return(RedirectToAction("Quanlytin"));
            }
        }
        public ActionResult Edit(TinTuc entity, HttpPostedFileBase HinhAnh)
        {
            // Lưu vào csdl
            var item = db.TinTucs.Find(entity.ID);

            if (item != null)
            {
                item.TieuDe = entity.TieuDe;

                if (HinhAnh != null)
                {
                    var fileName = Path.GetFileName(HinhAnh.FileName);
                    var path     = Path.Combine(Server.MapPath("/Images"), fileName);
                    HinhAnh.SaveAs(path);

                    item.HinhAnh = HinhAnh.FileName;
                }
                item.TomTat  = entity.TomTat;
                item.NoiDung = entity.NoiDung;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            return(View());
        }
Exemple #20
0
        public ActionResult ChiTietTin(int id)
        {
            if (KiemTraSession() == true)
            {
                return(RedirectToAction("DangNhap", "QuanTri"));
            }

            Tools    tool   = new Tools();
            DateTime dtNow  = DateTime.Now;
            TinTuc   layTin = db.TinTucs.SingleOrDefault(n => n.MaTinTuc == id);

            ViewBag.LoaiVanBans     = db.LoaiTaiLieux.OrderBy(n => n.ThuTu);
            ViewBag.LoaiCongTruongs = db.LoaiCongTruongs.OrderBy(n => n.ThuTu);
            ViewBag.VanBans         = db.TaiLieux;
            ViewBag.DMTinTuc        = db.DanhMucs.Where(n => n.DanhMucCha == Tools.MaDanhMucTin).OrderBy(n => n.ThuTu);
            //ViewBag.LoaiVanBan = new SelectList(db.LoaiTaiLieux.OrderBy(n => n.CapTaiLieu), "MaLoaiTL", "TenLoaiTL", LoaiVanBan);
            ViewBag.dsTinTuc = db.TinTucs.Where(n => n.TrangThai == true && n.NgayDang <= dtNow).OrderByDescending(n => n.NgayDang);

            ViewBag.lstBanner   = db.Banners.OrderBy(n => n.Order);
            ViewBag.lstBinhLuan = db.BinhLuans.Where(n => n.MaTin == id);
            ViewBag.lstDanhGia  = db.DanhGias;

            if (layTin.TrangThai == true)
            {
                return(View(layTin));
            }
            else
            {
                return(RedirectToAction("Index", "TrangChinh"));
            }
        }
Exemple #21
0
        public bool TinTuc_Update(TinTuc data)
        {
            bool check = false;

            try
            {
                using (SqlCommand dbCmd = new SqlCommand("sp_TinTuc_Update", openConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@ID", data.ID));
                    dbCmd.Parameters.Add(new SqlParameter("@TieuDe", data.TieuDe));
                    dbCmd.Parameters.Add(new SqlParameter("@Mota", data.MoTa));
                    dbCmd.Parameters.Add(new SqlParameter("@NoiDung", data.NoiDung));
                    dbCmd.Parameters.Add(new SqlParameter("@AnhDaiDien", data.AnhDaiDien));
                    int r = dbCmd.ExecuteNonQuery();
                    if (r > 0)
                    {
                        check = true;
                    }
                }
                //Clear cache
                System.Web.HttpContext.Current.Cache.Remove("TinTuc");
            }
            catch
            {
            }
            return(check);
        }
        //protected void Save_Click(object sender, EventArgs e)
        //{
        //    string tenLoai = dropDownListLoaiTin.SelectedValue.ToString();
        //    int idLoai = GetIDLoaiTinFollowTenLoai(tenLoai);
        //    WebPortal.Model.TinTuc news = new Model.TinTuc();
        //    if (Libs.LibSession.Get(Libs.Constants.ACCOUNT_LOGIN) != null)
        //    {
        //        string nguoiDang = Libs.LibSession.Get(Libs.Constants.ACCOUNT_LOGIN).ToString();
        //        DateTime date = DateTime.Now;
        //        news.IDLoaiTin = idLoai;
        //        news.MoTaTinTuc = summary.Text;
        //        news.NgayDang = date;
        //        news.NguoiDang = nguoiDang;
        //        news.NoiDung = Request.Form["elm1"].ToString();
        //        news.TenTinTuc = titleNews.Text;
        //        news.HinhAnh = PathLabel.Text;
        //        WebPortal.TinTuc tintuc = new TinTuc();
        //        try
        //        {
        //            int idNews = tintuc.Add(news);
        //            SaveStatus.Text = "Lưu tin tức mới thành công!";
        //            IDTinTuc.Text = idNews.ToString();
        //            titleNews.Text = "";
        //            summary.Text = "";
        //            StatusLabel.Text = "";
        //        }
        //        catch (Exception ex)
        //        {
        //            SaveStatus.Text = "Quá trình lưu xảy ra lỗi! Vui lòng thử lại.";
        //        }
        //    }
        //    else
        //    {
        //        Response.Redirect("AdminLogin.aspx");
        //    }
        //}
        public bool SaveNews(ref int id)
        {
            string tenLoai = dropDownListLoaiTin.SelectedValue.ToString();
            int idLoai = GetIDLoaiTinFollowTenLoai(tenLoai);
            WebPortal.Model.TinTuc news = new Model.TinTuc();
            if (Libs.LibSession.Get(Libs.Constants.ACCOUNT_LOGIN) != null)
            {
                string nguoiDang = Libs.LibSession.Get(Libs.Constants.ACCOUNT_LOGIN).ToString();
                DateTime date = DateTime.Now;

                news.IDLoaiTin = idLoai;
                news.MoTaTinTuc = summary.Text;
                news.NgayDang = date;
                news.NguoiDang = nguoiDang;
                news.NoiDung = Request.Form["elm1"].ToString();
                news.TenTinTuc = titleNews.Text;
                news.HinhAnh = PathLabel.Text;
                WebPortal.TinTuc tintuc = new TinTuc();
                try
                {
                    id = tintuc.Add(news);
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
            else
            {
                Response.Redirect("AdminLogin.aspx");
                return false;
            }
        }
Exemple #23
0
        public ActionResult Upload(HttpPostedFileBase file, TinTuc obj)
        {
            try
            {
                if (file.ContentLength > 0)
                {
                    string fileName = Path.GetFileNameWithoutExtension(file.FileName);
                    fileName += "_" + obj.matt;
                    fileName += Path.GetExtension(file.FileName);
                    string folderPath = Server.MapPath("~") + @"\AnhTinTuc\anhtintuc";
                    if (!Directory.Exists(folderPath))
                    {
                        Directory.CreateDirectory(folderPath);
                    }
                    string path = Path.Combine(folderPath, fileName);

                    file.SaveAs(path);
                    var dao = new TinTucDao();
                    dao.Upload(obj.matt, fileName);
                }
                return(RedirectToAction("Index"));
            }
            catch (System.Exception ex)
            {
                return(View(obj));
            }
        }
Exemple #24
0
        public ActionResult ThemTT(TinTuc tt, HttpPostedFileBase fileUpload)
        {
            var fileName = Path.GetFileName(fileUpload.FileName);
            var path     = Path.Combine(Server.MapPath("~/image/TinTuc"), fileName);

            if (System.IO.File.Exists(path))
            {
                ViewBag.ThongBao = "Hình ảnh đã tồn tại...";
            }
            else
            {
                if (ModelState.IsValid)
                {
                    TinTuc tt1 = new TinTuc();
                    fileUpload.SaveAs(path);
                    tt1.TenTT  = tt.TenTT;
                    tt1.TenTT  = tt.TenTT;
                    tt1.AnhBia = fileName;
                    tt1.MoTa   = tt.MoTa;
                    cn.TinTucs.Add(tt1);
                    cn.SaveChanges();
                    SetAlert("Thêm thành công!", "success");
                }
            }
            return(RedirectToAction("TinTuc", "QuanLyTinTuc"));
        }
Exemple #25
0
 public ActionResult Sua(TinTuc tt)
 {
     SetViewBag1();
     SetViewBag();
     if (ModelState.IsValid)
     {
         var dao    = new TinTucDAO();
         var result = dao.Sua(tt);
         if (result)
         {
             logger.Info("Cập nhật tin tức " + tt.Id + " thành công!");
             SetAlert("Sửa tin tức thành công!", "success");
             if (Session["returnUrl"] == null)
             {
                 return(RedirectToAction("Them"));
             }
             else
             {
                 return(Redirect(Session["returnUrl"].ToString()));
             }
         }
         else
         {
             logger.Info("Cập nhật tin tức không thành công!");
             SetAlert("Sửa không thành công!", "error");
             ModelState.AddModelError("", "Sửa không thành công!");
         }
     }
     return(View());
 }
Exemple #26
0
    private void LoadTinTuc(int tintucid)
    {
        try
        {
            TinTuc tt = new TinTuc();
            DataSet ds = tt.SelectByID(tintucid);

            if (ds.Tables[0].Rows.Count > 0)
            {
                lblTieuDe.Text = ds.Tables[0].Rows[0]["tieude"].ToString();
                if (ds.Tables[0].Rows[0]["anh"] != null)
                {
                    spnImage.InnerHtml = "<br><br><img width=\"200px\" src=\"" + ds.Tables[0].Rows[0]["anh"]
                                         + "\" border=\"0\" /><br>";
                }

                spnTinTuc.InnerHtml = "<br>" +
                                      "<div>" + ds.Tables[0].Rows[0]["NoiDung"] + "</div>";
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("../message.aspx?msg=" + ex.ToString().Replace("\r\n", " "));
        }
    }
Exemple #27
0
        public bool TinTuc_Update(TinTuc Data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("sp_TinTuc_Update", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@id", Data.Id));

                    dbCmd.Parameters.Add(new SqlParameter("@tieuDe", Data.TieuDe));
                    dbCmd.Parameters.Add(new SqlParameter("@tomtat", Data.Tomtat));
                    dbCmd.Parameters.Add(new SqlParameter("@noidung", Data.Noidung));
                    dbCmd.Parameters.Add(new SqlParameter("@ngayviet", Data.Ngayviet));
                    dbCmd.Parameters.Add(new SqlParameter("@id_nhanvien", Data.Id_nhanvien));
                    dbCmd.Parameters.Add(new SqlParameter("@urlHinhAnh", Data.UrlHinhAnh));
                    dbCmd.Parameters.Add(new SqlParameter("@Active", Data.Active));

                    dbCmd.ExecuteNonQuery();
                }
                //Clear cache
                System.Web.HttpContext.Current.Cache.Remove("TinTuc");
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #28
0
 public ActionResult Them(TinTuc tt)
 {
     SetViewBag1();
     SetViewBag();
     if (ModelState.IsValid)
     {
         var dao = new TinTucDAO();
         tt.LuotXem = 0;
         tt.NgayTao = DateTime.Now;
         tt.NgaySua = null;
         long id = dao.Them(tt);
         if (id > 0)
         {
             logger.Info("Thêm mới tin tức " + tt.Id + " thành công!");
             SetAlert("Thêm mới tin thành công!", "success");
             return(RedirectToAction("Them"));
         }
         else
         {
             logger.Info("Thêm mới tin tức không thành công!");
             SetAlert("Thêm mới không thành công!", "error");
         }
     }
     return(View());
 }
Exemple #29
0
        public IActionResult UpdateUser([FromBody] Dictionary <string, object> formData)
        {
            var model = new TinTuc();

            model.id     = int.Parse(formData["id"].ToString());
            model.tieude = formData["tieude"].ToString();
            model.idloai = int.Parse(formData["idloai"].ToString());
            model.mota   = formData["mota"].ToString();
            var hinhanh = formData["hinhanh"];

            model.noidung = formData["noidung"].ToString();

            if (hinhanh != null)
            {
                var arrData = hinhanh.ToString().Split(';');
                if (arrData.Length == 3)
                {
                    var savePath = $@"assets/images/{arrData[0]}";
                    model.hinhanh = $"{savePath}";
                    SaveFileFromBase64String(savePath, arrData[2]);
                }
            }
            else
            {
                var tintuc = _itemBusiness.GetDatabyID("" + model.id);
                model.hinhanh = tintuc.hinhanh;
            }
            var kq = _itemBusiness.Update(model);

            return(Ok(kq));
        }
        public JsonResult Delete(int id)
        {
            TinTuc obj = db.TinTucs.Find(id);

            obj.Active = false;
            return(Json(db.SaveChanges()));
        }
Exemple #31
0
        public void Delete(TinTuc New)
        {
            try
            {
                var delete = context.TinTucs.FirstOrDefault(x => x.NewID == New.NewID);
                if (delete != null)
                {
                    context.TinTucs.Remove(delete);
                }
                context.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                var sqlex = ex.InnerException.InnerException as SqlException;

                if (sqlex != null)
                {
                    switch (sqlex.Number)
                    {
                    case 547: throw new Exception("Xóa Thất Bại - Danh Mục Đang Được Sử Dụng Ở Chức Năng Khác !");     //FK exception

                    case 2627:
                    case 2601:
                        throw new Exception("Lỗi Khóa Chính"); //primary key exception

                    default: throw sqlex;                      //otra excepcion que no controlo.
                    }
                }
                throw ex;
            }
        }
Exemple #32
0
        public void SaveNew(TinTuc New)
        {
            var saveNew = GetNewById(New.NewID);

            try {
                if (saveNew == null)
                {
                    New.TrangThai = true;
                    New.NgayTao   = DateTime.Now;
                    context.TinTucs.Add(New);
                }
                else
                {
                    saveNew.LuotXem       = New.LuotXem;
                    saveNew.Ten           = New.Ten;
                    saveNew.NoiDungTinTuc = New.NoiDungTinTuc;
                    saveNew.NewCategoryID = New.NewCategoryID;
                    saveNew.ThuTuHienThi  = New.ThuTuHienThi;
                    saveNew.HinhAnh       = New.HinhAnh;
                    saveNew.TrangThai     = New.TrangThai;
                    saveNew.NoiDungTinTuc = New.NoiDungTinTuc;
                    saveNew.NgayChinhSua  = DateTime.Now;
                }
                context.SaveChanges();
            }
            catch (Exception es)
            {
                throw new Exception(es.Message);
            }
        }
Exemple #33
0
    private void LoadTinTucForAll()
    {
        TinTuc tt = new TinTuc();
        DataSet ds = tt.SelectAdminNews();
        lblTieuDe.Text = "Các tin mới nhất.";

        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            spnTinTuc.InnerHtml += "<br><a href=\"news.aspx?nid="
                                   + dr["TinTucID"]
                                   + "\" ><b>" + dr["tieude"]
                                   + "</b><br><img border=\"0\"width=\"48\" src=\""
                                   + dr["anh"] + "\" /></a>&nbsp;&nbsp;"
                                   + dr["tomtat"] + "<br><a href=\"news.aspx?nid="
                                   + dr["TinTucID"]
                                   + "\" >Xem tiếp</a><br><hr>";
        }
    }
Exemple #34
0
    private void LoadData()
    {
        TinTuc tt = new TinTuc();
        DataSet ds;

        if (Cache["tintuc"] == null)
        {
            ds = tt.SelectTinTucByNguoiDungID(Common.NguoiDungID());
            Cache["tintuc"] = ds;
        }
        else
        {
            ds = (DataSet) Cache["tintuc"];
        }

        grdTinTuc.DataSource = ds.Tables[0];
        grdTinTuc.DataBind();
    }
Exemple #35
0
    private void LoadTinTucMoiVaCu()
    {
        TinTuc tt = new TinTuc();
        DataSet ds = tt.SelectByNguoiDungIDPaging(ChuCuaHangID, 1, 10);

        string content = "<ul class=\"list-news\">";
        string content1 = "<ul class=\"list-news\">";
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++ )
        {
            DataRow dr = ds.Tables[0].Rows[i];
            if (i < 5)
            {
                content += "<li><a href=\"EstoreNews.aspx?sid=" + CuaHangID + "&nid=" + dr["TinTucID"].ToString() + "\">"
                    + dr["TieuDe"].ToString() + "</a></li>";
            }
            else
            {
                content1 += "<li><a href=\"EstoreNews.aspx?sid=" + CuaHangID + "&nid=" + dr["TinTucID"].ToString() + "\">"
                   + dr["TieuDe"].ToString() + "</a></li>";
            }
        }
        content += "</ul>";
        content1 += "</ul>";
        spnTinTucMoi.InnerHtml = content;
        spnTinTucCu.InnerHtml = content1;
    }
Exemple #36
0
    private void LoadTinTuc()
    {
        TinTuc tt = new TinTuc();
        int currentrow;
        int totalrows;
        if ((ViewState["currentrow"] != null) && (ViewState["totalrow"] != null))
        {
            currentrow = int.Parse(ViewState["currentrow"].ToString());
            totalrows = int.Parse(ViewState["totalrow"].ToString());
        }
        else
        {
            currentrow = 1;
            totalrows = 1;
        }

        if (HidTinTuc.Value == "down")
        {
            if (currentrow != totalrows)
            {
                currentrow += 1;
            }
            else
            {
                currentrow = 1;
            }
        }
        else if (HidTinTuc.Value == "up")
        {
            if (currentrow != 1)
            {
                currentrow -= 1;
            }
            else
            {
                currentrow = totalrows;
            }
        }

        DataSet ds = tt.GetTinTucByThuTu(currentrow);
        ViewState["totalrow"] = ds.Tables[1].Rows[0][0].ToString();
        ViewState["currentrow"] = currentrow;

        if (ds.Tables[0].Rows.Count > 0)
        {
            lblTieuDe.Text = ds.Tables[0].Rows[0]["TieuDe"].ToString();
            divTinTuc.InnerText = ds.Tables[0].Rows[0]["TomTat"].ToString();
        }
    }
    private void LoadTinTucMoi()
    {
        TinTuc tt = new TinTuc();
        DataSet ds = tt.SelectByNguoiDungIDPaging(ChuCuaHangID, 1, 5);

        string content = "<ul class=\"list-news\">";
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            content += "<li><a href=\"EstoreNews.aspx?sid=" + CuaHangID + "&nid=" + dr["TinTucID"].ToString() + "\">"
                + dr["TieuDe"].ToString() + "</a></li>";
        }
        content += "</ul>";
        spnTinTuc.InnerHtml = content;
    }
 //protected void Save_Click(object sender, EventArgs e)
 //{
 //    string tenLoai = dropDownListLoaiTin.SelectedValue.ToString();
 //    int idLoai = GetIDLoaiTinFollowTenLoai(tenLoai);
 //    string nguoiDang = "admin";
 //    DateTime date = DateTime.Now;
 //    WebPortal.Model.TinTuc news = new Model.TinTuc();
 //    news.IDLoaiTin = idLoai;
 //    news.MoTaTinTuc = summary.Text;
 //    news.NgayDang = date;
 //    news.NguoiDang = nguoiDang;
 //    news.NoiDung = Request.Form["elm1"].ToString();
 //    news.TenTinTuc = titleNews.Text;
 //    news.HinhAnh = PathLabel.Text;
 //    news.IDTinTuc=Convert.ToInt32(Request.QueryString["id"]);
 //    WebPortal.TinTuc tintuc = new TinTuc();
 //    try
 //    {
 //        tintuc.Update(news);
 //        SaveNews.Text = "Lưu thay đổi thành công!";
 //        IDTinTuc.Text = Request.QueryString["id"];
 //        IDTinTuc.Text = news.IDTinTuc.ToString();
 //        StatusLabel.Text = "";
 //    }
 //    catch (Exception ex)
 //    {
 //        SaveNews.Text = "Quá trình lưu xảy ra lỗi: " + ex.Message;
 //        SaveNews.Text = "";
 //    }
 //}
 public bool UpdateNews()
 {
     string tenLoai = dropDownListLoaiTin.SelectedValue.ToString();
     int idLoai = GetIDLoaiTinFollowTenLoai(tenLoai);
     string nguoiDang = "admin";
     DateTime date = DateTime.Now;
     WebPortal.Model.TinTuc news = new Model.TinTuc();
     news.IDLoaiTin = idLoai;
     news.MoTaTinTuc = summary.Text;
     news.NgayDang = date;
     news.NguoiDang = nguoiDang;
     news.NoiDung = Request.Form["elm1"].ToString();
     news.TenTinTuc = titleNews.Text;
     news.HinhAnh = PathLabel.Text;
     news.IDTinTuc = Convert.ToInt32(Request.QueryString["id"]);
     WebPortal.TinTuc tintuc = new TinTuc();
     try
     {
         tintuc.Update(news);
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
 public WebPortal.Model.TinTuc GetNews(int id)
 {
     WebPortal.TinTuc tinTuc = new TinTuc();
     return tinTuc.Single(id);
 }
 public List<WebPortal.Model.TinTuc> GetAllNews()
 {
     WebPortal.TinTuc tinTuc = new TinTuc();
     return tinTuc.All();
 }
Exemple #41
0
    protected void btnXoa_Click(object sender, EventArgs e)
    {
        try
        {
            switch (ViewState["TYPE"].ToString())
            {
                case "thuoctinh":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        ThuocTinh tt = new ThuocTinh();
                        tt.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "nhomsanpham":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        NhomSanPham nhomsanpham = new NhomSanPham();
                        nhomsanpham.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "vitrisanpham":
                    if ((Common.LoaiNguoiDungID() == 3) || (Common.LoaiNguoiDungID() == 2))
                    {
                        ViTriSanPham vtsp = new ViTriSanPham();
                        vtsp.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "cuahangnhomsanpham":
                    if (Common.LoaiNguoiDungID() == 2)
                    {
                        deleteCuaHangNhomSanPham(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "nhomsanphamcuahang":
                    if (Common.LoaiNguoiDungID() == 2)
                    {
                        deleteNhomSanPhamCuaHang(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;

                case "nhanxetsanpham":
                    if (Common.LoaiNguoiDungID() != 1)
                    {
                        NhanXetSanPham nhanxet = new NhanXetSanPham();
                        nhanxet.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "tintuc":
                    if ((Common.LoaiNguoiDungID() == 3) || (Common.LoaiNguoiDungID() == 2))
                    {
                        TinTuc tt = new TinTuc();
                        tt.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "hotrotructuyen":
                    if ((Common.LoaiNguoiDungID() == 3) || (Common.LoaiNguoiDungID() == 2))
                    {
                        HoTroTrucTuyen ht = new HoTroTrucTuyen();
                        ht.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "hoidapsanpham":
                    if (Common.LoaiNguoiDungID() != 1)
                    {
                        HoiDapSanPham hoidap = new HoiDapSanPham();
                        hoidap.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "nguoidung":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        if (CheckExistCuaHang(id) != true)
                        {
                            NguoiDung nguoidung = new NguoiDung();
                            nguoidung.Delete(id);
                        }
                        else
                        {
                            Response.Redirect("../message.aspx?msg=Không thể xóa người dùng đã có cửa hàng", false);
                        }
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "hangsanxuat":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        HangSanXuat hsx = new HangSanXuat();
                        hsx.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "khuvuc":
                    if (Common.LoaiNguoiDungID() == 3)
                    {
                        KhuVuc kv = new KhuVuc();
                        kv.Delete(id);
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "quangcao":
                    if (Common.LoaiNguoiDungID() == 2 || Common.LoaiNguoiDungID() == 3)
                    {
                        QuangCao qcao = new QuangCao();
                        DataSet ds = qcao.SelectByQuangCaoID(id);
                        if (ds.Tables[0].Rows.Count == 1)
                        {
                            if (Common.LoaiNguoiDungID() == 3)
                            {
                                //Administrator
                                if (ds.Tables[0].Rows[0]["LoaiNguoiDungID"].ToString() == "3") qcao.Delete(id);
                            }
                            else
                            {
                                //e-Store
                                if (ds.Tables[0].Rows[0]["LoaiNguoiDungID"].ToString() == "2"
                                    && ds.Tables[0].Rows[0]["NguoiDungID"].ToString() == Common.NguoiDungID().ToString())
                                    qcao.Delete(id);
                            }
                        }
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
                case "sanpham":
                    {
                        SanPham sanpham = new SanPham();
                        DataSet dssp = sanpham.SelectBySanPhamID(id);
                        if (Common.LoaiNguoiDungID() == 2)
                        {
                            if (dssp.Tables[0].Rows.Count == 1)
                            {
                                //e-Store
                                if (dssp.Tables[0].Rows[0]["LoaiNguoiDungID"].ToString() ==
                                    Common.LoaiNguoiDungID().ToString()
                                    &&
                                    dssp.Tables[0].Rows[0]["NguoiDungID"].ToString() == Common.NguoiDungID().ToString())
                                {
                                    sanpham.Delete(id);
                                }
                            }
                        }
                        else if (Common.LoaiNguoiDungID() == 3)
                        {
                            if (dssp.Tables[0].Rows.Count == 1)
                            {
                                sanpham.Delete(id);
                            }
                        }
                        else
                        {
                            Response.Redirect("../message.aspx?msg=Access denied");
                        }
                    }
                    break;
                case "sanphammau":
                    {
                        SanPhamMau sanpham = new SanPhamMau();
                        DataSet dssp = sanpham.SelectByID(id);
                        if (Common.LoaiNguoiDungID() == 3)
                        {
                            if (dssp.Tables[0].Rows.Count == 1)
                            {
                                sanpham.Delete(id);
                            }
                        }
                        else
                        {
                            Response.Redirect("../message.aspx?msg=Access denied");
                        }
                    }
                    break;
                case "anhsanpham":
                    if ((Common.LoaiNguoiDungID() == 2) || (Common.LoaiNguoiDungID() == 3))
                    {
                        Anh anhsanpham = new Anh();
                        DataSet dssp = anhsanpham.SelectByID(id);
                        if (dssp.Tables[0].Rows.Count == 1)
                        {
                            anhsanpham.Delete(id);

                            if (File.Exists(Server.MapPath(Request.QueryString["src"])))
                            {
                                File.Delete(Server.MapPath(Request.QueryString["src"]));
                            }
                        }
                    }
                    else
                    {
                        Response.Redirect("../message.aspx?msg=Access denied");
                    }
                    break;
            }
            string strScript = "<script language='JavaScript'>" + "window.parent.Refresh();</script>";
            ClientScript.RegisterStartupScript(Type.GetType("System.String"), "Refresh", strScript);
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
    private void LoadDanhMucTinTuc()
    {
        TinTuc tt = new TinTuc();
        DataSet ds = tt.SelectByNguoiDungID(ChuCuaHangID);

        string content = "";
        //foreach (DataRow dr in ds.Tables[0].Rows)
        //{
        content += "<li><a href=\"#\">Tin cong ty</a></li>"
                        + "<li><a href=\"#\">Tin tuc lien quan</a></li>";
        //}
        spnDanhMucTinTuc.InnerHtml = content;
    }
Exemple #43
0
    private void LoadData(string Id)
    {
        try
        {
            TinTuc tt = new TinTuc();
            DataSet ds = tt.SelectByID(Convert.ToInt32(Id));

            if (ds.Tables[0].Rows.Count > 0)
            {
                txtTieuDe.Text = ds.Tables[0].Rows[0]["TieuDe"].ToString();
                txtTomTat.Text = ds.Tables[0].Rows[0]["TomTat"].ToString();
                wheNoiDung.Text = ds.Tables[0].Rows[0]["NoiDung"].ToString();
                imgAnhChinh.ImageUrl = "." + ds.Tables[0].Rows[0]["Anh"];
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
Exemple #44
0
    protected void btnLuu_Click(object sender, EventArgs e)
    {
        try
        {
            Cache.Remove("tintuc");
            TinTuc tt = new TinTuc();
            int LoaiTinTuc = rbtTroGiup.Checked ? 1 : 0;
            string relativePath = null;
            string path = Server.MapPath("../Upload/NewsImages");
            if (fileAnhChinh.PostedFile.FileName != "")
            {
                if ((fileAnhChinh.PostedFile.ContentLength <= 100000) || (Common.LoaiNguoiDungID() == 3))
                {
                    string randomString = "";
                    path += "\\" + Common.NguoiDungID();
                    relativePath = "./Upload/NewsImages" + "/" + Common.NguoiDungID() + "/";
                    int pos = fileAnhChinh.PostedFile.FileName.LastIndexOf('\\');
                    string absolutePath = path + "\\" + fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1);

                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    if (File.Exists(absolutePath))
                    {
                        randomString = DateTime.Now.Ticks + "_";
                        absolutePath = path + "\\" + randomString + fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1);
                    }
                    Common.ResizeFromStream(absolutePath, 300, fileAnhChinh.PostedFile.InputStream);
                    //fileAnhChinh.PostedFile.SaveAs(absolutePath);
                    relativePath += randomString + fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1);

                    if (Request.QueryString["nid"] == null)
                    {
                        tt.InsertFields(txtTieuDe.Text, wheNoiDung.TextXhtml, txtTomTat.Text, Common.NguoiDungID(),
                                        DateTime.Now, relativePath, LoaiTinTuc);
                    }
                    else
                    {
                        tt.UpdateFields(Convert.ToInt32(Request.QueryString["nid"]),
                                        txtTieuDe.Text, wheNoiDung.Text, txtTomTat.Text, Common.NguoiDungID(),
                                        DateTime.Now, relativePath, LoaiTinTuc);
                    }
                    imgAnhChinh.ImageUrl = "." + relativePath;
                }
                else
                {
                    lblAnhChinhErr.Text = "Kích cỡ ảnh quá lớn!";
                    return;
                }
            }
            else
            {
                if (Request.QueryString["nid"] == null)
                {
                    tt.InsertFields(txtTieuDe.Text, wheNoiDung.TextXhtml, txtTomTat.Text, Common.NguoiDungID(),
                                    DateTime.Now, relativePath, LoaiTinTuc);
                }
                else
                {
                    tt.UpdateFields(Convert.ToInt32(Request.QueryString["nid"]),
                                    txtTieuDe.Text, wheNoiDung.Text, txtTomTat.Text, Common.NguoiDungID(), DateTime.Now,
                                    relativePath, LoaiTinTuc);
                }
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("../message.aspx?msg=" + ex.Message.Replace("\r\n", ""), false);
        }

        string strScript = "<script language='JavaScript'>" + "window.parent.RefreshNews();</script>";
        ClientScript.RegisterStartupScript(GetType(), "Refresh", strScript);
    }