// GET: /Instructor/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Instructor instructor = _instructorRepository.FindById(id.Value); if (instructor == null) { return(HttpNotFound()); } return(View(instructor)); }
public models.Instructor Save(VMInstructor entity) { var existingUser = _userRepository.FindByEmail(entity.Email); if (existingUser != null) { throw new CustomHttpException(422, " Esse “E-mail” já existe na base de dados."); } var existingUserWithCpf = _userRepository.FindByCPF(entity.cpf); if (existingUserWithCpf != null) { throw new CustomHttpException(422, " Esse “CPF” já existe na base de dados."); } var existingUserWithRG = _userRepository.FindByRg(entity.RG); if (existingUserWithRG != null) { throw new CustomHttpException(422, " Esse “RG” já existe na base de dados."); } var user = _mapper.Map <User>(entity); user.UserTypeId = 3; user.Password = _passwordManager.HashPassword(user.Password); var transaction = _context.Database.BeginTransaction(); try { var createdUser = _userRepository.Save(user); var instructor = _mapper.Map <models.Instructor>(entity); instructor.userId = createdUser; var createdInstructor = _instructorRepository.Save(instructor); transaction.Commit(); return(_instructorRepository.FindById(createdInstructor)); } catch (Exception ex) { //TODO: Log ex transaction.Rollback(); throw new CustomHttpException(500, "Internal server error"); } }
public IActionResult Courses(int theId) { Instructor instructor = _instructorRepository.FindById(theId); if (instructor == null) { throw new NotFoundInstrunctorException("Not found Instructor"); } ViewBag.Instructor = instructor; return(View(instructor.Courses)); }