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
38 changes: 21 additions & 17 deletions Lesson01/StartOfLesson/ToDo/Controllers/ToDoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,27 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ToDoApp.Models;
using ToDoApp.Services;
using System.Linq;

namespace ToDoApp.Controllers
{
public class ToDoController : Controller
{
private static Dictionary<int, Status> status = new Dictionary<int, Status>
{
{ 1, new Status { Id = 1, Value = "Not Started" } },
{ 2, new Status { Id = 2, Value = "In Progress" } },
{ 3, new Status { Id = 3, Value = "Done" } }
};

private static List<ToDo> list = new List<ToDo>
{
new ToDo { Id = 1, Title = "My First ToDo", Description = "Get the app working", Status = status[2] }
};


// GET: ToDo
public ActionResult Index()
{
return View(list);
return View(Repository.list);
}

// GET: ToDo/Details/5
public ActionResult Details(int id)
{
return View();
var todo = Repository.GetTodoById(id);
return View(todo);

}

// GET: ToDo/Create
Expand All @@ -44,6 +38,9 @@ public ActionResult Create(IFormCollection collection)
{
try
{
Repository.CreateToDo(collection);
// call the Repository with new method "CreateToDo" we will create
//Repository.CreateToDo --> missing something?
// TODO: Add insert logic here

return RedirectToAction(nameof(Index));
Expand All @@ -55,19 +52,21 @@ public ActionResult Create(IFormCollection collection)
}

// GET: ToDo/Edit/5
[HttpGet]
public ActionResult Edit(int id)
{
return View();
var todo = Repository.GetTodoById(id);
return View(todo);
}

// POST: ToDo/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
public ActionResult Edit(int id, IFormCollection collection) //(ToDo newtodo)
{
try
{
// TODO: Add update logic here
Repository.SaveToDo(id, collection);

return RedirectToAction(nameof(Index));
}
Expand All @@ -80,7 +79,8 @@ public ActionResult Edit(int id, IFormCollection collection)
// GET: ToDo/Delete/5
public ActionResult Delete(int id)
{
return View();
var todo = Repository.GetTodoById(id);
return View(todo);
}

// POST: ToDo/Delete/5
Expand All @@ -91,6 +91,10 @@ public ActionResult Delete(int id, IFormCollection collection)
try
{
// TODO: Add delete logic here
Repository.DeleteToDo(id);

//Repository.DeleteToDo() --> missing something? (parameter)
//all you need is id, dont pass in anything

return RedirectToAction(nameof(Index));
}
Expand Down
1 change: 1 addition & 0 deletions Lesson01/StartOfLesson/ToDo/Models/ToDo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace ToDoApp.Models
{
public class ToDo
{

public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
Expand Down
65 changes: 65 additions & 0 deletions Lesson01/StartOfLesson/ToDo/Services/Repository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ToDoApp.Models;
using System.Linq;
using Microsoft.AspNetCore.Http;

namespace ToDoApp.Services
{
public class Repository
{

public static Dictionary<int, Status> status = new Dictionary<int, Status>
{
{ 1, new Status { Id = 1, Value = "Not Started" } },
{ 2, new Status { Id = 2, Value = "In Progress" } },
{ 3, new Status { Id = 3, Value = "Done" } }
};

public static List<ToDo> list = new List<ToDo>
{
new ToDo { Id = 1, Title = "My First ToDo", Description = "Get the app working", Status = status[2] }
};

public static ToDo GetTodoById(int id)
{
var todo = list.SingleOrDefault( t => t.Id == id);
return todo;
}

public static ToDo SaveToDo(int id, IFormCollection collection)
{
var todo = GetTodoById(id);
todo.Id = Convert.ToInt32(collection["Id"]);
todo.Title = collection["Title"];
todo.Description = collection["Description"];

return todo;

// get the current todo based on id
//overwrite each property with vales from collection
//return saved todo
}

public static void CreateToDo(IFormCollection collection)
{
var todo = new ToDo { Id = Convert.ToInt32(collection["Id"]), Title = collection["Title"], Description = collection["Description"], Status = status[1] };
list.Add(todo);

// no need to get anything from list
//create a new object of type todo and append values from collection
//add new todo to list
}

public static void DeleteToDo(int id)
{
// find todo
var todo = GetTodoById(id);
// delete from list
list.Remove(todo);

}
}
}
43 changes: 43 additions & 0 deletions Lesson01/StartOfLesson/ToDo/Views/ToDo/Create.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@model ToDoApp.Models.ToDo

@{
ViewData["Title"] = "Create";
}

<h2>Create</h2>

<h4>ToDo</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Id" class="control-label"></label>
<input asp-for="Id" class="form-control" />
<span asp-validation-for="Id" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Title" class="control-label"></label>
<input asp-for="Title" class="form-control" />
<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" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</form>
</div>
</div>

<div>
<a asp-action="Index">Back to List</a>
</div>

@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
38 changes: 38 additions & 0 deletions Lesson01/StartOfLesson/ToDo/Views/ToDo/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@model ToDoApp.Models.ToDo

@{
ViewData["Title"] = "Delete";
}

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<div>
<h4>ToDo</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Id)
</dt>
<dd>
@Html.DisplayFor(model => model.Id)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Title)
</dt>
<dd>
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Description)
</dt>
<dd>
@Html.DisplayFor(model => model.Description)
</dd>
</dl>

<form asp-action="Delete">
<input type="submit" value="Delete" class="btn btn-default" /> |
<a asp-action="Index">Back to List</a>
</form>
</div>
36 changes: 36 additions & 0 deletions Lesson01/StartOfLesson/ToDo/Views/ToDo/Details.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@model ToDoApp.Models.ToDo

@{
ViewData["Title"] = "Details";
}

<h2>Details</h2>

<div>
<h4>ToDo</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Id)
</dt>
<dd>
@Html.DisplayFor(model => model.Id)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Title)
</dt>
<dd>
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Description)
</dt>
<dd>
@Html.DisplayFor(model => model.Description)
</dd>
</dl>
</div>
<div>
@Html.ActionLink("Edit", "Edit", new { /* id = Model.PrimaryKey */ }) |
<a asp-action="Index">Back to List</a>
</div>
43 changes: 43 additions & 0 deletions Lesson01/StartOfLesson/ToDo/Views/ToDo/Edit.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@model ToDoApp.Models.ToDo

@{
ViewData["Title"] = "Edit";
}

<h2>Edit</h2>

<h4>ToDo</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Edit">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Id" class="control-label"></label>
<input asp-for="Id" class="form-control" />
<span asp-validation-for="Id" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Title" class="control-label"></label>
<input asp-for="Title" class="form-control" />
<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" />
<span asp-validation-for="Description" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</form>
</div>
</div>

<div>
<a asp-action="Index">Back to List</a>
</div>

@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
12 changes: 9 additions & 3 deletions Lesson01/StartOfLesson/ToDo/Views/ToDo/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@
@Html.DisplayFor(modelItem => item.Status)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
@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>
}
Expand Down
34 changes: 34 additions & 0 deletions practice/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

namespace practice
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("OMG");

string myNumber = "1.2345";
string[] numParts = myNumber.Split('.');

string wholeNum = numParts[0];
string decimalPart = numParts[1];

if (decimalPart.Length == 1)
{
decimalPart = decimalPart + "0";
}
else if (decimalPart.Length > 2)
{
decimalPart = decimalPart.Substring(0,2);
}
else
{
decimalPart = "00";
}

string finalAnswer = wholeNum + "." + decimalPart;

}
}
}
8 changes: 8 additions & 0 deletions practice/practice.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

</Project>