public async Task <IActionResult> Edit(string id, [Bind("ProgrammeID,ProgrammeName,ProgrammeDescription,ProgrammeQQILevel,ProgrammeCredits,ProgrammeCost")] Programme programme) { if (id != programme.ProgrammeID) { return(NotFound()); } if (ModelState.IsValid) { try { programmeRepository.Update(programme); await programmeRepository.SaveChangesAsync(); return(RedirectToAction("Details", new { id = programme.ProgrammeID })); } catch (DataAccessException e) { if (!ProgrammeExists(programme.ProgrammeID)) { return(NotFound()); } ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e); return(RedirectToAction("Unknown", "Error")); } catch (Exception e) { ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e); return(RedirectToAction("Unknown", "Error")); } } return(View(programme)); }
public async Task <IActionResult> PutProgrammeAsync(string id, [FromBody] ProgrammeDto programme) { if (id != programme.ProgrammeId) { _logger.LogWarning($"Put programme. Id {id} does not match {programme.ProgrammeId}."); return(BadRequest()); } try { var programmeFromDb = await _programmeRepository.FindByIdAsync(id); if (programmeFromDb == null) { _logger.LogWarning($"Get programme. Id {id} not found."); return(NotFound($"Programme {id} not found")); } // Map all properties except Id programmeFromDb.Name = programme.Name; programmeFromDb.Description = programme.Description; var result = _programmeRepository.Update(programmeFromDb); if (result == null) { _logger.LogWarning($"Put programme. Id {id} not found."); return(NotFound()); } await _programmeRepository.SaveChangesAsync(); } catch (DataAccessException e) { _logger.LogCritical(e, "Update failed."); return(BadRequest($"Update of programme {id} failed.")); } return(NoContent()); }