public async Task <ActionResult> Edit([Bind(Include = "Id,ImgPath,StaffId")] StaffImage staffImage) { if (ModelState.IsValid) { db.Entry(staffImage).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(staffImage)); }
public async Task <ActionResult> Create([Bind(Include = "Id,ImgPath,StaffId")] StaffImage staffImage, HttpPostedFileBase file) { //if (ModelState.IsValid) //{ //var staffId = "stf001"; var fileName = string.Empty; var filePath = string.Empty; if (file.ContentLength > 0 && file != null) { filePath = file.FileName; fileName = Path.GetFileName(file.FileName); } else { ViewBag.Error = " please select image to continue."; return(View(staffImage)); } //AppDomain.CurrentDomain.BaseDirectory + "/App_Data/StaffImages"; //var folderPath = Server.MapPath("~/Captures"); var folderPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/Captures"); //var folderPath = AppDomain.CurrentDomain.BaseDirectory + "~/Content/Captures"; //Server.MapPath("~/Captures"); var fullFilePath = Path.Combine(folderPath, filePath); file.SaveAs(fullFilePath); staffImage.ImgPath = filePath; staffImage.StaffId = Utility.StaffId; //staffImage.StaffId = staffId; db.StaffImages.Add(staffImage); await db.SaveChangesAsync(); return(RedirectToAction("Index", "Home")); //} //return View(staffImage); }