Last active
June 3, 2016 13:08
-
-
Save tomasherceg/d59334522ad80ce96a131969063d4070 to your computer and use it in GitHub Desktop.
Vzorová databáze pro kurz IoC/DI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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