Skip to content

Instantly share code, notes, and snippets.

View hudo's full-sized avatar

Hrvoje Hudo hudo

View GitHub Profile
@hudo
hudo / 201201311705.cs
Created February 1, 2012 12:22
FluentMigrator primjer migracijskih skripti
[Migration(1)]
// Može se postaviti i timestamp umijesto rednog broja
// [Migration(201201311705)]
public class CreateUserTable : Migration
{
public override void Up()
{
Create.Table("User")
.WithColumn("Id").AsInt32().NotNullable().PrimaryKey().Identity();
.WithColumn("Username").AsString(50).NotNullable()
@hudo
hudo / 201201311710.cs
Created February 1, 2012 12:31
FluentMigrator primjer indexa i key-eva
[Migration(2)]
// Može se postaviti i timestamp umijesto rednog broja
// [Migration(201201311710)]
public class CreateUserTable : Migration
{
public override void Up()
{
Create.ForeignKey("fk_tag_user")
.FromTable("Tag").ForeignColumn("CreatorId")
.ToTable("User").PrimaryColumn("Id")
@hudo
hudo / gist:3609590
Created September 3, 2012 14:10
webmatrix db primjer
@{
// sve unutar ovog bloka je c#, a ostalo je HTML
var db = Database.Open("ImeBaze");
var news = db.Query("SELECT * FROM NewsItems ORDER BY NewsDate DESC");
db.Execute("INSERT INTO NewsItems (Title) VALUES (@0)", "Naslov");
}
<html>
<body>
<table>
@foreach(var newsItem in news)
@hudo
hudo / gist:3979750
Created October 30, 2012 11:40
webshop model
public class Product
{
public int ProductId { get; set; }
public int Name { get; set; }
public decimal Price { get; set; }
public virtual Category Category { get; set; }
}
@hudo
hudo / gist:3979782
Created October 30, 2012 11:56
init migration
public partial class Init : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Products",
c => new
{
ProductId = c.Int(nullable: false, identity: true),
Name = c.Int(nullable: false),
@hudo
hudo / gist:4104991
Last active October 12, 2015 23:38
Validation helper
public static class Extensions
{
public static MvcHtmlString WriteIfError<M, P>(this HtmlHelper<M> htmlHelper, Expression<Func<M, P>> expression, string value)
{
string expressionText = ExpressionHelper.GetExpressionText(expression);
string modelName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText);
if (!htmlHelper.ViewData.ModelState.ContainsKey(modelName))
{
@hudo
hudo / gist:5083014
Last active December 14, 2015 11:58
sample ef config
/* data context */
class MyDataContext : DbContext, IDataContext
{
public IDbSet<BlogPost> BlogPosts { get; set; }
}
interface IDataContext
{
IDbSet<BlogPost> BlogPosts { get; set; }
@hudo
hudo / gist:5187024
Created March 18, 2013 13:09
kill all casini web server processes
Get-Process WebDev.WebServer40 | Stop-Process
@hudo
hudo / gist:5879552
Created June 27, 2013 19:24
count duplicated titles
update rp
set rp.TitleDuplicateCount = rj.tcount
from ReportPages rp
inner join
(
select count(rp2.TitleHash) as tcount, rp2.TitleHash
from ReportPages rp2
where rp2.ProjectId = {0} and PageType = 1 and HasTitle = 1
group by rp2.TitleHash
having COUNT(rp2.titleHash) > 1
@hudo
hudo / HomeController.cs
Last active August 29, 2015 13:55
Two view models controller
public class HomeController : Controller
{
public ActionResult Index()
{
var first = new FirstModel();
var second = new SecondModel();
return View(Tuple.Create(first,second));
}
}