From 5b4b7fb2dc8e07cdfe9a30c321191444d05fe24a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Fri, 12 Feb 2016 02:41:51 +0100 Subject: [PATCH] Automatically update creation and modification date --- .../Controllers/ProjectTasksController.cs | 5 +++- Projects/Controllers/ProjectsController.cs | 7 +++-- Projects/Views/ProjectTasks/Create.cshtml | 16 ---------- Projects/Views/ProjectTasks/Edit.cshtml | 29 +++++++++---------- Projects/Views/Projects/Create.cshtml | 16 ---------- Projects/Views/Projects/Edit.cshtml | 29 +++++++++---------- 6 files changed, 35 insertions(+), 67 deletions(-) diff --git a/Projects/Controllers/ProjectTasksController.cs b/Projects/Controllers/ProjectTasksController.cs index 05d73ac..81cb093 100644 --- a/Projects/Controllers/ProjectTasksController.cs +++ b/Projects/Controllers/ProjectTasksController.cs @@ -54,6 +54,8 @@ namespace Projects.Controllers { if (ModelState.IsValid) { + projectTask.created_at = DateTime.Now; + projectTask.updated_at = DateTime.Now; db.ProjectTasks.Add(projectTask); db.SaveChanges(); return RedirectToAction("Index"); @@ -88,10 +90,11 @@ namespace Projects.Controllers // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [HttpPost] [ValidateAntiForgeryToken] - public ActionResult Edit([Bind(Include = "id,project_id,name,description,created_at,updated_at,task_status_id,user_id")] ProjectTask projectTask) + public ActionResult Edit([Bind(Include = "id,project_id,name,description,task_status_id,user_id,created_at")] ProjectTask projectTask) { if (ModelState.IsValid) { + projectTask.updated_at = DateTime.Now; db.Entry(projectTask).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); diff --git a/Projects/Controllers/ProjectsController.cs b/Projects/Controllers/ProjectsController.cs index 73205a8..b6f57e6 100644 --- a/Projects/Controllers/ProjectsController.cs +++ b/Projects/Controllers/ProjectsController.cs @@ -47,10 +47,12 @@ namespace Projects.Models // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [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"); @@ -81,10 +83,11 @@ namespace Projects.Models // more details see http://go.microsoft.com/fwlink/?LinkId=317598. [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"); diff --git a/Projects/Views/ProjectTasks/Create.cshtml b/Projects/Views/ProjectTasks/Create.cshtml index 82477af..a167294 100644 --- a/Projects/Views/ProjectTasks/Create.cshtml +++ b/Projects/Views/ProjectTasks/Create.cshtml @@ -39,22 +39,6 @@ -
- @Html.LabelFor(model => model.created_at, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.created_at, "", new { @class = "text-danger" }) -
-
- -
- @Html.LabelFor(model => model.updated_at, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.updated_at, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.updated_at, "", new { @class = "text-danger" }) -
-
-
@Html.LabelFor(model => model.task_status_id, "task_status_id", htmlAttributes: new { @class = "control-label col-md-2" })
diff --git a/Projects/Views/ProjectTasks/Edit.cshtml b/Projects/Views/ProjectTasks/Edit.cshtml index 7940148..4a934bf 100644 --- a/Projects/Views/ProjectTasks/Edit.cshtml +++ b/Projects/Views/ProjectTasks/Edit.cshtml @@ -16,6 +16,19 @@
@Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.id) +
+ +
+

@Html.DisplayFor(model => model.created_at)

+ @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control", @type = "hidden" } }) +
+
+
+ +
+ +
+
@Html.LabelFor(model => model.project_id, "project_id", htmlAttributes: new { @class = "control-label col-md-2" }) @@ -41,22 +54,6 @@
-
- @Html.LabelFor(model => model.created_at, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.created_at, "", new { @class = "text-danger" }) -
-
- -
- @Html.LabelFor(model => model.updated_at, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.updated_at, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.updated_at, "", new { @class = "text-danger" }) -
-
-
@Html.LabelFor(model => model.task_status_id, "task_status_id", htmlAttributes: new { @class = "control-label col-md-2" })
diff --git a/Projects/Views/Projects/Create.cshtml b/Projects/Views/Projects/Create.cshtml index 0f4357a..ca38e5c 100644 --- a/Projects/Views/Projects/Create.cshtml +++ b/Projects/Views/Projects/Create.cshtml @@ -39,22 +39,6 @@
-
- @Html.LabelFor(model => model.created_at, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.created_at, "", new { @class = "text-danger" }) -
-
- -
- @Html.LabelFor(model => model.updated_at, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.updated_at, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.updated_at, "", new { @class = "text-danger" }) -
-
-
diff --git a/Projects/Views/Projects/Edit.cshtml b/Projects/Views/Projects/Edit.cshtml index 991750a..b74df62 100644 --- a/Projects/Views/Projects/Edit.cshtml +++ b/Projects/Views/Projects/Edit.cshtml @@ -16,6 +16,19 @@
@Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.id) +
+ +
+

@Html.DisplayFor(model => model.created_at)

+ @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control", @type = "hidden" } }) +
+
+
+ +
+ +
+
@Html.LabelFor(model => model.user_id, "user_id", htmlAttributes: new { @class = "control-label col-md-2" }) @@ -41,22 +54,6 @@
-
- @Html.LabelFor(model => model.created_at, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.created_at, "", new { @class = "text-danger" }) -
-
- -
- @Html.LabelFor(model => model.updated_at, htmlAttributes: new { @class = "control-label col-md-2" }) -
- @Html.EditorFor(model => model.updated_at, new { htmlAttributes = new { @class = "form-control" } }) - @Html.ValidationMessageFor(model => model.updated_at, "", new { @class = "text-danger" }) -
-
-
-- 2.30.2