public ActionResult PostUpdate(posttable p1, string nopostphoto, string nopwphoto) { var post = db.posttables.Find(p1.id); var zaman = p1.posttime; if (p1.postphoto != null) { var image = Request.Files[0]; if ((5 * 1024 * 1024) < image.ContentLength) { throw new Exception("hata mesaaji"); } var fileInfo = new FileInfo(image.FileName); var pic = "pic_" + DateTime.Now.Ticks + fileInfo.Extension; //new file name var filePath = "/Photos/post/" + pic; //sen bunu db'ye yaz.. var tempFilePath = Server.MapPath("~\\Photos\\post\\" + pic); image.SaveAs(tempFilePath); post.postphoto = filePath; } if (p1.previewphoto != null) { var image = Request.Files[1]; if ((5 * 1024 * 1024) < image.ContentLength) { throw new Exception("hata mesaaji"); } var fileInfo = new FileInfo(image.FileName); var pic = "pic_" + DateTime.Now.Ticks + fileInfo.Extension; //new file name var filePath = "/Photos/post/" + pic; //sen bunu db'ye yaz.. var tempFilePath = Server.MapPath("~\\Photos\\post\\" + pic); image.SaveAs(tempFilePath); post.previewphoto = filePath; } if (nopostphoto == "sil") { post.postphoto = null; } if (nopwphoto == "sil") { post.previewphoto = null; } post.monthid = p1.monthid; post.categoryid = p1.categoryid; post.userid = p1.userid; post.sorusturmaid = p1.sorusturmaid; post.postcontent = p1.postcontent; post.posttime = Convert.ToDateTime(zaman); post.posttitle = p1.posttitle; post.postspot = p1.postspot; post.isaktif = p1.isaktif; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult NewPost(string posttitle, string postcontent, int categoryid, int userid, int isaktif, string previewphoto, string postphoto, string posttime, int monthid, int sorusturmaid, string postspot) { string zaman = posttime; var ekle = new posttable { posttitle = posttitle, postcontent = postcontent, categoryid = categoryid, userid = userid, previewphoto = previewphoto, postphoto = postphoto, isaktif = isaktif, posttime = Convert.ToDateTime(zaman), monthid = monthid, sorusturmaid = sorusturmaid, postspot = postspot, }; if (postphoto != null) { var image = Request.Files[0]; if ((5 * 1024 * 1024) < image.ContentLength) //5MB { throw new Exception("hata mesaaji"); } var fileInfo = new FileInfo(image.FileName); var pic = "pic_" + DateTime.Now.Ticks + fileInfo.Extension; var filePath = "/Photos/post/" + pic; var tempFilePath = Server.MapPath("~\\Photos\\post\\" + pic); image.SaveAs(tempFilePath); ekle.postphoto = filePath; } if (previewphoto != null) { var smallimage = Request.Files[1]; var smallfileInfo = new FileInfo(smallimage.FileName); var smallpic = "smallpic_" + DateTime.Now.Ticks + smallfileInfo.Extension; var smallfilePath = "/Photos/post/" + smallpic; var smalltempFilePath = Server.MapPath("~\\Photos\\post\\" + smallpic); smallimage.SaveAs(smalltempFilePath); ekle.previewphoto = smallfilePath; } db.posttables.Add(ekle); db.SaveChanges(); return(RedirectToAction("Index")); }