示例#1
0
        public ActionResult Edit(int id)
        {
            newsPost             newsPost    = new newsPost();
            newsManagement_Admin newsManager = new newsManagement_Admin();

            newsPost   = newsManager.GetPostByID(id);
            ViewBag.ID = id;
            return(View(newsPost));
        }
示例#2
0
        public void UploadImage(HttpPostedFileBase file, int id)
        {
            if (file != null && file.ContentLength > 0)
            {
                newsPost             p_Post        = new newsPost();
                newsManagement_Admin newsManager   = new newsManagement_Admin();
                Image_Resize_Manager image_resizer = new Image_Resize_Manager();
                p_Post = newsManager.GetPostByID(id);
                var extension = System.IO.Path.GetExtension(file.FileName);
                if (file.FileName != "")
                {
                    var path = System.IO.Path.Combine(Server.MapPath("~/uploads"), "new_post" + extension);
                    file.SaveAs(path);

                    //save post image
                    System.IO.FileInfo fileInf = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_post" + extension);
                    fileInf.CopyTo(System.Configuration.ConfigurationManager.AppSettings["newsImageStorage_Path"] + "\\" + p_Post.post_guid + fileInf.Extension, true);
                    //
                    // resize image old
                    int video_width = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["postImage_maxWidth"]);
                    image_resizer.Resize_Image(System.Configuration.ConfigurationManager.AppSettings["newsImageStorage_Path"] + "\\" + p_Post.post_guid + fileInf.Extension, video_width, -1, System.Drawing.Imaging.ImageFormat.Jpeg);

                    //save thumbnail
                    System.IO.FileInfo thumb_file     = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_post" + extension);
                    string             new_thumb_path = System.Configuration.ConfigurationManager.AppSettings["newsImageStorage_Path"] + "\\thumb_" + p_Post.post_guid + thumb_file.Extension;
                    thumb_file.CopyTo(new_thumb_path, true);

                    int thumb_width = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["postThumb_maxWidth"]);
                    image_resizer.Resize_Image(new_thumb_path, thumb_width, -1, System.Drawing.Imaging.ImageFormat.Jpeg);

                    //save new image
                    System.IO.FileInfo newim_file = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_post" + extension);
                    string             newim_path = System.Configuration.ConfigurationManager.AppSettings["newsImageStorage_Path"] + "\\img_" + p_Post.post_guid + newim_file.Extension;
                    newim_file.CopyTo(newim_path, true);

                    int newim_width = Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["newPostImage_maxWidth"]);
                    image_resizer.Resize_Image(newim_path, newim_width, -1, System.Drawing.Imaging.ImageFormat.Jpeg);

                    //delete file
                    System.IO.FileInfo del_file = new System.IO.FileInfo(Server.MapPath("~/uploads") + "\\" + "new_post" + extension);
                    del_file.Delete();
                    p_Post.post_image = p_Post.post_guid + fileInf.Extension;
                    //
                    // save post after image is done
                    newsManager.EditPost(p_Post);
                }
            }
        }
示例#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 AddNewPost()
        {
            newsPost newPost = new newsPost();

            return(View(newPost));
        }
示例#6
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"));
        }