// GET: Projects
public ActionResult Index()
{
- var projects = db.Projects.Include(p => p.ProjectUser);
+ var projects = db.Projects.Include(p => p.User);
return View(projects.ToList());
}
}
// GET: Projects/Create
+ [Authorize(Roles = "admin")]
public ActionResult Create()
{
- ViewBag.user_id = new SelectList(db.ProjectUsers, "id", "login");
+ ViewBag.user_id = new SelectList(db.Users, "id", "login");
return View();
}
// POST: Projects/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
+ [Authorize(Roles = "admin")]
[HttpPost]
[ValidateAntiForgeryToken]
- public ActionResult Create([Bind(Include = "id,user_id,name,description,created_at,updated_at")] Project project)
+ public ActionResult Create([Bind(Include = "id,user_id,name,description")] Project project)
{
if (ModelState.IsValid)
{
+ project.created_at = DateTime.Now;
+ project.updated_at = DateTime.Now;
db.Projects.Add(project);
db.SaveChanges();
return RedirectToAction("Index");
}
- ViewBag.user_id = new SelectList(db.ProjectUsers, "id", "login", project.user_id);
+ ViewBag.user_id = new SelectList(db.Users, "id", "login", project.user_id);
return View(project);
}
// GET: Projects/Edit/5
+ [Authorize(Roles = "admin")]
public ActionResult Edit(int? id)
{
if (id == null)
{
return HttpNotFound();
}
- ViewBag.user_id = new SelectList(db.ProjectUsers, "id", "login", project.user_id);
+ ViewBag.user_id = new SelectList(db.Users, "id", "login", project.user_id);
return View(project);
}
// POST: Projects/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
+ [Authorize(Roles = "admin")]
[HttpPost]
[ValidateAntiForgeryToken]
- public ActionResult Edit([Bind(Include = "id,user_id,name,description,created_at,updated_at")] Project project)
+ public ActionResult Edit([Bind(Include = "id,user_id,name,description,created_at")] Project project)
{
if (ModelState.IsValid)
{
+ project.updated_at = DateTime.Now;
db.Entry(project).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
- ViewBag.user_id = new SelectList(db.ProjectUsers, "id", "login", project.user_id);
+ ViewBag.user_id = new SelectList(db.Users, "id", "login", project.user_id);
return View(project);
}
// GET: Projects/Delete/5
+ [Authorize(Roles = "admin")]
public ActionResult Delete(int? id)
{
if (id == null)
}
// POST: Projects/Delete/5
+ [Authorize(Roles = "admin")]
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)