(function () { 'use strict'; var serviceId = 'eventFactorAdminDataContext'; angular.module('eventFactorAdmin').factory(serviceId, ['$q', '$http', 'eventFactorAdminConfig', datacontext]); function datacontext($q, $http, config, $modal) { var service = { getFactor: getFactor, getAllFactors: getAllFactors, createFactor: createFactor, updateFactor: updateFactor, deleteFactor: deleteFactor, addCaseStudy: addCaseStudy }; return service; function handleError(response) { // The API response from the server should be returned in a // nomralized format. However, if the request was not handled by the // server (or what not handles properly - ex. server error), then we // may have to normalize it on our end, as best we can. if ( !angular.isObject(response.data) || !response.data.message ) { return ($q.reject("An unknown error occurred.")); } // Otherwise, use expected error message. return ($q.reject(response.data.message)); } // I transform the successful response, unwrapping the application data // from the API response payload. function handleSuccess(response) { return (response.data); } // Get all roles for app code function getFactor(factorId) { var request = $http({ method: "get", url: calendarUrl + 'api/calendareventfactors/' + factorId }); return (request.then(handleSuccess, handleError)); } // Get all roles for app code function getAllFactors() { var request = $http({ method: "get", url: calendarUrl + 'api/calendareventfactors' }); return (request.then(handleSuccess, handleError)); } // Get all roles for app code function createFactor(factor) { var request = $http({ method: "post", url: calendarUrl + 'api/calendareventfactors', data: factor }); return (request.then(handleSuccess, handleError)); } // Get all roles for app code function addCaseStudy(caseStudy) { var request = $http({ method: "post", url: calendarUrl + 'api/calendareventfactors/casestudys', data: caseStudy }); return (request.then(handleSuccess, handleError)); } // Get all roles for app code function updateFactor(factor) { var request = $http({ method: "put", url: calendarUrl + 'api/calendareventfactors', data: factor }); return (request.then(handleSuccess, handleError)); } // Get all roles for app code function deleteFactor(factor) { var request = $http({ method: "delete", url: calendarUrl + 'api/calendareventfactors/' + factor.id, data: factor }); return (request.then(handleSuccess, handleError)); } } })();