Skip to content
Permalink
Browse files

Added data access, web api controller, angular controller and data se…

…rvice
  • Loading branch information...
SangeetAgarwal committed Oct 24, 2014
1 parent 3059bde commit 05370d5e025c5da33f7851009b8786b6273ba1f7
@@ -26,7 +26,16 @@ protected override void Seed(NgWebApiGrid.Data.SchoolContext context)
new Student{FirstMidName="Yan",LastName="Li",EnrollmentDate=DateTime.Parse("2002-09-01")},
new Student{FirstMidName="Peggy",LastName="Justice",EnrollmentDate=DateTime.Parse("2001-09-01")},
new Student{FirstMidName="Laura",LastName="Norman",EnrollmentDate=DateTime.Parse("2003-09-01")},
new Student{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2005-09-01")}
new Student{FirstMidName="Nino",LastName="Olivetto",EnrollmentDate=DateTime.Parse("2005-09-01")},
new Student{FirstMidName="Darson",LastName="Olivia",EnrollmentDate=DateTime.Parse("2005-09-01")},
new Student{FirstMidName="Cheryl",LastName="Bruto",EnrollmentDate=DateTime.Parse("2002-09-01")},
new Student{FirstMidName="Angus",LastName="Doritho",EnrollmentDate=DateTime.Parse("2003-09-01")},
new Student{FirstMidName="Jeves",LastName="Baldaros",EnrollmentDate=DateTime.Parse("2002-09-01")},
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")}

};

students.ForEach(s => context.Students.Add(s));
@@ -4,6 +4,7 @@
using System.Net.Http.Headers;
using System.Web.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace NgWebApiGrid.Web
{
@@ -26,6 +27,8 @@ public static void Register(HttpConfiguration config)

config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling
= Newtonsoft.Json.ReferenceLoopHandling.Ignore;

config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
}
}
@@ -1,5 +1,5 @@
body {
padding-top: 50px;
padding-top: 70px;
padding-bottom: 20px;
}

@@ -22,3 +22,11 @@ select,
textarea {
max-width: 280px;
}

.nopadding {
padding: 0 !important;
margin: 0 !important;
}
.top-buffer { margin-top:20px; }

.button-top-buffer { margin-top: 5px;}
@@ -19,9 +19,13 @@ public class StudentsApiController : ApiController
private readonly SchoolContext db = new SchoolContext();

// GET: api/Students
public List<Student> GetStudents()
public StudentContainer GetStudents()
{
return db.Students.ToList();
var students = db.Students.ToList();

var studentsContainer = new StudentContainer { Students = students, RecordCount = students.Count() };

return studentsContainer;
}

// GET: api/Students/5
@@ -117,4 +121,11 @@ private bool StudentExists(int id)
return db.Students.Count(e => e.ID == id) > 0;
}
}

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

Large diffs are not rendered by default.

@@ -9,8 +9,8 @@
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="SchoolContext" connectionString="Data Source=(local);Initial Catalog=ContosoUniversity1;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-NgWebApiGrid.Web-20141019115808.mdf;Initial Catalog=aspnet-NgWebApiGrid.Web-20141019115808;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="SchoolContext" connectionString="Data Source=(local);Initial Catalog=ContosoUniversity1;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet-NgWebApiGrid.Web-20141019115808.mdf;Initial Catalog=aspnet-NgWebApiGrid.Web-20141019115808;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
@@ -3,17 +3,55 @@
.config(["$routeProvider", function ($routeProvider) {
$routeProvider.when("/", {
controller: "studentCtrl",
templateUrl: "app/simpleGrid/student.tpl.html"
templateUrl: "app/simpleGrid/students.tpl.html"
});

$routeProvider.otherwise("/");
}])

.controller("studentCtrl", ["$scope", "$http",
function ($scope, $http) {
$scope.controllerName = "studentCtrl";
.factory("dataService", ["$http", "$q", function ($http, $q) {

var _students = [];

var deferred = $q.defer();

var _getStudents = function (options) {

$http.get("api/StudentsApi")
.then(function (result) {
angular.copy(result.data.students, _students);
deferred.resolve();
},
function () {
deferred.reject();
});

return deferred.promise;
};

return {
students:_students,
getStudents: _getStudents,
};
}])
.controller("studentCtrl", ["$scope", "dataService",
function ($scope, dataService) {
$scope.data = dataService.students;

var options = {

};

dataService.getStudents(options)
.then(function() {

},
function() {

});


}])



This file was deleted.

@@ -0,0 +1,41 @@
<div class="row top-buffer">
<table class="table table-bordered table-striped table-responsive">
<thead>
<tr>
<th>
</th>
<th>
</th>
<th>
</th>
<th>
Last Name
</th>
<th>
First Name
</th>
<th>
Date of Enrollment
</th>

</tr>
</thead>
<tbody data-ng-repeat="i in data">
<tr>
<td></td>
<td></td>
<td></td>
<td>
<textarea class="form-control" style="width: 300px;height: 65px" ng-model="i.lastName"></textarea>
</td>
<td>
<textarea class="form-control" style="width: 300px;height: 65px" ng-model="i.firstMidName"></textarea>
</td>
<td>
<input type="text" class="form-control" style="width: 150px;height: 65px" ng-model="i.enrollmentDate" />
</td>
</tr>

</tbody>
</table>
</div>

0 comments on commit 05370d5

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