public IActionResult CreateProfessor(ProfessorInputViewModel model) { if (!ModelState.IsValid) { return(this.View()); } var professor = new Professor { FullName = model.FullName, ScienceDegree = model.ScienceDegree, PhoneNumber = model.PhoneNumber, Email = model.Email }; dbContext.Add(professor); try { dbContext.SaveChanges(); return(this.RedirectToAction("Details", new { Id = professor.Id })); } catch (Exception e) { return(this.BadRequest(e.Message)); } }
public IActionResult EditProfessor(ProfessorInputViewModel model, int id) { if (!ModelState.IsValid) { return(this.View(model)); } var professor = dbContext.Professors.FirstOrDefault(c => c.Id == id); if (professor == null) { return(this.BadRequest("Invalid professor ID.")); } professor.FullName = model.FullName; professor.ScienceDegree = model.ScienceDegree; professor.PhoneNumber = model.PhoneNumber; professor.Email = professor.Email; try { this.dbContext.SaveChanges(); return(this.RedirectToAction("Details", new { Id = id })); } catch (Exception e) { return(this.BadRequest(e.Message)); } }
public IActionResult DeleteProfessor(int id) { var professor = dbContext.Professors.FirstOrDefault(c => c.Id == id); if (professor == null) { return(this.BadRequest("Invalid professor ID.")); } var viewModel = new ProfessorInputViewModel { FullName = professor.FullName, ScienceDegree = professor.ScienceDegree, PhoneNumber = professor.PhoneNumber, Email = professor.Email }; return(this.View(viewModel)); }