Skip to content

Instantly share code, notes, and snippets.

View DmitrySikorsky's full-sized avatar

Dmitry Sikorsky DmitrySikorsky

View GitHub Profile
CREATE PROCEDURE [dbo].[UpdateChildItems]
@ParentItemId INT,
@ChildItems ChildItemsType READONLY
AS
BEGIN
MERGE ChildItems AS t
USING (SELECT Id, ParentItemId, SomeProperty1, SomeProperty2, SomeProperty3 FROM @ChildItems) AS s
ON t.Id = s.Id AND t.ParentItemId = s.ParentItemId
WHEN MATCHED THEN
UPDATE SET t.SomeProperty1 = s.SomeProperty1, t.SomeProperty2 = s.SomeProperty2, t.SomeProperty3 = s.SomeProperty3
CREATE TYPE [dbo].[ChildItemsType] AS TABLE(
[Id] [int] NOT NULL,
[ParentItemId] [int] NOT NULL,
[SomeProperty1] [nvarchar](64) NOT NULL,
[SomeProperty2] [nvarchar](64) NOT NULL,
[SomeProperty3] [nvarchar](64) NOT NULL
)
public void Merge(int parentItemId, IEnumerable<ChildItem> childItems)
{
using (IDbConnection db = this.CreateDbConnection())
db.Execute(
"UpdateChildItems",
new { ParentItemId = parentItemId, ChildItems = childItems.ToDataTable("ParentItem") },
commandType: CommandType.StoredProcedure
);
}
ChildItem childItem1 = new ChildItem();
childItem1.ParentItemId = parentItem.Id;
childItem1.SomeProperty1 = "Aaa1_1";
childItem1.SomeProperty2 = "Aaa1_2";
childItem1.SomeProperty3 = "Aaa1_3";
ChildItem childItem2 = new ChildItem();
childItem2.ParentItemId = parentItem.Id;
this.unitOfWork.CatRepository.GetAdults();
this.dbContext.Cats.Where(c => c.Age >= 3 && c.Age <= 7).OrderBy(c => c.Name);
<!DOCTYPE html>
<html>
<head>
<link href="//cdn.flexir.io/stable/flexir.min.css" rel="stylesheet" />
</head>
<body>
<div id="flexir"></div>
<script src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.11.3.min.js"></script>
<script src="//cdn.flexir.io/stable/flexir.min.js"></script>
<script>
public void Configure(IApplicationBuilder applicationBuilder)
{
RequestLocalizationOptions requestLocalizationOptions = new RequestLocalizationOptions();
requestLocalizationOptions.SupportedCultures = requestLocalizationOptions.SupportedUICultures =
new CultureInfo[] { new CultureInfo("en"), new CultureInfo("ru"), new CultureInfo("uk") }.ToList();
requestLocalizationOptions.RequestCultureProviders.Insert(0, new RouteValueRequestCultureProvider() { Options = requestLocalizationOptions });
applicationBuilder.UseRequestLocalization(requestLocalizationOptions);
applicationBuilder.UseMvc(configureRoutes =>
public class RouteValueRequestCultureProvider : RequestCultureProvider
{
public override Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext)
{
string cultureCode = null;
if (httpContext.Request.Path.HasValue && httpContext.Request.Path.Value == "/")
cultureCode = this.GetDefaultCultureCode();
// TODO: make it look more beautiful
IEnumerable<Category> categories = this.cache.GetWithDefaultValue<IEnumerable<Category>>(
"categories", () => this.storage.Categories.ToList()
);