예제 #1
0
 public void manageGenres(Hypster_Entities hyDB, newsManagement newsManager, int id, string postgenres, string old_pgenres)
 {
     if (postgenres != old_pgenres)
     {
         string[] posgn = postgenres.Split(';');
         for (int i = 0; i < posgn.Length; i++)
         {
             if (!old_pgenres.Contains(posgn[i]))
             {
                 Post_Genre postGen = new Post_Genre();
                 postGen.post_id  = id;
                 postGen.genre_id = Convert.ToInt32(posgn[i]);
                 hyDB.Post_Genre.AddObject(postGen);
                 hyDB.SaveChanges();
             }
         }
         string[] o_posgn = old_pgenres.Split(';');
         for (int j = 0; j < o_posgn.Length; j++)
         {
             if (!postgenres.Contains(o_posgn[j]))
             {
                 int genId = Convert.ToInt32(o_posgn[j]);
                 newsManager.DeletePostGenre(id, genId);
                 hyDB.SaveChanges();
             }
         }
     }
 }
예제 #2
0
        public string getAssociatedGenreIds(int id)
        {
            string         genres      = "";
            newsManagement newsManager = new newsManagement();
            List <int?>    allGenres   = new List <int?>();

            allGenres = newsManager.GetAsociatGenreIds(id);
            for (int i = 0; i < allGenres.Count; i++)
            {
                if (genres != "")
                {
                    genres += ";";
                }
                genres += allGenres[i];
            }
            return(genres);
        }
예제 #3
0
        //------------------------------------------------------------------------------------------

        //------------------------------------------------------------------------------------------
        public string addnewtag()
        {
            string ret_res  = "";
            string tag_name = "";

            if (Request.QueryString["tag_name"] != null)
            {
                tag_name = Request.QueryString["tag_name"].ToString();
            }

            int article_id = 0;

            if (Request.QueryString["article_id"] != null)
            {
                Int32.TryParse(Request.QueryString["article_id"], out article_id);
            }

            memberManagement memberManager = new memberManagement();
            Member           member        = new Member();

            member = memberManager.getMemberByUserName(User.Identity.Name);

            newsManagement newsManager  = new newsManagement();
            newsPost       curr_article = new newsPost();

            curr_article = newsManager.GetPostByID(article_id);

            if (curr_article.post_id != 0 && article_id == curr_article.post_id)
            {
                TagManagement tagManager = new TagManagement();
                int           tag_ID     = 0;
                tag_ID = tagManager.AddNewTag(tag_name);
                tagManager.AddTagToNewsArticle(tag_ID, article_id);
                ret_res = tag_ID.ToString() + "|" + article_id.ToString();
            }
            else
            {
                ret_res = "n/a";
            }
            return(ret_res.ToString());
        }
