Skip to content

Instantly share code, notes, and snippets.

View foyzulkarim's full-sized avatar
🚀
building awesome stuffs

Foyzul Karim foyzulkarim

🚀
building awesome stuffs
View GitHub Profile
@foyzulkarim
foyzulkarim / AuthorizationController.cs
Created August 22, 2017 16:12
Role-Based-Access-Control Authorization Logic based on ASP.NET Identity and System.Runtime.Caching.MemoryCache
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Net.Http;
using System.Runtime.Caching;
using System.Web.Http;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
@foyzulkarim
foyzulkarim / VSTS Build Fail Nuget Restore Error Access Denied
Created August 21, 2017 07:48
Suddenly our build system starts failing continuously for all of the builds of all repositories. We didn't change anything in the VSTS and we don't have a clue what might be the cause. If it were due to our code/repository, then the other existing previously succeeded builds should have ran well. One thing I would like to add here is, We have be…
2017-08-21T07:35:21.7899827Z ##[debug]Evaluating condition for step: 'NuGet restore Exception/Exception.sln'
2017-08-21T07:35:21.7899827Z ##[debug]Evaluating: succeeded()
2017-08-21T07:35:21.7909820Z ##[debug]Evaluating succeeded:
2017-08-21T07:35:21.7909820Z ##[debug]=> (Boolean) True
2017-08-21T07:35:21.7909820Z ##[debug]Expanded: True
2017-08-21T07:35:21.7909820Z ##[debug]Result: True
2017-08-21T07:35:21.7909820Z ##[section]Starting: NuGet restore Exception/Exception.sln
2017-08-21T07:35:21.7909820Z ==============================================================================
2017-08-21T07:35:21.7909820Z Task : NuGet Installer
2017-08-21T07:35:21.7909820Z Description : Installs or restores missing NuGet packages
@foyzulkarim
foyzulkarim / BarcodeImageHandler
Created July 17, 2017 09:29
Aspose.Barcode C#
private static void GenerateBarcode(string barCode, string text, string filename)
{
BarCodeBuilder builder = new BarCodeBuilder(barCode);
Caption captionBelow = new Caption(text)
{
TextAlign = StringAlignment.Center,
Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold)
};
builder.CaptionBelow = captionBelow;
builder.Save(filename, ImageFormat.Png);
@foyzulkarim
foyzulkarim / App.config.ts
Created June 18, 2017 16:41
Sample Angular UI Router configuration in typescript
module App {
"use strict";
export class AppConfig {
static $inject = ["$stateProvider", "$urlRouterProvider", "localStorageServiceProvider"];
constructor($stateProvider: angular.ui.IStateProvider,
$urlRouterProvider: angular.ui.IUrlRouterProvider,
localStorageProvider: angular.local.storage.ILocalStorageServiceProvider
@foyzulkarim
foyzulkarim / IsForeignKey.cs
Last active December 14, 2016 02:20
Check whether a specific property is actually a Foreign Key of that model
private static bool IsForeignKey(PropertyInfo property, List<PropertyInfo> allProperties)
{
return allProperties.Where(x => x.CustomAttributes.Any(y => y.AttributeType.Name == "ForeignKeyAttribute")).ToList()
.Any(x =>
x.CustomAttributes.Where(y => y.AttributeType.Name == "ForeignKeyAttribute")
.Any(z => z.ConstructorArguments.Any(a => a.Value.ToString() == property.Name)));
}
@foyzulkarim
foyzulkarim / Generic TypeScript Angular 1.X BaseController
Created June 4, 2016 15:48
Generic TypeScript Angular 1.X Controller (Base+Child)
module App {
export class BaseController<T extends Entity> {
// my services
searchService: SearchService;
saveService: SaveService;
authService: AuthService;
url: UrlService;
// my variables
searchRequest: SearchRequest;
@foyzulkarim
foyzulkarim / Generic Orderby Func
Last active December 21, 2015 15:00
Problem scenario:
private static Func<IQueryable<TSource>, IOrderedQueryable<TSource>> OrderByFunc<TSource>(string propertyName, bool ascending = true)
{
var source = Expression.Parameter(typeof(IQueryable<TSource>), "source");
var item = Expression.Parameter(typeof(TSource), "item");
var member = Expression.Property(item, propertyName);
var selector = Expression.Quote(Expression.Lambda(member, item));
var body = Expression.Call(
typeof(Queryable), ascending ? "OrderBy" : "OrderByDescending",
new Type[] { item.Type, member.Type },
source, selector);
@foyzulkarim
foyzulkarim / GroupbyFiltering.cs
Last active September 28, 2015 09:22
Complex LINQ Group by Query
var histories = await (from history in db.Histories
group history by history.SurahId
into h
select h.ToList().Select(x => new MemorizedAyahViewModel()
{
Id = x.Id,
Surah = new SurahViewModel()
{
Index = x.Surah.Index,
Name = x.Surah.Name,
@foyzulkarim
foyzulkarim / LinqListFiltering
Created January 4, 2015 15:47
Create a resultant list from another two list by a condition. You can change " r2.Id == r.Id" this part for different logics
[TestMethod]
public void LinqTest()
{
RouteManager manager = new RouteManager();
ResponseModel responseModel = manager.Search(new RouteRequestModel());
List<Route> routes = responseModel.Data as List<Route>;
List<Route> permittedRoutes = new List<Route>
{
new Route() {Id = 2},
new Route() {Id = 9},
@foyzulkarim
foyzulkarim / HTML page
Created December 2, 2014 15:02
HTML string to PDF. (Problem: Extra zoomed in)
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div>
<div class=" container ng-scope" ng-switch=" view">