Skip to content

Commit 964e32a

Browse files
committed
# Conflicts: # Client/app/containers/fetchdata/fetchdata.component.ts
2 parents f5bdadf + 928c28b commit 964e32a

21 files changed

+407
-58
lines changed

Asp2017.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
1010
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.0" />
1111
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="1.1.1" />
1214
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
1315
</ItemGroup>
1416
<ItemGroup>

Client/app/app.module.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { NgModule } from '@angular/core';
22
import { RouterModule } from '@angular/router';
33
import { CommonModule } from '@angular/common';
44
import { HttpModule } from '@angular/http';
5+
import { FormsModule } from '@angular/forms';
56

67
import { AppComponent } from './app.component';
78
import { NavMenuComponent } from './components/navmenu/navmenu.component';
89
import { HomeComponent } from './containers/home/home.component';
9-
import { FetchDataComponent } from './containers/fetchdata/fetchdata.component';
10+
import { UsersComponent } from './containers/users/users.component';
1011
import { CounterComponent } from './containers/counter/counter.component';
1112
import { ChatComponent } from './containers/chat/chat.component';
1213

@@ -18,13 +19,14 @@ import { ConnectionResolver } from './shared/route.resolver';
1819
AppComponent,
1920
NavMenuComponent,
2021
CounterComponent,
21-
FetchDataComponent,
22+
UsersComponent,
2223
HomeComponent,
2324
ChatComponent
2425
],
2526
imports: [
2627
CommonModule,
2728
HttpModule,
29+
FormsModule,
2830
// App Routing
2931
RouterModule.forRoot([
3032
{
@@ -61,13 +63,13 @@ import { ConnectionResolver } from './shared/route.resolver';
6163
}
6264
},
6365
{
64-
path: 'fetch-data', component: FetchDataComponent,
66+
path: 'users', component: UsersComponent,
6567
data: {
66-
title: 'REST demo',
67-
meta: [{ name: 'description', content: `We're hitting REST in this Demo!` }],
68+
title: 'Users REST example',
69+
meta: [{ name: 'description', content: 'This is User REST API example page Description!' }],
6870
links: [
69-
{ rel: 'canonical', href: 'http://blogs.example.com/%3Cspan%20class="x x-first x-last">fetch-data/canonicaldemo' },
70-
{ rel: 'alternate', hreflang: 'es', href: 'http://es.example.com/%3Cspan%20class="x x-first x-last">fetchstuff' }
71+
{ rel: 'canonical', href: 'http://blogs.example.com/%3Cspan%20class="x x-first x-last">chat/something' },
72+
{ rel: 'alternate', hreflang: 'es', href: 'http://es.example.com/%3Cspan%20class="x x-first x-last">users' }
7173
]
7274
}
7375
},

Client/app/components/navmenu/navmenu.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
</a>
2424
</li>
2525
<li [routerLinkActive]="['link-active']">
26-
<a [routerLink]="['/fetch-data']">
27-
<span class='glyphicon glyphicon-th-list'></span> Fetch data
26+
<a [routerLink]="['/users']">
27+
<span class='glyphicon glyphicon-user'></span> Users
2828
</a>
2929
</li>
3030
<!--<li [routerLinkActive]="['link-active']">

Client/app/containers/fetchdata/fetchdata.component.html

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<h1>This is a RestAPI Example (hitting WebAPI in our case)</h1>
2+
3+
<blockquote>
4+
Let's get some fake users from Rest:<br>
5+
You can find the Web API Routes in <code>{{ "/Server/RestAPI/ ... "}}</code>
6+
</blockquote>
7+
8+
<p *ngIf="!users"><em>Loading...</em></p>
9+
10+
<table class="table" *ngIf="users">
11+
<thead>
12+
<tr>
13+
<th>User ID</th>
14+
<th>Name</th>
15+
<th></th>
16+
<th></th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr *ngFor="let user of users" [@flyInOut]>
21+
<td>{{ user.id }}</td>
22+
<td>
23+
<input class="form-control" [(ngModel)]="user.name" #name="ngModel" />
24+
</td>
25+
<td>
26+
<button *ngIf="name.dirty" class="btn btn-success" (click)="editUser(user)">Save</button>
27+
</td>
28+
<td>
29+
<button class="btn btn-danger" (click)="deleteUser(user)">Delete</button>
30+
</td>
31+
</tr>
32+
<tr>
33+
<td><b>Add new user</b></td>
34+
<td>
35+
<input class="form-control" [(ngModel)]="newUserName" #newUser="ngModel" />
36+
</td>
37+
<td></td>
38+
<td>
39+
<button *ngIf="newUser.dirty" class="btn glyphicon-plus" (click)="addUser(newUserName)"></button>
40+
</td>
41+
</tr>
42+
</tbody>
43+
</table>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import {
2+
Component, OnInit,
3+
// animation imports
4+
trigger, state, style, transition, animate
5+
} from '@angular/core';
6+
7+
import { Http, URLSearchParams } from '@angular/http';
8+
9+
@Component({
10+
selector: 'fetchdata',
11+
templateUrl: './users.component.html',
12+
animations: [
13+
// Animation example
14+
// Triggered in the ngFor with [@flyInOut]
15+
trigger('flyInOut', [
16+
state('in', style({ transform: 'translateY(0)' })),
17+
transition('void => *', [
18+
style({ transform: 'translateY(-100%)' }),
19+
animate(1000)
20+
]),
21+
transition('* => void', [
22+
animate(1000, style({ transform: 'translateY(100%)' }))
23+
])
24+
])
25+
]
26+
})
27+
export class UsersComponent implements OnInit {
28+
29+
public newUserName: string;
30+
public users: IUser[];
31+
32+
// Use "constructor"s only for dependency injection
33+
constructor(private http: Http) { }
34+
35+
// Here you want to handle anything with @Input()'s @Output()'s
36+
// Data retrieval / etc - this is when the Component is "ready" and wired up
37+
ngOnInit() {
38+
this.newUserName = "";
39+
this.http.get('http://localhost:5000/api/user/all').map(res => res.json()).subscribe(result => {
40+
console.log(result);
41+
this.users = result as IUser[];
42+
});
43+
}
44+
45+
deleteUser(user) {
46+
this.http.delete("http://localhost:5000/api/user/delete/" + user.id).subscribe(result => {
47+
if (result.ok) {
48+
let position = this.users.indexOf(user);
49+
this.users.splice(position, 1);
50+
}
51+
else {
52+
alert("There was an issue, Could not delete user");
53+
}
54+
});
55+
}
56+
57+
editUser(user) {
58+
let urlSearchParams = new URLSearchParams();
59+
urlSearchParams.append('id', user.id);
60+
urlSearchParams.append('name', user.name);
61+
this.http.put('http://localhost:5000/api/user/update', urlSearchParams).subscribe(result => {
62+
if (!result.ok) {
63+
alert("There was an issue, Could not edit user");
64+
}
65+
});
66+
}
67+
68+
addUser(newUserName) {
69+
let urlSearchParams = new URLSearchParams();
70+
urlSearchParams.append('name', newUserName);
71+
this.http.post('http://localhost:5000/api/user/insert', urlSearchParams).subscribe(result => {
72+
if (result.ok) {
73+
this.users.push(result.json());
74+
this.newUserName = "";
75+
}
76+
else {
77+
alert("There was an issue, Could not edit user");
78+
}
79+
});
80+
}
81+
}
82+
83+
interface IUser {
84+
id: number;
85+
name: string;
86+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
import './polyfills.ts';
2+
13
import 'zone.js/dist/zone';
24
import 'reflect-metadata';
3-
4-
import './rx-imports';

Client/polyfills/polyfills.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
/***************************************************************************************************
3+
* BROWSER POLYFILLS
4+
*/
5+
6+
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
7+
import 'core-js/es6/symbol';
8+
import 'core-js/es6/object';
9+
import 'core-js/es6/function';
10+
import 'core-js/es6/parse-int';
11+
import 'core-js/es6/parse-float';
12+
import 'core-js/es6/number';
13+
import 'core-js/es6/math';
14+
import 'core-js/es6/string';
15+
import 'core-js/es6/date';
16+
import 'core-js/es6/array';
17+
import 'core-js/es6/regexp';
18+
import 'core-js/es6/map';
19+
import 'core-js/es6/set';
20+
21+
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
22+
// import 'classlist.js'; // Run `npm install --save classlist.js`.
23+
24+
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
25+
26+
/** Evergreen browsers require these. **/
27+
import 'core-js/es6/reflect';
28+
import 'core-js/es7/reflect';
29+
30+
/**
31+
* Date, currency, decimal and percent pipes.
32+
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
33+
*/
34+
// import 'intl'; // Run `npm install --save intl`.
35+
36+
import './rx-imports';

Client/polyfills/rx-imports.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@
33
*
44
* Here you can place any RxJs imports so you don't have to constantly
55
* import them throughout your App :)
6+
*
7+
* This file is automatically imported into `polyfills.ts` (which is imported into browser/server modules)
68
*/
79

8-
// Observable
9-
import 'rxjs/observable';
10-
import 'rxjs/observable/throw';
11-
12-
// Subject
13-
import 'rxjs/subject';
14-
15-
// Operators
16-
import 'rxjs/add/operator/filter';
17-
import 'rxjs/add/operator/first';
18-
import 'rxjs/add/operator/catch';
10+
// General Operators
1911
import 'rxjs/add/operator/map';
12+
import 'rxjs/add/operator/do';
13+
import 'rxjs/add/operator/throttleTime';
14+
import 'rxjs/add/operator/distinctUntilChanged';
15+
import 'rxjs/add/operator/switchMap';
16+
import 'rxjs/add/operator/take';
17+
import 'rxjs/add/operator/debounceTime';
18+
import 'rxjs/add/operator/filter';
2019
import 'rxjs/add/operator/mergeMap';
20+
import 'rxjs/add/operator/concat';
21+
import 'rxjs/add/operator/catch';
22+
import 'rxjs/add/operator/first';
23+
24+
// Observable operators
25+
import 'rxjs/add/observable/fromEvent';
26+
import 'rxjs/add/observable/interval';
27+
import 'rxjs/add/observable/fromPromise';
28+
import 'rxjs/add/observable/of';
29+
import 'rxjs/add/observable/concat';
30+
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import 'es6-promise';
2-
import 'es6-shim';
3-
import 'reflect-metadata';
1+
import './polyfills.ts';
42

3+
import 'reflect-metadata';
54
import 'zone.js';
6-
7-
import './rx-imports';

0 commit comments

Comments
 (0)