Skip to content

Instantly share code, notes, and snippets.

@tomasherceg
Last active June 3, 2016 13:08
Show Gist options
  • Save tomasherceg/d59334522ad80ce96a131969063d4070 to your computer and use it in GitHub Desktop.
Save tomasherceg/d59334522ad80ce96a131969063d4070 to your computer and use it in GitHub Desktop.
Vzorová databáze pro kurz IoC/DI
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DB" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS; Integrated Security=true; Initial Catalog=Blog"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using Riganti.Utils.Infrastructure.Core;
namespace Blog.DAL
{
public class Article : IEntity<int>
{
public int Id { get; set; }
public int BlogId { get; set; }
[ForeignKey("BlogId")]
[InverseProperty("Articles")]
public virtual Blog Blog { get; set; }
public string Title { get; set; }
public string Text { get; set; }
public DateTime PublishedDate { get; set; }
public virtual List<Comment> Comments { get; set; } = new List<Comment>();
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Riganti.Utils.Infrastructure.Core;
namespace Blog.DAL
{
public class Blog : IEntity<int>
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public virtual List<Article> Articles { get; set; } = new List<Article>();
public DateTime? DeletedDate { get; set; }
}
}
using System;
using Riganti.Utils.Infrastructure.Core;
namespace Blog.DAL
{
public class Comment : IEntity<int>
{
public int Id { get; set; }
public int ArticleId { get; set; }
public virtual Article Article { get; set; }
public string Text { get; set; }
public string AuthorName { get; set; }
public DateTime PostedDate { get; set; }
}
}
using System;
using System.ComponentModel;
using System.Windows.Input;
namespace Blog.App.Utils
{
public class DelegateCommand : ICommand
{
public Func<object, bool> CanExecuteDelegate { get; set; }
public Action<object> ExecuteDelegate { get; set; }
public DelegateCommand(Action execute, Func<bool> canExecute = null, INotifyPropertyChanged viewModel = null)
{
ExecuteDelegate = p => execute();
if (canExecute != null)
{
CanExecuteDelegate = p => canExecute();
viewModel.PropertyChanged += (s, a) => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
else
{
CanExecuteDelegate = p => true;
}
}
public DelegateCommand(Action<object> execute, Func<object, bool> canExecute = null, INotifyPropertyChanged viewModel = null)
{
ExecuteDelegate = execute;
if (canExecute != null)
{
CanExecuteDelegate = canExecute;
viewModel.PropertyChanged += (s, a) => CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
else
{
CanExecuteDelegate = p => true;
}
}
public bool CanExecute(object parameter)
{
return CanExecuteDelegate(parameter);
}
public void Execute(object parameter)
{
ExecuteDelegate(parameter);
}
public event EventHandler CanExecuteChanged;
}
}
using System.Data.Entity;
namespace Blog.DAL
{
public class MyDb : DbContext
{
public MyDb() : base("DB")
{
}
public virtual DbSet<Blog> Blogs { get; set; }
public virtual DbSet<Article> Articles { get; set; }
public virtual DbSet<Comment> Comments { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment