Automatically update creation and modification date
authorRafał Długołęcki <dlugolecki.rafal@gmail.com>
Fri, 12 Feb 2016 01:41:51 +0000 (02:41 +0100)
committerRafał Długołęcki <dlugolecki.rafal@gmail.com>
Fri, 12 Feb 2016 01:41:51 +0000 (02:41 +0100)
Projects/Controllers/ProjectTasksController.cs
Projects/Controllers/ProjectsController.cs
Projects/Views/ProjectTasks/Create.cshtml
Projects/Views/ProjectTasks/Edit.cshtml
Projects/Views/Projects/Create.cshtml
Projects/Views/Projects/Edit.cshtml

index 05d73ac97e2e681570c3328246de5c31c6159260..81cb093977cc6bce6d1207d6a71ce35f6061bdd7 100644 (file)
@@ -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");
index 73205a873fce7718732831287ff24ec44f7b6c20..b6f57e603962ab524df4f0eeb5fcf27c5cfd70eb 100644 (file)
@@ -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");
index 82477afb0c8103cbce4aa64425e72e505c5a9a90..a1672947d0e38cd6962d4c81c57fa4674cc3212b 100644 (file)
             </div>
         </div>
 
-        <div class="form-group">
-            @Html.LabelFor(model => model.created_at, htmlAttributes: new { @class = "control-label col-md-2" })
-            <div class="col-md-10">
-                @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.created_at, "", new { @class = "text-danger" })
-            </div>
-        </div>
-
-        <div class="form-group">
-            @Html.LabelFor(model => model.updated_at, htmlAttributes: new { @class = "control-label col-md-2" })
-            <div class="col-md-10">
-                @Html.EditorFor(model => model.updated_at, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.updated_at, "", new { @class = "text-danger" })
-            </div>
-        </div>
-
         <div class="form-group">
             @Html.LabelFor(model => model.task_status_id, "task_status_id", htmlAttributes: new { @class = "control-label col-md-2" })
             <div class="col-md-10">
index 7940148ceb8fe85d8ca628eff45769a3754e385c..4a934bf609f6d55f4f39dc1af60be72054e26c4a 100644 (file)
         <hr />
         @Html.ValidationSummary(true, "", new { @class = "text-danger" })
         @Html.HiddenFor(model => model.id)
+        <div class="form-group">
+            <label class="control-label col-sm-2" for="createdAt">Wpis utworzony:</label>
+            <div class="col-sm-10">
+                <p class="form-control-static">@Html.DisplayFor(model => model.created_at)</p>
+                @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control", @type = "hidden" } })
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="control-label col-sm-2" for="updatedAt">Ostatnio modyfikowany:</label>
+            <div class="col-sm-10">
+                <input type="text" class="form-control" id="updatedAt" placeholder="@Html.DisplayFor(model => model.updated_at)" readonly>
+            </div>
+        </div>
 
         <div class="form-group">
             @Html.LabelFor(model => model.project_id, "project_id", htmlAttributes: new { @class = "control-label col-md-2" })
             </div>
         </div>
 
-        <div class="form-group">
-            @Html.LabelFor(model => model.created_at, htmlAttributes: new { @class = "control-label col-md-2" })
-            <div class="col-md-10">
-                @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.created_at, "", new { @class = "text-danger" })
-            </div>
-        </div>
-
-        <div class="form-group">
-            @Html.LabelFor(model => model.updated_at, htmlAttributes: new { @class = "control-label col-md-2" })
-            <div class="col-md-10">
-                @Html.EditorFor(model => model.updated_at, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.updated_at, "", new { @class = "text-danger" })
-            </div>
-        </div>
-
         <div class="form-group">
             @Html.LabelFor(model => model.task_status_id, "task_status_id", htmlAttributes: new { @class = "control-label col-md-2" })
             <div class="col-md-10">
index 0f4357a8d687ede2f10505be5d6f8972c774c007..ca38e5c8a7406ccc8d04410a774e975858888f27 100644 (file)
             </div>
         </div>
 
-        <div class="form-group">
-            @Html.LabelFor(model => model.created_at, htmlAttributes: new { @class = "control-label col-md-2" })
-            <div class="col-md-10">
-                @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.created_at, "", new { @class = "text-danger" })
-            </div>
-        </div>
-
-        <div class="form-group">
-            @Html.LabelFor(model => model.updated_at, htmlAttributes: new { @class = "control-label col-md-2" })
-            <div class="col-md-10">
-                @Html.EditorFor(model => model.updated_at, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.updated_at, "", new { @class = "text-danger" })
-            </div>
-        </div>
-
         <div class="form-group">
             <div class="col-md-offset-2 col-md-10">
                 <input type="submit" value="Stwórz" class="btn btn-default" />
index 991750af8cae7494b31c71ffd97a337d4224e729..b74df62284063334f04a4dc58b5b105aa5a7bcff 100644 (file)
         <hr />
         @Html.ValidationSummary(true, "", new { @class = "text-danger" })
         @Html.HiddenFor(model => model.id)
+        <div class="form-group">
+            <label class="control-label col-sm-2" for="createdAt">Wpis utworzony:</label>
+            <div class="col-sm-10">
+                <p class="form-control-static">@Html.DisplayFor(model => model.created_at)</p>
+                @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control", @type = "hidden" } })
+            </div>
+        </div>
+        <div class="form-group">
+            <label class="control-label col-sm-2" for="updatedAt">Ostatnio modyfikowany:</label>
+            <div class="col-sm-10">
+                <input type="text" class="form-control" id="updatedAt" placeholder="@Html.DisplayFor(model => model.updated_at)" readonly>
+            </div>
+        </div>
 
         <div class="form-group">
             @Html.LabelFor(model => model.user_id, "user_id", htmlAttributes: new { @class = "control-label col-md-2" })
             </div>
         </div>
 
-        <div class="form-group">
-            @Html.LabelFor(model => model.created_at, htmlAttributes: new { @class = "control-label col-md-2" })
-            <div class="col-md-10">
-                @Html.EditorFor(model => model.created_at, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.created_at, "", new { @class = "text-danger" })
-            </div>
-        </div>
-
-        <div class="form-group">
-            @Html.LabelFor(model => model.updated_at, htmlAttributes: new { @class = "control-label col-md-2" })
-            <div class="col-md-10">
-                @Html.EditorFor(model => model.updated_at, new { htmlAttributes = new { @class = "form-control" } })
-                @Html.ValidationMessageFor(model => model.updated_at, "", new { @class = "text-danger" })
-            </div>
-        </div>
-
         <div class="form-group">
             <div class="col-md-offset-2 col-md-10">
                 <input type="submit" value="Zapisz" class="btn btn-default" />