public ActionResult EditimgNew(imgNew im) { HttpPostedFileBase file = Request.Files["imgfile"]; if (file != null && file.ContentLength > 0) { try { file.SaveAs(Server.MapPath("~/imgs/" + file.FileName)); im.img = "~/imgs/" + file.FileName; con.Open(); com = new SqlCommand("update imgNew set Headertxt=N'" + im.Headertxt + "',Maintxt=N'" + im.Maintxt + "',img='" + im.img + "',DateNew=N'" + im.DateNew + "',enHeadertxt='" + im.enHeadertxt + "', enMaintxt='" + im.enMaintxt + "' where NewID=" + im.NewID, con); com.ExecuteNonQuery(); con.Close(); return(RedirectToAction("lastNew")); } catch { ViewBag.Emsg = "فشل التعديل"; return(View()); } } else { ViewBag.Emsg = "file not uploaded"; return(View()); } }
public ActionResult EditimgNew(int id) { if (Session["UserLog"] != null) { try { con.Open(); imgNew j = new imgNew(); com = new SqlCommand("select * from imgNew where NewID=" + id + " ", con); SqlDataReader SqlDr = com.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(SqlDr); j.NewID = int.Parse(dt.Rows[0]["NewID"].ToString()); j.Headertxt = dt.Rows[0]["Headertxt"].ToString(); j.Maintxt = dt.Rows[0]["Maintxt"].ToString(); j.enHeadertxt = dt.Rows[0]["enHeadertxt"].ToString(); j.enMaintxt = dt.Rows[0]["enMaintxt"].ToString(); j.img = dt.Rows[0]["img"].ToString(); j.DateNew = Convert.ToDateTime(dt.Rows[0]["DateNew"].ToString()); con.Close(); return(View(j)); } catch { ViewBag.Emsg = "Error occured"; return(View()); }; } else { return(Redirect("Login")); } }
public ActionResult LastNew(imgNew singlenews) { HttpPostedFileBase file = Request.Files["imgfile"]; if (file != null && file.ContentLength > 0) { try { file.SaveAs(Server.MapPath("~/imgs/" + file.FileName)); singlenews.img = "~/imgs/" + file.FileName; con.Open(); com = new SqlCommand("insert into imgNew Values ('" + singlenews.img + "',N'" + singlenews.Headertxt + "','" + singlenews.DateNew + "',N'" + singlenews.Maintxt + "',N'" + singlenews.enHeadertxt + "',N'" + singlenews.enMaintxt + "')", con); com.ExecuteNonQuery(); con.Close(); return(View()); } catch { ViewBag.msg = "your news didn't insert correctly"; return(View()); } } else { ViewBag.msg = "file not uploaded"; return(View()); } }