Skip to content

Instantly share code, notes, and snippets.

@jpolvora
jpolvora / web.config
Created Aug 30, 2014
WebGrease web.config entry for Nuget Package 1.6.0
View web.config
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
@jpolvora
jpolvora / gist:e0c168263ea4d57fff6d
Created Aug 31, 2014
Convert a Git SubModule to Subtrees
View gist:e0c168263ea4d57fff6d
cat .gitmodules |while read i
do
if [[ $i == \[submodule* ]]; then
mpath=$(echo $i | cut -d\" -f2)
read i; read i;
murl=$(echo $i|cut -d\ -f3)
mcommit=`eval "git submodule status ${mpath} |cut -d\ -f2"`
mname=$(basename $mpath)
echo -e "$name\t$mpath\t$murl\t$mcommit"
git submodule deinit $mpath
@jpolvora
jpolvora / Ignore Routes
Last active Aug 29, 2015
Instrui o ASP.NET MVC a ignorar arquivos estáticos e ignorar algumas pastas, evitando erros 404 desnecessários.
View Ignore Routes
/*Global.asax.cs ou RouteConfig.cs*/
var routes = RouteTable.Routes;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(?i)(asp|aspx|css|js|xml|txt|png|gif|jpg|jpeg|bmp|ico|woff|svg|ttf|eot)(/.*)?" });
routes.IgnoreRoute("Content/{*pathInfo}");
routes.IgnoreRoute("Scripts/{*pathInfo}");
routes.IgnoreRoute("Bundles/{*pathInfo}");
@jpolvora
jpolvora / estoquerepository.cs
Created Oct 22, 2014
teste repository pattern
View estoquerepository.cs
public class EstoqueRepository : RepositoryBase<Estoque>
{
public EstoqueRepository(CustomUnitOfWork uow)
: base(uow)
{
}
public override bool Validate(Estoque estoque)
{
var isValid = base.Validate(estoque);
@jpolvora
jpolvora / controller.cs
Created Oct 22, 2014
teste controller + repository
View controller.cs
[HttpPost]
public ActionResult Salvar(Estoque estoque)
{
if (!ModelState.IsValid)
{
return new HttpStatusCodeResult(400, "Erros de Validação");
}
using (var unitOfWork = new CustomUnitOfWork())
{
@jpolvora
jpolvora / RepositoryPattern.cs
Last active Aug 29, 2015
Repository Pattern 2014 + UnitOfWork
View RepositoryPattern.cs
public interface IRepository<T> where T : class, new()
{
T Find(object key);
IEnumerable<T> Query(Func<T, bool> predicate);
IQueryable<T> AsQueryable();
void Add(T instance);
void Edit(T instance);
void Remove(T instance);
}
@jpolvora
jpolvora / RepositoryBase.cs
Last active Aug 29, 2015
simple repository base based on EF
View RepositoryBase.cs
public class DbContextUnitOfWork //: IUnitOfWork
{
public System.Data.Entity.DbContext Context { get; private set; }
private bool _disposed;
public DbContextUnitOfWork(System.Data.Entity.DbContext context)
{
Context = context;
}
View ignore_routes.cs
routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(css|js|txt|png|gif|jpg|jpeg|bmp)(/.*)?" });
routes.IgnoreRoute("{*staticfile}", new { staticfile = ".*\\.(?i)(css|js|xml|txt|png|gif|jpg|jpeg|bmp|ico|woff|svg|ttf|eot)(\\/.*)?" });
var error = Server.GetLastError(); //filterContext.Exception
var exception = error as HttpException ?? new HttpException("Error", error);
if (exception.GetHttpCode() == 404)
return;
View propertyinjection.cs
public class Funcionario
{
private ICalculadorDeBonus _calculador;
// setter público para a dependência possa ser alterada
public ICalculadorDeBonus Calculador {
get {
return _calculador ?? (_calculador = new BonificacaoPadrao());
}
set {
View razor.cshtml
@if (TempData.ContainsKey("error"))
{
<script>alert('@Html.Raw(TempData["error"].ToString())')</script>
}