update-user.service.js 4.95 KB
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = require('@angular/core');
var http_1 = require('@angular/http');
var router_1 = require('@angular/router');
var Observable_1 = require('rxjs/Observable');
require('rxjs/add/operator/map');
require('rxjs/add/operator/catch');
//import { AppSettings, User } from '../model/data-model';
var UpdateUserService = (function () {
    function UpdateUserService(http, router) {
        //if (this.currentUser == null) {
        //    var user = localStorage.getItem("currentUser");
        this.http = http;
        this.router = router;
        //    if (user != null) {
        //        this.currentUser = JSON.parse(user);
        //        this.loggedIn = true;
        //    }
        //}
        this.userId = 0;
        this.firstName = "";
        this.lastName = "";
        this.emailId = "";
    }
    UpdateUserService.prototype.extractData = function (res) {
        var body = res.json();
        return body || {};
    };
    UpdateUserService.prototype.handleError = function (error) {
        // In a real world app, we might use a remote logging infrastructure
        var errMsg;
        if (error instanceof http_1.Response) {
            var body = error.json() || '';
            var err = body.error || JSON.stringify(body);
            errMsg = error.status + " - " + (error.statusText || '') + " " + err;
        }
        else {
            errMsg = error.message ? error.message : error.toString();
        }
        console.error(errMsg);
        return Observable_1.Observable.throw(errMsg);
    };
    UpdateUserService.prototype.UpdateUserProfile = function (applicationName, strFirstName, strLastName, strEmailID) {
        console.log('inside application service');
        var usrID;
        usrID = 1;
        var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
        //let headers = new Headers();
        //headers.append('Content-type', 'application/x-www-form-urlencoded');
        var options = new http_1.RequestOptions({ headers: headers });
        var body = JSON.stringify({ userId: usrID, emailId: strEmailID, firstName: strFirstName, lastName: strLastName });
        console.log(body);
        return this.http.post('http://localhost:85/AIAHTML5.Server/api/updateprofile', body, options)
            .map(this.extractData)
            .catch(this.handleError);
    };
    UpdateUserService.prototype.UpdateUserProfile2 = function (applicationName, strFirstName, strLastName, strEmailID) {
        console.log('inside update-user service -2');
        var usrID;
        usrID = 1;
        //let headers = new Headers({ 'Content-Type': 'application/json' });
        var headers = new http_1.Headers();
        headers.append('Content-type', 'application/x-www-form-urlencoded');
        var options = new http_1.RequestOptions({ headers: headers });
        var body = 'userId=' + usrID + '&emailId=' + strEmailID + '&firstName=' + strFirstName + '&lastName=' + strLastName;
        console.log(body);
        var urlSearchParams = new http_1.URLSearchParams();
        urlSearchParams.append('userId', usrID.toString());
        urlSearchParams.append('firstName', strFirstName);
        urlSearchParams.append('lastName', strLastName);
        urlSearchParams.append('emailId', strEmailID);
        var body2 = urlSearchParams.toString();
        return this.http.post('http://localhost:85/AIAHTML5.Server/api/updateprofile', body, options)
            .map(function (response) {
            console.log(response);
            var body = response.json();
            console.log(body);
        })
            .catch(this.logError);
    };
    UpdateUserService.prototype.extractData2 = function (res) {
        var body = res.json();
        console.log('ServiceResult: ' + body);
        return body || {};
    };
    UpdateUserService.prototype.logError = function (error) {
        console.log('ServiceError: ' + err);
    };
    UpdateUserService = __decorate([
        core_1.Injectable(), 
        __metadata('design:paramtypes', [http_1.Http, router_1.Router])
    ], UpdateUserService);
    return UpdateUserService;
}());
exports.UpdateUserService = UpdateUserService;
//# sourceMappingURL=update-user.service.js.map