Get version from request header

private string GetVersionFromAcceptHeaderVersion(HttpRequestMessage request) { string temp = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, “Controllers”); if (System.Web.HttpContext.Current.Request.Headers[“X-Api-Version”] != null) { IEnumerable<string> headerValues = request.Headers.GetValues(“X-Api-Version”); if (headerValues != null) { return headerValues.FirstOrDefault(); } return string.Empty; } else { var latestversion = Directory.GetDirectories(temp) .OrderByDescending(dir => dir) .FirstOrDefault(); return latestversion.Substring(latestversion.Length – 1); } }

Dirty read set flag for update record angular js

$scope.Update = function () { var index = 0; var arrPermissions = []; $scope.dataResult.forEach(function (row) { if (row.IsDirty == true) { arrPermissions.push(row); } }); SpinStart(); $“Security/Update”, { ViewModels: arrPermissions }) .success(function (data) { alert(” updated successfully.”); }) .error(function () { SpinStop(); alert(“Not valid.”); }); } // key press event $scope.Changed = function (id) { var… Read More Dirty read set flag for update record angular js

chosen js dropdown last select issue

Error on last item selection When I select last item on second time. It is giving an error “Uncaught TypeError: Cannot set property ‘selected’ of undefined” on every chosen. solution I had the same problem with this behavior. I used the following as workaround: <select chosen data-placeholder=”Placeholder” ng-model=”myValue” ng-options=” for item in itemList” > <option… Read More chosen js dropdown last select issue

Custom Media formatter – HttpClient

send file from one solution to other solution Client public void¬†UploadDomainAssembly(string filename) { String strFile = System.IO.Path.GetFileName(filename); using (var client = new HttpClient()) using (var content = new MultipartFormDataContent()) { // Make sure to change API address client.BaseAddress = new Uri(“http://localhost:8090/&#8221;); var fileContent = new ByteArrayContent(File.ReadAllBytes(filename)); fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue(“AssemblyAttachment”) { FileName = strFile };… Read More Custom Media formatter – HttpClient

Custom Media formatter

for byte[] send a file into stream (byte[]) and get uploaded into other solution. Add new class to web api service public class BinaryMediaTypeFormatter : MediaTypeFormatter { private static Type _supportedType = typeof(byte[]); private const int BufferSize = 8192; // 8K public BinaryMediaTypeFormatter() { SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue(“application/octet-stream”)); } public override bool CanReadType(Type type) { return type… Read More Custom Media formatter

Api Versioning – with header and with url

  WebApiConfig.cs public static class WebApiConfig { public static void Register(HttpConfiguration config) { //// CODE IS FOR VERSIONING USING HEADER config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: “DefaultApi”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional } ); config.Services.Replace(typeof(IHttpControllerSelector), new CustomControllerSelector((config))); // //// CODE IS FOR VERSIONING USING URL //var constraintsResolver = new DefaultInlineConstraintResolver(); //constraintsResolver.ConstraintMap.Add(“apiVersion1Constraint”, typeof(ApiVersion1Constraint)); //constraintsResolver.ConstraintMap.Add(“apiVersion2Constraint”, typeof(ApiVersion2Constraint)); //config.MapHttpAttributeRoutes(constraintsResolver);… Read More Api Versioning – with header and with url