Skip to content

Instantly share code, notes, and snippets.

View mesuttalebi's full-sized avatar

Mesut Talebi mesuttalebi

View GitHub Profile
@mesuttalebi
mesuttalebi / DeleteRange.cs
Created March 12, 2019 11:31
delete range repository
public void DeleteWhere(Expression<Func<T, bool>> filter)
{
var query = DbSet.Where(filter);
string selectSql = query.ToString();
string deleteSql = "DELETE [Extent1] " + selectSql.Substring(selectSql.IndexOf("FROM"));
var internalQuery = query.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).Where(field => field.Name == "_internalQuery").Select(field => field.GetValue(query)).First();
var objectQuery = internalQuery.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).Where(field => field.Name == "_objectQuery").Select(field => field.GetValue(internalQuery)).First() as ObjectQuery;
var parameters = objectQuery.Parameters.Select(p => new SqlParameter(p.Name, p.Value)).ToArray();
@mesuttalebi
mesuttalebi / ClientMessageInspectorInjector.cs
Created October 18, 2019 12:23
ClientMessageInspectorInjector
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace Helper
{
public static class ClientMessageInspectorInjector
{
@mesuttalebi
mesuttalebi / Impersonate.cs
Created October 19, 2019 12:56
Imporsonation using Asp.net mvc 5 Identity
[Authorize(Roles = "Administrator")]
public ActionResult Impersonate(string email)
{
var impersonatedUser = UserManager.FindByEmail(email);
var impersonatedIdentity = UserManager.CreateIdentity(impersonatedUser, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, impersonatedIdentity);
return RedirectToAction("Index", "Home");
@mesuttalebi
mesuttalebi / BaseRepository.cs
Created February 25, 2020 09:41
GetByIdNotracking Method added.
public virtual T GetByIdNoTracking(params object[] id)
{
_context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
var item = DbSet.Find(id);
if (item != null)
if (typeof(ISoftDeleteEnabled).IsAssignableFrom(typeof(T)))
item = (bool)typeof(T).GetProperty("IsDeleted").GetValue(item) == false ? item : null;
_context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.TrackAll;
@mesuttalebi
mesuttalebi / TransactionService.cs
Created February 25, 2020 12:36
Transaction Business service able to handle nested transactions
public class TransactionService : ITransactionService
{
private IDbContextTransaction _transaction;
private readonly IUnitOfWork _unitOfWork;
private Queue _transactions;
public TransactionService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
_transactions = new Queue();
@mesuttalebi
mesuttalebi / PredicateBuilder.cs
Created April 15, 2021 08:26
Predicate Builder to join predicates with "AND" and "OR"
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> True<T>() { return f => true; }
public static Expression<Func<T, bool>> False<T>() { return f => false; }
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
@mesuttalebi
mesuttalebi / up.html
Created December 15, 2023 06:24
Blue-Green Deployment - Up.html
<html>
<body>
UP - Blue
</body>
</html>
@mesuttalebi
mesuttalebi / SwitchBlueToGreen.ps1
Last active December 22, 2023 18:25
IIS binding switch for Blue-Green Deployment
param (
[string]$blueSiteName = "testblue.mydomain.com",
[string]$greenSiteName = "testgreen.mydomain.com",
[string]$ipAddress = "192.168.1.108",
[int]$httpPort = 80,
[int]$httpsPort = 443,
[string]$certificateThumbprint = "20437383726bb2e609619ee345825c4854ab0598",
[string]$certificateStore = "My"
)
@mesuttalebi
mesuttalebi / SwitchGreenToBlue.ps1
Last active December 22, 2023 18:24
switch IIS Binding to achieve Blue-Green Deployment.
param (
[string]$blueSiteName = "testblue.mydomain.com",
[string]$greenSiteName = "testgreen.mydomain.com",
[string]$ipAddress = "192.168.1.108",
[int]$httpPort = 80,
[int]$httpsPort = 443,
[string]$certificateThumbprint = "20437383726bb2e609619ee345825c4854ab0598",
[string]$certificateStore = "My"
)
@mesuttalebi
mesuttalebi / cities.sql
Created February 28, 2024 13:33
cities of Turkey
/*
Source Server : SqlServer_MesutTalebi
Source Server Version : 105000
Target Server Type : SQL Server
Target Server Version : 105000
File Encoding : 65001
Date: 2014-07-17 16:09:37
*/