Skip to content

Instantly share code, notes, and snippets.

View adhamankar's full-sized avatar

Abhijeet adhamankar

View GitHub Profile
@adhamankar
adhamankar / WebApiConfig-cors-setup
Last active August 29, 2015 14:13
WebApi and AngularJS CORS setup
//http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
//Install-Package Microsoft.AspNet.WebApi.Cors
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
config.EnableCors(new EnableCorsAttribute("*", "*", "GET,POST,PUT,DELETE"));
@adhamankar
adhamankar / IControllerScope.ts
Created January 20, 2015 13:34
AngularJs modalService - Popup service
/// <reference path="../references.ts" />
module Common.Framework {
"use strict";
export interface IControllerScope<T> extends ng.IScope {
vm: T;
}
export class BaseCtrl {
public static $inject = ["$scope"];
@adhamankar
adhamankar / XmlSerializationUtil.cs
Created February 2, 2015 12:50
XML Serialization helper code
public static class XmlSerializationUtil
{
public static string Serialize<T>(this T toSerialize)
{
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
StringWriter textWriter = new StringWriter();
xmlSerializer.Serialize(textWriter, toSerialize);
return textWriter.ToString();
}
@adhamankar
adhamankar / XslUtil.cs
Created February 2, 2015 12:53
Xsl transform implementation
public static class XslUtil
{
public static string Transform(this string xml, string transformXslFile)
{
XslTransform xslt = new XslTransform();
xslt.Load(transformXslFile);
XPathDocument xpath = new XPathDocument(XmlReader.Create(new StringReader(xml)));
XmlReader xmlReader = xslt.Transform(xpath, null);
if (xmlReader != null)
@adhamankar
adhamankar / AuthenticationInterceptor.ts
Created February 16, 2015 05:31
Implementing angularjs Interceptor using TypeScript
module App {
"use strict";
//Method name should be exactly "response" - http://docs.angularjs.org/api/ng/service/$http
export interface IInterceptor {
request: Function;
requestError: Function;
response: Function;
responseError: Function;
}
@adhamankar
adhamankar / ClientContainerCtrl.ts
Created May 4, 2015 11:30
Angular popup service
export class ClientContainerCtrl {
public static $inject = ["$scope", "$http", "$state", "ApiConfig", "popup"];
constructor(public $scope: ng-IScope, public $http: ng.IHttpService
, public $state: ng.ui.IStateService, public ApiConfig: IApiConfig, public popup: Common.Services.ModalService
) {
super($scope, $http);
this.init();
}
@adhamankar
adhamankar / DataService.ts
Last active November 1, 2015 21:01
TypeScript+ Angular DataService based on observer pattern
module CommonServices {
export class DataService<T> {
public data: T;
private observerCallbacks = []; // Observer pattern implementation
public registerCallback = (callback) => {
this.observerCallbacks.push(callback);
};
public setData = (instance: T) => {
this.data = instance;
@adhamankar
adhamankar / Application.ts
Created August 13, 2015 06:47
Localization provider
myApp.provider("Localization", {
loadResource: ["Localization", (Localization) =>
Localization.loadResource(this.resourceName === undefined || this.resourceName === null ? this.controller : this.resourceName)
],
$get: ["$http", ($http: angular.IHttpService) => {
return {
loadResource: (resourceName?: string) => $http.get("<localization api>")
};
}]
@adhamankar
adhamankar / Modal-service.ts
Created January 18, 2016 12:18
Angular- ModalService - wrapper on top of $modal service
/// <reference path="../../_references.ts" />
module Common.Services {
"use strict";
export class ModalService implements Common.Framework.IModalContainer {
public static $inject = ["$modal"];
public static Factory($modal: ng.ui.bootstrap.IModalService) {
return new ModalService($modal);
public static class Extensions
{
public static string GetEnumDescription(this Enum value)
{
if (value == null) return string.Empty;
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
return (attributes != null && attributes.Length > 0) ? attributes[0].Description : value.ToString();
}