-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathContactsController.cs
More file actions
89 lines (77 loc) · 2.11 KB
/
Copy pathContactsController.cs
File metadata and controls
89 lines (77 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using SharpRepository.Repository;
using SharpRepository.Samples.MVC5.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SharpRepository.Samples.MVC5.Controllers
{
public class ContactsController : Controller
{
IRepository<Contact, int> repository;
public ContactsController(IRepository<Contact, int> repository)
{
this.repository = repository;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
repository.Dispose();
}
base.Dispose(disposing);
}
// GET: Contacts
public ActionResult Index()
{
var contacs = repository.GetAll();
return View(contacs);
}
// GET: Contacts/Details/5
public ActionResult Details(int id)
{
var contact = repository.Get(id);
return View(contact);
}
// GET: Contacts/Create
public ActionResult Create()
{
return View();
}
// POST: Contacts/Create
[HttpPost]
public ActionResult Create(Contact contact)
{
repository.Add(contact);
return RedirectToAction("Index");
}
// GET: Contacts/Edit/5
public ActionResult Edit(int id)
{
var contact = repository.Get(id);
return View(contact);
}
// POST: Contacts/Edit/5
[HttpPost]
public ActionResult Edit(Contact contact)
{
repository.Update(contact);
return RedirectToAction("Index");
}
// GET: Contacts/Delete/5
public ActionResult Delete(int id)
{
var contact = repository.Get(id);
return View(contact);
}
// POST: Contacts/Delete/5
[HttpPost]
[ActionName("Delete")]
public ActionResult DeletePost(int id)
{
repository.Delete(id);
return RedirectToAction("Index");
}
}
}