diff --git a/Lesson02/StartOfLesson/ToDo/Controllers/SocialViewComponent.cs b/Lesson02/StartOfLesson/ToDo/Controllers/SocialViewComponent.cs new file mode 100644 index 0000000..3a13076 --- /dev/null +++ b/Lesson02/StartOfLesson/ToDo/Controllers/SocialViewComponent.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace ToDo.Controllers +{ + public class SocialViewComponent : ViewComponent + { + public IViewComponentResult Invoke() + { + return View(); + } + } +} diff --git a/Lesson02/StartOfLesson/ToDo/Controllers/ToDoController.cs b/Lesson02/StartOfLesson/ToDo/Controllers/ToDoController.cs index 5a36be4..39544ff 100644 --- a/Lesson02/StartOfLesson/ToDo/Controllers/ToDoController.cs +++ b/Lesson02/StartOfLesson/ToDo/Controllers/ToDoController.cs @@ -29,7 +29,7 @@ public ActionResult Create() // POST: ToDo/Create [HttpPost] [ValidateAntiForgeryToken] - public ActionResult Create(ToDo toDo) + public ActionResult Create(Models.ToDo toDo) { try { @@ -52,7 +52,7 @@ public ActionResult Edit(int id) // POST: ToDo/Edit/5 [HttpPost] [ValidateAntiForgeryToken] - public ActionResult Edit(int id, ToDo toDo) + public ActionResult Edit(int id, Models.ToDo toDo) { try { @@ -75,7 +75,7 @@ public ActionResult Delete(int id) // POST: ToDo/Delete/5 [HttpPost] [ValidateAntiForgeryToken] - public ActionResult Delete(int id, ToDo collection) + public ActionResult Delete(int id, Models.ToDo collection) { try { diff --git a/Lesson02/StartOfLesson/ToDo/Services/Repository.cs b/Lesson02/StartOfLesson/ToDo/Services/Repository.cs index 3e97a1f..930c3e2 100644 --- a/Lesson02/StartOfLesson/ToDo/Services/Repository.cs +++ b/Lesson02/StartOfLesson/ToDo/Services/Repository.cs @@ -17,9 +17,9 @@ public class Repository new Status { Id = 3, Value = "Done" } }; - private static List _toDos = new List + private static List _toDos = new List { - new ToDo + new Models.ToDo { Id = 1, Title = "My First ToDo", @@ -27,15 +27,15 @@ public class Repository Status = _statuses[2], Created = DateTime.Today }, - new ToDo + new Models.ToDo { Id = 2, Title = "Add DateTime", Description = "Should track when the ToDo was created", Status = _statuses[1], - Created = DateTime.Today.AddDays(4) + Created = DateTime.Today.AddDays(-4) }, - new ToDo + new Models.ToDo { Id = 3, Title = "Add day-of-the-week TagHelper", @@ -43,7 +43,7 @@ public class Repository Status = _statuses[1], Created = DateTime.Today }, - new ToDo + new Models.ToDo { Id = 4, Title = "Add ViewComponent", @@ -53,18 +53,18 @@ public class Repository } }; - public static IReadOnlyList ToDos => _toDos; + public static IReadOnlyList ToDos => _toDos; public static IReadOnlyList Statuses => _statuses; - public static void Add(ToDo toDo) + public static void Add(Models.ToDo toDo) { toDo.Id = Interlocked.Increment(ref toDoKeyCounter); toDo.Status = _statuses.Find(x => x.Id == toDo.Status?.Id); _toDos.Add(toDo); } - public static void Update(int id, ToDo toDo) + public static void Update(int id, Models.ToDo toDo) { var index = _toDos.FindIndex(x => x.Id == id); _toDos.RemoveAt(index); @@ -79,7 +79,7 @@ public static void DeleteToDo(int id) _toDos.RemoveAt(index); } - public static ToDo GetToDo(int id) + public static Models.ToDo GetToDo(int id) { return _toDos.Find(x => x.Id == id); } diff --git a/Lesson02/StartOfLesson/ToDo/TagHelpers/AutocompleteOff.cs b/Lesson02/StartOfLesson/ToDo/TagHelpers/AutocompleteOff.cs new file mode 100644 index 0000000..61c53c3 --- /dev/null +++ b/Lesson02/StartOfLesson/ToDo/TagHelpers/AutocompleteOff.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNetCore.Razor.TagHelpers; +using System.Threading.Tasks; +using System; +using System.Collections.Generic; +using System.Linq; + + + +namespace ToDoApp.TagHelpers +{ + [HtmlTargetElement("*", Attributes = "autocomplete-off")] + public class AutocompleteOffTagHelper : TagHelper + { + + + + public override void Process(TagHelperContext context, TagHelperOutput output) + { + + output.Attributes.SetAttribute("autocomplete", "off"); + + } + } +} diff --git a/Lesson02/StartOfLesson/ToDo/TagHelpers/DayOfTheWeek.cs b/Lesson02/StartOfLesson/ToDo/TagHelpers/DayOfTheWeek.cs new file mode 100644 index 0000000..5705b3e --- /dev/null +++ b/Lesson02/StartOfLesson/ToDo/TagHelpers/DayOfTheWeek.cs @@ -0,0 +1,29 @@ +using Microsoft.AspNetCore.Razor.TagHelpers; +using System.Threading.Tasks; +using System; +using System.Collections.Generic; +using System.Linq; + + + +namespace ToDoApp.TagHelpers +{ + [HtmlTargetElement("*", Attributes = "day-of-the-week")] + public class DayOfWeekTagHelper : TagHelper + { + + public DateTime TodoDate { get; set; } + + public override void Process(TagHelperContext context, TagHelperOutput output) + { + + + var stringDate = TodoDate < DateTime.Now.AddDays(-7) + ? TodoDate.ToString("MM/dd/yyyy") + : TodoDate.DayOfWeek.ToString(); + + output.Content.SetContent(stringDate); + // item.Created < DateTime.Now.AddDays(7) ? item.Created.DayOfWeek.ToString() : item.Created.ToString("mm/dd/yyyy") + } + } +} diff --git a/Lesson02/StartOfLesson/ToDo/Views/Home/Components/Social/Default.cshtml b/Lesson02/StartOfLesson/ToDo/Views/Home/Components/Social/Default.cshtml new file mode 100644 index 0000000..9c2cf81 --- /dev/null +++ b/Lesson02/StartOfLesson/ToDo/Views/Home/Components/Social/Default.cshtml @@ -0,0 +1,4 @@ + + W3Schools + + W3Schools diff --git a/Lesson02/StartOfLesson/ToDo/Views/Home/Index.cshtml b/Lesson02/StartOfLesson/ToDo/Views/Home/Index.cshtml index f42d2a0..cfbd9c2 100644 --- a/Lesson02/StartOfLesson/ToDo/Views/Home/Index.cshtml +++ b/Lesson02/StartOfLesson/ToDo/Views/Home/Index.cshtml @@ -24,7 +24,7 @@ Visual Studio +@await Component.InvokeAsync("Social") \ No newline at end of file diff --git a/Lesson02/StartOfLesson/ToDo/Views/Status/Index.cshtml b/Lesson02/StartOfLesson/ToDo/Views/Status/Index.cshtml index 342c3ab..13b83bb 100644 --- a/Lesson02/StartOfLesson/ToDo/Views/Status/Index.cshtml +++ b/Lesson02/StartOfLesson/ToDo/Views/Status/Index.cshtml @@ -4,10 +4,12 @@ ViewData["Title"] = "Index"; } -

