Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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;
}
}
public virtual ActionResult Index2()
{
using (MiniProfiler.Current.Step("Index2 action"))
{
IEnumerable<UserViewModel> viewModels;
var models = db.Users.ToList();
using (MiniProfiler.Current.Step("Mapping with automapper"))
{
viewModels = Mapper.Map<List<UserViewModel>>(models);
@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())
@danielplawgo
danielplawgo / Program.cs
Created June 14, 2018 11:10
Fluent Validation
static void Main(string[] args)
{
var user = new User()
{
CreateInvoice = true,
Nip = "123",
Email = "daniel@plawgo.pl",
Orders = new List<Order>()
{
new Order(){Product = "Laptop"},
@danielplawgo
danielplawgo / IRuleBuilderExtensions.cs
Created June 14, 2018 12:35
Fluent Validation własny walidator
public static class IRuleBuilderExtensions
{
public static IRuleBuilderOptions<T, TProperty> Nip<T, TProperty>(this IRuleBuilder<T, TProperty> ruleBuilder)
{
return ruleBuilder.SetValidator(new NipValidator());
}
}
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/elmah" />
<errorMail from="test@test.com" to="test@test.com" subject="Application Exception" async="false" smtpPort="25" smtpServer="***" userName="***" password="***" />
@danielplawgo
danielplawgo / BaseMailer.cs
Created June 19, 2018 04:52
Hangfire - wysyłka email w tle
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 ViewEngineCollectionWithoutResolver();
engines.Add(new FileSystemRazorViewEngine(viewsPath));
@danielplawgo
danielplawgo / BaseIntegrationTests.cs
Created June 27, 2018 04:35
Testowanie wysyłki email w ASP.NET MVC
public class BaseIntegrationTests
{
protected Lazy<IEmailServiceFactory> CreateEmailServiceFactory()
{
return new Lazy<IEmailServiceFactory>(() =>
new EmailServiceFactory(new Lazy<IHostingEnviromentService>(() => new TestHostingEnviromentService())));
}
}
@danielplawgo
danielplawgo / Program1.cs
Created July 1, 2018 06:56
Entity Framework - aktualizacja danych bez ich pobierania
using (DataContext db = new DataContext())
{
db.Database.Log = m => _logger.Info(m);
var product = db.Products.FirstOrDefault(p => p.Id == productId);
if (product == null)
{
return;
}
@danielplawgo
danielplawgo / FilterConfig.cs
Created July 8, 2018 05:37
Log using action filters
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new LogFilterAttribute());
}
}