Skip to content
Permalink
Browse files

added ability to page through records

  • Loading branch information...
SangeetAgarwal committed Oct 25, 2014
1 parent 05370d5 commit 47c22bb628c8989f9a546bdc24ab536db4cabb7a

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,59 @@
namespace NgWebApiGrid.Data.Migrations
{
using System;
using System.Data.Entity.Migrations;

public partial class InitialSeed : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Course",
c => new
{
CourseID = c.Int(nullable: false),
Title = c.String(),
Credits = c.Int(nullable: false),
})
.PrimaryKey(t => t.CourseID);

CreateTable(
"dbo.Enrollment",
c => new
{
EnrollmentID = c.Int(nullable: false, identity: true),
CourseID = c.Int(nullable: false),
StudentID = c.Int(nullable: false),
Grade = c.Int(),
})
.PrimaryKey(t => t.EnrollmentID)
.ForeignKey("dbo.Course", t => t.CourseID, cascadeDelete: true)
.ForeignKey("dbo.Student", t => t.StudentID, cascadeDelete: true)
.Index(t => t.CourseID)
.Index(t => t.StudentID);

CreateTable(
"dbo.Student",
c => new
{
ID = c.Int(nullable: false, identity: true),
LastName = c.String(),
FirstMidName = c.String(),
EnrollmentDate = c.DateTime(nullable: false),
})
.PrimaryKey(t => t.ID);

}

public override void Down()
{
DropForeignKey("dbo.Enrollment", "StudentID", "dbo.Student");
DropForeignKey("dbo.Enrollment", "CourseID", "dbo.Course");
DropIndex("dbo.Enrollment", new[] { "StudentID" });
DropIndex("dbo.Enrollment", new[] { "CourseID" });
DropTable("dbo.Student");
DropTable("dbo.Enrollment");
DropTable("dbo.Course");
}
}
}
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Target" xml:space="preserve">
<value>H4sIAAAAAAAEAN1azW7jNhC+F+g7CDq1RTbKTw/bwN5F1kkWxq6TRZxsewtoaewQpShVpAIbRZ+shz5SX6HUHyWS+rU3TlDkEJmaGQ5nvpkhh/r3739G79c+sZ4gYjigY/v48Mi2gLqBh+lqbMd8+eat/f7d99+NLj1/bX0t6E4TOsFJ2dh+5Dw8cxzm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9ww+wwq5m6Jl0Cyk2xGq2UcXGK0i5LNcRskvfgoMe/763X/+ir8uUy4AAA==</value>
</data>
<data name="DefaultSchema" xml:space="preserve">
<value>dbo</value>
</data>
</root>
@@ -34,7 +34,24 @@ protected override void Seed(NgWebApiGrid.Data.SchoolContext context)
new Student{FirstMidName="Kan",LastName="Chan",EnrollmentDate=DateTime.Parse("2002-09-01")},
new Student{FirstMidName="David",LastName="Stosky",EnrollmentDate=DateTime.Parse("2001-09-01")},
new Student{FirstMidName="Lauda",LastName="Chris",EnrollmentDate=DateTime.Parse("2003-09-01")},
new Student{FirstMidName="Cheeko",LastName="Madus",EnrollmentDate=DateTime.Parse("2005-09-01")}
new Student{FirstMidName="Cheeko",LastName="Madus",EnrollmentDate=DateTime.Parse("2005-09-01")},

new Student{FirstMidName="Datson",LastName="Palton",EnrollmentDate=DateTime.Parse("2005-09-01")},
new Student{FirstMidName="Zakky",LastName="Chan",EnrollmentDate=DateTime.Parse("2002-09-01")},
new Student{FirstMidName="Arbele",LastName="Dan",EnrollmentDate=DateTime.Parse("2003-09-01")},
new Student{FirstMidName="Dalton",LastName="Evan",EnrollmentDate=DateTime.Parse("2002-09-01")},
new Student{FirstMidName="Joshua",LastName="Bigit",EnrollmentDate=DateTime.Parse("2002-09-01")},
new Student{FirstMidName="Elizabeth",LastName="Judge",EnrollmentDate=DateTime.Parse("2001-09-01")},
new Student{FirstMidName="Peter",LastName="Theory",EnrollmentDate=DateTime.Parse("2003-09-01")},
new Student{FirstMidName="Ninol",LastName="Olivia",EnrollmentDate=DateTime.Parse("2005-09-01")},
new Student{FirstMidName="Newton",LastName="Isaack",EnrollmentDate=DateTime.Parse("2005-09-01")},
new Student{FirstMidName="Sasha",LastName="Brain",EnrollmentDate=DateTime.Parse("2007-09-01")},
new Student{FirstMidName="Aliba",LastName="Zate",EnrollmentDate=DateTime.Parse("2003-09-01")},
new Student{FirstMidName="Raman",LastName="Rastogi",EnrollmentDate=DateTime.Parse("2003-07-01")},
new Student{FirstMidName="Chan",LastName="Doodle",EnrollmentDate=DateTime.Parse("2009-09-01")},
new Student{FirstMidName="Andy",LastName="Sam",EnrollmentDate=DateTime.Parse("2005-09-01")},
new Student{FirstMidName="Sasson",LastName="Saca",EnrollmentDate=DateTime.Parse("2007-08-01")},
new Student{FirstMidName="Cito",LastName="Moran",EnrollmentDate=DateTime.Parse("2005-07-01")}

};

@@ -46,9 +46,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Migrations\201410220400049_Initial.cs" />
<Compile Include="Migrations\201410220400049_Initial.Designer.cs">
<DependentUpon>201410220400049_Initial.cs</DependentUpon>
<Compile Include="Migrations\201410250229130_Initial-Seed.cs" />
<Compile Include="Migrations\201410250229130_Initial-Seed.Designer.cs">
<DependentUpon>201410250229130_Initial-Seed.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Models\Course.cs" />
@@ -62,8 +62,8 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Migrations\201410220400049_Initial.resx">
<DependentUpon>201410220400049_Initial.cs</DependentUpon>
<EmbeddedResource Include="Migrations\201410250229130_Initial-Seed.resx">
<DependentUpon>201410250229130_Initial-Seed.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@@ -19,11 +19,17 @@ public class StudentsApiController : ApiController
private readonly SchoolContext db = new SchoolContext();

// GET: api/Students
public StudentContainer GetStudents()
public StudentsContainer GetStudents()
{
var students = db.Students.ToList();
var queryStringParams = Request.RequestUri.ParseQueryString();
var pageNumber = Convert.ToInt32(queryStringParams["currentPage"]);
var pageSize = Convert.ToInt32(queryStringParams["recordsPerPage"]);
var begin = (pageNumber - 1) * pageSize;

var studentsContainer = new StudentContainer { Students = students, RecordCount = students.Count() };
var totalNumberOfRecords = db.Students.Count();
var students = db.Students.OrderBy(r=>r.ID).Skip(begin).Take(pageSize).ToList();

var studentsContainer = new StudentsContainer { Students = students, RecordCount = totalNumberOfRecords };

return studentsContainer;
}
@@ -122,7 +128,7 @@ private bool StudentExists(int id)
}
}

public class StudentContainer
public class StudentsContainer
{
public List<Student> Students { get; set; }
public int RecordCount

0 comments on commit 47c22bb

Please sign in to comment.
You can’t perform that action at this time.