public bool GetFilesUploaded(tblFileUploaded f) { ComfortComplianceDeadlineDBEntities1 context = new ComfortComplianceDeadlineDBEntities1(); using (context) { using (context) { context.tblFileUploadeds.Add(f); context.SaveChanges(); return(true); } } }
public ActionResult Index(UploadFileModel filemodel, HttpPostedFileBase fileUpload) { if (ModelState.IsValid) { HttpPostedFileBase file = fileUpload; ViewBag.Branch = CommonHelper.ToSelectItemList(ch.GetBranch()); ViewBag.FileCategory = CommonHelper.ToSelectItemList(ch.GetFileCategory()); tblFileUploaded fu = new tblFileUploaded(); fu.Dateofentery = DateTime.Today; //fu.Filuploaded_Id = new FileToUploadedDetail { Id = uh.GetFileDetail(Convert.ToInt32(productmodel.Branch), Convert.ToInt32(productmodel.Department)) }; ; fu.Filuploaded_Id = uh.GetFileDetail(Convert.ToInt32(filemodel.FileType), Convert.ToInt32(filemodel.Department)); ; if (!string.IsNullOrEmpty(file.FileName)) { try { string path = Path.Combine(Server.MapPath("~/Images/"), Path.GetFileName(fileUpload.FileName)); if (System.IO.File.Exists(path)) { ViewBag.Message = "The File Already Exists in System"; } else { file.SaveAs(path); fu.Path = path; } } catch (Exception exception) { ViewBag.Message = "ERROR:" + exception.Message.ToString(); } } //else //{ // ViewBag.Message = "Specify the file"; //} //if (!string.IsNullOrEmpty(file.FileName)) //{ // //string url = "~/Images/" + file.FileName.Substring(file.FileName.LastIndexOf(".")); // //string path = Server.MapPath(url); //} fu.User_Id = 1; ufh.AddNewFile(fu); } return(View()); }