Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("WebModulId,WebModulName")] WebModul webModul)
        {
            /*Check Session */
            var page            = "73";
            var typeofuser      = "";
            var PermisionAction = "";

            // CheckSession
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Username")))
            {
                Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                typeofuser      = HttpContext.Session.GetString("TypeOfUserId");
                PermisionAction = HttpContext.Session.GetString("PermisionAction");
                if (PermisionHelper.CheckPermision(typeofuser, PermisionAction, page) == false)
                {
                    Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(webModul);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(webModul));
        }
Exemplo n.º 2
0
        //public static void GetNews(ref IWorkbook wk, WebModul nm, int MaxNewsCount, MainWindow mw)
        //{
        //    int startIndex = int.Parse(nm.Min);
        //    int Step = int.Parse(nm.Step);
        //    int EndIndex = startIndex + Step*(MaxNewsCount/10);

        //    List<string> urlList = new List<string>();
        //    List<NewsModul> nachrichtList = new List<NewsModul>();

        //    string htmlLinkResponsestr= "";
        //    Crawler crawler = new Crawler(nm.StartURL, nm.RegularLink,nm.RegularIntroduction, nm.RegularTitel, nm.RegularDate,
        //        nm.RegularContent);

        //    foreach (WebModul.UrlModel url in nm.Urls)
        //    {
        //        urlList.Clear();
        //        for (int i = startIndex; i <= EndIndex; i += Step)
        //        {
        //            string htmlurl = "";
        //            if (nm.Modul.Equals("0"))
        //            {
        //                if ( i == 0) htmlurl = url.URLT1;
        //                else if (!url.URLT3.Equals("")) htmlurl = url.URLT1 + url.URLT2 + i.ToString() + url.URLT3;
        //                else htmlurl = url.URLT1 + url.URLT2 + i.ToString() + "/";
        //            }
        //            else
        //            {
        //                if (i == 1 || i == 0) htmlurl = url.URLT1;
        //                else if (!url.URLT3.Equals("")) htmlurl = url.URLT1 + url.URLT2 + i.ToString() + url.URLT3;
        //                else htmlurl = url.URLT1 + url.URLT2 + i.ToString() + "/";
        //            }

        //            htmlLinkResponsestr = crawler.GetResponsetHtmlStr(htmlurl);
        //            urlList = urlList.Concat(crawler.GetLinks(htmlLinkResponsestr)).ToList();
        //        }
        //        nachrichtList = nachrichtList.Concat(crawler.GetNews(urlList, url.CatName,MaxNewsCount,mw)).ToList();
        //    }
        //    WriteDataToFile(wk, nachrichtList,nm.Name);
        //}

        public static void GetNewsToTool(WebModul nm, int MaxNewsCount, MainWindow mw)
        {
            int startIndex = int.Parse(nm.Min);
            int Step       = int.Parse(nm.Step);
            int EndIndex   = int.Parse(nm.Max);

            List <string>    urlList  = new List <string>();
            List <NewsModul> NewsList = new List <NewsModul>();

            Crawler crawler = new Crawler(nm.StartURL, nm.RegularLink, nm.RegularIntroduction, nm.RegularTitel, nm.RegularDate, nm.RegularContent);

            foreach (WebModul.UrlModel url in nm.Urls)
            {
                urlList.Clear();
                int  i          = startIndex;
                bool IsReloaded = false;
                do
                {
                    string htmlurl             = CheckUrl(nm.Modul, url, i);
                    string htmlLinkResponsestr = crawler.GetResponsetHtmlStr(htmlurl);
                    urlList = urlList.Concat(crawler.GetLinks(htmlLinkResponsestr)).ToList();
                    if (!IsReloaded)
                    {
                        EndIndex = startIndex + Step * (MaxNewsCount / urlList.Count); IsReloaded = true;
                    }
                    i++;
                }while (i <= EndIndex);
                NewsList = crawler.GetNews(urlList, url.CatName, nm.Name, MaxNewsCount, mw);
                mw.AddNewsList(NewsList);
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit([Bind("WebModulId,WebModulName")] WebModul webModul)
        {
            /*Check Session */
            var page            = "74";
            var typeofuser      = "";
            var PermisionAction = "";

            // CheckSession
            if (string.IsNullOrEmpty(HttpContext.Session.GetString("Username")))
            {
                Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                typeofuser      = HttpContext.Session.GetString("TypeOfUserId");
                PermisionAction = HttpContext.Session.GetString("PermisionAction");
                if (PermisionHelper.CheckPermision(typeofuser, PermisionAction, page) == false)
                {
                    Alert("คุณไม่มีสิทธิ์ใช้งานหน้าดังกล่าว", NotificationType.error);
                    return(RedirectToAction("Index", "Home"));
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(webModul);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WebModulExists(webModul.WebModulId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction("Index", "Home"));
        }