Index

+

Create New + james +

@@ -22,20 +24,21 @@ -@foreach (var item in Model) { - - - - - -} + @foreach (var item in Model) + { + + + + + + }
- @Html.DisplayFor(modelItem => item.Id) - - @Html.DisplayFor(modelItem => item.Value) - - @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | - @Html.ActionLink("Details", "Details", new { id = item.Id }) | - @Html.ActionLink("Delete", "Delete", new { id = item.Id }) -
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Value) + + @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | + @Html.ActionLink("Details", "Details", new { id = item.Id }) | + @Html.ActionLink("Delete", "Delete", new { id = item.Id }) +
diff --git a/Lesson02/StartOfLesson/ToDo/Views/ToDo/Create.cshtml b/Lesson02/StartOfLesson/ToDo/Views/ToDo/Create.cshtml index c0ca766..ebfac81 100644 --- a/Lesson02/StartOfLesson/ToDo/Views/ToDo/Create.cshtml +++ b/Lesson02/StartOfLesson/ToDo/Views/ToDo/Create.cshtml @@ -14,12 +14,12 @@
- +
- +
@@ -29,7 +29,7 @@
- +
diff --git a/Lesson02/StartOfLesson/ToDo/Views/ToDo/Edit.cshtml b/Lesson02/StartOfLesson/ToDo/Views/ToDo/Edit.cshtml index 5cc68b0..0ba90db 100644 --- a/Lesson02/StartOfLesson/ToDo/Views/ToDo/Edit.cshtml +++ b/Lesson02/StartOfLesson/ToDo/Views/ToDo/Edit.cshtml @@ -12,29 +12,29 @@
-
+
- +
-
+
- +
-
+
- +
-
+
@Html.EditorFor(x => x.Status)
-
+
- +
diff --git a/Lesson02/StartOfLesson/ToDo/Views/ToDo/Index.cshtml b/Lesson02/StartOfLesson/ToDo/Views/ToDo/Index.cshtml index abc6b31..35b22af 100644 --- a/Lesson02/StartOfLesson/ToDo/Views/ToDo/Index.cshtml +++ b/Lesson02/StartOfLesson/ToDo/Views/ToDo/Index.cshtml @@ -5,6 +5,9 @@ }

Index

+ +
+

Create New @@ -31,14 +34,14 @@ @foreach (var item in Model) { - + @Html.DisplayFor(modelItem => item.Id) @Html.DisplayFor(modelItem => item.Title) - - @(item.Created < DateTime.Now.AddDays(7) ? item.Created.DayOfWeek.ToString() : item.Created.ToString("mm/dd/yyyy")) + + @*@(item.Created < DateTime.Now.AddDays(-7) ? item.Created.ToString("mm/dd/yyyy") : item.Created.DayOfWeek.ToString())*@ @Html.DisplayFor(modelItem => item.Status) diff --git a/Lesson02/StartOfLesson/ToDo/Views/_ViewImports.cshtml b/Lesson02/StartOfLesson/ToDo/Views/_ViewImports.cshtml index ed5f6da..8b46004 100644 --- a/Lesson02/StartOfLesson/ToDo/Views/_ViewImports.cshtml +++ b/Lesson02/StartOfLesson/ToDo/Views/_ViewImports.cshtml @@ -1,3 +1,5 @@ @using ToDoApp @using ToDoApp.Models +@addTagHelper *, ToDoApp @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers + \ No newline at end of file