示例#1
0
 private void EditValueBind(Article model)
 {
     Session["file_info"] = model.FileName;
     Session["db_file"] = model.FileName;
     ViewBag.Picture = "<img src=\"" + model.FileName + "\" />";
     ViewBag.Count = model.Content;
 }
示例#2
0
        private void SavePicture(Article article)
        {
            if (Session["file_info"] != null)
            {
                List<Thumbnail> thumbnails = Session["file_info"] as List<Thumbnail>;

                string UploadPath = Server.MapPath(filePath);

                var fileName = "";
                var orginalImge = Session["OriginalImage"] as HttpPostedFile;
                if (orginalImge != null)
                {
                    var extension = Path.GetExtension(orginalImge.FileName);
                    foreach (Thumbnail img in thumbnails)
                    {
                        fileName = img.ID + extension;
                        orginalImge.SaveAs(Path.Combine(UploadPath, fileName));
                        FileStream fs = new FileStream(UploadPath + "s_" + fileName, FileMode.Create);
                        BinaryWriter bw = new BinaryWriter(fs);
                        bw.Write(img.Data);
                        bw.Close();
                        fs.Close();
                    }
                }
                article.FileName = isSaveFilePath ? (filePath + fileName) : fileName;
                //Session.Remove("file_info");
            }
        }
示例#3
0
        public JsonResult Save(Article article, FormCollection formCollection)
        {
            int result = 0;
            //if (ModelState.IsValid)
            //{
            bool flag;

            article.CategoryId = article.CategoryId == 0 ? Convert.ToInt32(formCollection.Get("CategoryId")) : article.CategoryId;
            article.ID = !string.IsNullOrEmpty(formCollection.Get("id")) ? Convert.ToInt32(formCollection.Get("id")) : article.ID;

            article.UpdateDate = DateTime.Now;
            if (Session["file_info"] != null)
            {
                List<Thumbnail> thumbnails = Session["file_info"] as List<Thumbnail>;
                if (thumbnails != null && thumbnails.Count > 0)
                {
                    article.FileName = thumbnails[0].ID + ".jpg";
                }
            }

            if (Session["db_file"] != Session["file_info"])
            {
                SavePicture(article);
            }
            if (article.ID != 0)
            {
                article.CreateDate = DateTime.Now;
            }
            flag = (article.ID != 0 ? ArticleService.Update(article) : ArticleService.Add(article)) > 0;
            if (flag)
            {
                //if (ContentTemplate.Contains(categoryId.ToString()))
                //{
                TempData["Article"] = article;
                //  return RedirectToAction("Add", new { id = article.ID, cid = categoryId });
                result = 1;

                //}
                // RedirectToAction("List", new { cid = CId });
            }
            // }
            //CategoryBuild();
            //ViewBag.Picture = "<img src=\"" + filePath + Session["file_info"] + "\" />";
            // View(article);
            // return "aa";
            return Json(result);
        }