Skip to content

Instantly share code, notes, and snippets.

View bariloce's full-sized avatar

Marek Barilla bariloce

  • CreditInfo Solutions
View GitHub Profile
@bariloce
bariloce / sqlTest.cs
Created February 19, 2015 10:23
SQL insert from C# - not compiled, just written.
using(var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connSpionshopString"].ConnectionString))
{
connection.Open();
string sql = "INSERT INTO dbo.Table(userId, imagePath, userComments, dateCommented) VALUES (@userId, @imagePath, @userComments, @dateCommented)";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.Parameters.Add("@userId", SqlDbType.Int).value = userId
cmd.Parameters.Add("@imagePath", SqlDbType.Varchar, 50).value = imagePath;
cmd.Parameters.Add("@userComments", SqlDbType.Varchar, 50).value = userComments;
cmd.Parameters.Add("@dateCommented", SqlDbType.DateTime).value = dateCommented;
cmd.CommandType = CommandType.Text;
@bariloce
bariloce / Blobbed.cs
Last active March 5, 2024 21:29
NHibernate, Fluent.NHibernate and PostgreSql: How to map PostgreSql Json type using Fluent.NHibernate
[Serializable]
public class Blobbed<T> : IUserType where T : class
{
public new bool Equals(object x, object y)
{
if (x == null && y == null)
return true;
if (x == null || y == null)
return false;
@bariloce
bariloce / LocalizationService.cs
Last active August 29, 2015 14:04
Localization extension on Views - not buildable, just to see example of implementation
public class LocalizationService : ILocalizationService
{
//some injections
//...
//ctor
//...
public virtual string GetResource(string resourceKey)
{
@bariloce
bariloce / BindingExtensions.cs
Created July 15, 2014 09:26
Nancy Dictionary<string, customClass> binding
//necessary to call custom binding (method Create in my model)
public class BindingExtensions : IModelBinder
{
public object Bind(NancyContext context, Type modelType, object instance, BindingConfig configuration, params string[] blackList)
{
var data = GetDataFields(context);
var model = QueryHistoryConfigurationModel.Create(data);
return model;
@bariloce
bariloce / GenericFactory.cs
Last active August 29, 2015 14:01
Learning factory - what should I change in my unit tests? Is it ok?
public abstract class CarFactory
{
public abstract Car CreateSportsCar();
public abstract Car CreateFamilyCar();
}
public abstract class Car
{
public abstract string CompareSpeed(Car car);
}