Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AngularDemo/include/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
$scope.employeeView = 'listEmployee.html'

$scope.sortData = function (column) {
$scope.reverse = $scope.sortColumn == column ? !$scope.reverse : $scope.column = false
$scope.reverse = $scope.sortColumn === column ? !$scope.reverse : false
$scope.sortColumn = column
}

$scope.getSortClass = function (column) {
return $scope.sortColumn == column ? $scope.reverse ? 'arrow-up' : 'arrow-down' : ''
return $scope.sortColumn === column ? ($scope.reverse ? 'arrow-up' : 'arrow-down') : ''
}
}).filter('status', function () {
return function (input) {
Expand Down
19 changes: 11 additions & 8 deletions AngularDemo/service/service.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
app.factory('myService', function () {
return {
transformString: function (input) {
if (input != '') {
var output = ''
if (!input) {
return ''
}

for (var i = 0; i < input.length; i++) {
if (i > 0 && input[i] == input[i].toUpperCase()) {
output += ' '
}
input = input.toString()
var output = ''

output += input[i]
for (var i = 0; i < input.length; i++) {
if (i > 0 && input[i] === input[i].toUpperCase() && input[i] !== input[i].toLowerCase()) {
output += ' '
}

return output
output += input[i]
}

return output
}
}
})
47 changes: 27 additions & 20 deletions AngularDemo/web/Employees.asmx.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
Expand All @@ -7,7 +8,6 @@
using static Newtonsoft.Json.DateTimeZoneHandling;
using static Newtonsoft.Json.JsonConvert;
using static System.Configuration.ConfigurationManager;
using static System.DateTime;
using static System.Web.Services.WsiProfiles;

namespace AngularDemo.web
Expand All @@ -27,32 +27,39 @@ public void GetAll()
var employees = new List<Employee>();

using (var conn = new SqlConnection(ConnectionStrings["Default"].ConnectionString))
using (var cmd = new SqlCommand("SELECT Id, Name, DoB, Salary, Gender, Status FROM Employees", conn))
{
var cmd = new SqlCommand("SELECT * FROM Employees", conn);

conn.Open();

var reader = cmd.ExecuteReader();

while (reader.Read())
using (var reader = cmd.ExecuteReader())
{
employees.Add(new Employee
var idOrdinal = reader.GetOrdinal(nameof(Employee.Id));
var nameOrdinal = reader.GetOrdinal(nameof(Employee.Name));
var doBOrdinal = reader.GetOrdinal(nameof(Employee.DoB));
var salaryOrdinal = reader.GetOrdinal(nameof(Employee.Salary));
var genderOrdinal = reader.GetOrdinal(nameof(Employee.Gender));
var statusOrdinal = reader.GetOrdinal(nameof(Employee.Status));

while (reader.Read())
{
Id = int.Parse(reader[nameof(Employee.Id)].ToString()),
Name = reader[nameof(Employee.Name)].ToString(),
DoB = Parse(reader[nameof(Employee.DoB)].ToString()),
Salary = decimal.Parse(reader[nameof(Employee.Salary)].ToString()),
Gender = reader[nameof(Employee.Gender)].ToString(),
Status = bool.Parse(reader[nameof(Employee.Status)].ToString())
});
employees.Add(new Employee
{
Id = reader.GetInt32(idOrdinal),
Name = reader.IsDBNull(nameOrdinal) ? string.Empty : reader.GetString(nameOrdinal),
DoB = reader.IsDBNull(doBOrdinal) ? DateTime.MinValue : reader.GetDateTime(doBOrdinal),
Salary = reader.IsDBNull(salaryOrdinal) ? 0m : reader.GetDecimal(salaryOrdinal),
Gender = reader.IsDBNull(genderOrdinal) ? string.Empty : reader.GetString(genderOrdinal),
Status = !reader.IsDBNull(statusOrdinal) && reader.GetBoolean(statusOrdinal)
});
}
}

Context.Response.Write(SerializeObject(employees, new JsonSerializerSettings
{
DateFormatString = "yyyy-MM-ddTHH:mm:ss.fffZ",
DateTimeZoneHandling = Utc
}));
}

Context.Response.Write(SerializeObject(employees, new JsonSerializerSettings
{
DateFormatString = "yyyy-MM-ddTHH:mm:ss.fffZ",
DateTimeZoneHandling = Utc
}));
}
}
}
Loading