public async Task <IActionResult> Edit(int id, [Bind("PkJobAttachmentId,FkAttachmentJob,JobAttachmentFilePath,JobAttachmentFileName,JobAttachmentDownloadName")] TblJobAttachment tblJobAttachment) { if (id != tblJobAttachment.PkJobAttachmentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(tblJobAttachment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TblJobAttachmentExists(tblJobAttachment.PkJobAttachmentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), new{ tblJobAttachment.FkAttachmentJob })); } ViewData["FkAttachmentJob"] = new SelectList(_context.TblJob, "PkJobId", "JobBudget", tblJobAttachment.FkAttachmentJob); return(View(tblJobAttachment)); }
public async Task <IActionResult> Create([Bind("PkJobAttachmentId,FkAttachmentJob,JobAttachmentFilePath,JobAttachmentFileName,JobAttachmentDownloadName")] AttachmentViewModel tblJobAttachment) { if (ModelState.IsValid) { string uniqufilename = null; if (tblJobAttachment.JobAttachmentFilePath != null && tblJobAttachment.JobAttachmentFilePath.Count > 0) { foreach (var attachment in tblJobAttachment.JobAttachmentFilePath) { string filefolder = Path.Combine(_environment.WebRootPath, "Files"); uniqufilename = Guid.NewGuid().ToString() + "_" + attachment.FileName; string filepath = Path.Combine(filefolder, uniqufilename); attachment.CopyTo(new FileStream(filepath, FileMode.Create)); TblJobAttachment jobAttachment = new TblJobAttachment() { FkAttachmentJob = tblJobAttachment.FkAttachmentJob, JobAttachmentDownloadName = tblJobAttachment.JobAttachmentDownloadName, JobAttachmentFileName = tblJobAttachment.JobAttachmentFileName, JobAttachmentFilePath = uniqufilename, }; _context.Add(jobAttachment); } } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index), "TblJobs")); } ViewData["FkAttachmentJob"] = new SelectList(_context.TblJob, "PkJobId", "JobBudget", tblJobAttachment.FkAttachmentJob); return(View(tblJobAttachment)); }
public async Task <IActionResult> Create([Bind("PkJobAttachmentId,FkAttachmentJob,JobAttachmentFilePath,JobAttachmentFileName,JobAttachmentDownloadName")] TblJobAttachment tblJobAttachment) { if (ModelState.IsValid) { _context.Add(tblJobAttachment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FkAttachmentJob"] = new SelectList(_context.TblJob, "PkJobId", "JobBudget", tblJobAttachment.FkAttachmentJob); return(View(tblJobAttachment)); }