public JsonResult UploadFile() { var status = false; HttpPostedFileBase myFile = null; if (Request.Files.Count > 0) myFile = Request.Files[0]; if (myFile != null && myFile.ContentLength != 0) { string pathForSaving = Server.MapPath("~/ImageUploads"); if (SharedFunction.CreateFolderIfNeeded(pathForSaving)) { try { string fileName = DateTime.Now.ToString("MMddyyyyHHmmss") + Path.GetExtension(myFile.FileName); myFile.SaveAs(Path.Combine(pathForSaving, fileName)); string path = "~/ImageUploads/" + fileName; var officesManager = new DataAccess.OfficeMananer(); status = officesManager.Add(Request.Form["name"].ToString(), Request.Form["contactNo"].ToString(), Request.Form["city"].ToString(), Request.Form["userID"].Split(',').ToList(), path, myFile.FileName); } catch (Exception ex) { return Json(ex.InnerException); } } } return Json(status); }
public JsonResult Add(string name, string contactNo, string city, List<string> userID) { if (!IsAdmin) { return Json(false); } var officesManager = new DataAccess.OfficeMananer(); return Json(officesManager.Add(name, contactNo, city, userID)); }