2 using System.Collections.Generic;
4 using System.Data.Entity;
10 namespace Projects.Models
12 public class ProjectsController : Controller
14 private ProjectsDBEntities db = new ProjectsDBEntities();
17 public ActionResult Index()
19 var projects = db.Projects.Include(p => p.ProjectUser);
20 return View(projects.ToList());
23 // GET: Projects/Details/5
24 public ActionResult Details(int? id)
28 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
30 Project project = db.Projects.Find(id);
33 return HttpNotFound();
38 // GET: Projects/Create
39 public ActionResult Create()
41 ViewBag.user_id = new SelectList(db.ProjectUsers, "id", "login");
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.
49 [ValidateAntiForgeryToken]
50 public ActionResult Create([Bind(Include = "id,user_id,name,description,created_at,updated_at")] Project project)
52 if (ModelState.IsValid)
54 db.Projects.Add(project);
56 return RedirectToAction("Index");
59 ViewBag.user_id = new SelectList(db.ProjectUsers, "id", "login", project.user_id);
63 // GET: Projects/Edit/5
64 public ActionResult Edit(int? id)
68 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
70 Project project = db.Projects.Find(id);
73 return HttpNotFound();
75 ViewBag.user_id = new SelectList(db.ProjectUsers, "id", "login", project.user_id);
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.
83 [ValidateAntiForgeryToken]
84 public ActionResult Edit([Bind(Include = "id,user_id,name,description,created_at,updated_at")] Project project)
86 if (ModelState.IsValid)
88 db.Entry(project).State = EntityState.Modified;
90 return RedirectToAction("Index");
92 ViewBag.user_id = new SelectList(db.ProjectUsers, "id", "login", project.user_id);
96 // GET: Projects/Delete/5
97 public ActionResult Delete(int? id)
101 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
103 Project project = db.Projects.Find(id);
106 return HttpNotFound();
108 return View(project);
111 // POST: Projects/Delete/5
112 [HttpPost, ActionName("Delete")]
113 [ValidateAntiForgeryToken]
114 public ActionResult DeleteConfirmed(int id)
116 Project project = db.Projects.Find(id);
117 db.Projects.Remove(project);
119 return RedirectToAction("Index");
122 protected override void Dispose(bool disposing)
128 base.Dispose(disposing);