Skip to content

Instantly share code, notes, and snippets.

@oclockvn
Created June 12, 2015 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oclockvn/6be34bbe44e4ec16133e to your computer and use it in GitHub Desktop.
Save oclockvn/6be34bbe44e4ec16133e to your computer and use it in GitHub Desktop.
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