public async Task <IActionResult> Get(int id) { Instructor dbInstructor = await InstructorRepository.GetAsync(id); if (dbInstructor == null) { return(BadRequest()); } return(Ok(dbInstructor)); }
public async Task <ActionResult> InstructorIndex() { Instructor instructor = null; List <Instructor> res = new List <Instructor>(); using (_instructorRepository = new InstructorRepository()) { ViewBag.Enrollments = await _instructorRepository.GetInstructorEnrollmentsAsync(HttpContext.User.Identity.GetUserId()); instructor = await _instructorRepository.GetAsync(HttpContext.User.Identity.GetUserId()); } return(View(instructor)); }
public async Task <ActionResult> Delete(int id) { Instructor instructor = await InstructorRepository.GetAsync(id); if (instructor == null) { return(NotFound()); } if (!InstructorRepository.Delete(instructor)) { throw new Exception($"Deleting a instructor {id} failed on save."); } return(NoContent()); }
public async Task <ActionResult> Put(int id, [FromBody] InstructorDto instructor) { Instructor dbInstructor = await InstructorRepository.GetAsync(id); if (instructor == null) { return(BadRequest()); } Mapper.Map(instructor, dbInstructor); if (!InstructorRepository.Update(dbInstructor)) { throw new Exception($"Updating a instructor {id} failed on save."); } return(NoContent()); }