public ActionResult setNewCatArticle(string image, string title) { string pathString = "~/images/panelimages"; if (!Directory.Exists(Server.MapPath(pathString))) { DirectoryInfo di = Directory.CreateDirectory(Server.MapPath(pathString)); } string imagename = ""; for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase hpf = Request.Files[i]; if (hpf.ContentLength == 0) { continue; } imagename = RandomString(7) + Path.GetExtension(hpf.FileName); string savedFileName = Path.Combine(Server.MapPath(pathString), imagename); hpf.SaveAs(savedFileName); } string device = RandomString(10); //string code = MD5Hash(device + "ncase8934f49909"); articleCat NewCat = new articleCat() { image = imagename, title = title, titleEn = RandomString(5), }; dbRespose res = manager.addArticleCat(NewCat); if (res.status == 200) { return(RedirectToAction("blog")); } else { return(RedirectToAction("blog")); } }
public ActionResult updateCArticle(int CIDupdate, string Cimageupdate, string Ctitleupdate) { string imagename = ""; string pathString = "~/images/panelimages"; if (Cimageupdate != "") { string oldFileName = Path.Combine(Server.MapPath(pathString), Path.GetFileName(Cimageupdate)); System.IO.File.Delete(oldFileName); } if (!Directory.Exists(Server.MapPath(pathString))) { DirectoryInfo di = Directory.CreateDirectory(Server.MapPath(pathString)); } for (int i = 0; i < Request.Files.Count; i++) { HttpPostedFileBase hpf = Request.Files[i]; if (hpf.ContentLength == 0) { continue; } imagename = RandomString(7) + Path.GetExtension(hpf.FileName); string savedFileName = Path.Combine(Server.MapPath(pathString), imagename); hpf.SaveAs(savedFileName); } articleCat model = new articleCat() { image = imagename, title = Ctitleupdate, articleCatID = CIDupdate, }; dbRespose response = manager.updataCatArtice(model); if (response.status == 200) { return(RedirectToAction("blog")); } else { return(RedirectToAction("blog")); } //string device = RandomString(10); //string code = MD5Hash(device + "ncase8934f49909"); //string result = ""; //using (WebClient client = new WebClient()) //{ // var collection = new NameValueCollection(); // collection.Add("servername", servername); // collection.Add("device", device); // collection.Add("code", code); // collection.Add("image", imagename); // collection.Add("title", Ctitleupdate); // collection.Add("ID", CIDupdate); // byte[] response = client.UploadValues(ConfigurationManager.AppSettings["server"] + "/Admin/UpdateCArticles.php", collection); // result = System.Text.Encoding.UTF8.GetString(response); //} }