Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
danielplawgo / Configuration.cs
Created June 14, 2018 10:59
Nbuilder oraz Faker.NET
protected override void Seed(NugetForAspMvc.Models.DataContext context)
{
if (context.Users.Any() == false)
{
var users = Builder<User>.CreateListOfSize(20)
.All()
.With(u => u.Email = Faker.Internet.Email())
.With(u => u.FirstName = Faker.Name.First())
.With(u => u.LastName = Faker.Name.Last())
.With(u => u.UserName = Faker.Internet.UserName())
public virtual ActionResult Index2()
{
using (MiniProfiler.Current.Step("Index2 action"))
{
IEnumerable&lt;UserViewModel&gt; viewModels;
var models = db.Users.ToList();
using (MiniProfiler.Current.Step("Mapping with automapper"))
{
viewModels = Mapper.Map&lt;List&lt;UserViewModel&gt;&gt;(models);
@danielplawgo
danielplawgo / DateService1.cs
Created June 14, 2018 09:21
DateTime.Now i podróż w czasie
public class DateService : IDateService
{
public DateTime Now
{
get
{
return DateTime.Now;
}
}
@danielplawgo
danielplawgo / CreateUserViewModel.cs
Created June 14, 2018 04:22
Integracja Fluent Validation z ASP.NET MVC
[Validator(typeof(CreateUserViewModelValidator))]
public class CreateUserViewModel
{
public string Email { get; set; }
public bool CreateInvoice { get; set; }
public string Nip { get; set; }
}
@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}"
@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 / 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 / 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 / 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 / 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));