Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lesson02/StartOfLesson/ToDo/Controllers/SocialViewComponent.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
6 changes: 3 additions & 3 deletions Lesson02/StartOfLesson/ToDo/Controllers/ToDoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ActionResult Create()
// POST: ToDo/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(ToDo toDo)
public ActionResult Create(Models.ToDo toDo)
{
try
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand Down
20 changes: 10 additions & 10 deletions Lesson02/StartOfLesson/ToDo/Services/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ public class Repository
new Status { Id = 3, Value = "Done" }
};

private static List<ToDo> _toDos = new List<ToDo>
private static List<Models.ToDo> _toDos = new List<Models.ToDo>
{
new ToDo
new Models.ToDo
{
Id = 1,
Title = "My First ToDo",
Description = "Get the app working",
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",
Description = "Need an attribute we can use in our view that will pretty format the DateTime as a weekday when possible",
Status = _statuses[1],
Created = DateTime.Today
},
new ToDo
new Models.ToDo
{
Id = 4,
Title = "Add ViewComponent",
Expand All @@ -53,18 +53,18 @@ public class Repository
}
};

public static IReadOnlyList<ToDo> ToDos => _toDos;
public static IReadOnlyList<Models.ToDo> ToDos => _toDos;

public static IReadOnlyList<Status> 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);
Expand All @@ -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);
}
Expand Down
24 changes: 24 additions & 0 deletions Lesson02/StartOfLesson/ToDo/TagHelpers/AutocompleteOff.cs
Original file line number Diff line number Diff line change
@@ -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");

}
}
}
29 changes: 29 additions & 0 deletions Lesson02/StartOfLesson/ToDo/TagHelpers/DayOfTheWeek.cs
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
 <a href="https://www.facebook.com">
<img border="0" alt="W3Schools" src="http://www.premierforkids.com/wp-content/uploads/2015/05/facebook-logo-png-transparent-background-150x150.png" width="100" height="100"></a>
<a href="https://www.twitter.com">
<img border="0" alt="W3Schools" src="https://media.glassdoor.com/sql/100569/twitter-squarelogo-1502093939446.png" width="100" height="100"></a>
3 changes: 2 additions & 1 deletion Lesson02/StartOfLesson/ToDo/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<img src="~/images/banner2.svg" alt="Visual Studio" class="img-responsive" />
<div class="carousel-caption" role="option">
<p>
There are powerful new features in Visual Studio for building modern web apps.
There are SHITTY new features in Visual Studio for building modern web apps.
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525030&clcid=0x409">
Learn More
</a>
Expand Down Expand Up @@ -92,3 +92,4 @@
</ul>
</div>
</div>
@await Component.InvokeAsync("Social")
35 changes: 19 additions & 16 deletions Lesson02/StartOfLesson/ToDo/Views/Status/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
ViewData["Title"] = "Index";
}

<h2>Index</h2>


<p>
<a asp-action="Create">Create New</a>
<email>james</email>

</p>
<table class="table">
<thead>
Expand All @@ -22,20 +24,21 @@
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Value)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Value)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
</tbody>
</table>
6 changes: 3 additions & 3 deletions Lesson02/StartOfLesson/ToDo/Views/ToDo/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Title" class="control-label"></label>
<input asp-for="Title" class="form-control" />
<input asp-for="Title" class="form-control" autocomplete-off/>
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Description" class="control-label"></label>
<input asp-for="Description" class="form-control" />
<input asp-for="Description" class="form-control" autocomplete-off/>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
Expand All @@ -29,7 +29,7 @@
</div>
<div class="form-group">
<label asp-for="Created" class="control-label"></label>
<input asp-for="Created" class="form-control" />
<input asp-for="Created" class="form-control" autocomplete-off/>
<span asp-validation-for="Created" class="text-danger"></span>
</div>
<div class="form-group">
Expand Down
18 changes: 9 additions & 9 deletions Lesson02/StartOfLesson/ToDo/Views/ToDo/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@
<div class="col-md-4">
<form asp-action="Edit">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<div class="form-group" >
<label asp-for="Id" class="control-label"></label>
<input asp-for="Id" readonly class="form-control" />
<input asp-for="Id" readonly class="form-control" autocomplete-off/>
<span asp-validation-for="Id" class="text-danger"></span>
</div>
<div class="form-group">
<div class="form-group" >
<label asp-for="Title" class="control-label"></label>
<input asp-for="Title" class="form-control" />
<input asp-for="Title" class="form-control" autocomplete-off/>
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<div class="form-group" >
<label asp-for="Description" class="control-label"></label>
<input asp-for="Description" class="form-control" />
<input asp-for="Description" class="form-control" autocomplete-off/>
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
<div class="form-group" >
<label asp-for="Status" class="control-label"></label>
@Html.EditorFor(x => x.Status)
<span asp-validation-for="Status" class="text-danger"></span>
</div>
<div class="form-group">
<div class="form-group" >
<label asp-for="Created" class="control-label"></label>
<input asp-for="Created" class="form-control" />
<input asp-for="Created" class="form-control" autocomplete-off />
<span asp-validation-for="Created" class="text-danger"></span>
</div>
<div class="form-group">
Expand Down
9 changes: 6 additions & 3 deletions Lesson02/StartOfLesson/ToDo/Views/ToDo/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
}

<h2>Index</h2>

<div day-of-the-week></div>


<p>
<a asp-action="Create">Create New</a>
Expand All @@ -31,14 +34,14 @@
@foreach (var item in Model)
{
<tr>
<td>
<td >
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@(item.Created < DateTime.Now.AddDays(7) ? item.Created.DayOfWeek.ToString() : item.Created.ToString("mm/dd/yyyy"))
<td day-of-the-week todo-date="item.Created">
@*@(item.Created < DateTime.Now.AddDays(-7) ? item.Created.ToString("mm/dd/yyyy") : item.Created.DayOfWeek.ToString())*@
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
Expand Down
2 changes: 2 additions & 0 deletions Lesson02/StartOfLesson/ToDo/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@using ToDoApp
@using ToDoApp.Models
@addTagHelper *, ToDoApp
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers