public ActionResult TaoMoi(TruyenModel truyen, HttpPostedFileBase AnhBia) { DaoTruyen truyen2 = new DaoTruyen(); ViewBag.TheLoai = truyen2.LayTheLoai(); ViewBag.TrangThai = truyen2.LayTrangThai(); if (ModelState.IsValid) { DaoCTTruyen ct = new DaoCTTruyen(); NguoiDung nguoi = (NguoiDung)Session["TaiKhoan"]; var truyen1 = new Truyen(); truyen.AnhBia = ThemAnh(AnhBia); int maproject = truyen2.ThemVao(truyen2.Tao(truyen, nguoi)); string theloais = Request.Form["DSTheLoai"]; string[] DSTheLoai = theloais.Split(new char[] { ',' }); if (ct.Get(DSTheLoai, maproject)) { return(RedirectToAction("Index", "User")); } else { ModelState.AddModelError("", "Lỗi"); } } else { ModelState.AddModelError("", "Yêu cầu nhập các trường bắt buộc"); } return(View(truyen)); }
public ActionResult Create([Bind(Include = "idTruyen" + ",idTL" + ",tenTruyen" + ",tacGia" + ",tinhTrang" + ",tomTat" + ",ngayDang")] Truyen truyen , HttpPostedFileBase uploadhinh) { if (ModelState.IsValid) { if (uploadhinh != null && uploadhinh.ContentLength > 0) { string fileName = Path.GetFileName(uploadhinh.FileName); string path = Path.Combine(Server.MapPath("~/Areas/Admin/Content/images"), fileName); uploadhinh.SaveAs(path); truyen.anhDaidien = fileName; db.Truyens.Add(truyen); db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.idTL = new SelectList(db.TheLoais, "idTL", "tenLoai", truyen.idTL); return(View(truyen)); }
// GET: admin/CheckTheLoais/Details/5 public ActionResult Details(string id) { Truyen mytruyen = db.Truyens.Find(id); List <string> listTheLoai = tool.listTheLoai(id); ViewBag.listTheLoai = listTheLoai; return(View(mytruyen)); }
public ActionResult DeleteConfirmed(int id) { Truyen truyen = db.Truyens.Find(id); db.Truyens.Remove(truyen); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ChapterLoadData> GetChapterNumber(Truyen truyen, int indexOfchapter) { var page = indexOfchapter / NumberChapterPerPage + 1;// trang bat' dau` la` 1 var result = await GetPageChapTer(truyen, page, true); result.IndexStartOfChapter = indexOfchapter - ((page - 1) * NumberChapterPerPage); return(result); }
public async void RemoveStoryFavorite(Truyen story) { var value = await Connection.Table <TruyenSqlFavoriteData>().Where(o => o.Site == story.Site && o.TruyenUrl == story.TruyenUrl).FirstOrDefaultAsync(); if (value != null) { await Connection.DeleteAsync(value); } }
public ActionResult Edit([Bind(Include = "IDTruyen,tentruyen,tacgia,nguon,trangthai,yeuthich,gioithieu,anh")] Truyen truyen) { if (ModelState.IsValid) { db.Entry(truyen).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(truyen)); }
public async Task <bool> IsStoryFavorite(Truyen truyen) { var value = await Connection.Table <TruyenSqlFavoriteData>().Where(o => o.Site == truyen.Site && o.TruyenUrl == truyen.TruyenUrl).FirstOrDefaultAsync(); if (value == null) { return(false); } return(true); }
public async void AddStoryFavorite(Truyen story) { // kiem tra xem thu trong favorite database co' no' k0 var value = await Connection.Table <TruyenSqlFavoriteData>().Where(o => o.Site == story.Site && o.TruyenUrl == story.TruyenUrl).FirstOrDefaultAsync(); if (value == null) { var truyenfavorite = TruyenSqlFavoriteData.Convert(story); await Connection.InsertAsync(truyenfavorite); } }
public static Truyen Convert(TruyenSqlFavoriteData dataTruyensql) { var item = new Truyen(dataTruyensql.Site); item.TruyenUrl = dataTruyensql.TruyenUrl; item.Author = dataTruyensql.Author; item.Category = dataTruyensql.Category; item.MaxPageTruyen = dataTruyensql.MaxPageTruyen; item.Title = dataTruyensql.Title; return(item); }
public ActionResult Edit([Bind(Include = "idTruyen,idTL,tenTruyen,tacGia,tinhTrang,anhDaidien,tomTat,ngayDang")] Truyen truyen) { if (ModelState.IsValid) { db.Entry(truyen).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idTL = new SelectList(db.TheLoais, "idTL", "tenLoai", truyen.idTL); return(View(truyen)); }
public static TruyenSqlFavoriteData Convert(Truyen dataTruyen) { var item = new TruyenSqlFavoriteData(); item.Site = dataTruyen.Site; item.TruyenUrl = dataTruyen.TruyenUrl; item.Author = dataTruyen.Author; item.Category = dataTruyen.Category; item.MaxPageTruyen = dataTruyen.MaxPageTruyen; item.Title = dataTruyen.Title; return(item); }
public void TestTungHoanhGetChapter() { var top = WrapperCreator.Create(SiteTruyen.TungHoanh); var truyen = new Truyen(SiteTruyen.TruyenConvert); truyen.TruyenUrl = "http://tunghoanh.com/huan-luyen-vien-huyen-thoai-Cqaaaab.html"; var result = Task.Run(() => top.GetChapterNumber(truyen, 22)).Result; Assert.AreEqual(result.IndexStartOfChapter, 22, " Chỉ số bị sai"); var chapter = result.ListChapter[0]; Debug.WriteLine("Nội dung " + chapter.NoiDung); }
public void TestTruyenConvertGetChapter() { var top = WrapperCreator.Create(SiteTruyen.TruyenConvert); var truyen = new Truyen(SiteTruyen.TruyenConvert); truyen.TruyenUrl = "http://truyencv.com/thien-vuc-thuong-khung/"; var result = Task.Run(() => top.GetChapterNumber(truyen, 22)).Result; Assert.AreEqual(result.IndexStartOfChapter, 22, " Chỉ số bị sai"); var chapter = result.ListChapter[0]; Debug.WriteLine("Nội dung " + chapter.NoiDung); }
public int CapNhat(int id, TruyenModel truyen) { Truyen truyendangupdate = data.Truyens.SingleOrDefault(m => m.MaProject == id); truyendangupdate.MoTa = truyen.MoTa; truyendangupdate.TacGia = truyen.Tacgia; truyendangupdate.TenKhac = truyen.TenKhac; truyendangupdate.TenProject = truyen.TenTruyen; truyendangupdate.TrangThai = truyen.MaTrangThai; truyendangupdate.AnhBia = truyen.AnhBia; data.SaveChanges(); return(truyendangupdate.MaProject); }
public void TestLSBGetChapter() { var top = WrapperCreator.Create(SiteTruyen.LuongSonBac); var truyen = new Truyen(SiteTruyen.LuongSonBac); truyen.TruyenUrl = "trieu-hoan-than-binh-tac-gia-ha-nhat-dich-lanh-134355858.html"; var result = Task.Run(() => top.GetChapterNumber(truyen, 22)).Result; Assert.AreEqual(result.IndexStartOfChapter, 2, " Chỉ số bị sai"); var chapter = result.ListChapter[result.IndexStartOfChapter]; Assert.AreEqual(chapter.TenChuong, "Ngươi là Độc Cô Nhai ?", "Chương bị sai"); Debug.WriteLine("Tìm kiếm " + chapter.TenChuong); }
public override void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode, Dictionary <string, object> viewModelState) { if (navigationParameter != null && navigationMode != NavigationMode.Back) { if (_truyen != null && navigationParameter is Truyen) { _truyen = (Truyen)navigationParameter; TrangDocTruyen = _truyen.Site; _truyen.PropertyChanged += _truyen_PropertyChanged; FirstLoadCommand.Execute(); } } base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState); }
public TruyenModel LayTruyenModel(int id, int[] theloai) { Truyen truyen = data.Truyens.SingleOrDefault(m => m.MaProject == id); TruyenModel truyen1 = new TruyenModel(); truyen1.MoTa = truyen.MoTa; truyen1.Tacgia = truyen.TacGia; truyen1.MaTrangThai = truyen.TrangThai; truyen1.TenKhac = truyen.TenKhac; truyen1.TenTruyen = truyen.TenProject; truyen1.AnhBia = truyen.AnhBia; truyen1.DStheloai = theloai; return(truyen1); }
public override void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode, Dictionary <string, object> viewModelState) { if (navigationParameter is ThNavParamater) { var obj = navigationParameter as ThNavParamater; CurrentChapter = obj.Chap; _tempIndexOfNumberChapterInPage = CurrentChapter.IndexNumberPageOfChapter; _truyen = new Truyen(obj.TrangTruyen); _truyen.TruyenUrl = CurrentChapter.TruyenUrl; _truyen.CurrentPageRead = CurrentChapter.PageOfChapter; FirstLoadCommand.Execute(); } base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState); }
// GET: Admin/Truyens/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Truyen truyen = db.Truyens.Find(id); if (truyen == null) { return(HttpNotFound()); } return(View(truyen)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Truyen truyen = db.Truyens.Find(id); if (truyen == null) { return(HttpNotFound()); } ViewBag.idTL = new SelectList(db.TheLoais, "idTL", "tenLoai", truyen.idTL); return(View(truyen)); }
public Truyen Tao(TruyenModel truyen, NguoiDung nguoi) { Truyen truyendangtao = new Truyen(); truyendangtao.TrangThai = truyen.MaTrangThai; truyendangtao.NgayTao = DateTime.Now; truyendangtao.DaXoa = false; truyendangtao.AnhBia = truyen.AnhBia; truyendangtao.TenProject = truyen.TenTruyen; truyendangtao.TenKhac = truyen.TenKhac; truyendangtao.MoTa = truyen.MoTa; truyendangtao.TacGia = truyen.Tacgia; truyendangtao.MaNguoiDung = nguoi.MaNguoiDung; return(truyendangtao); }
public TruyenPageViewModel(INavigationService navigationService, ISettingService settingService) { _navigationService = navigationService; _settingService = settingService; Chapters = new ObservableCollection <Chapter>(); Truyen = new Truyen(TrangDocTruyen); Truyen.Title = "Thần Mộ"; FirstLoadCommand = new DelegateCommand(async() => { PrcocessDisplayForSiteTruyen(); await LoadChapter(); }); LoadNextListChapterCommand = new DelegateCommand(async() => { _truyen.CurrentPageRead += 1; await LoadChapter(); }); NavigateToChapterCommand = new DelegateCommand <SelectionChangedEventArgs>(NavigateToChapter); LoadEndChapterCommand = new DelegateCommand(LoadEndChapter); LoadBeginChapterCommand = new DelegateCommand(LoadBeginChapter); AddFavoriteCommand = new DelegateCommand(AddFavorite); RemoveFavoriteCommand = new DelegateCommand(RemoveFavorite); ReadFirstChapterCommand = new DelegateCommand(() => { NavigateToChapter(1, _truyen.Site == Wrapper.SiteTruyen.LuongSonBac ? 0 : 1); }); ReadLastChapterCommand = new DelegateCommand(() => { NavigateToChapter(_truyen.MaxPageTruyen, _truyen.Site == Wrapper.SiteTruyen.LuongSonBac ? 0 : _truyen.MaxPageTruyen); }); ReadNewChapterCommand = new DelegateCommand(async() => { var truyenStorage = await _settingService.GetTruyenStorageData(_truyen.Site, _truyen.TruyenUrl); if (truyenStorage == null) { await ReadFirstChapterCommand.Execute(); } else { NavigateToChapter(truyenStorage.LastPageRead, truyenStorage.LastChapterRead); } }); }
public ActionResult Create([Bind(Include = "IDTruyen,tentruyen,tacgia,nguon,trangthai,yeuthich,gioithieu")] Truyen truyen, HttpPostedFileBase file) { if (ModelState.IsValid) { try { if (file != null) { string fileName = Path.GetFileName(file.FileName); string urlImage = Server.MapPath("~/Assets/image/" + fileName); file.SaveAs(urlImage); } ViewBag.FileStatus = "Tạo truyện mới thành công."; } catch (Exception) { ViewBag.FileStatus = "Lỗi upload ảnh."; } truyen.anh = file.FileName; db.Truyens.Add(truyen); db.SaveChanges(); } return(View(truyen)); }
public async Task <ChapterLoadData> GetPageChapTer(Truyen truyen, int page, bool allowGetNoidung = true) { var pageUrl = string.Format(TRUYEN_URL, truyen.TruyenUrl, page); var htmlData = await WebUtils.DoRequestSimpleGet(pageUrl, null, "", HOME_PAGE); if (htmlData.Status) { var dom = new HtmlDocument(); dom.LoadHtml(htmlData.Data); var chapterDoms = dom.DocumentNode.SelectNodes(DANH_SACH_CHUONG_XPATH); var maxPage = 1; if (chapterDoms != null) { var i = 0; var j = 0; var lchapter = new List <Chapter>(); foreach (var chapDom in chapterDoms) { i++; if (i < 3) { continue; } var chap = new Chapter(); HtmlNode tdom = null; chap.TruyenUrl = truyen.TruyenUrl; chap.PageOfChapter = page; tdom = chapDom.SelectSingleNode(CHUONGNUMBER_XPATH); if (tdom != null) { chap.SoThuTu = tdom.InnerText.Trim(); } tdom = chapDom.SelectSingleNode(TENCHUONG_XPATH); if (tdom != null) { chap.TenChuong = tdom.InnerText.Trim(); } else { continue; } tdom = chapDom.SelectSingleNode(SOURCE_XPATH); if (tdom != null) { chap.Nguon = tdom.InnerText.Trim(); } if (allowGetNoidung) { tdom = chapDom.SelectSingleNode(NOIDUNG_XPATH); if (tdom != null) { List <HtmlNode> listRemove = tdom.ChildNodes.Where(iNode => iNode.Name == "span").ToList(); foreach (var iNode in listRemove) { tdom.RemoveChild(iNode); } chap.NoiDung = tdom.InnerText.Trim(); } else { continue; } } chap.IndexNumberPageOfChapter = j++; lchapter.Add(chap); } var ldom = dom.DocumentNode.SelectNodes(MAX_PAGE_TRUYEN_XPATH); if (ldom != null) { foreach (var idom in ldom) { var cdom = idom.SelectSingleNode("./a"); if (cdom != null) { var href = cdom.GetAttributeValue("href", ""); if (href.IndexOf("=") != -1 && href.IndexOf("&") != -1) { try { href = href.Substring(href.IndexOf("=") + 1, href.IndexOf("&") - href.IndexOf("=") - 1); } catch (Exception) { // ignored } } var n = 0; int.TryParse(href, out n); if (n > maxPage) { maxPage = n; } } } } var result = new ChapterLoadData(); result.ListChapter = lchapter; result.MaxPageIndex = maxPage; result.IndexStartOfChapter = 0; return(result); } } return(null); }
public int ThemVao(Truyen truyen) { data.Truyens.Add(truyen); data.SaveChanges(); return(truyen.MaProject); }
private static SiteTruyenData ReadSiteTruyenHtmlData(string htmlData) { var siteTruyen = new SiteTruyenData(); var dom = new HtmlDocument(); dom.LoadHtml(htmlData); var tdom = dom.DocumentNode.SelectNodes(DANHSACHTOPTRUYEN_XPATH); if (tdom != null) { var i = 0; var listTruyen = new List <Truyen>(); foreach (var idom in tdom) { i++; // bo? 2 node dau` if (i < 3) { continue; } var truyen = new Truyen(SiteTruyen.LuongSonBac); try { var cdom = idom.SelectSingleNode("./td[2]"); if (cdom != null) { truyen.Category = WebUtility.HtmlDecode(cdom.InnerText.Trim()); } else { continue; } cdom = idom.SelectSingleNode("./td[3]"); if (cdom != null) { truyen.Title = cdom.InnerText.Trim(); } cdom = idom.SelectSingleNode("./td[4]"); if (cdom != null) { truyen.Author = cdom.InnerText.Trim(); } cdom = idom.SelectSingleNode("./td[6]"); if (cdom != null) { truyen.NumberChaper = int.Parse(cdom.InnerText.Trim()); } cdom = idom.SelectSingleNode("./td[7]"); if (cdom != null) { truyen.NumberView = int.Parse(cdom.InnerText.Trim().Replace(".", "")); } cdom = idom.SelectSingleNode("./td[3]/a[1]"); if (cdom != null) { truyen.TruyenUrl = cdom.GetAttributeValue("href", ""); } else { continue; } } catch (Exception) { continue; } listTruyen.Add(truyen); } // tim so trang tdom = dom.DocumentNode.SelectNodes(MAXPAGEINDEX_XPATH); var maxPage = 1; if (tdom != null) { foreach (var idom in tdom) { var href = idom.GetAttributeValue("href", ""); if (href.LastIndexOf('-') != -1) { href = href.Substring(href.LastIndexOf('-', href.Length - href.LastIndexOf("-"))); var n = 0; int.TryParse(href, out n); if (n > maxPage) { maxPage = n; } } } } siteTruyen.ListTruyen = listTruyen; siteTruyen.MaxPageIndex = maxPage; return(siteTruyen); } return(siteTruyen); }