Skip to content

Instantly share code, notes, and snippets.

View ismaelgasparin's full-sized avatar

Ismael "Bill" Gasparin ismaelgasparin

View GitHub Profile
public class TrimmingModelPropertiesBinder : IModelBinder
{
private static readonly Type[] SimpleTypes =
{
typeof(Enum),
typeof(String),
typeof(Decimal),
typeof(DateTime),
typeof(DateTimeOffset),
typeof(TimeSpan),
public static string Parse(this DbEntityValidationException e)
{
var builder = new StringBuilder();
foreach (var eve in e.EntityValidationErrors)
{
builder.AppendFormat("Entity type: {0} | State: {1}",eve.Entry.Entity.GetType().Name,eve.Entry.State);
foreach (var ve in eve.ValidationErrors)
builder.AppendFormat("Property name: {0} | Current value: {1} | Error message: {2}",
ve.PropertyName,
eve.Entry.CurrentValues.GetValue<Object>(ve.PropertyName),
@ismaelgasparin
ismaelgasparin / QueryableHelper.cs
Last active November 5, 2022 23:07
Queryable helper
using System.Collections.Generic;
using System.Linq.Expressions;
namespace System.Linq
{
public static class QueryableHelper
{
public static IQueryable<TEntity> Search<TEntity>(this IQueryable<TEntity> query, string searchValue, params Expression<Func<TEntity, string>>[] propertiesToSearch)
{
if (string.IsNullOrEmpty(searchValue)) return query;
using System;
using System.Linq;
public class Program
{
private static string GetDigitoVerificadorIBGE(string codigo)
{
var pesos = new[] { 1, 2, 1, 2, 1, 2 };
var codigoStr = codigo.ToString();
var soma = 0;
package meuPacote;
import java.util.InputMismatchException;
public class ValidaCNPJ {
public static boolean isCNPJ(String CNPJ) {
// considera-se erro CNPJ's formados por uma sequencia de numeros iguais
if (CNPJ.equals("00000000000000") || CNPJ.equals("11111111111111") ||
CNPJ.equals("22222222222222") || CNPJ.equals("33333333333333") ||
package meuPacote;
import java.util.InputMismatchException;
public class ValidaCPF {
public static boolean isCPF(String CPF) {
// considera-se erro CPF's formados por uma sequencia de numeros iguais
if (CPF.equals("00000000000") || CPF.equals("11111111111") ||
CPF.equals("22222222222") || CPF.equals("33333333333") ||
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
public IQueryable<T> GetAll(params Expression<Func<T, object>>[] includes)
{
IQueryable<T> result = Context.Set<T>();
if (includes.Any())
{
foreach (var include in includes)
{
result = result.Include(include);
}