Code: Select all
// POST: SAEs/Create
[HttpPost]
[ValidateAntiForgeryToken]
public async Task Create([Bind("SAEID,ProjectID,SAEorSUSAR,DateofEvent,DateofNotification,SAECategory,PatientStudyNumber,ReportedToRDOG,DateReportedtoRDOG")] SAE sAE,
string action,
string returnUrl)
{
SAEValidator saevalidator = new SAEValidator();
ValidationResult result = saevalidator.Validate(sAE);
// When validation failed, return to Index View
if (!ModelState.IsValid)
{
foreach (var failure in result.Errors)
{
ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage);
}
ViewData["ProjectID"] = new SelectList(_context.PIF, "ProjectID", "ProjectID", sAE.ProjectID);
var saesusars = _context.SAESUSAR?.ToList();
ViewBag.saesusars = saesusars;
var subcats = _context.SAESubCat?.ToList();
ViewBag.subcats = subcats;
var report = _context.YesNoList?.ToList();
ViewBag.report = report;
return View(sAE);
}
// Perform DB update after validation is passed
try
{
_context.Add(sAE);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!SAEExists(sAE.SAEID))
{
return NotFound();
}
else
{
throw;
}
}
// Ensure all code paths return a value
// Redirection after model validation passed and successfully update to database
if (action == "SaveAndBack" && !String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
return RedirectToAction(nameof(Index));
}
// GET: SAEs/Edit/5
public async Task Edit(int? id)
{
if (id == null || _context.SAE == null)
{
return NotFound();
}
var sAE = await _context.SAE.FindAsync(id);
if (sAE == null)
{
return NotFound();
}
ViewData["ProjectID"] = new SelectList(_context.PIF, "ProjectID", "ProjectID", sAE.ProjectID);
var saesusars = _context.SAESUSAR!.ToList();
ViewBag.saesusarslist = saesusars;
var subcats = _context.SAESubCat!.ToList();
ViewBag.subcatslist = subcats;
var report = _context.YesNoList!.ToList();
ViewBag.reportlist = report;
return View(sAE);
}
// POST: SAEs/Edit/5
// To protect from overposting attacks, enable the specific properties you want to bind to.
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task Edit(int id, [Bind("SAEID,ProjectID,SAEorSUSAR,DateofEvent,DateofNotification,SAECategory,PatientStudyNumber,ReportedToRDOG,DateReportedtoRDOG")] SAE sAE,
string action,
string returnUrl)
{
if (id != sAE.SAEID)
{
return NotFound();
}
SAEValidator saevalidator = new SAEValidator();
ValidationResult result = saevalidator.Validate(sAE);
{
if (!ModelState.IsValid)
{
foreach (var failure in result.Errors)
{
ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage);
}
ViewData["ProjectID"] = new SelectList(_context.PIF, "ProjectID", "ProjectID", sAE.ProjectID);
var report = _context.YesNoList!.ToList();
ViewBag.reportlist = report;
//ViewData["ProjectID"] = new SelectList(_context.PIF, "ProjectID", "ProjectID", sAE.ProjectID);
var saesusars = _context.SAESUSAR!.ToList();
ViewBag.saesusarslist = saesusars;
var subcats = _context.SAESubCat!.ToList();
ViewBag.subcatslist = subcats;
return View(sAE);
}
// Perform DB update after validation is passed
try
{
_context.Update(sAE);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!SAEExists(sAE.SAEID))
{
return NotFound();
}
else
{
throw;
}
}
}
if (action == "SaveAndBack" && !String.IsNullOrEmpty(returnUrl))
{
return Redirect(returnUrl);
}
//return View(sAE);
return RedirectToAction(nameof(Index));
Mobile version