Skip to content

Commit

Permalink
add show page, begin delete
Browse files Browse the repository at this point in the history
Co-authored-by: Dani Renner <[email protected]>
Co-authored-by: Woo Jin Kim <[email protected]>
  • Loading branch information
3 people committed Mar 3, 2021
1 parent 227e748 commit b46c721
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 1 deletion.
35 changes: 35 additions & 0 deletions Packer/Controllers/ItemsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.AspNetCore.Mvc;
using Packer.Models;
using System.Collections.Generic;

namespace Packer.Controllers
{
public class ItemsController : Controller
{
[HttpGet("/items")]
public ActionResult Index()
{
List<Item> allItems = Item.GetAll();
return View(allItems);
}
[HttpGet("/items/new")]
public ActionResult New()
{
return View();
}
[HttpPost("/items")]
public ActionResult Create(string name, bool packed, bool purchased)
{
Item userItem = new Item(name, packed, purchased);
return RedirectToAction("Index");
}
[HttpGet("/items/{id}")]
public ActionResult Show(int id)
{
Item findItem = Item.Find(id);
return View(findItem);
}
}
}


34 changes: 34 additions & 0 deletions Packer/Models/Item.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
using System.Collections.Generic;

namespace Packer.Models
{
public class Item
{
public string Name { get; set; }
public bool Packed { get; set; }
public bool Purchased { get; set; }
public int Id { get; }

private static List<Item> _instances = new List<Item>{};

public Item(string name, bool packed, bool purchased)
{
Name = name;
Packed = packed;
Purchased = purchased;
_instances.Add(this);
Id = _instances.Count;
}

public static List<Item> GetAll()
{
return _instances;
}
public static void ClearAll()
{
_instances.Clear();
}

public static Item Find(int searchId)
{
return _instances[searchId-1];
}
}

}
3 changes: 2 additions & 1 deletion Packer/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<p> hello! </p>
<a href='/items'>See your packing list.</a>
<a href='/items/new'>Let's add to your packing list!</a>
Empty file.
8 changes: 8 additions & 0 deletions Packer/Views/Items/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@using Packer.Models;

<ul>
@foreach(Item item in Model)
{
<li><a href='items/@item.Id'>@item.Name</a></li>
}
</ul
22 changes: 22 additions & 0 deletions Packer/Views/Items/New.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<form action="/items" method="post">
<label for="name">Add a new item</label>
<input id="name" name="name" type="text">
<label for="packed">
Packed
<input id="packed" name="packed" value="true" type="radio">
</label>
<label for="notPacked">
Not Packed
<input id="notPacked" name="packed" value="false" type="radio">
</label>
<label for="purchased">
Purchased
<input id="purchased" name="purchased" value="true" type="radio">
</label>
<label for="notPurchased">
Not Purchased
<input id="notPurchased" name="purchased" value="false" type="radio">
</label>

<button type="submit">Submit</button>
</form>
5 changes: 5 additions & 0 deletions Packer/Views/Items/Show.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<p>ITEM DETAILS</p>

<p>@Model.Name</p>
<p>Packed: @Model.Packed</p>
<p>Purchased: @Model.Purchased</p>

0 comments on commit b46c721

Please sign in to comment.