Exemplo n.º 1
0
 public JsonResult Deleting()
 {
     try
     {
         var data  = Request.Form;
         var check = new CateDao().DeleteCate(Convert.ToInt32(data["cateId"]));
         if (check)
         {
             return(Json(new
             {
                 status = true
             }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             return(Json(new
             {
                 status = false
             }, JsonRequestBehavior.AllowGet));
         }
     }
     catch
     {
         return(Json(new
         {
             status = false
         }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 2
0
        //
        // GET: /Admin/Cate/

        public ActionResult Index(int page = 1, int pageSize = 5)
        {
            var dao   = new CateDao();
            var model = dao.ListAll(page, pageSize);

            return(View(model));
        }
Exemplo n.º 3
0
        // GET: Client/Home
        public ActionResult Index()
        {
            //Chạy dòng này khi muốn đưa crawl dữ liệu vào db
            //new CrawlerController().Crawler("https://gamek.vn/");

            //Lấy thể loại tin hiện lên header
            var cates = new CateDao().GetAllCate();

            ViewBag.cates = cates;
            //Lọc bài viết hiện ra
            List <baiviet> posts     = new List <baiviet>();
            List <baiviet> all_posts = new List <baiviet>();

            foreach (var cate in cates)
            {
                var cate_posts = new PostDao().GetAllPost(cate.id);
                posts.AddRange(cate_posts.Where(x => x.noibat == true).OrderByDescending(x => x.ngaytao).Take(3).ToList());
                all_posts.AddRange(cate_posts);
            }
            ViewBag.posts = posts;
            var hotNews = all_posts.Where(x => x.noibat == true).OrderByDescending(x => x.soluotxem).Take(4).ToList(); //100 25 20 15

            foreach (var hotNew in hotNews)
            {
                hotNew.theloaitin = new CateDao().GetSingleCate(hotNew.theloai_id.Value);
            }
            ViewBag.hotNews = hotNews;
            return(View());
        }
Exemplo n.º 4
0
        public ActionResult Type(string metatitle, int id = -1, int page = 1, int pageSize = 1)
        {
            if (page <= 0)
            {
                page = 1;
            }
            var cate       = new CateDao();
            var cateDetail = cate.GetCateByIdAndMetatitle(metatitle, id);

            if (cateDetail == null)
            {
                return(Redirect("/"));
            }
            ViewBag.cate = cateDetail.Name;

            string url = "/san-pham/" + cateDetail.MetaTitle + "-" + cateDetail.ID;

            ViewBag.url = url;

            int total = 0;

            ViewBag.page = page;

            var product = new ProductDao().GetListProductByCateID(id, ref total, page, pageSize);

            ViewBag.totalPage = (int)Math.Ceiling(((double)total / (double)pageSize));
            return(View(product));
        }
Exemplo n.º 5
0
        // GET: Admin/Cate
        public ActionResult Index()
        {
            List <Category> list = new List <Category>();
            var             dao  = new CateDao();

            list = dao.GetListCate();
            return(View(list));
        }
Exemplo n.º 6
0
        public ActionResult ActionAdding()
        {
            var data       = Request.Form;
            var preCate_id = new CateDao().CountCate();

            new CateDao().AddCate(data["name"], data["slug"], preCate_id + 1);
            return(Redirect("Index"));
        }
Exemplo n.º 7
0
        public ActionResult Update(long id = 1)
        {
            var      dao  = new CateDao();
            Category cate = dao.GetCategoryById(id);

            if (cate == null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.image = cate.Image;
            return(View(cate));
        }
Exemplo n.º 8
0
        // GET: Client/Search
        public ActionResult Index(string search)
        {
            var data = search;
            //Lấy thể loại tin hiện lên header
            var cates = new CateDao().GetAllCate();
            ViewBag.cates = cates;

            ViewBag.searchString = search;

            var posts = new PostDao().SearchPost(search);
            ViewBag.posts = posts;

            return View();
        }
Exemplo n.º 9
0
        public ActionResult Delete(int id = 1)
        {
            bool result = new CateDao().Delete(id);

            if (result)
            {
                TempData["Success"] = "Xóa loại sản phẩm thành công!";
            }
            else
            {
                TempData["Error"] = "Xóa loại sản phẩm thất bại!";
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 10
0
        public ActionResult Editing(int id)
        {
            if (Session[CommonConstants.USER_SESSION] != null)
            {
                var session = new UserLogin();
                session = (UserLogin)Session[CommonConstants.USER_SESSION]; // lấy từ session
                var name = new UserDao().GetName(session.userName);
                ViewBag.session = name;
            }

            var cate = new CateDao().GetSingleCate(id);

            ViewBag.cate = cate;
            return(View());
        }
Exemplo n.º 11
0
        public ActionResult Adding()
        {
            if (Session[CommonConstants.USER_SESSION] != null)
            {
                var session = new UserLogin();
                session = (UserLogin)Session[CommonConstants.USER_SESSION]; // lấy từ session
                var name = new UserDao().GetName(session.userName);
                ViewBag.session = name;
            }

            var cates = new CateDao().GetAllCate();

            ViewBag.cates = cates;
            return(View());
        }
Exemplo n.º 12
0
 public ActionResult Create(Category cate, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         var dao = new CateDao();
         cate.CreatedDate = DateTime.Now;
         cate.MetaTitle   = Slug.ConvertToUnSign(cate.Name.ToLower());
         bool isIsset = dao.CheckIssetCate(cate.Name);
         if (isIsset)
         {
             ModelState.AddModelError("", "Loại sản phẩm này đã tồn tại");
             return(View());
         }
         else
         {
             if (image != null)
             {
                 string   fileName = Path.GetFileName(image.FileName);
                 string[] tokens   = fileName.Split('.');
                 if (tokens[tokens.Count() - 1] == "png" || tokens[tokens.Count() - 1] == "jpg" || tokens[tokens.Count() - 1] == "jpeg" || tokens[tokens.Count() - 1] == "gif")
                 {
                     string folderPath = Path.Combine(Server.MapPath("/Assets/client/images"), fileName);
                     image.SaveAs(folderPath);
                     cate.MetaTitle   = Slug.ConvertToUnSign(cate.Name);
                     cate.CreatedDate = DateTime.Now;
                     cate.Image       = "/Assets/client/images/" + fileName;
                     dao.Insert(cate);
                     TempData["Success"] = "Thêm loại sản phẩm thành công!";
                     return(RedirectToAction("Index"));
                 }
                 else
                 {
                     ModelState.AddModelError("", "File hình ảnh chưa phù hợp!");
                     return(View());
                 }
             }
             else
             {
                 ModelState.AddModelError("", "Chưa chọn hình ảnh!");
                 return(View());
             }
         }
     }
     else
     {
         return(View());
     }
 }
Exemplo n.º 13
0
 public ActionResult AddCate(CHUYENMUC cm)
 {
     if (ModelState.IsValid)
     {
         var  DAO = new CateDao();
         long id  = DAO.addCate(cm);
         if (id > 0)
         {
             return(RedirectToAction("Index", "CateManager"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm thể loại thất bại");
         }
     }
     return(View("Index"));
 }
Exemplo n.º 14
0
        public bool FuncUpdate(Category cate, string fileName, CateDao dao)
        {
            cate.Image     = "/Assets/client/images/" + fileName;
            cate.MetaTitle = Slug.ConvertToUnSign(cate.Name);
            bool result = dao.Update(cate);

            if (result)
            {
                TempData["Success"] = "Cập nhật loại sản phẩm thành công!!";
                return(true);
            }
            else
            {
                TempData["Error"] = "Cập nhật loại sản phẩm thất bại!";
                return(false);
            }
        }
Exemplo n.º 15
0
 public void Crawler(string url)
 {
     try
     {
         string[] cates  = { "Mobile", "Esport", "Khám phá", "Manga Film", "Tin tức game", "Cộng đồng mạng" };
         int      cateId = 1;
         foreach (var item in cates)
         {
             var cate_id = new CateDao().AddCate(item, ToUrlSlug(item), cateId);
             if (cate_id == -1)
             {
                 Console.WriteLine("Lỗi " + item);
             }
             else
             {
                 Console.WriteLine("Thêm " + item);
                 cateId += 1;
             }
         }
         for (int j = 0; j < cates.Length; j++)
         {
             var cate_slug = ToUrlSlug(cates[j]);
             if (cates[j] == "Tin tức game" || cates[j] == "Cộng đồng mạng")
             {
                 CrawlerSingleCate(url + "/" + cate_slug + ".htm", j + 1);
             }
             else if (cates[j] == "Mobile")
             {
                 CrawlerSingleCate(url + "/" + cate_slug + "-social.chn", j + 1);
             }
             else
             {
                 CrawlerSingleCate(url + "/" + cate_slug + ".chn", j + 1);
             }
             //https://gamek.vn/tin-tuc-game.htm
             //https://gamek.vn/kham-pha.chn
         }
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 16
0
        // GET: Admin/Category
        public ActionResult Index(int page = 1, int pageSize = 10)
        {
            try
            {
                if (Session[CommonConstants.USER_SESSION] != null)
                {
                    var session = new UserLogin();
                    session = (UserLogin)Session[CommonConstants.USER_SESSION]; // lấy từ session
                    var name = new UserDao().GetName(session.userName);
                    ViewBag.session = name;
                }

                var cates = new CateDao().GetPagedListCate(page, pageSize);
                return(View(cates));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 17
0
 public JsonResult Searching()
 {
     try
     {
         var data  = Request.Form;
         var cates = new CateDao().SearchCate(data["search"]);
         return(Json(new
         {
             status = true,
             data = cates
         }, JsonRequestBehavior.AllowGet));
     }
     catch
     {
         return(Json(new
         {
             status = false
         }, JsonRequestBehavior.AllowGet));
     }
 }
Exemplo n.º 18
0
        // GET: Detail
        public ActionResult Detail(string metatitle, int id = 1)
        {
            var dao     = new ProductDao();
            var product = dao.GetProductByIdAndMetatitle(metatitle, id);

            if (product == null)
            {
                return(Redirect("/"));
            }

            var cateDao = new CateDao();

            ViewBag.cate = cateDao.GetCategoryById(product.CategoryID).Name;

            ViewBag.NewProduct    = dao.Get3NewProduct(3);
            ViewBag.RelateProduct = dao.GetListRelateProduct(product.ID, 5);

            ViewBag.NewProduct = dao.Get3NewProduct(3);
            return(View(product));
        }
Exemplo n.º 19
0
        // GET: Client/Category
        public ActionResult Index(string slug)
        {
            //Lấy thể loại tin hiện lên header
            var cates = new CateDao().GetAllCate();

            ViewBag.cates = cates;

            //Lấy thông tin cate được chọn
            var            theloai_id = new CateDao().GetId(slug);
            var            cateName   = new CateDao().GetName(theloai_id);
            List <baiviet> posts      = new List <baiviet>();

            if (theloai_id != -1)
            {
                posts = new PostDao().GetAllPost(theloai_id);
            }
            ViewBag.posts    = posts;
            ViewBag.cateName = cateName;
            ViewBag.cateSlug = slug;
            return(View());
        }
Exemplo n.º 20
0
        // GET: Admin/Home
        public ActionResult Index()
        {
            if (Session[CommonConstants.USER_SESSION] != null)
            {
                var session = new UserLogin();
                session = (UserLogin)Session[CommonConstants.USER_SESSION]; // lấy từ session
                var name = new UserDao().GetName(session.userName);
                ViewBag.session = name;
            }

            var user_count    = new UserDao().CountUser();
            var post_count    = new PostDao().CountPost();
            var cate_count    = new CateDao().CountCate();
            var comment_count = new CommentDao().CountComment();

            ViewBag.user_count    = user_count;
            ViewBag.post_count    = post_count;
            ViewBag.cate_count    = cate_count;
            ViewBag.comment_count = comment_count;
            return(View());
        }
Exemplo n.º 21
0
        public ActionResult Index(string cateslug, string postslug)
        {
            //Lấy thể loại tin hiện lên header
            var cates = new CateDao().GetAllCate();

            ViewBag.cates = cates;

            //Lấy thông tin cate được chọn
            int     cateId = new CateDao().GetId(cateslug);
            baiviet post   = new PostDao().GetSinglePost(postslug, cateId);

            ViewBag.post = post;

            string cateName = new CateDao().GetName(post.theloai_id.Value);

            ViewBag.cateName = cateName;
            string cateSlug = new CateDao().GetSlug(post.theloai_id.Value);

            ViewBag.cateSlug = cateSlug;
            //tang luot xem moi khi vao bai viet
            var view = new PostDao().IncViews(postslug, post.theloai_id.Value);
            //loc ra hot-news
            var cate_posts = new PostDao().GetAllPost(cateId);
            var hotNews    = cate_posts.Where(x => x.noibat == true && x.id != post.id).OrderByDescending(x => x.soluotxem).Take(6).ToList(); //100 25 20 15

            foreach (var hotNew in hotNews)
            {
                hotNew.theloaitin = new CateDao().GetSingleCate(hotNew.theloai_id.Value);
            }
            ViewBag.hotNews = hotNews;
            var relatedNews = cate_posts.Where(x => x.id != post.id).OrderByDescending(x => x.ngaytao).Take(6).ToList();

            ViewBag.relatedNews = relatedNews;

            var comments = new CommentDao().GetAllComment(post.id);

            ViewBag.comments = comments;

            return(View());
        }
Exemplo n.º 22
0
        public ActionResult Update(Category cate, HttpPostedFileBase image)
        {
            var dao = new CateDao();
            var c   = dao.GetCategoryById(cate.ID);

            ViewBag.image = c.Image;
            if (ModelState.IsValid)
            {
                // nếu model valid

                if (image != null)
                {
                    // nếu có thay đổi hình ảnh
                    string   fileName = Path.GetFileName(image.FileName);
                    string[] tokens   = fileName.Split('.');
                    if (tokens[tokens.Count() - 1] == "png" || tokens[tokens.Count() - 1] == "jpg" || tokens[tokens.Count() - 1] == "jpeg" || tokens[tokens.Count() - 1] == "gif")
                    {
                        // nếu hình ảnh hợp lệ
                        bool isntChange = dao.CheckChange(cate.ID, cate.Name);
                        if (isntChange)
                        {
                            // nếu tên ko thay đổi
                            string folderPath = Path.Combine(Server.MapPath("/Assets/client/images"), fileName);
                            image.SaveAs(folderPath);
                            FuncUpdate(cate, fileName, dao);
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            // nếu tên thay đổi
                            var isIsset = dao.CheckIssetCate(cate.Name);
                            if (isIsset)
                            {
                                // nếu tên đã tồn tại
                                ModelState.AddModelError("", "Loại sản phẩm này đã tồn tại !");
                            }
                            else
                            {
                                // nếu tên chưa tồn tại
                                string folderPath = Path.Combine(Server.MapPath("/Assets/client/images"), fileName);
                                image.SaveAs(folderPath);
                                FuncUpdate(cate, fileName, dao);
                                return(RedirectToAction("Index"));
                            }
                        }
                    }
                    else
                    {
                        // nếu hình ảnh ko hợp lệ
                        ModelState.AddModelError("", "File hình ảnh chưa phù hợp!");
                    }
                }
                else
                {
                    // nếu ko thay đổi hình ảnh
                    string fileName   = "";
                    bool   isntChange = dao.CheckChange(cate.ID, cate.Name);
                    if (isntChange)
                    {
                        // nếu tên ko thay đổi
                        FuncUpdate(cate, fileName, dao);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        // nếu tên thay đổi
                        var isIsset = dao.CheckIssetCate(cate.Name);
                        if (isIsset)
                        {
                            // nếu tên đã tồn tại
                            ModelState.AddModelError("", "Loại sản phẩm này đã tồn tại !");
                        }
                        else
                        {
                            // nếu tên chưa tồn tại
                            FuncUpdate(cate, fileName, dao);
                            return(RedirectToAction("Index"));
                        }
                    }
                }
            }

            return(View());
        }
Exemplo n.º 23
0
        public ActionResult _Brand()
        {
            var cate = new CateDao().GetListCategoryShow();

            return(View(cate));
        }
Exemplo n.º 24
0
        public void DropDownCate(long?id = null)
        {
            var dao = new CateDao();

            ViewBag.CategoryID = new SelectList(dao.GetListCate(), "ID", "Name", id);
        }
Exemplo n.º 25
0
        public ActionResult MainMenu()
        {
            var model = new CateDao().ListCate();

            return(PartialView(model));
        }