index route works

main
Matt Huntington 5 years ago
parent cc82434314
commit 84dd2cd4ed

@ -12,13 +12,31 @@ namespace contacts.Controllers
public class PeopleController : ControllerBase public class PeopleController : ControllerBase
{ {
[HttpGet] [HttpGet]
// public Person[] Get()
public Person[] Get() public Person[] Get()
{ {
Person p1 = new Person(1, "Matt", 40); using (var db = new PeopleContext())
Person p2 = new Person(2, "Sally", 32); {
Person p3 = new Person(3, "Zagthrop", 834); // Console.WriteLine("Hello World!");
// Console.WriteLine(p1.name); // db.Add(new Person { Name = "Matt", Age = 40 });
return new Person[] { p1, p2, p3 }; // db.SaveChanges();
// var person = db.People
var people = db.People
.OrderBy(person => person.PersonId)
// .Last();
.ToArray();
// Console.WriteLine(person.Age);
Console.WriteLine(db.People.OrderBy(person => person.PersonId).ToArray());
// return person;
return people;
}
// Person p1 = new Person(1, "Matt", 40);
// Person p2 = new Person(2, "Sally", 32);
// Person p3 = new Person(3, "Zagthrop", 834);
// // Console.WriteLine(p1.name);
// return new Person[] { p1, p2, p3 };
} }
} }
} }

@ -0,0 +1,39 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using contacts;
namespace contacts.Migrations
{
[DbContext(typeof(PeopleContext))]
[Migration("20201017005725_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.9");
modelBuilder.Entity("contacts.Person", b =>
{
b.Property<int>("PersonId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("PersonId");
b.ToTable("People");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace contacts.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "People",
columns: table => new
{
PersonId = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(nullable: true),
Age = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_People", x => x.PersonId);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "People");
}
}
}

@ -0,0 +1,37 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using contacts;
namespace contacts.Migrations
{
[DbContext(typeof(PeopleContext))]
partial class PeopleContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.9");
modelBuilder.Entity("contacts.Person", b =>
{
b.Property<int>("PersonId")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("PersonId");
b.ToTable("People");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,20 @@
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
namespace contacts
{
public class PeopleContext : DbContext
{
public DbSet<Person> People { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite("Data Source=people.db");
}
public class Person
{
public int PersonId { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
}

@ -1,18 +0,0 @@
using System;
namespace contacts
{
public class Person
{
public int id { get; set; }
public string name { get; set; }
public int age { get; set; }
public Person(int idParam, string nameParam, int ageParam)
{
this.id = idParam;
this.name = nameParam;
this.age = ageParam;
}
}
}

@ -11,6 +11,11 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.8" /> <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.9" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Binary file not shown.
Loading…
Cancel
Save