73205a873fce7718732831287ff24ec44f7b6c20
[wsti_pai.git] / Projects / Controllers / ProjectsController.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Data;
4 using System.Data.Entity;
5 using System.Linq;
6 using System.Net;
7 using System.Web;
8 using System.Web.Mvc;
9
10 namespace Projects.Models
11 {
12     public class ProjectsController : Controller
13     {
14         private ProjectsDBEntities db = new ProjectsDBEntities();
15
16         // GET: Projects
17         public ActionResult Index()
18         {
19             var projects = db.Projects.Include(p => p.User);
20             return View(projects.ToList());
21         }
22
23         // GET: Projects/Details/5
24         public ActionResult Details(int? id)
25         {
26             if (id == null)
27             {
28                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
29             }
30             Project project = db.Projects.Find(id);
31             if (project == null)
32             {
33                 return HttpNotFound();
34             }
35             return View(project);
36         }
37
38         // GET: Projects/Create
39         public ActionResult Create()
40         {
41             ViewBag.user_id = new SelectList(db.Users, "id", "login");
42             return View();
43         }
44
45         // POST: Projects/Create
46         // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
47         // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
48         [HttpPost]
49         [ValidateAntiForgeryToken]
50         public ActionResult Create([Bind(Include = "id,user_id,name,description,created_at,updated_at")] Project project)
51         {
52             if (ModelState.IsValid)
53             {
54                 db.Projects.Add(project);
55                 db.SaveChanges();
56                 return RedirectToAction("Index");
57             }
58
59             ViewBag.user_id = new SelectList(db.Users, "id", "login", project.user_id);
60             return View(project);
61         }
62
63         // GET: Projects/Edit/5
64         public ActionResult Edit(int? id)
65         {
66             if (id == null)
67             {
68                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
69             }
70             Project project = db.Projects.Find(id);
71             if (project == null)
72             {
73                 return HttpNotFound();
74             }
75             ViewBag.user_id = new SelectList(db.Users, "id", "login", project.user_id);
76             return View(project);
77         }
78
79         // POST: Projects/Edit/5
80         // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
81         // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
82         [HttpPost]
83         [ValidateAntiForgeryToken]
84         public ActionResult Edit([Bind(Include = "id,user_id,name,description,created_at,updated_at")] Project project)
85         {
86             if (ModelState.IsValid)
87             {
88                 db.Entry(project).State = EntityState.Modified;
89                 db.SaveChanges();
90                 return RedirectToAction("Index");
91             }
92             ViewBag.user_id = new SelectList(db.Users, "id", "login", project.user_id);
93             return View(project);
94         }
95
96         // GET: Projects/Delete/5
97         public ActionResult Delete(int? id)
98         {
99             if (id == null)
100             {
101                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
102             }
103             Project project = db.Projects.Find(id);
104             if (project == null)
105             {
106                 return HttpNotFound();
107             }
108             return View(project);
109         }
110
111         // POST: Projects/Delete/5
112         [HttpPost, ActionName("Delete")]
113         [ValidateAntiForgeryToken]
114         public ActionResult DeleteConfirmed(int id)
115         {
116             Project project = db.Projects.Find(id);
117             db.Projects.Remove(project);
118             db.SaveChanges();
119             return RedirectToAction("Index");
120         }
121
122         protected override void Dispose(bool disposing)
123         {
124             if (disposing)
125             {
126                 db.Dispose();
127             }
128             base.Dispose(disposing);
129         }
130     }
131 }