Skip to content

Commit

Permalink
Cleaned up comments in Lesson 3 code to merge with master branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaytonanderson committed Jan 23, 2017
1 parent 0276532 commit 598d2d8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
1 change: 0 additions & 1 deletion CharacterSheetApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public IActionResult Create(string characterName)

Models.Character.Create(characterName);

// instead of returning a view, this RedirectToAction will take us to the Index action in the Home controller. This will prevent the user from accidentally saving the same character twice by refreshing, avoids duplicate code.
return RedirectToAction("Index");
}
}
Expand Down
4 changes: 0 additions & 4 deletions CharacterSheetApp/GlobalVariables.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// "Using Directives"
using System.Collections.Generic;
using CharacterSheetApp.Models;

namespace CharacterSheetApp
{
public static class GlobalVariables
{
// adding a get setter to a field or variable changes it into a property

// adding the = new line to this will set a default value. So in the event that our list is null, it'll use whatever is set after the = as the default value.
public static List<Character> Characters { get; set; }
= new List<Character>();
}
Expand Down
16 changes: 6 additions & 10 deletions CharacterSheetApp/Models/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@ namespace CharacterSheetApp.Models
public class Character
{
public string Name;

// need to write methods to set and retrieve information

// we are making this method static
public static void Create(string characterName)
{
var character = new Character();
character.Name = characterName;
// make sure the Characters List isn't null. Trying to add a character to a null list will return an error.
if(GlobalVariables.Characters == null)
GlobalVariables.Characters = new List<Character>();

// list collections have a .Add() method to use for adding objects to the list.
// no longer need this since we set a default value in GlobalVariabels.cs
// if(GlobalVariables.Characters == null)
// GlobalVariables.Characters = new List<Character>();

GlobalVariables.Characters.Add(character);
}

public static List<Character> GetAll()
{
// again, need to make sure the variable isn't null.
if(GlobalVariables.Characters == null)
GlobalVariables.Characters = new List<Character>();
// if(GlobalVariables.Characters == null)
// GlobalVariables.Characters = new List<Character>();

return GlobalVariables.Characters;
}
Expand Down
5 changes: 2 additions & 3 deletions CharacterSheetApp/Views/Home/index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@

<div>
<ul>
<!-- need to iterate through our list -->
<!-- one way is a C# foreach loop: -->

@foreach (var item in Model)
{
<li>
<label>@item.Name</label>
</li>
}

</ul>
</div>

Expand Down

0 comments on commit 598d2d8

Please sign in to comment.