public ActionResult AddImg(ProfileImg model, HttpPostedFileBase imageUpload) { var db = new NewsEntities(); string currentUserId = User.Identity.GetUserId(); model.jourId = currentUserId; ProfileImg img1 = db.ProfileImgs.FirstOrDefault(i => i.jourId == currentUserId); //if (db.ProfileImgs.Where(m => model.jourId == currentUserId) == null) //{ if (img1 == null) { if (imageUpload != null) { model.img = new byte[imageUpload.ContentLength]; imageUpload.InputStream.Read(model.img, 0, imageUpload.ContentLength); var fileName = Path.GetFileName(imageUpload.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); imageUpload.SaveAs(path); ViewBag.fileName = imageUpload.FileName; } db.ProfileImgs.Add(model); db.SaveChanges(); ViewBag.Message = "File uploaded successfully."; } else { ViewBag.Message = "You have already upload an profile image before."; } return(View(model)); }
// GET: Journalists/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Journalist journalist = db.Journalists.Find(id); if (journalist == null) { return(HttpNotFound()); } ProfileImg imgRecord = journalist.ProfileImgs.FirstOrDefault(i => i.jourId == id); if (imgRecord != null) { ViewBag.img = imgRecord.img; ViewBag.message = ""; } else { ViewBag.img = db.ProfileImgs.Find(13).img; ViewBag.message = "There are no profile image uploaded."; } return(View(journalist)); }
public ActionResult AddImg() { ProfileImg proImg = new ProfileImg(); ViewBag.fileName = "noImg.png"; return(View(proImg)); }
public IActionResult Index() { ProfileImg img = new ProfileImg("user1.jpg"); ViewBag.UserProfile = new Profile("Matt13", img, new Sex("male")); List <Profile> profiles = new List <Profile>() { new Profile("BrianDoggy", null, new Sex("male")), new Profile("Meggy", null, new Sex("female")), new Profile("Warmachine", null, new Sex("ah-64")) }; ViewData["profiles"] = profiles; return(View()); }
protected void ProfileImgSaveBtn_Click(object sender, EventArgs e) { string jk = "select * from app_setting"; DataSet ds = new DataSet(); ds = dc.getdata(jk); if (ds.Tables[0].Rows.Count == 0) { string ext = System.IO.Path.GetExtension(ProfileImg.FileName); if (ext == ".jpg" || ext == ".png" || ext == ".jpeg" || ext == ".gif" || ext == ".GIF" || ext == ".PNG" || ext == ".JPEG" || ext == ".JPG") { ProfileImg.SaveAs(Server.MapPath("~//admin//AppSetting//ProfileImage//" + ProfileImg.FileName)); string path = "~//admin//AppSetting//ProfileImage//" + ProfileImg.FileName; string jkp = "insert into app_setting values('App1','" + path + "')"; dc.setdata(jkp); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Image Added.');", true); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Please select Image Only');", true); } } else { string ext = System.IO.Path.GetExtension(ProfileImg.FileName); if (ext == ".jpg" || ext == ".png" || ext == ".jpeg" || ext == ".gif" || ext == ".GIF" || ext == ".PNG" || ext == ".JPEG" || ext == ".JPG") { ProfileImg.SaveAs(Server.MapPath("~//admin//AppSetting//ProfileImage//" + ProfileImg.FileName)); string path = "~//admin//AppSetting//ProfileImage//" + ProfileImg.FileName; string jkp = "update app_setting set ProfileImg='" + path + "' where Id='App1'"; dc.setdata(jkp); ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Image Updated.');", true); } else { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Please select Image Only');", true); } } }