public JsonResult Create(Employee anEmployee) { string msg = ""; int value = 1; HttpPostedFileBase imageFile = Request.Files["UploadedImage"]; imageFile.SaveAs(HttpContext.Server.MapPath("~/ImageUpload/" + imageFile.FileName)); anEmployee.ImagePath = imageFile.FileName; try { if (ModelState.IsValid) { db.Employees.Add(anEmployee); db.SaveChanges(); value = 1; msg = "Successfully employee added"; } } catch (Exception ex) { value = 2; msg = "there have an error."; } return Json(new{valid = value, message = msg,},JsonRequestBehavior.AllowGet); }
public JsonResult Edit(Employee anEmployee) { string msg = ""; int value = 1; HttpPostedFileBase imageFile = Request.Files["UploadedImage"]; imageFile.SaveAs(HttpContext.Server.MapPath("~/ImageUpload/" + imageFile.FileName)); anEmployee.ImagePath = imageFile.FileName; try { if (ModelState.IsValid) { db.Entry(anEmployee).State = EntityState.Modified; db.SaveChanges(); value = 1; msg = "Successfully updated"; } } catch (Exception ex) { value = 2; msg = ex.Message; } return Json(new {valid = value,message = msg}, JsonRequestBehavior.AllowGet); }