Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
danielplawgo / CacheInterceptor.cs
Last active January 21, 2019 05:17
Jak automatycznie ponawiać operacja oraz cachować dane z interceptorami w Autofac?
public class CacheInterceptor : IInterceptor
{
private ICacheService _cacheService;
public CacheInterceptor(ICacheService cacheService)
{
_cacheService = cacheService;
}
public void Intercept(IInvocation invocation)
public class CategoriesController : Controller
{
private Lazy<ICategoryRepository> _categoryRepository;
protected ICategoryRepository CategoryRepository
{
get { return _categoryRepository.Value; }
}
private Lazy<IMapper> _mapper;
@danielplawgo
danielplawgo / IVerb.cs
Created September 20, 2018 04:26
Obsługa parametrów w aplikacji konsolowej za pomocą CommandLineParser
public interface IVerb
{
void Run();
}
@danielplawgo
danielplawgo / AddCategory.cs
Created September 27, 2018 03:36
Migracja schematu bazy danych w Entity Framework
public partial class AddCategory : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Categories",
c => new
{
Id = c.Int(nullable: false, identity: true),
Name = c.String(),
[Migration(201810030717)]
public class AddCategory : Migration
{
public override void Up()
{
Create.Table("Categories")
.WithColumn("Id").AsInt32().NotNullable().PrimaryKey().Identity()
.WithColumn("Name").AsString();
Execute.Sql("INSERT INTO dbo.Categories SELECT DISTINCT Category FROM dbo.Products;");
@danielplawgo
danielplawgo / AddCategories.sql
Created October 12, 2018 04:05
Migracja schematu bazy danych z DbUp
CREATE TABLE [dbo].[Categories] (
[Id] INT NOT NULL IDENTITY(1,1),
[Name] NVARCHAR(255) NOT NULL,
CONSTRAINT [PK_Categories] PRIMARY KEY ([Id])
)
INSERT INTO dbo.Categories SELECT DISTINCT Category FROM dbo.Products;
ALTER TABLE [dbo].[Products] ADD [CategoryId] INT
@danielplawgo
danielplawgo / Product.cs
Last active October 23, 2018 03:49
Swagger - dokumentowanie REST API
/// <summary>
/// The product.
/// </summary>
public class Product
{
/// <summary>
/// Gets or sets the identifier.
/// </summary>
/// <value>
/// The identifier.
public static class ControllerExtensions
{
public static string GetUserClaim(this ApiController controller, string claimName)
{
var principal = controller.User as ClaimsPrincipal;
if (principal == null)
{
return null;
}
@danielplawgo
danielplawgo / Address.cshtml
Created November 5, 2018 05:49
Dlaczego Editor Template jest lepsze niż Partial View do tworzenia formularzy?
@model PartialForms.ViewModels.Shared.AddressViewModel
<div class="form-group">
@Html.LabelFor(model => model.Street, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Street, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Street, "", new { @class = "text-danger" })
</div>
</div>
@danielplawgo
danielplawgo / BaseModel.cs
Created November 12, 2018 13:26
EF Plus - aktualizacja wielu obiektów jednym zapytaniem
public class BaseModel
{
public BaseModel()
{
IsActive = true;
}
public int Id { get; set; }
public bool IsActive { get; set; }