예제 #4
0
        public ActionResult AddNewPost(newsPost p_newPost, HttpPostedFileBase file, string scheduled, string datetimepicker, string postgenres, string attributes)
        {
            Hypster_Entities     hyDB = new Hypster_Entities();
            newsManagement_Admin newsManager_admin = new newsManagement_Admin();
            newsManagement       newsManager       = new newsManagement();

            if (p_newPost.post_title != null && p_newPost.post_title != "")
            {
                if (p_newPost.post_content == null || p_newPost.post_content == "")
                {
                    ModelState.AddModelError("", "Please Enter the Post Content; it is REQUIRED!!");
                }
                if (p_newPost.post_short_content == null || p_newPost.post_short_content == "")
                {
                    ModelState.AddModelError("", "Please Enter the Short Post Content; it is REQUIRED!!");
                }

                p_newPost.post_date   = DateTime.Now;
                p_newPost.post_guid   = p_newPost.post_title.Replace("/", "").Replace("\\", "").Replace("&", "").Replace("+", "").Replace(" ", "-").Replace("?", "").Replace("!", "").Replace("*", "").Replace("$", "").Replace("\"", "").Replace("'", "").Replace("{", "").Replace("}", "").Replace(")", "").Replace("(", "").Replace("[", "").Replace("]", "").Replace("|", "").Replace(".", "").Replace(",", "").Replace(":", "").Replace(";", "");
                p_newPost.post_status = (int)postStatus.NoActive;
                //
                //check if post guid is exist in database
                newsPost post_check = newsManager_admin.GetPostByGUID(p_newPost.post_guid);
                if (post_check.post_id != 0 && newsManager_admin.GetPostByGUID(post_check.post_guid).post_guid != "")
                {
                    ModelState.AddModelError("", "NOT ABLE TO GENERATE POST GUID.Please choose modify title. Post with following title already exist.");
                }
                else //if post guid is unique then procceed to finish
                {
                    hyDB.newsPosts.AddObject(p_newPost);
                    hyDB.SaveChanges();
                    int id = p_newPost.post_id;
                    UploadImage(file, id);
                    if (scheduled == "Yes")
                    {
                        ScheduledPost sPost = new ScheduledPost();
                        sPost.post_id        = id;
                        sPost.scheduled_date = convertDateTime(datetimepicker);
                        sPost.activated      = 0;
                        hyDB.ScheduledPost.AddObject(sPost);
                        hyDB.SaveChanges();
                    }
                    if (attributes != "")
                    {
                        string[] attribute = attributes.Split(';');
                        foreach (string attr in attribute)
                        {
                            postNewsletter pNewsletter = new postNewsletter();
                            pNewsletter.post_id   = id;
                            pNewsletter.attribute = attr;
                            hyDB.postNewsletters.AddObject(pNewsletter);
                            hyDB.SaveChanges();
                        }
                    }
                    if (postgenres.Length != 0)
                    {
                        string[] postgenre = postgenres.Split(';');
                        for (int i = 0; i < postgenre.Length; i++)
                        {
                            Post_Genre postGenre = new Post_Genre();
                            postGenre.post_id  = id;
                            postGenre.genre_id = Convert.ToInt32(postgenre[i]);
                            hyDB.Post_Genre.AddObject(postGenre);
                            hyDB.SaveChanges();
                        }
                    }
                    return(RedirectToAction("Index", "managePost"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Please enter post title. It must be unique from previous posts!!!");
            }

            // if no success
            return(View(new newsPost()));
        }
예제 #5
0
        public ActionResult Edit(newsPost p_Post, HttpPostedFileBase file, string scheduled, string datetimepicker, string postgenres, string attributes)
        {
            newsManagement_Admin newsManager_admin = new newsManagement_Admin();
            newsManagement       newsManager       = new newsManagement();
            Hypster_Entities     hyDB  = new Hypster_Entities();
            ScheduledPost        sPost = new ScheduledPost();

            if (p_Post.post_status == 0 && scheduled == "Yes")
            {
                try
                {
                    // newsManager.GetSchedulePostByID(p_Post.post_id) may throw ArgumentOutOfRangeException error
                    sPost = newsManager_admin.GetSchedulePostByID(p_Post.post_id);
                    sPost.scheduled_date = convertDateTime(datetimepicker);
                    sPost.activated      = 0;
                    newsManager_admin.EditSPost(sPost);
                }
                catch (ArgumentOutOfRangeException e)
                {
                    // newsManager.GetSchedulePostByID(p_Post.post_id) throws ArgumentOutOfRangeException error which was occurred because the post is not having any records in the schedule post table.
                    // Therefore, one must be created.
                    Console.WriteLine(e.Message + " Scheduled Post does not exist previously for this post. Therefore, one must be created.\n\n" + e.StackTrace.ToString());
                    sPost.post_id        = p_Post.post_id;
                    sPost.scheduled_date = convertDateTime(datetimepicker);
                    sPost.activated      = 0;
                    hyDB.ScheduledPost.AddObject(sPost);
                }
            }
            else
            {
                try
                {
                    // newsManager.GetSchedulePostByID(p_Post.post_id) may throw ArgumentOutOfRangeException error
                    sPost           = newsManager_admin.GetSchedulePostByID(p_Post.post_id);
                    sPost.activated = 1;
                    newsManager_admin.EditSPost(sPost);
                }
                catch (ArgumentOutOfRangeException e)
                {
                    // newsManager.GetSchedulePostByID(p_Post.post_id) throws ArgumentOutOfRangeException error which was occurred because the post is not having any records in the schedule post table.
                    // Therefore, one must be created.
                    Console.WriteLine(e.Message + " Scheduled Post does not exist previously for this post. Therefore, one must be created.\n\n" + e.StackTrace.ToString());
                    sPost.post_id        = p_Post.post_id;
                    sPost.scheduled_date = DateTime.Now;
                    sPost.activated      = 1;
                    hyDB.ScheduledPost.AddObject(sPost);
                }
            }
            manageGenres(hyDB, newsManager, p_Post.post_id, postgenres, getAssociatedGenreIds(p_Post.post_id));
            manageAttributes(hyDB, newsManager_admin, p_Post.post_id, attributes, getAttrs(p_Post.post_id));
            newsManager_admin.EditPost(p_Post);
            UploadImage(file, p_Post.post_id);
            hyDB.SaveChanges();
            //update sitemaps date and ping google and bing
            //
            int sitemapNewsID = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["sitemap_newsID"]);

            SitemapManagement sitemapManager = new SitemapManagement();

            sitemapManager.UpdateDateChanged(sitemapNewsID, DateTime.Now);

            HttpWebRequest  ping_google_request   = (HttpWebRequest)WebRequest.Create("http://www.google.com/webmasters/sitemaps/ping?sitemap=http://hypster.com/sitemaps/sitemap_index");
            HttpWebResponse ping_google_response  = (HttpWebResponse)ping_google_request.GetResponse();
            Stream          google_resStream      = ping_google_response.GetResponseStream();
            String          google_responseString = "";

            using (google_resStream)
            {
                StreamReader google_reader = new StreamReader(google_resStream, Encoding.UTF8);
                google_responseString = google_reader.ReadToEnd();
            }

            HttpWebRequest  ping_bing_request   = (HttpWebRequest)WebRequest.Create("http://www.bing.com/webmaster/ping.aspx?siteMap=http://hypster.com/sitemaps/sitemap_index");
            HttpWebResponse ping_bing_response  = (HttpWebResponse)ping_bing_request.GetResponse();
            Stream          bing_resStream      = ping_bing_response.GetResponseStream();
            String          bing_responseString = "";

            using (bing_resStream)
            {
                StreamReader bing_reader = new StreamReader(bing_resStream, Encoding.UTF8);
                bing_responseString = bing_reader.ReadToEnd();
            }
            //-------------------------------------------------------------------------------------------------------------
            return(RedirectToAction("Index"));
        }