Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
danielplawgo / RegisterUser.cshtml
Created Apr 24, 2018
Send Emails with Hangfire and Postal
View RegisterUser.cshtml
@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
Filtry Akcji – ASP.NET MVC
View FilterConfig.cs
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
@danielplawgo
danielplawgo / InvoiceLogic.cs
Last active May 17, 2018
Własny filtr akcji – autoryzacja z wykorzystaniem logiki biznesowej
View InvoiceLogic.cs
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
Wstrzykiwanie zależności z wykorzystaniem Lazy
View GetWithLazy.txt
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 Jun 1, 2018
Wykorzystanie modułów do konfiguracji kontenera Autofac
View AutofacConfig.cs
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 Jun 7, 2018
T4MVC - sposób na stringi w aplikacji ASP.NET MVC
View HomeController.cs
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 Jun 12, 2018
Bogus – generowanie danych testowych
View Models.cs
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 Jun 13, 2018
Postal - wysyłka email w ASP.NET MVC
View BaseMailer.cs
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 Jun 13, 2018
Integracja Fluent Validation z WPF wersja async
View MainWindow.xaml
<TextBox
Text="{Binding Email,
UpdateSourceTrigger=PropertyChanged,
Mode=TwoWay,
ValidatesOnNotifyDataErrors=True}"
Name="Email"/>
@danielplawgo
danielplawgo / CreateUserViewModel.cs
Created Jun 14, 2018
Integracja Fluent Validation z ASP.NET MVC
View CreateUserViewModel.cs
[Validator(typeof(CreateUserViewModelValidator))]
public class CreateUserViewModel
{
public string Email { get; set; }
public bool CreateInvoice { get; set; }
public string Nip { get; set; }
}