Created
June 12, 2015 15:31
-
-
Save oclockvn/6be34bbe44e4ec16133e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StudentController : Controller | |
{ | |
private StudentRepository _studentRepo = new StudentRepository(); | |
public ActionResult Index() | |
{ | |
var students = _studentRepo.SelectAll().ToList(); | |
return View(students); | |
} | |
[HttpPost] | |
public ActionResult Insert(Student student) | |
{ | |
if (!ModelState.IsValid) | |
{ | |
// todo | |
} | |
try | |
{ | |
_studentRepo.Insert(student); | |
_studentRepo.Save(); | |
} | |
catch (Exception) | |
{ | |
// todo | |
} | |
return RedirectToAction("Index"); | |
} | |
[HttpPost] | |
public ActionResult Update(Student student) | |
{ | |
if (!ModelState.IsValid) | |
{ | |
// todo | |
} | |
try | |
{ | |
_studentRepo.Update(student); | |
_studentRepo.Save(); | |
} | |
catch (Exception) | |
{ | |
// todo | |
} | |
return RedirectToAction("Index"); | |
} | |
public ActionResult Delete(int? id) | |
{ | |
if (!ModelState.IsValid) | |
{ | |
// todo | |
} | |
try | |
{ | |
_studentRepo.Delete(id); | |
_studentRepo.Save(); | |
} | |
catch (Exception) | |
{ | |
// todo | |
} | |
return RedirectToAction("Index"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment