function ServiceFactory($rootScope, $http,localStorageService) { var sm = this; sm.characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; sm.assignModal = {}; sm.holdContent = {}; sm.EditContent = {}; sm.ViewContent = {}; sm.OptionContent = {}; sm.StoreData = {}; sm.StoreUserProfile = {}; sm.SelectedTab = {}; sm.UserInfo = {}; sm.HoldUsers = {}; sm.UserProfile= (function(key, value ){ localStorageService.set(key,value) }); sm.ReadLocally= (function(key) { return localStorageService.get(key); }); sm.ClearAll= (function() { localStorageService.clearAll; }); sm.Api_Key = (function() { try{ return this.ReadLocally("loginResults").Api_Key; } catch(err) { } return null; }) sm.baseurl = (function (name) { var base = window.location.origin; return base + '/api/' + name; }); this.$http = $http; sm.endpoints = { DocumentList: sm.baseurl('documentlist'), Store: sm.baseurl('store'), register: sm.baseurl('register'), invoice: sm.baseurl('invoice'), profile: sm.baseurl('profile'), support: sm.baseurl('support'), contact: sm.baseurl('contact'), login: sm.baseurl('login'), email: sm.baseurl('email'), Validate: sm.baseurl('validate'), Validate: sm.baseurl('validate'), creditcard: sm.baseurl('creditcard'), Message: sm.baseurl('message'), createcustomer: sm.baseurl('payment') + '/createcustomer', updatecustomer: sm.baseurl('payment') + '/updatecustomer', training : 'https://afuntraining.azurewebsites.net/api/Request1' }; sm.Create = (function (url, payload) { return this.$http.post(url, payload ).then(function (response) { return response.data; }); }); sm.Read = (function (url) { return this.$http.get(url).then(function (response) { return response.data; }); }); sm.ReadPost = (function (url, payload) { return this.$http.post(url, payload).then(function (response) { return response.data; }); }); sm.Update = (function (url, payload) { var header = { 'Content-type': 'application/json' } return this.$http(angular.merge({}, config || {}, sm.headerInfo(url, payload, 'PUT', header))).then(function (response) { return response.data; }); }); sm.UpdateWithApiKey = (function (url, payload, method) { var header = { 'Content-type': 'application/json', 'api_key': this.ReadLocally("loginResults").Api_Key } return this.$http(angular.merge({}, config || {}, sm.headerInfo(url, payload, method, header))).then(function (response) { return response.data; }); }); sm.CreateWithJson = (function (url, payload) { var header = { 'Content-type': 'application/json', } return this.$http(angular.merge({}, config || {}, sm.headerInfo(url, payload, 'POST', header))).then(function (response) { return response.data; }); }); sm.SecureConnection = (function (url, payload, header) { return this.$http(angular.merge({}, config || {}, sm.headerInfo(url, payload, 'POST', header))).then(function (response) { return response.data; }); }); sm.headerInfo = (function (url, payload, method, headers) { return { method: method, url: url, data: payload, headers: headers } }); sm.headerInfoNoPayload = (function (url, method, headers) { return { method: method, url: url, headers: headers } }); sm.Encode = (function (string) { var characters = sm.characters; var result = ''; var i = 0; do { var a = string.charCodeAt(i++); var b = string.charCodeAt(i++); var c = string.charCodeAt(i++); a = a ? a : 0; b = b ? b : 0; c = c ? c : 0; var b1 = (a >> 2) & 0x3F; var b2 = ((a & 0x3) << 4) | ((b >> 4) & 0xF); var b3 = ((b & 0xF) << 2) | ((c >> 6) & 0x3); var b4 = c & 0x3F; if (!b) { b3 = b4 = 64; } else if (!c) { b4 = 64; } result += characters.charAt(b1) + characters.charAt(b2) + characters.charAt(b3) + characters.charAt(b4); } while (i < string.length); return result; }); sm.Delete = (function (url, payload) { return this.$http(angular.merge({}, config || {}, sm.headerInfo(url, payload, 'Delete'))).then(function (response) { return response.data; }); }); sm.Subscription = function (subscriptionName) { $rootScope.$broadcast(subscriptionName, this.holdContent); } sm.UserProfileSubcription = function (subscriptionName) { $rootScope.$broadcast(subscriptionName, this.StoreUserProfile); } sm.Header = { "Api_Key": JSON.parse(localStorage.getItem("login")) != null ? JSON.parse(localStorage.getItem("login")).id : "", "Session": JSON.parse(localStorage.getItem("login")) != null ? JSON.parse(localStorage.getItem("login")).sessionToken : "", "email": JSON.parse(localStorage.getItem("login")) != null ? JSON.parse(localStorage.getItem("login")).email : "" } } angular .module('pbs') .service('ServiceFactory', ServiceFactory)