4 |
5 |
6 | {{ alert.message }}
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | {{prod.Name}}
19 |
20 |
21 | Price:{{prod.UnitPrice}}
22 |
23 |
24 | {{prod.Description}}
25 |
26 |
27 |
28 | Add to cart
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "deep-cart",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e"
11 | },
12 | "private": true,
13 | "dependencies": {
14 | "@angular/animations": "^6.0.0",
15 | "@angular/common": "^6.0.0",
16 | "@angular/compiler": "^6.0.0",
17 | "@angular/core": "^6.0.0",
18 | "@angular/forms": "^6.0.0",
19 | "@angular/http": "^6.0.0",
20 | "@angular/platform-browser": "^6.0.0",
21 | "@angular/platform-browser-dynamic": "^6.0.0",
22 | "@angular/router": "^6.0.0",
23 | "@ng-bootstrap/ng-bootstrap": "^3.0.0",
24 | "bootstrap-scss": "^4.1.3",
25 | "core-js": "^2.5.4",
26 | "rxjs": "^6.0.0",
27 | "zone.js": "^0.8.26"
28 | },
29 | "devDependencies": {
30 | "@angular/compiler-cli": "^6.0.0",
31 | "@angular-devkit/build-angular": "~0.6.0",
32 | "typescript": "~2.7.2",
33 | "@angular/cli": "~6.0.0",
34 | "@angular/language-service": "^6.0.0",
35 | "@types/jasmine": "~2.8.6",
36 | "@types/jasminewd2": "~2.0.3",
37 | "@types/node": "~8.9.4",
38 | "codelyzer": "~4.2.1",
39 | "jasmine-core": "~2.99.1",
40 | "jasmine-spec-reporter": "~4.2.1",
41 | "karma": "~1.7.1",
42 | "karma-chrome-launcher": "~2.2.0",
43 | "karma-coverage-istanbul-reporter": "~1.4.2",
44 | "karma-jasmine": "~1.1.1",
45 | "karma-jasmine-html-reporter": "^0.2.2",
46 | "protractor": "~5.3.0",
47 | "ts-node": "~5.0.1",
48 | "tslint": "~5.9.1"
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DeepCart
2 | This is the hard work of Deep and contributing this code for free for learning purpose.
3 | No has copy rights on this except code owner.
4 |
5 | I would request you to please subscribe , like and comment on my channel.
6 | The way I am hellping you ,please help me as well.
7 |
8 |
9 | Here are the video tutorials of this comeplete series.
10 |
11 | Lesson-1
12 | https://youtu.be/JjVyvy3ctFE
13 |
14 | Lesson-2
15 | https://youtu.be/SrmShkVhKhU
16 |
17 | Lesson-3
18 | https://youtu.be/wWknX6eaWjg
19 |
20 | Lesson-4
21 | https://youtu.be/CLqoEHt2aNk
22 |
23 | Lesson-5
24 | https://youtu.be/orRQrwPpbac
25 |
26 | Lesson-6
27 | https://youtu.be/qbGdKW-RWw0
28 |
29 | Lesson-7
30 | https://youtu.be/HeYsF01c5iw
31 |
32 | Lesson-8
33 | https://youtu.be/Oylx-hpaUDc
34 |
35 | Please , please subscribe my channel.Comment your views about my channel and social work of giving the source code.
36 |
37 |
38 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.0.0.
39 |
40 | ## Development server
41 |
42 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
43 |
44 | ## Code scaffolding
45 |
46 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
47 |
48 | ## Build
49 |
50 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
51 |
52 | ## Running unit tests
53 |
54 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
55 |
56 | ## Running end-to-end tests
57 |
58 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
59 |
60 | ## Further help
61 |
62 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
63 | # DeepCart
64 |
--------------------------------------------------------------------------------
/src/app/Services/authentication.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient,HttpClientModule, HttpHeaders } from '@angular/common/http';
3 | import { Http, Response } from '@angular/http';
4 | import { Observable, of, throwError, pipe} from "rxjs"
5 | import { map, filter, catchError, mergeMap } from 'rxjs/operators';
6 |
7 | @Injectable({
8 | providedIn: 'root'
9 | })
10 | export class AuthenticationService {
11 | public apiURL:string="http://localhost:50148/";
12 |
13 | constructor(private httpClient:HttpClient) { }
14 | // This tutorial is by DotNet Techy YouTube Channel
15 | // For more info about channel You can visit this link
16 | // https://www.youtube.com/c/dotnettechy
17 | ValidateUser (user:any)
18 | {
19 | var userData = "username=" + user.UserName + "&password=" + user.Password + "&grant_type=password";
20 | var reqHeader = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded','No-Auth':'True' });
21 |
22 | return this.httpClient.post(this.apiURL+ '/token',userData,{ headers: reqHeader })
23 | .pipe(
24 | map(res => res),
25 | catchError( this.errorHandler)
26 | );
27 | }
28 | getClaims ()
29 | {
30 | var reqHeader = new HttpHeaders({ 'Authorization':'Bearer '+this.getToken()});
31 | reqHeader.append('Content-Type', 'application/json');
32 | return this.httpClient.get(this.apiURL+ 'api/Users',{ headers: reqHeader })
33 | .pipe(
34 | map(res => res),
35 | catchError( this.errorHandler)
36 | );
37 | }
38 | public isAuthenticated(): boolean {
39 | return this.getToken() !== null;
40 | }
41 | storeToken(token: string) {
42 | localStorage.setItem("token", token);
43 | }
44 | getToken() {
45 | return localStorage.getItem("token");
46 | }
47 | removeToken() {
48 | return localStorage.removeItem("token");
49 | }
50 | storeRole(role: any) {
51 | this.removeRole();
52 | localStorage.setItem('role', JSON.stringify(role));
53 | }
54 | getRole() {
55 | // return localStorage.getItem("role");
56 | return JSON.parse(localStorage.getItem('role'));
57 | }
58 | removeRole() {
59 | return localStorage.removeItem("role");
60 | }
61 | errorHandler(error: Response) {
62 | console.log(error);
63 | return throwError(error);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/app/Services/product.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient,HttpClientModule, HttpHeaders } from '@angular/common/http';
3 | import { Http, Response } from '@angular/http';
4 | import { Observable, of, throwError, pipe} from "rxjs"
5 | import { map, filter, catchError, mergeMap } from 'rxjs/operators';
6 | import { AuthenticationService } from './authentication.service';
7 | import { Product } from '../Models/Product.Model';
8 |
9 | @Injectable({
10 | providedIn: 'root'
11 | })
12 | export class ProductService {
13 |
14 | public apiURL:string="http://localhost:50148/api/Products";
15 | constructor(private httpClient:HttpClient, private authService:AuthenticationService) { }
16 |
17 | saveProductInfo (product:any)
18 | {
19 | var reqHeader = new HttpHeaders({ 'Authorization':'Bearer '+this.authService.getToken()});
20 | reqHeader.append('Content-Type', 'application/json');
21 | const formData: FormData = new FormData();
22 | formData.append('UnitPrice', product['Price']);
23 | formData.append('Name', product.Name.toString());
24 | formData.append('SellerId', product.SellerId.toString());
25 | formData.append('SellerName', product.SellerName.toString());
26 | formData.append('Category', product.Category.toString());
27 | formData.append('TC', product['Conditions']);
28 | formData.append('Quantity', product.Quantity.toString());
29 | formData.append('Description', product.Description.toString());
30 | formData.append('Image', product['ImageFile']);
31 |
32 |
33 | return this.httpClient.post(this.apiURL,formData,{ headers: reqHeader })
34 | .pipe(
35 | map(res => res),
36 | catchError( this.errorHandler)
37 | );
38 | }
39 | getAllProducts ()
40 | {
41 | return this.httpClient.get(this.apiURL)
42 | .pipe(
43 | map(res => res),
44 | catchError( this.errorHandler)
45 | );
46 | }
47 | addProductToCart(prodcuts: any) {
48 | localStorage.setItem("product", JSON.stringify(prodcuts));
49 | }
50 | getProductFromCart() {
51 | //return localStorage.getItem("product");
52 | return JSON.parse(localStorage.getItem('product'));
53 | }
54 | removeAllProductFromCart() {
55 | return localStorage.removeItem("product");
56 | }
57 | errorHandler(error: Response) {
58 | console.log(error);
59 | return throwError(error);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/app/dashboard/dashboard.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit,Input } from '@angular/core';
2 | import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
3 | import { AuthenticationService } from '../Services/authentication.service';
4 | import { Product } from '../Models/Product.Model';
5 | import { ProductService } from '../Services/product.service';
6 | import { IAlert } from '../Models/IAlert';
7 |
8 | @Component({
9 | selector: 'app-dashboard',
10 | templateUrl: './dashboard.component.html',
11 | styleUrls: ['./dashboard.component.scss']
12 | })
13 | export class DashboardComponent implements OnInit {
14 |
15 | productForm: FormGroup;
16 | sellerName:string="";
17 | sellerId:number=0;
18 | productFormInputs: Product[];
19 | @Input()
20 | public alerts: Array
= [];
21 | public globalResponse: any;
22 | productImage:File=null;
23 |
24 | constructor(private fb: FormBuilder,private authService:AuthenticationService,private productService:ProductService) { }
25 |
26 | ngOnInit() {
27 | this.productForm = this.fb.group({
28 | Name: ['', Validators.compose([Validators.required, Validators.minLength(3),Validators.maxLength(50)])],
29 | Description:['',Validators.compose([Validators.required, Validators.minLength(3),Validators.maxLength(50)])],
30 | Price:['',Validators.compose([Validators.required])],
31 | Category:['',Validators.required],
32 | Quantity:['',Validators.required],
33 | Address:['',Validators.required],
34 | image:['',Validators.required],
35 | Conditions:['',''],
36 |
37 | });
38 | this.GetSellerDetails();
39 | }
40 | GetSellerDetails()
41 | {
42 | let details=this.authService.getRole();
43 | // console.log(details);
44 | this.sellerId=details["Id"];
45 | this.sellerName=details["UserName"];
46 | }
47 | handleImageFile(file:FileList)
48 | {
49 | this.productImage=file.item(0);
50 | }
51 | OnSaveProduct()
52 | {
53 | let productFormInputs=this.productForm.value;
54 | productFormInputs.SellerId=this.sellerId;
55 | productFormInputs.SellerName=this.sellerName;
56 | productFormInputs.ImageFile=this.productImage;
57 |
58 | this.alerts=[];
59 | // console.log(productFormInputs);
60 | this.productService.saveProductInfo(productFormInputs)
61 | .subscribe((result) => {
62 | this.globalResponse = result;
63 | },
64 | error => { //This is error part
65 | console.log(error.message);
66 | this.alerts.push({
67 | id: 2,
68 | type: 'danger',
69 | message: 'Something went wrong while saving the product, Please try after sometime.'
70 | });
71 | },
72 | () => {
73 | // This is Success part
74 | // console.log(this.globalResponse);
75 | this.alerts.push({
76 | id: 1,
77 | type: 'success',
78 | message: 'Product has been saved successfully. Now you can add more prodcut , if you wish to.',
79 | });
80 |
81 | }
82 | )
83 | }
84 | public closeAlert(alert: IAlert) {
85 | const index: number = this.alerts.indexOf(alert);
86 | this.alerts.splice(index, 1);
87 | }
88 | }
89 |
90 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "deprecation": {
15 | "severity": "warn"
16 | },
17 | "eofline": true,
18 | "forin": true,
19 | "import-blacklist": [
20 | true,
21 | "rxjs/Rx"
22 | ],
23 | "import-spacing": true,
24 | "indent": [
25 | true,
26 | "spaces"
27 | ],
28 | "interface-over-type-literal": true,
29 | "label-position": true,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": false,
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-arg": true,
47 | "no-bitwise": true,
48 | "no-console": [
49 | true,
50 | "debug",
51 | "info",
52 | "time",
53 | "timeEnd",
54 | "trace"
55 | ],
56 | "no-construct": true,
57 | "no-debugger": true,
58 | "no-duplicate-super": true,
59 | "no-empty": false,
60 | "no-empty-interface": true,
61 | "no-eval": true,
62 | "no-inferrable-types": [
63 | true,
64 | "ignore-params"
65 | ],
66 | "no-misused-new": true,
67 | "no-non-null-assertion": true,
68 | "no-shadowed-variable": true,
69 | "no-string-literal": false,
70 | "no-string-throw": true,
71 | "no-switch-case-fall-through": true,
72 | "no-trailing-whitespace": true,
73 | "no-unnecessary-initializer": true,
74 | "no-unused-expression": true,
75 | "no-use-before-declare": true,
76 | "no-var-keyword": true,
77 | "object-literal-sort-keys": false,
78 | "one-line": [
79 | true,
80 | "check-open-brace",
81 | "check-catch",
82 | "check-else",
83 | "check-whitespace"
84 | ],
85 | "prefer-const": true,
86 | "quotemark": [
87 | true,
88 | "single"
89 | ],
90 | "radix": true,
91 | "semicolon": [
92 | true,
93 | "always"
94 | ],
95 | "triple-equals": [
96 | true,
97 | "allow-null-check"
98 | ],
99 | "typedef-whitespace": [
100 | true,
101 | {
102 | "call-signature": "nospace",
103 | "index-signature": "nospace",
104 | "parameter": "nospace",
105 | "property-declaration": "nospace",
106 | "variable-declaration": "nospace"
107 | }
108 | ],
109 | "unified-signatures": true,
110 | "variable-name": false,
111 | "whitespace": [
112 | true,
113 | "check-branch",
114 | "check-decl",
115 | "check-operator",
116 | "check-separator",
117 | "check-type"
118 | ],
119 | "no-output-on-prefix": true,
120 | "use-input-property-decorator": true,
121 | "use-output-property-decorator": true,
122 | "use-host-property-decorator": true,
123 | "no-input-rename": true,
124 | "no-output-rename": true,
125 | "use-life-cycle-interface": true,
126 | "use-pipe-transform-interface": true,
127 | "component-class-suffix": true,
128 | "directive-class-suffix": true
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following for the Reflect API. */
41 | // import 'core-js/es6/reflect';
42 |
43 |
44 | /** Evergreen browsers require these. **/
45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
46 | import 'core-js/es7/reflect';
47 |
48 |
49 | /**
50 | * Web Animations `@angular/platform-browser/animations`
51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
53 | **/
54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
55 |
56 | /**
57 | * By default, zone.js will patch all possible macroTask and DomEvents
58 | * user can disable parts of macroTask/DomEvents patch by setting following flags
59 | */
60 |
61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
64 |
65 | /*
66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
68 | */
69 | // (window as any).__Zone_enable_cross_context_check = true;
70 |
71 | /***************************************************************************************************
72 | * Zone JS is required by default for Angular itself.
73 | */
74 | import 'zone.js/dist/zone'; // Included with Angular CLI.
75 |
76 |
77 |
78 | /***************************************************************************************************
79 | * APPLICATION IMPORTS
80 | */
81 |
--------------------------------------------------------------------------------
/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "DeepCart": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "prefix": "app",
11 | "schematics": {
12 | "@schematics/angular:component": {
13 | "styleext": "scss"
14 | }
15 | },
16 | "architect": {
17 | "build": {
18 | "builder": "@angular-devkit/build-angular:browser",
19 | "options": {
20 | "outputPath": "dist/DeepCart",
21 | "index": "src/index.html",
22 | "main": "src/main.ts",
23 | "polyfills": "src/polyfills.ts",
24 | "tsConfig": "src/tsconfig.app.json",
25 | "assets": [
26 | "src/favicon.ico",
27 | "src/assets"
28 | ],
29 | "styles": [
30 | "src/styles.scss"
31 | ],
32 | "scripts": []
33 | },
34 | "configurations": {
35 | "production": {
36 | "fileReplacements": [
37 | {
38 | "replace": "src/environments/environment.ts",
39 | "with": "src/environments/environment.prod.ts"
40 | }
41 | ],
42 | "optimization": true,
43 | "outputHashing": "all",
44 | "sourceMap": false,
45 | "extractCss": true,
46 | "namedChunks": false,
47 | "aot": true,
48 | "extractLicenses": true,
49 | "vendorChunk": false,
50 | "buildOptimizer": true
51 | }
52 | }
53 | },
54 | "serve": {
55 | "builder": "@angular-devkit/build-angular:dev-server",
56 | "options": {
57 | "browserTarget": "DeepCart:build"
58 | },
59 | "configurations": {
60 | "production": {
61 | "browserTarget": "DeepCart:build:production"
62 | }
63 | }
64 | },
65 | "extract-i18n": {
66 | "builder": "@angular-devkit/build-angular:extract-i18n",
67 | "options": {
68 | "browserTarget": "DeepCart:build"
69 | }
70 | },
71 | "test": {
72 | "builder": "@angular-devkit/build-angular:karma",
73 | "options": {
74 | "main": "src/test.ts",
75 | "polyfills": "src/polyfills.ts",
76 | "tsConfig": "src/tsconfig.spec.json",
77 | "karmaConfig": "src/karma.conf.js",
78 | "styles": [
79 | "styles.scss"
80 | ],
81 | "scripts": [],
82 | "assets": [
83 | "src/favicon.ico",
84 | "src/assets"
85 | ]
86 | }
87 | },
88 | "lint": {
89 | "builder": "@angular-devkit/build-angular:tslint",
90 | "options": {
91 | "tsConfig": [
92 | "src/tsconfig.app.json",
93 | "src/tsconfig.spec.json"
94 | ],
95 | "exclude": [
96 | "**/node_modules/**"
97 | ]
98 | }
99 | }
100 | }
101 | },
102 | "DeepCart-e2e": {
103 | "root": "e2e/",
104 | "projectType": "application",
105 | "architect": {
106 | "e2e": {
107 | "builder": "@angular-devkit/build-angular:protractor",
108 | "options": {
109 | "protractorConfig": "e2e/protractor.conf.js",
110 | "devServerTarget": "DeepCart:serve"
111 | }
112 | },
113 | "lint": {
114 | "builder": "@angular-devkit/build-angular:tslint",
115 | "options": {
116 | "tsConfig": "e2e/tsconfig.e2e.json",
117 | "exclude": [
118 | "**/node_modules/**"
119 | ]
120 | }
121 | }
122 | }
123 | }
124 | },
125 | "defaultProject": "DeepCart"
126 | }
--------------------------------------------------------------------------------
/src/app/productdisplay/productdisplay.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, EventEmitter, Output,OnInit } from '@angular/core';
2 | import { ProductDisplay } from '../Models/ProductDisplay.Model';
3 |
4 | import { ProductService } from '../Services/product.service';
5 | import { Product } from '../Models/Product.Model';
6 | import { IAlert } from '../Models/IAlert';
7 | import { SharedService } from '../Services/shared.service';
8 |
9 | @Component({
10 | selector: 'app-productdisplay',
11 | templateUrl: './productdisplay.component.html',
12 | styleUrls: ['./productdisplay.component.scss'],
13 | providers:[ProductService]
14 | })
15 | export class ProductdisplayComponent implements OnInit {
16 |
17 | public alerts: Array = [];
18 | cartItemCount: number = 0;
19 | @Output() cartEvent = new EventEmitter();
20 | public globalResponse: any;
21 | yourByteArray:any;
22 | allProducts: ProductDisplay[];
23 | productAddedTocart:Product[];
24 | constructor(private productService:ProductService,private sharedService:SharedService) { }
25 |
26 | ngOnInit() {
27 | this.productService.getAllProducts()
28 | .subscribe((result) => {
29 | this.globalResponse = result;
30 | },
31 | error => { //This is error part
32 | console.log(error.message);
33 | },
34 | () => {
35 | // This is Success part
36 | console.log("Product fetched sucssesfully.");
37 | //console.log(this.globalResponse);
38 | this.allProducts=this.globalResponse;
39 | }
40 | )
41 |
42 | }
43 | OnAddCart(product:Product)
44 | {
45 | console.log(product);
46 |
47 | this.productAddedTocart=this.productService.getProductFromCart();
48 | if(this.productAddedTocart==null)
49 | {
50 | this.productAddedTocart=[];
51 | this.productAddedTocart.push(product);
52 | this.productService.addProductToCart(this.productAddedTocart);
53 | this.alerts.push({
54 | id: 1,
55 | type: 'success',
56 | message: 'Product added to cart.'
57 | });
58 | setTimeout(()=>{
59 | this.closeAlert(this.alerts);
60 | }, 3000);
61 |
62 | }
63 | else
64 | {
65 | let tempProduct=this.productAddedTocart.find(p=>p.Id==product.Id);
66 | if(tempProduct==null)
67 | {
68 | this.productAddedTocart.push(product);
69 | this.productService.addProductToCart(this.productAddedTocart);
70 | this.alerts.push({
71 | id: 1,
72 | type: 'success',
73 | message: 'Product added to cart.'
74 | });
75 | //setTimeout(function(){ }, 2000);
76 | setTimeout(()=>{
77 | this.closeAlert(this.alerts);
78 | }, 3000);
79 | }
80 | else
81 | {
82 | this.alerts.push({
83 | id: 2,
84 | type: 'warning',
85 | message: 'Product already exist in cart.'
86 | });
87 | setTimeout(()=>{
88 | this.closeAlert(this.alerts);
89 | }, 3000);
90 | }
91 |
92 | }
93 | //console.log(this.cartItemCount);
94 | this.cartItemCount=this.productAddedTocart.length;
95 | // this.cartEvent.emit(this.cartItemCount);
96 | this.sharedService.updateCartCount(this.cartItemCount);
97 | }
98 | public closeAlert(alert:any) {
99 | const index: number = this.alerts.indexOf(alert);
100 | this.alerts.splice(index, 1);
101 | }
102 | }
103 |
104 |
105 |
--------------------------------------------------------------------------------
/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import {Input, Component, OnInit } from '@angular/core';
2 | import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';
3 | import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
4 | import { HttpClient,HttpClientModule } from '@angular/common/http';
5 | import { Registration } from './Models/User.Models';
6 | import {RegistrationService} from './Services/Registration.Service'
7 | import { AuthenticationService } from './Services/authentication.service';
8 | import { SharedService } from './Services/shared.service';
9 |
10 |
11 | @Component({
12 | selector: 'app-root',
13 | templateUrl: './app.component.html',
14 | styleUrls: ['./app.component.scss'],
15 | providers:[RegistrationService]
16 | })
17 | export class AppComponent implements OnInit {
18 | closeResult: string;
19 | registrationForm: FormGroup;
20 | loginForm:FormGroup;
21 | registrationInputs: Registration[];
22 | currentUser: Registration[];
23 | isLoggedIn:boolean=false;
24 |
25 | cartItemCount:number=0;
26 | approvalText:string="";
27 |
28 | @Input()
29 | public alerts: Array = [];
30 |
31 | message = "";
32 | public globalResponse: any;
33 |
34 | constructor(private sharedService:SharedService, private modalService: NgbModal,private fb: FormBuilder,private regService:RegistrationService ,private authService:AuthenticationService) {
35 |
36 | }
37 | ngOnInit()
38 | {
39 | this.sharedService.currentMessage.subscribe(msg => this.cartItemCount = msg);
40 | this.registrationForm = this.fb.group({
41 | UserName: ['', Validators.compose([Validators.required, Validators.minLength(3),Validators.maxLength(50)])],
42 | Password:['',Validators.compose([Validators.required, Validators.minLength(3),Validators.maxLength(50)])],
43 | Email:['',Validators.compose([Validators.required,Validators.email])],
44 | Role:['',Validators.required],
45 | Phone:['',Validators.required],
46 | Gender:['',''],
47 | });
48 | this.loginForm = this.fb.group({
49 | UserName: ['', [Validators.required]],
50 | Password:['',[Validators.required]],
51 | });
52 | }
53 |
54 | open(content) {
55 | this.alerts=[];
56 | this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title',size: 'lg'}).result.then((result) => {
57 | this.closeResult = `Closed with: ${result}`;
58 | }, (reason) => {
59 | //this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
60 | });
61 | }
62 |
63 | private getDismissReason(reason: any): string {
64 | if (reason === ModalDismissReasons.ESC) {
65 | return 'by pressing ESC';
66 | } else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
67 | return 'by clicking on a backdrop';
68 | } else {
69 | return `with: ${reason}`;
70 | }
71 | }
72 | Login()
73 | {
74 | let user=this.loginForm.value;
75 | this.isLoggedIn=false;
76 | this.authService.removeToken();
77 | this.alerts=[];
78 | //console.log(user);
79 | this.authService.ValidateUser(user)
80 | .subscribe((result) => {
81 | this.globalResponse = result;
82 | },
83 | error => { //This is error part
84 | console.log(error.message);
85 | this.alerts.push({
86 | id: 2,
87 | type: 'danger',
88 | message: 'Either user name or password is incorrect.'
89 | });
90 | },
91 | () => {
92 | // This is Success part
93 | // console.log(this.globalResponse);
94 | this.authService.storeToken(this.globalResponse.access_token);
95 | this.alerts.push({
96 | id: 1,
97 | type: 'success',
98 | message: 'Login successful. Now you can close and proceed further.',
99 | });
100 | this.isLoggedIn=true;
101 | this.GetClaims();
102 |
103 | }
104 | )
105 | }
106 |
107 | OnRegister()
108 | {
109 | this.registrationInputs=this.registrationForm.value;
110 |
111 | console.log(this.registrationInputs);
112 | this.regService.RegisterUser(this.registrationInputs)
113 | .subscribe((result) => {
114 | this.globalResponse = result;
115 | },
116 | error => { //This is error part
117 | this.alerts.push({
118 | id: 2,
119 | type: 'danger',
120 | message: 'Registration failed with fallowing error:'+error,
121 | });
122 | },
123 | () => {
124 | // This is Success part
125 | this.alerts.push({
126 | id: 1,
127 | type: 'success',
128 | message: 'Registration successful.',
129 | });
130 |
131 | }
132 | )
133 | }
134 | public closeAlert(alert: IAlert) {
135 | const index: number = this.alerts.indexOf(alert);
136 | this.alerts.splice(index, 1);
137 | }
138 | GetClaims()
139 | {
140 | this.authService.getClaims()
141 | .subscribe((result) => {
142 | this.globalResponse = result;
143 | },
144 | error => { //This is error part
145 | console.log(error.message);
146 | },
147 | () => {
148 | // This is Success part
149 | // console.log(this.globalResponse );
150 | let a=this.globalResponse;
151 | this.currentUser=this.globalResponse;
152 | this.authService.storeRole(this.currentUser);
153 | }
154 | )
155 |
156 | }
157 | LogOut()
158 | {
159 | this.isLoggedIn=false;
160 | this.authService.removeToken();
161 | }
162 |
163 |
164 | }
165 | export interface IAlert {
166 | id: number;
167 | type: string;
168 | message: string;
169 | }
--------------------------------------------------------------------------------
/src/app/mycart/mycart.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
3 | import { Product } from '../Models/Product.Model';
4 | import { ProductService } from '../Services/product.service';
5 | import { IAlert } from '../Models/IAlert';
6 | import { OrderDetail } from '../Models/OrderDetail.Model';
7 | import { Registration } from '../Models/User.Models';
8 | import { AuthenticationService } from '../Services/authentication.service';
9 | import { OrderService } from '../Services/order.service';
10 | import { OrderItem } from '../Models/OrderItem.Model';
11 |
12 | @Component({
13 | selector: 'app-mycart',
14 | templateUrl: './mycart.component.html',
15 | styleUrls: ['./mycart.component.scss']
16 | })
17 | export class MycartComponent implements OnInit {
18 | dafualtQuantity:number=1;
19 | productAddedTocart:Product[];
20 | allTotal:number;
21 | currentUser: Registration[];
22 | orderDetail:OrderDetail;
23 | orderItem:OrderItem[];
24 |
25 | public globalResponse: any;
26 | public alerts: Array = [];
27 |
28 | deliveryForm:FormGroup;
29 |
30 |
31 | constructor(private productService:ProductService,private fb: FormBuilder,private authService:AuthenticationService,private orderService:OrderService)
32 | {
33 |
34 | }
35 |
36 | ngOnInit() {
37 | this.productAddedTocart=this.productService.getProductFromCart();
38 | for (let i in this.productAddedTocart) {
39 | this.productAddedTocart[i].Quantity=1;
40 | }
41 | this.productService.removeAllProductFromCart();
42 | this.productService.addProductToCart(this.productAddedTocart);
43 | this.calculteAllTotal(this.productAddedTocart);
44 |
45 | this.GetLoggedinUserDetails();
46 |
47 | this.deliveryForm = this.fb.group({
48 | UserName: ['', [Validators.required]],
49 | DeliveryAddress:['',[Validators.required]],
50 | Phone:['',[Validators.required]],
51 | Email:['',[Validators.required]],
52 | Message:['',[]],
53 | Amount:['',[Validators.required]],
54 |
55 | });
56 |
57 | this.deliveryForm.controls['UserName'].setValue(this.currentUser["UserName"]);
58 | this.deliveryForm.controls['Phone'].setValue(this.currentUser["Phone"]);
59 | this.deliveryForm.controls['Email'].setValue(this.currentUser["Email"]);
60 | this.deliveryForm.controls['Amount'].setValue(this.allTotal);
61 | }
62 | onAddQuantity(product:Product)
63 | {
64 | //Get Product
65 | this.productAddedTocart=this.productService.getProductFromCart();
66 | this.productAddedTocart.find(p=>p.Id==product.Id).Quantity = product.Quantity+1;
67 | //Find produc for which we want to update the quantity
68 | //let tempProd= this.productAddedTocart.find(p=>p.Id==product.Id);
69 | //tempProd.Quantity=tempProd.Quantity+1;
70 |
71 | //this.productAddedTocart=this.productAddedTocart.splice(this.productAddedTocart.indexOf(product), 1)
72 | //Push the product for cart
73 | // this.productAddedTocart.push(tempProd);
74 | this.productService.removeAllProductFromCart();
75 | this.productService.addProductToCart(this.productAddedTocart);
76 | this.calculteAllTotal(this.productAddedTocart);
77 | this.deliveryForm.controls['Amount'].setValue(this.allTotal);
78 |
79 | }
80 | onRemoveQuantity(product:Product)
81 | {
82 | this.productAddedTocart=this.productService.getProductFromCart();
83 | this.productAddedTocart.find(p=>p.Id==product.Id).Quantity = product.Quantity-1;
84 | this.productService.removeAllProductFromCart();
85 | this.productService.addProductToCart(this.productAddedTocart);
86 | this.calculteAllTotal(this.productAddedTocart);
87 | this.deliveryForm.controls['Amount'].setValue(this.allTotal);
88 |
89 | }
90 | calculteAllTotal(allItems:Product[])
91 | {
92 | let total=0;
93 | for (let i in allItems) {
94 | total= total+(allItems[i].Quantity *allItems[i].UnitPrice);
95 | }
96 | this.allTotal=total;
97 | }
98 |
99 | GetLoggedinUserDetails()
100 | {
101 | this.currentUser=this.authService.getRole();
102 |
103 | }
104 | ConfirmOrder()
105 | {
106 | const date: Date = new Date();
107 | var id=this.currentUser['Id'];
108 | var name=this.currentUser["UserName"];
109 | var day = date.getDate();
110 | var monthIndex = date.getMonth();
111 | var year = date.getFullYear();
112 | var minutes = date.getMinutes();
113 | var hours = date.getHours();
114 | var seconds = date.getSeconds();
115 | var dateTimeStamp=day.toString()+monthIndex.toString()+year.toString()+minutes.toString()+hours.toString()+seconds.toString();
116 | let orderDetail:any={};
117 |
118 | //Orderdetail is object which hold all the value, which needs to be saved into database
119 | orderDetail.CustomerId=this.currentUser['Id'];
120 | orderDetail.CustomerName=this.currentUser["UserName"];
121 | orderDetail.DeliveryAddress=this.deliveryForm.controls['DeliveryAddress'].value;
122 | orderDetail.Phone=this.deliveryForm.controls['Phone'].value;
123 |
124 | orderDetail.PaymentRefrenceId=id+"-"+name+dateTimeStamp;
125 | orderDetail.OrderPayMethod="Cash On Delivery";
126 |
127 | //Assigning the ordered item details
128 | this.orderItem=[];
129 | for (let i in this.productAddedTocart) {
130 | this.orderItem.push({
131 | ID:0,
132 | ProductID:this.productAddedTocart[i].Id,
133 | SellerID:this.productAddedTocart[i].SellerId,
134 | ProductName:this.productAddedTocart[i].Name,
135 | OrderedQuantity:this.productAddedTocart[i].Quantity,
136 | PerUnitPrice:this.productAddedTocart[i].UnitPrice,
137 | OrderID:0,
138 | }) ;
139 | }
140 | //So now compelte object of order is
141 | orderDetail.OrderItems=this.orderItem;
142 |
143 | this.orderService.PlaceOrder(orderDetail)
144 | .subscribe((result) => {
145 | this.globalResponse = result;
146 | },
147 | error => { //This is error part
148 | console.log(error.message);
149 | this.alerts.push({
150 | id: 2,
151 | type: 'danger',
152 | message: 'Something went wrong while placing the order, Please try after sometime.'
153 | });
154 | },
155 | () => {
156 | // This is Success part
157 | //console.log(this.globalResponse);
158 | this.alerts.push({
159 | id: 1,
160 | type: 'success',
161 | message: 'Order has been placed succesfully.',
162 | });
163 |
164 | }
165 | )
166 |
167 | }
168 | public closeAlert(alert: IAlert) {
169 | const index: number = this.alerts.indexOf(alert);
170 | this.alerts.splice(index, 1);
171 | }
172 |
173 | }
174 |
--------------------------------------------------------------------------------
/src/app/mycart/mycart.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
Items in your cart:
11 | Total value is: {{allTotal}}
12 | CheckOut
13 |
14 |
15 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | ★ Order Details ★
49 |
50 |
51 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | Item Details
82 | Delivery Details
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 | Name & Description
91 | Price
92 | Quantity
93 | Total For Item
94 |
95 |
96 |
97 | {{prod.Name}}
98 | {{prod.UnitPrice}}
99 | {{prod.Quantity}}
100 | {{prod.UnitPrice * prod.Quantity}}
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 | Name
111 | Delivery Address
112 | Phone
113 | Email
114 | Message
115 |
116 |
117 |
118 | {{deliveryForm.value.UserName}}
119 | {{deliveryForm.value.DeliveryAddress}}
120 | {{deliveryForm.value.Phone}}
121 | {{deliveryForm.value.Email}}
122 | {{deliveryForm.value.Message}}
123 |
124 |
125 |
126 |
127 |
128 |
129 | Confirm Order
130 |
131 |
132 |
133 |
134 | {{ alert.message }}
135 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/src/app/dashboard/dashboard.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Add Products
8 |
9 |
10 |
11 |
149 | Save
150 |
151 |
152 | {{ alert.message }}
153 |
154 |
155 |
156 |
157 |
158 | Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid.
159 | Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table
160 | craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl
161 | cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia
162 | yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean
163 | shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero
164 | sint qui sapiente accusamus tattooed echo park.
165 |
166 |
167 |
168 |
169 | Sed commodo, leo at suscipit dictum, quam est porttitor sapien, eget sodales nibh elit id diam. Nulla facilisi. Donec egestas ligula vitae odio interdum aliquet. Duis lectus turpis, luctus eget tincidunt eu, congue et odio. Duis pharetra et nisl at faucibus. Quisque luctus pulvinar arcu, et molestie lectus ultrices et. Sed diam urna, egestas ut ipsum vel, volutpat volutpat neque. Praesent fringilla tortor arcu. Vivamus faucibus nisl enim, nec tristique ipsum euismod facilisis. Morbi ut bibendum est, eu tincidunt odio. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris aliquet odio ac lorem aliquet ultricies in eget neque. Phasellus nec tortor vel tellus pulvinar feugiat.
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
--------------------------------------------------------------------------------
/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | Login & Signup
18 |
19 |
20 |
User Details
21 |
22 |
23 |
28 |
29 |
30 |
31 |
More
32 |
33 |
34 |
39 |
40 |
41 |
42 |
43 |
44 | Cart {{cartItemCount}}
45 | unread messages
46 |
47 |
48 |
49 | Admin
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
64 |
65 |
66 |
67 |
68 | Login
69 |
70 |
71 |
72 |
86 | Login
87 |
88 |
89 |
90 |
91 | Register
92 |
93 |
94 |
95 |
198 | Register
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
--------------------------------------------------------------------------------