Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
danielplawgo / RegisterUser.cshtml
Created April 24, 2018 08:49
Send Emails with Hangfire and Postal
@model HangfireAndPostal.Models.RegisterUserEmail
To: @Model.Email
Subject: New Account
<h1>Hi @Model.FirstName!</h1>
<p>Thank you for creating an account.</p>
@danielplawgo
danielplawgo / FilterConfig.cs
Last active May 16, 2018 06:29
Filtry Akcji – ASP.NET MVC
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
@danielplawgo
danielplawgo / InvoiceLogic.cs
Last active May 17, 2018 08:06
Własny filtr akcji – autoryzacja z wykorzystaniem logiki biznesowej
public bool HasAccess(ApplicationUser user, Invoice entity)
{
if(user == null)
{
throw new ArgumentNullException("user");
}
if(entity == null)
{
throw new ArgumentNullException("entity");
@danielplawgo
danielplawgo / GetWithLazy.txt
Last active May 21, 2018 07:32
Wstrzykiwanie zależności z wykorzystaniem Lazy
Activating: System.Lazy`1[DependencyInjectionWithLazy.Logics.IUserLogic]
Activating: DependencyInjectionWithLazy.Controllers.UsersController
Before call controller: Users.create (GET)
After call controller: Users.create (GET)
@danielplawgo
danielplawgo / AutofacConfig.cs
Created June 1, 2018 04:55
Wykorzystanie modułów do konfiguracji kontenera Autofac
public class AutofacConfig
{
public static IContainer Configure()
{
var builder = new ContainerBuilder();
builder.RegisterAssemblyModules(typeof(AutofacConfig).Assembly);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
@danielplawgo
danielplawgo / HomeController.cs
Created June 7, 2018 07:41
T4MVC - sposób na stringi w aplikacji ASP.NET MVC
public virtual ActionResult Action(int id)
{
return Content(id.ToString());
}
public virtual ActionResult RedirectToActionUsingString()
{
return RedirectToAction("Action", "Home", new { id = 10 });
}
@danielplawgo
danielplawgo / Models.cs
Last active June 12, 2018 06:30
Bogus – generowanie danych testowych
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public Gender Gender { get; set; }
}
@danielplawgo
danielplawgo / BaseMailer.cs
Last active June 13, 2018 03:56
Postal - wysyłka email w ASP.NET MVC
public class BaseMailer
{
protected void Send(Email email)
{
var mailerName = GetType().Name.Replace("Mailer", string.Empty);
var viewsPath = Path.GetFullPath(string.Format(HostingEnvironment.MapPath(@"~/Views/Emails/{0}"), mailerName));
var engines = new ViewEngineCollection();
engines.Add(new FileSystemRazorViewEngine(viewsPath));
@danielplawgo
danielplawgo / MainWindow.xaml
Last active June 13, 2018 13:11
Integracja Fluent Validation z WPF wersja async
<TextBox
Text="{Binding Email,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay,
ValidatesOnNotifyDataErrors=True}"
Name="Email"/>
@danielplawgo
danielplawgo / MainWindow.xaml
Created June 14, 2018 04:06
Integracja Fluent Validation z WPF
<Window x:Class="FluentValidationWithWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:FluentValidationWithWPF"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel>
<TextBox Text="{Binding Email, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, ValidatesOnDataErrors=True}"