Exemple #1
0
        public ActionResult UploadPostImageEdit(HttpPostedFileBase file, int post_id)
        {
            if (Session["Roles"] != null && Session["Roles"].Equals("Admin"))
            {
                if (file != null && file.ContentLength > 0)
                {
                    hypster_tv_DAL.newsManagement_Admin newsManager   = new hypster_tv_DAL.newsManagement_Admin();
                    hypster_tv_DAL.Image_Resize_Manager image_resizer = new hypster_tv_DAL.Image_Resize_Manager();

                    hypster_tv_DAL.newsPost p_Post = new hypster_tv_DAL.newsPost();
                    p_Post = newsManager.GetPostByID(post_id);

                    var extension = System.IO.Path.GetExtension(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);
                }
                return(RedirectToAction("Edit", new { id = post_id }));
            }
            else
            {
                return(RedirectPermanent("/home/"));
            }
        }
Exemple #2
0
 public ActionResult Edit(int id)
 {
     if (Session["Roles"] != null && Session["Roles"].Equals("Admin"))
     {
         hypster_tv_DAL.newsPost             newsPost    = new hypster_tv_DAL.newsPost();
         hypster_tv_DAL.newsManagement_Admin newsManager = new hypster_tv_DAL.newsManagement_Admin();
         newsPost   = newsManager.GetPostByID(id);
         ViewBag.ID = id;
         return(View(newsPost));
     }
     else
     {
         return(RedirectPermanent("/home/"));
     }
 }