From 028b9cb21b7961d530b392d372a11d6f1c930359 Mon Sep 17 00:00:00 2001 From: tjasek225 Date: Wed, 22 Feb 2017 11:17:19 +0100 Subject: [PATCH 01/41] deleted default readme.md --- Labs/IW5-Excercise-02/README.md | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 Labs/IW5-Excercise-02/README.md diff --git a/Labs/IW5-Excercise-02/README.md b/Labs/IW5-Excercise-02/README.md deleted file mode 100644 index 39af52c0..00000000 --- a/Labs/IW5-Excercise-02/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# README # - -This README would normally document whatever steps are necessary to get your application up and running. - -### What is this repository for? ### - -* Quick summary -* Version -* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo) - -### How do I get set up? ### - -* Summary of set up -* Configuration -* Dependencies -* Database configuration -* How to run tests -* Deployment instructions - -### Contribution guidelines ### - -* Writing tests -* Code review -* Other guidelines - -### Who do I talk to? ### - -* Repo owner or admin -* Other community or team contact \ No newline at end of file From 42aa735bb848f5e33eb7dd4530efbde00abf6415 Mon Sep 17 00:00:00 2001 From: tjasek225 Date: Wed, 22 Feb 2017 11:19:56 +0100 Subject: [PATCH 02/41] created CookBook solution - EF BbContext, initial CookBook classes --- .../CookBook.DAL/CookBook.DAL/App.config | 13 ++++ .../CookBook.DAL/CookBook.DAL.csproj | 70 +++++++++++++++++++ .../CookBook.DAL/CookBookDbContext.cs | 40 +++++++++++ .../CookBook.DAL/Entities/FoodType.cs | 10 +++ .../CookBook.DAL/Entities/IngredientEntity.cs | 10 +++ .../CookBook.DAL/Entities/RecipeEntity.cs | 13 ++++ .../CookBook.DAL/Properties/AssemblyInfo.cs | 36 ++++++++++ .../CookBook.DAL/CookBook.DAL/packages.config | 5 ++ .../CookBook.DAL/CookBook.sln | 22 ++++++ 9 files changed, 219 insertions(+) create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/FoodType.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntity.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Properties/AssemblyInfo.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.sln diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config new file mode 100644 index 00000000..01f6c9b5 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config @@ -0,0 +1,13 @@ + + + + +
+ + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj new file mode 100644 index 00000000..4454ee44 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -0,0 +1,70 @@ + + + + + + Debug + AnyCPU + {9247FC0B-1D73-4343-9BE0-6974EC0CD834} + Library + Properties + CookBook.DAL + CookBook.DAL + v4.5.2 + 512 + b00d45d5 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs new file mode 100644 index 00000000..74e1239e --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs @@ -0,0 +1,40 @@ +using CookBook.DAL.Entities; +using System.Data.Entity; + +namespace CookBook.DAL +{ + public class CookBookDbContext : DbContext + { + public IDbSet Recipes { get; set; } + public IDbSet Ingredients { get; set; } + + + public CookBookDbContext() + : base("LocalDb") + { + } + + public override int SaveChanges() + { + //FixAttachedEntities(); + return base.SaveChanges(); + } + + //private void FixAttachedEntities() + //{ + // // We don't want to reInsert ingredients with existing ID so we need to attach them to db context + // foreach (var entry in ChangeTracker.Entries()) + // { + // if (entry.Entity is IEntity) + // { + // var intEntity = (IEntity)entry.Entity; + // if (intEntity.Id != Guid.Empty && (entry.State == EntityState.Detached || entry.State == EntityState.Added)) + // { + // Set(intEntity.GetType()).Attach(intEntity); + // Entry(intEntity).State = EntityState.Modified; + // } + // } + // } + //} + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/FoodType.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/FoodType.cs new file mode 100644 index 00000000..26fe355a --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/FoodType.cs @@ -0,0 +1,10 @@ +namespace CookBook.DAL.Entities +{ + public enum FoodType + { + Soup, + MainCourse, + Dessert, + Other + } +} diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntity.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntity.cs new file mode 100644 index 00000000..c6722182 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntity.cs @@ -0,0 +1,10 @@ +using System; + +namespace CookBook.DAL.Entities +{ + public class IngredientEntity + { + public Guid Id { get; set; } = Guid.NewGuid(); + public string Name { get; set; } + } +} diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs new file mode 100644 index 00000000..694fd72a --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs @@ -0,0 +1,13 @@ +using System; + +namespace CookBook.DAL.Entities +{ + public class RecipeEntity + { + public Guid RecipeEntityId { get; set; } = Guid.NewGuid(); + public string Name { get; set; } + public FoodType Type { get; set; } + public string Description { get; set; } + public TimeSpan Duration { get; set; } + } +} diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..ab41cd23 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CookBook.DAL")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CookBook.DAL")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("daf05d99-54ee-453d-a975-8b33813281f2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config new file mode 100644 index 00000000..b351bc54 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.sln b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.sln new file mode 100644 index 00000000..73e92248 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.DAL", "CookBook.DAL\CookBook.DAL.csproj", "{9247FC0B-1D73-4343-9BE0-6974EC0CD834}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From 37defd79079ce3c2b7519b9ab92fc0166f772752 Mon Sep 17 00:00:00 2001 From: tjasek225 Date: Wed, 22 Feb 2017 11:22:01 +0100 Subject: [PATCH 03/41] renamed solution file --- .../CookBook.DAL/{CookBook.sln => IW5-Excercise-02.sln} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Labs/IW5-Excercise-02/CookBook.DAL/{CookBook.sln => IW5-Excercise-02.sln} (100%) diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.sln b/Labs/IW5-Excercise-02/CookBook.DAL/IW5-Excercise-02.sln similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.sln rename to Labs/IW5-Excercise-02/CookBook.DAL/IW5-Excercise-02.sln From 21804f231177e61f80617a1dbfb9f2573bef3a98 Mon Sep 17 00:00:00 2001 From: tjasek225 Date: Wed, 22 Feb 2017 11:56:41 +0100 Subject: [PATCH 04/41] removed EF package --- .../CookBook.DAL/CookBook.DAL/App.config | 2 +- .../CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj | 9 --------- .../CookBook.DAL/CookBook.DAL/packages.config | 5 ----- 3 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config index 01f6c9b5..ba200051 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config @@ -3,7 +3,7 @@
- + diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj index 4454ee44..7af4fa21 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -40,17 +40,8 @@ - - - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll - True - - - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll - True - diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config deleted file mode 100644 index b351bc54..00000000 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file From 69f772788e6191f8393cf4bd24adcf20f0cc2db4 Mon Sep 17 00:00:00 2001 From: tjasek225 Date: Wed, 22 Feb 2017 12:27:28 +0100 Subject: [PATCH 05/41] fixed EF referencing --- .../CookBook.DAL/CookBook.DAL/App.config | 2 +- .../CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj | 9 +++++++++ .../CookBook.DAL/CookBook.DAL/packages.config | 4 ++++ Labs/IW5-Excercise-02/CookBook.DAL/IW5-Excercise-02.sln | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config index ba200051..01f6c9b5 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config @@ -3,7 +3,7 @@
- + diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj index 7af4fa21..4454ee44 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -40,8 +40,17 @@ + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config new file mode 100644 index 00000000..44091730 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/IW5-Excercise-02.sln b/Labs/IW5-Excercise-02/CookBook.DAL/IW5-Excercise-02.sln index 73e92248..161a1ec2 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/IW5-Excercise-02.sln +++ b/Labs/IW5-Excercise-02/CookBook.DAL/IW5-Excercise-02.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.40629.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.DAL", "CookBook.DAL\CookBook.DAL.csproj", "{9247FC0B-1D73-4343-9BE0-6974EC0CD834}" EndProject From 19b52a15966dedebcd68d66e54f5ca02b8d3ffee Mon Sep 17 00:00:00 2001 From: tjasek225 Date: Wed, 22 Feb 2017 14:03:57 +0100 Subject: [PATCH 06/41] fixed refs --- .../CookBook.DAL/CookBook.DAL.sln | 22 ++++++++++++ .../CookBook.DAL/CookBook.DAL/App.config | 13 ------- .../CookBook.DAL/CookBook.DAL.csproj | 35 ++++++------------- .../CookBook.DAL/CookBookDbContext.cs | 2 +- .../CookBook.DAL/Properties/AssemblyInfo.cs | 2 +- .../CookBook.DAL/CookBook.DAL/packages.config | 4 --- 6 files changed, 35 insertions(+), 43 deletions(-) create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL.sln delete mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config delete mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL.sln b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL.sln new file mode 100644 index 00000000..769d4069 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.24720.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.DAL", "CookBook.DAL\CookBook.DAL.csproj", "{707FC4D3-FCB6-4686-84A6-6ABF270243AD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {707FC4D3-FCB6-4686-84A6-6ABF270243AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {707FC4D3-FCB6-4686-84A6-6ABF270243AD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {707FC4D3-FCB6-4686-84A6-6ABF270243AD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {707FC4D3-FCB6-4686-84A6-6ABF270243AD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config deleted file mode 100644 index 01f6c9b5..00000000 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config +++ /dev/null @@ -1,13 +0,0 @@ - - - - -
- - - - - - - - \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj index 4454ee44..f9264ed7 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -1,6 +1,5 @@  - - + Debug @@ -12,7 +11,6 @@ CookBook.DAL v4.5.2 512 - b00d45d5 true @@ -31,6 +29,16 @@ prompt 4 + + + + + + + + + + @@ -38,28 +46,7 @@ - - - - - - - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll - True - - - ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll - True - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - +
+ + + + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj index f9264ed7..7087c646 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -30,7 +30,16 @@ 4 + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + @@ -46,6 +55,10 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + H4sIAAAAAAAEAO1Y224bNxB9L9B/WOxTCziiLw9tjVUCR7ICo5ZtWE7eqd2RTIRLbngxpG/LQz+pv9Dh3pcrKZLtpgVaBA4kcubMlXPRn1//iN6tUh48gdJMimF4MjgOAxCxTJhYDkNrFm9+Dd+9/fGH6DJJV8Gniu7M0SGn0MPw0ZjsnBAdP0JK9SBlsZJaLswglimhiSSnx8e/kZMTAggRIlYQRPdWGJZC/gW/jqSIITOW8qlMgOvyHG9mOWpwQ1PQGY1hGI6k/Pwe/wbji+swuOCMog4z4IswoEJIQw1qeP5Rw8woKZazDA8of1hngHQLyjWUmp835PsacXzqjCANYwUVW21keiDgyVnpFeKzP8u3Ye019Nsl+tesndW574bhlVgqSBgIU1yFgS/0fMSVY+i6eJCTM9ADH+EoaNMd1cmBOeT+4bXlxioYCrBGUX4U3Nk5Z/HvsH6Qn0EMheW8rTSqjXedAzy6UzIDZdb3sKhMScKAdPmIz1iztXgK4z5Yhp9vUDadc6hTguxkd/9XAJhX+DjCYEpX1yCW5nEY4scwmLAVJNVJifpRMHxLyGSU9YREpInRzsjdQ8wyeG7U2tz/R+xFEesLcfC1ECxBg4mUSXF4oLpj0LFiWfH4/2atx1bRtqAHln5L4e3JatNWqjbmX+kJp8um4h6athXS66Qs+icBxdfoz0LolTBnp14mTyGdgyotmUmbhcEnyi1+Oe55tEM7pUyMpFXOzpLjZDcHRltjQGry093kt+YRVE181g9NEYR+FcG+alC5Gqjy5XjubmBlNgQGO2cZG12mU1ezAnkGptdYdBg0WVI+iH7bIbvhinq1CapbBzdlZ21uMz+QYoCoBg2yZdKIpjTLMDtak0d5EszKsePN7PCunBYYJNYbmnOtbS3JSEWX4N26qCUwYUqbMTV0Tl2ajZJ0A5kf3C2eruT14+dX8iYGFY/73M2l/N32wuwhNf6coIkp0uXWQq3ThgGlB5GPg5RTtaFTjCS3qdjWbXZxF42izV+c9BEi4tngu4v0/OX1PD8EewWoehHPDk7n4RwemN3s/3RQtiEUbaiNUJzsj9BpyW2gzsUBeHXb7YDVp9854XpF0yeppdfF0yuSUVmw9tnZvApWkIQBuuiJJa56zdbaQDpwBIPZFz7irhI0BFMq2AK0KZp6iMvTqbf8/XsWMaJ1wg/cxr77UG0F+2IBXYvyF8yNFy8YsMUTVfEjVT+ldPVzG+m11p7/jHt27xjMPYmXbxYv0sffHky+PdwpDFfx29Avz94lNo+s/vCz7zhaTYp7zKRFORqGyVyiWYXmHhVzM+les+tWud3rTTJbFD15Bwy5/bockfYvbhHmBFs2EO73NwGxi2oDWtFciYWsUgBNbWtUkXgZMgVDE4zWhcK3Q2OD1zEuPPkyW+4wl7jdJFfi1prMmgtchtI57wz1EdktP5/kuzpHt3mS69cwAdVkaALciveW8aTWe7IhnbdAuMT9AHievxZc5hFuua6RbqTYE6h03xgyEK4ePUCacQTTt2JGn+A5uuGOdw1LGq+r9rod5NuB6Lo9GjO6VDTVJUbD735FJu5n5Ld/AUOrq9J4FgAA + + + dbo + + \ No newline at end of file From 8337e92b3be34e8508b00354484a7f6f70c6ade2 Mon Sep 17 00:00:00 2001 From: tjasek Date: Mon, 6 Mar 2017 00:07:15 +0100 Subject: [PATCH 15/41] added connecting entity for RecipeEntity and IngredientEntity holding Amount and Unit added enum Unit added data annotations for properties --- .../CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj | 2 ++ .../CookBook.DAL/CookBookDbContext.cs | 1 - .../Entities/IngredientEntityAmount.cs | 15 +++++++++++++++ .../CookBook.DAL/Entities/RecipeEntity.cs | 5 +++++ .../CookBook.DAL/CookBook.DAL/Entities/Unit.cs | 11 +++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntityAmount.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj index f27d29dd..22a7f4b2 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -50,11 +50,13 @@ + + 201703052255249_Init.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs index 74e1239e..e197f48a 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs @@ -8,7 +8,6 @@ public class CookBookDbContext : DbContext public IDbSet Recipes { get; set; } public IDbSet Ingredients { get; set; } - public CookBookDbContext() : base("LocalDb") { diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntityAmount.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntityAmount.cs new file mode 100644 index 00000000..5283c5ab --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntityAmount.cs @@ -0,0 +1,15 @@ +using CookBook.DAL.Entities.Base.Implementation; +using System.ComponentModel.DataAnnotations; + +namespace CookBook.DAL.Entities +{ + public class IngredientEntityAmount : EntityBase + { + [Required] + public double Amount { get; set; } + [Required] + public Unit Unit { get; set; } + [Required] + public IngredientEntity Ingredient { get; set; } + } +} diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs index e8370fcc..3442fd04 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs @@ -1,13 +1,18 @@ using CookBook.DAL.Entities.Base.Implementation; using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; namespace CookBook.DAL.Entities { public class RecipeEntity : EntityBase { + [Required] public string Name { get; set; } public FoodType Type { get; set; } public string Description { get; set; } public TimeSpan Duration { get; set; } + [Required] + public virtual ICollection Ingredients { get; set; } = new List(); } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs new file mode 100644 index 00000000..9891a93e --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs @@ -0,0 +1,11 @@ +namespace CookBook.DAL.Entities +{ + public enum Unit + { + Kg = 1, + L, + Pound, + Spoon, + LittleSpoon + } +} \ No newline at end of file From 610cd9085643825a60809c748027c3c954264842 Mon Sep 17 00:00:00 2001 From: tjasek Date: Mon, 6 Mar 2017 09:41:49 +0100 Subject: [PATCH 16/41] renamed connecting entity added EF migration for IngredientAmountEntity --- .../CookBook.DAL/CookBook.DAL.csproj | 9 +- ...ityAmount.cs => IngredientAmountEntity.cs} | 4 +- .../CookBook.DAL/Entities/RecipeEntity.cs | 3 +- ...0839276_IngredientAmountEntity.Designer.cs | 29 ++++ .../201703060839276_IngredientAmountEntity.cs | 39 ++++++ ...01703060839276_IngredientAmountEntity.resx | 126 ++++++++++++++++++ 6 files changed, 206 insertions(+), 4 deletions(-) rename Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/{IngredientEntityAmount.cs => IngredientAmountEntity.cs} (72%) create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj index 22a7f4b2..f80adffb 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -50,7 +50,7 @@ - + @@ -61,6 +61,10 @@ 201703052255249_Init.cs + + + 201703060839276_IngredientAmountEntity.cs + @@ -72,6 +76,9 @@ 201703052255249_Init.cs + + 201703060839276_IngredientAmountEntity.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file From b0683f292a4b6f273b03782c9fcbe07fd37e0009 Mon Sep 17 00:00:00 2001 From: tjasek Date: Mon, 6 Mar 2017 09:52:57 +0100 Subject: [PATCH 17/41] added properties to IngredientEntity + migration --- .../CookBook.DAL/CookBook.DAL.csproj | 8 ++ .../CookBook.DAL/Entities/IngredientEntity.cs | 19 +++ ...ddedPropertiesIngredientEntity.Designer.cs | 29 ++++ ...0851297_AddedPropertiesIngredientEntity.cs | 22 +++ ...51297_AddedPropertiesIngredientEntity.resx | 126 ++++++++++++++++++ 5 files changed, 204 insertions(+) create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj index f80adffb..4e7f0eec 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -41,6 +41,7 @@ + @@ -65,6 +66,10 @@ 201703060839276_IngredientAmountEntity.cs + + + 201703060851297_AddedPropertiesIngredientEntity.cs + @@ -79,6 +84,9 @@ 201703060839276_IngredientAmountEntity.cs + + 201703060851297_AddedPropertiesIngredientEntity.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file From ebf0d17d5b9daafe01bd9b2297d5c428f7d97c8e Mon Sep 17 00:00:00 2001 From: tjasek Date: Mon, 6 Mar 2017 20:24:19 +0100 Subject: [PATCH 18/41] added item into Unit added Seed data created only one Migration --- .../CookBook.DAL/CookBook.DAL.csproj | 24 +---- .../CookBook.DAL/CookBookDbContext.cs | 25 +---- .../CookBook.DAL/Entities/Unit.cs | 3 +- .../Migrations/201703052255249_Init.cs | 39 -------- ...er.cs => 201703061916184_Init.Designer.cs} | 2 +- .../Migrations/201703061916184_Init.cs | 62 +++++++++++++ ...49_Init.resx => 201703061916184_Init.resx} | 2 +- .../CookBook.DAL/Migrations/Configuration.cs | 93 ++++++++++++++++--- 8 files changed, 153 insertions(+), 97 deletions(-) delete mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.cs rename Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/{201703052255249_Init.Designer.cs => 201703061916184_Init.Designer.cs} (93%) create mode 100644 Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.cs rename Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/{201703052255249_Init.resx => 201703061916184_Init.resx} (69%) diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj index 4e7f0eec..775bab6d 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj @@ -58,17 +58,9 @@ - - - 201703052255249_Init.cs - - - - 201703060839276_IngredientAmountEntity.cs - - - - 201703060851297_AddedPropertiesIngredientEntity.cs + + + 201703061916184_Init.cs @@ -78,14 +70,8 @@ - - 201703052255249_Init.cs - - - 201703060839276_IngredientAmountEntity.cs - - - 201703060851297_AddedPropertiesIngredientEntity.cs + + 201703061916184_Init.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs index e197f48a..55a16bd2 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs @@ -9,31 +9,8 @@ public class CookBookDbContext : DbContext public IDbSet Ingredients { get; set; } public CookBookDbContext() - : base("LocalDb") + : base("CookBookContext") { } - - public override int SaveChanges() - { - //FixAttachedEntities(); - return base.SaveChanges(); - } - - //private void FixAttachedEntities() - //{ - // // We don't want to reInsert ingredients with existing ID so we need to attach them to db context - // foreach (var entry in ChangeTracker.Entries()) - // { - // if (entry.Entity is IEntity) - // { - // var intEntity = (IEntity)entry.Entity; - // if (intEntity.Id != Guid.Empty && (entry.State == EntityState.Detached || entry.State == EntityState.Added)) - // { - // Set(intEntity.GetType()).Attach(intEntity); - // Entry(intEntity).State = EntityState.Modified; - // } - // } - // } - //} } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs index 9891a93e..ad992633 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs @@ -6,6 +6,7 @@ public enum Unit L, Pound, Spoon, - LittleSpoon + LittleSpoon, + Pieces } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.cs deleted file mode 100644 index 698d5eef..00000000 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace CookBook.DAL.Migrations -{ - using System; - using System.Data.Entity.Migrations; - - public partial class Init : DbMigration - { - public override void Up() - { - CreateTable( - "dbo.IngredientEntities", - c => new - { - Id = c.Guid(nullable: false), - Name = c.String(), - }) - .PrimaryKey(t => t.Id); - - CreateTable( - "dbo.RecipeEntities", - c => new - { - Id = c.Guid(nullable: false), - Name = c.String(), - Type = c.Int(nullable: false), - Description = c.String(), - Duration = c.Time(nullable: false, precision: 7), - }) - .PrimaryKey(t => t.Id); - - } - - public override void Down() - { - DropTable("dbo.RecipeEntities"); - DropTable("dbo.IngredientEntities"); - } - } -} diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.Designer.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs similarity index 93% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.Designer.cs rename to Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs index 939055d0..74227743 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.Designer.cs +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs @@ -13,7 +13,7 @@ public sealed partial class Init : IMigrationMetadata string IMigrationMetadata.Id { - get { return "201703052255249_Init"; } + get { return "201703061916184_Init"; } } string IMigrationMetadata.Source diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.cs new file mode 100644 index 00000000..0681f659 --- /dev/null +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.cs @@ -0,0 +1,62 @@ +namespace CookBook.DAL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class Init : DbMigration + { + public override void Up() + { + CreateTable( + "dbo.IngredientEntities", + c => new + { + Id = c.Guid(nullable: false), + Name = c.String(nullable: false), + Description = c.String(), + Argb = c.Int(nullable: false), + }) + .PrimaryKey(t => t.Id); + + CreateTable( + "dbo.RecipeEntities", + c => new + { + Id = c.Guid(nullable: false), + Name = c.String(nullable: false), + Type = c.Int(nullable: false), + Description = c.String(), + Duration = c.Time(nullable: false, precision: 7), + }) + .PrimaryKey(t => t.Id); + + CreateTable( + "dbo.IngredientAmountEntities", + c => new + { + Id = c.Guid(nullable: false), + Amount = c.Double(nullable: false), + Unit = c.Int(nullable: false), + Ingredient_Id = c.Guid(nullable: false), + RecipeEntity_Id = c.Guid(nullable: false), + }) + .PrimaryKey(t => t.Id) + .ForeignKey("dbo.IngredientEntities", t => t.Ingredient_Id, cascadeDelete: true) + .ForeignKey("dbo.RecipeEntities", t => t.RecipeEntity_Id, cascadeDelete: true) + .Index(t => t.Ingredient_Id) + .Index(t => t.RecipeEntity_Id); + + } + + public override void Down() + { + DropForeignKey("dbo.IngredientAmountEntities", "RecipeEntity_Id", "dbo.RecipeEntities"); + DropForeignKey("dbo.IngredientAmountEntities", "Ingredient_Id", "dbo.IngredientEntities"); + DropIndex("dbo.IngredientAmountEntities", new[] { "RecipeEntity_Id" }); + DropIndex("dbo.IngredientAmountEntities", new[] { "Ingredient_Id" }); + DropTable("dbo.IngredientAmountEntities"); + DropTable("dbo.RecipeEntities"); + DropTable("dbo.IngredientEntities"); + } + } +} diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.resx b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.resx similarity index 69% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.resx rename to Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.resx index ce0988ef..cef7af14 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703052255249_Init.resx +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 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 dbo diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs index b5ecfe8b..019a9ceb 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs @@ -1,6 +1,9 @@ -namespace CookBook.DAL.Migrations +namespace CookBook.DAL.Migrations { + using Entities; + using System; using System.Data.Entity.Migrations; + using System.Drawing; internal sealed class Configuration : DbMigrationsConfiguration { @@ -11,18 +14,84 @@ public Configuration() protected override void Seed(CookBookDbContext context) { - // This method will be called after migrating to the latest version. + var darkChocolate = new IngredientEntity + { + Id = new Guid("5abdfee1-c970-4afd-aff8-aa3cfef8b1ac"), + Name = "Tmavá čokoláda", + Description = "Tmavá čokoláda s 80% kakaa.", + Color = Color.Black + }; + context.Ingredients.AddOrUpdate(i => i.Id, darkChocolate); - // You can use the DbSet.AddOrUpdate() helper extension method - // to avoid creating duplicate seed data. E.g. - // - // context.People.AddOrUpdate( - // p => p.FullName, - // new Person { FullName = "Andrew Peters" }, - // new Person { FullName = "Brice Lambson" }, - // new Person { FullName = "Rowan Miller" } - // ); - // + var wholeMilk = new IngredientEntity + { + Id = new Guid("83041385-cb60-401b-bf11-cc5ffb8bc570"), + Name = "Plnotučné mlieko", + Description = "Plnotučné mlieko so 4% tuku.", + Color = Color.White + }; + context.Ingredients.AddOrUpdate(i => i.Id, wholeMilk); + + var almondFlour = new IngredientEntity + { + Id = new Guid("cb181669-4e02-449f-bf02-ab6020dfecb4"), + Name = "Mandlová múka", + Description = "Najemno umletá mandlová múka", + Color = Color.Yellow + }; + context.Ingredients.AddOrUpdate(i => i.Id, almondFlour); + + var egg = new IngredientEntity + { + Id = new Guid("012ac89a-94e3-4bc2-94b5-c9b05fc83375"), + Name = "Vajíčko", + Description = "Slepačie vajíčko.", + Color = Color.Orange + }; + context.Ingredients.AddOrUpdate(i => i.Id, egg); + + //var test = context.Ingredients.FirstOrDefault(); + + context.Recipes.AddOrUpdate( + r => r.Id, + new RecipeEntity + { + Id = new Guid("cb8db9b3-799c-4ef2-9d85-ce32a9ffa843"), + Name = "Čokoládová torta", + Duration = TimeSpan.FromMinutes(30), + Type = FoodType.Dessert, + Ingredients = + { + new IngredientAmountEntity + { + Id = new Guid("1d2e7873-3e35-4d40-877c-a3d0d78de3c0"), + Amount = 0.5, + Unit = Unit.Kg, + Ingredient = darkChocolate + }, + new IngredientAmountEntity + { + Id = new Guid("2711f535-3566-446c-9ac6-58261efe3fa3"), + Amount = 0.3, + Unit = Unit.L, + Ingredient = wholeMilk + }, + new IngredientAmountEntity + { + Id = new Guid("c8cdbff9-6692-42ad-93aa-69cb56f95019"), + Amount = 5, + Unit = Unit.Pieces, + Ingredient = egg + }, + new IngredientAmountEntity + { + Id = new Guid("b417ad46-b94c-487e-8cc1-97ebd7551b13"), + Amount = 7, + Unit = Unit.Spoon, + Ingredient = almondFlour + } + } + }); } } } From a57bd9367cf03283b61b3ceaa67dbd9a14564b0a Mon Sep 17 00:00:00 2001 From: tjasek Date: Mon, 6 Mar 2017 20:31:18 +0100 Subject: [PATCH 19/41] deleted debugging code --- .../CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs index 019a9ceb..358baa61 100644 --- a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs +++ b/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs @@ -50,8 +50,6 @@ protected override void Seed(CookBookDbContext context) }; context.Ingredients.AddOrUpdate(i => i.Id, egg); - //var test = context.Ingredients.FirstOrDefault(); - context.Recipes.AddOrUpdate( r => r.Id, new RecipeEntity From 3135a1136668e13e735402e193c86150b7b08ffc Mon Sep 17 00:00:00 2001 From: Martin Dybal Date: Wed, 8 Mar 2017 01:56:21 +0100 Subject: [PATCH 20/41] Rename solution --- Labs/{IW5-Excercise-02 => IW5-Excercise-CookBook}/.gitignore | 0 .../CookBook}/CookBook.DAL/App.config | 0 .../CookBook}/CookBook.DAL/CookBook.DAL.csproj | 0 .../CookBook}/CookBook.DAL/CookBookDbContext.cs | 0 .../CookBook.DAL/Entities/Base/Implementation/EntityBase.cs | 0 .../CookBook}/CookBook.DAL/Entities/Base/Interface/IEntity.cs | 0 .../CookBook}/CookBook.DAL/Entities/FoodType.cs | 0 .../CookBook}/CookBook.DAL/Entities/IngredientAmountEntity.cs | 0 .../CookBook}/CookBook.DAL/Entities/IngredientEntity.cs | 0 .../CookBook}/CookBook.DAL/Entities/RecipeEntity.cs | 0 .../CookBook}/CookBook.DAL/Entities/Unit.cs | 0 .../Migrations/201703060839276_IngredientAmountEntity.Designer.cs | 0 .../Migrations/201703060839276_IngredientAmountEntity.cs | 0 .../Migrations/201703060839276_IngredientAmountEntity.resx | 0 .../201703060851297_AddedPropertiesIngredientEntity.Designer.cs | 0 .../Migrations/201703060851297_AddedPropertiesIngredientEntity.cs | 0 .../201703060851297_AddedPropertiesIngredientEntity.resx | 0 .../CookBook.DAL/Migrations/201703061916184_Init.Designer.cs | 0 .../CookBook}/CookBook.DAL/Migrations/201703061916184_Init.cs | 0 .../CookBook}/CookBook.DAL/Migrations/201703061916184_Init.resx | 0 .../CookBook}/CookBook.DAL/Migrations/Configuration.cs | 0 .../CookBook}/CookBook.DAL/Properties/AssemblyInfo.cs | 0 .../CookBook}/CookBook.DAL/packages.config | 0 .../CookBook/CookBook.sln} | 0 24 files changed, 0 insertions(+), 0 deletions(-) rename Labs/{IW5-Excercise-02 => IW5-Excercise-CookBook}/.gitignore (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/App.config (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/CookBook.DAL.csproj (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/CookBookDbContext.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Entities/Base/Interface/IEntity.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Entities/FoodType.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Entities/IngredientAmountEntity.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Entities/IngredientEntity.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Entities/RecipeEntity.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Entities/Unit.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703061916184_Init.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/201703061916184_Init.resx (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Migrations/Configuration.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/Properties/AssemblyInfo.cs (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL => IW5-Excercise-CookBook/CookBook}/CookBook.DAL/packages.config (100%) rename Labs/{IW5-Excercise-02/CookBook.DAL/CookBook.DAL.sln => IW5-Excercise-CookBook/CookBook/CookBook.sln} (100%) diff --git a/Labs/IW5-Excercise-02/.gitignore b/Labs/IW5-Excercise-CookBook/.gitignore similarity index 100% rename from Labs/IW5-Excercise-02/.gitignore rename to Labs/IW5-Excercise-CookBook/.gitignore diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/App.config similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/App.config rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/App.config diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBook.DAL.csproj rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBookDbContext.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/CookBookDbContext.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBookDbContext.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Base/Interface/IEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Base/Interface/IEntity.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Base/Interface/IEntity.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Base/Interface/IEntity.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/FoodType.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/FoodType.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/FoodType.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/FoodType.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientAmountEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientAmountEntity.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientAmountEntity.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientAmountEntity.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientEntity.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/IngredientEntity.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientEntity.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/RecipeEntity.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/RecipeEntity.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/RecipeEntity.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Unit.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Entities/Unit.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Unit.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703061916184_Init.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703061916184_Init.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.resx b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703061916184_Init.resx similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/201703061916184_Init.resx rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703061916184_Init.resx diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Migrations/Configuration.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Properties/AssemblyInfo.cs similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/Properties/AssemblyInfo.cs rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Properties/AssemblyInfo.cs diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/packages.config similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL/packages.config rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/packages.config diff --git a/Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL.sln b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln similarity index 100% rename from Labs/IW5-Excercise-02/CookBook.DAL/CookBook.DAL.sln rename to Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln From afc7c084cd139b9e55da7c9727abd4a33d1a88d8 Mon Sep 17 00:00:00 2001 From: Martin Dybal Date: Wed, 8 Mar 2017 02:14:19 +0100 Subject: [PATCH 21/41] Prepare DAL for exercise 3 --- .../Base/Implementation/EntityBase.cs | 8 +++--- .../CookBook.DAL/Entities/FoodType.cs | 2 +- .../Entities/IngredientAmountEntity.cs | 13 +++++++--- .../CookBook.DAL/Entities/IngredientEntity.cs | 26 +++++-------------- .../CookBook.DAL/Entities/RecipeEntity.cs | 4 +-- .../CookBook/CookBook.DAL/Entities/Unit.cs | 18 ++++++++----- .../CookBook.DAL/Migrations/Configuration.cs | 4 --- 7 files changed, 35 insertions(+), 40 deletions(-) diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs index c8bc9170..047987d2 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs @@ -1,10 +1,12 @@ -using CookBook.DAL.Entities.Base.Interface; -using System; +using System; +using System.ComponentModel.DataAnnotations.Schema; +using CookBook.DAL.Entities.Base.Interface; namespace CookBook.DAL.Entities.Base.Implementation { public abstract class EntityBase : IEntity { - public Guid Id { get; set; } = Guid.NewGuid(); + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/FoodType.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/FoodType.cs index 26fe355a..949642e8 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/FoodType.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/FoodType.cs @@ -7,4 +7,4 @@ public enum FoodType Dessert, Other } -} +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientAmountEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientAmountEntity.cs index 94d0dacb..a403bd21 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientAmountEntity.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientAmountEntity.cs @@ -1,5 +1,6 @@ -using CookBook.DAL.Entities.Base.Implementation; +using System; using System.ComponentModel.DataAnnotations; +using CookBook.DAL.Entities.Base.Implementation; namespace CookBook.DAL.Entities { @@ -9,9 +10,13 @@ public class IngredientAmountEntity : EntityBase public double Amount { get; set; } [Required] public Unit Unit { get; set; } + [Required] - public IngredientEntity Ingredient { get; set; } + public Guid IngredientId { get; set; } + public virtual IngredientEntity Ingredient { get; set; } + [Required] - public RecipeEntity RecipeEntity { get; set; } + public Guid RecipeId { get; set; } + public virtual RecipeEntity Recipe { get; set; } } -} +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientEntity.cs index 7f4bbeee..f2d95a8e 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientEntity.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/IngredientEntity.cs @@ -1,28 +1,14 @@ -using CookBook.DAL.Entities.Base.Implementation; -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Drawing; +using System.ComponentModel.DataAnnotations; +using CookBook.DAL.Entities.Base.Implementation; +using CookBook.DAL.Entities.Base.Interface; namespace CookBook.DAL.Entities { - public class IngredientEntity : EntityBase + public class IngredientEntity : EntityBase, IEntity { [Required] public string Name { get; set; } + public string Description { get; set; } - public Int32 Argb - { - get - { - return Color.ToArgb(); - } - set - { - Color = Color.FromArgb(value); - } - } - [NotMapped] - public Color Color { get; set; } } -} +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/RecipeEntity.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/RecipeEntity.cs index 1cb524ef..d0759b42 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/RecipeEntity.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/RecipeEntity.cs @@ -1,7 +1,7 @@ -using CookBook.DAL.Entities.Base.Implementation; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using CookBook.DAL.Entities.Base.Implementation; namespace CookBook.DAL.Entities { diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Unit.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Unit.cs index ad992633..648651d5 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Unit.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Entities/Unit.cs @@ -1,12 +1,18 @@ -namespace CookBook.DAL.Entities +using System.ComponentModel.DataAnnotations; + +namespace CookBook.DAL.Entities { public enum Unit { Kg = 1, - L, - Pound, - Spoon, - LittleSpoon, - Pieces + L = 2, + Pound = 3, + Spoon = 4, + LittleSpoon = 5, + Pieces = 6, + G = 7, + Ml = 8, + Piece = 9, + TeaSpoon = 10 } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs index 358baa61..6dbdc868 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs @@ -19,7 +19,6 @@ protected override void Seed(CookBookDbContext context) Id = new Guid("5abdfee1-c970-4afd-aff8-aa3cfef8b1ac"), Name = "Tmavá čokoláda", Description = "Tmavá čokoláda s 80% kakaa.", - Color = Color.Black }; context.Ingredients.AddOrUpdate(i => i.Id, darkChocolate); @@ -28,7 +27,6 @@ protected override void Seed(CookBookDbContext context) Id = new Guid("83041385-cb60-401b-bf11-cc5ffb8bc570"), Name = "Plnotučné mlieko", Description = "Plnotučné mlieko so 4% tuku.", - Color = Color.White }; context.Ingredients.AddOrUpdate(i => i.Id, wholeMilk); @@ -37,7 +35,6 @@ protected override void Seed(CookBookDbContext context) Id = new Guid("cb181669-4e02-449f-bf02-ab6020dfecb4"), Name = "Mandlová múka", Description = "Najemno umletá mandlová múka", - Color = Color.Yellow }; context.Ingredients.AddOrUpdate(i => i.Id, almondFlour); @@ -46,7 +43,6 @@ protected override void Seed(CookBookDbContext context) Id = new Guid("012ac89a-94e3-4bc2-94b5-c9b05fc83375"), Name = "Vajíčko", Description = "Slepačie vajíčko.", - Color = Color.Orange }; context.Ingredients.AddOrUpdate(i => i.Id, egg); From ead8f5b7e2a8226b0b50b45a939789db09454741 Mon Sep 17 00:00:00 2001 From: Martin Dybal Date: Wed, 8 Mar 2017 03:12:02 +0100 Subject: [PATCH 22/41] Prepare database --- .../CookBook/CookBook.DAL/CookBook.DAL.csproj | 7 + .../Base/Implementation/EntityBase.cs | 4 +- ...080209034_PrepareForExcercise3.Designer.cs | 29 ++++ .../201703080209034_PrepareForExcercise3.cs | 26 ++++ .../201703080209034_PrepareForExcercise3.resx | 126 ++++++++++++++++++ .../CookBook.DAL/Migrations/Configuration.cs | 21 +-- 6 files changed, 201 insertions(+), 12 deletions(-) create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.Designer.cs create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.cs create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.resx diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj index 775bab6d..2faf2d0e 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj @@ -62,6 +62,10 @@ 201703061916184_Init.cs + + + 201703080209034_PrepareForExcercise3.cs + @@ -73,6 +77,9 @@ 201703061916184_Init.cs + + 201703080209034_PrepareForExcercise3.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs index 6dbdc868..c0e233c9 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs @@ -20,7 +20,6 @@ protected override void Seed(CookBookDbContext context) Name = "Tmavá čokoláda", Description = "Tmavá čokoláda s 80% kakaa.", }; - context.Ingredients.AddOrUpdate(i => i.Id, darkChocolate); var wholeMilk = new IngredientEntity { @@ -28,7 +27,6 @@ protected override void Seed(CookBookDbContext context) Name = "Plnotučné mlieko", Description = "Plnotučné mlieko so 4% tuku.", }; - context.Ingredients.AddOrUpdate(i => i.Id, wholeMilk); var almondFlour = new IngredientEntity { @@ -36,7 +34,6 @@ protected override void Seed(CookBookDbContext context) Name = "Mandlová múka", Description = "Najemno umletá mandlová múka", }; - context.Ingredients.AddOrUpdate(i => i.Id, almondFlour); var egg = new IngredientEntity { @@ -44,13 +41,15 @@ protected override void Seed(CookBookDbContext context) Name = "Vajíčko", Description = "Slepačie vajíčko.", }; - context.Ingredients.AddOrUpdate(i => i.Id, egg); + context.Ingredients.AddOrUpdate(i => i.Id, wholeMilk, darkChocolate, almondFlour, egg); + + var chocolateCakeId = new Guid("cb8db9b3-799c-4ef2-9d85-ce32a9ffa843"); context.Recipes.AddOrUpdate( r => r.Id, new RecipeEntity { - Id = new Guid("cb8db9b3-799c-4ef2-9d85-ce32a9ffa843"), + Id = chocolateCakeId, Name = "Čokoládová torta", Duration = TimeSpan.FromMinutes(30), Type = FoodType.Dessert, @@ -61,28 +60,32 @@ protected override void Seed(CookBookDbContext context) Id = new Guid("1d2e7873-3e35-4d40-877c-a3d0d78de3c0"), Amount = 0.5, Unit = Unit.Kg, - Ingredient = darkChocolate + RecipeId = chocolateCakeId, + IngredientId = darkChocolate.Id }, new IngredientAmountEntity { Id = new Guid("2711f535-3566-446c-9ac6-58261efe3fa3"), Amount = 0.3, Unit = Unit.L, - Ingredient = wholeMilk + RecipeId = chocolateCakeId, + IngredientId = wholeMilk.Id }, new IngredientAmountEntity { Id = new Guid("c8cdbff9-6692-42ad-93aa-69cb56f95019"), Amount = 5, Unit = Unit.Pieces, - Ingredient = egg + RecipeId = chocolateCakeId, + IngredientId = egg.Id }, new IngredientAmountEntity { Id = new Guid("b417ad46-b94c-487e-8cc1-97ebd7551b13"), Amount = 7, Unit = Unit.Spoon, - Ingredient = almondFlour + RecipeId = chocolateCakeId, + IngredientId = almondFlour.Id } } }); From 0804de806f29c3a0ab4f4282b1699a0f38b3fee8 Mon Sep 17 00:00:00 2001 From: Martin Dybal Date: Wed, 8 Mar 2017 03:12:14 +0100 Subject: [PATCH 23/41] Add test project --- .../CookBook/CookBook.Tests/App.config | 16 ++++ .../CookBook.Tests/CookBook.Tests.csproj | 89 +++++++++++++++++++ .../CookBook.Tests/CookBookDbContextTests.cs | 23 +++++ .../CookBook.Tests/Properties/AssemblyInfo.cs | 36 ++++++++ .../CookBook/CookBook.Tests/packages.config | 10 +++ .../CookBook/CookBook.sln | 11 +++ 6 files changed, 185 insertions(+) create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/App.config create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/Properties/AssemblyInfo.cs create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/App.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/App.config new file mode 100644 index 00000000..6b71cbb8 --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/App.config @@ -0,0 +1,16 @@ + + + + +
+ + + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj new file mode 100644 index 00000000..d04d4545 --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC} + Library + Properties + CookBook.Tests + CookBook.Tests + v4.6.1 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + + + + + + + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + True + + + ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll + True + + + ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll + True + + + ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll + True + + + + + + + + + + + + + {9247fc0b-1d73-4343-9be0-6974ec0cd834} + CookBook.DAL + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs new file mode 100644 index 00000000..67d5207e --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CookBook.DAL; +using CookBook.DAL.Migrations; +using Xunit; + +namespace CookBook.Tests +{ + public class CookBookDbContextTests + { + [Fact] + public void DbConnectionTest() + { + using (var cookBookDbContext = new CookBookDbContext()) + { + cookBookDbContext.Recipes.Any(); + } + } + } +} diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..003c66ca --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CookBook.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CookBook.Tests")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ee318c24-4329-4ed1-8960-9fc4dc9eb6fc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config new file mode 100644 index 00000000..04c620cb --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln index c0ab3375..730b09b3 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln @@ -5,6 +5,10 @@ VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.DAL", "CookBook.DAL\CookBook.DAL.csproj", "{9247FC0B-1D73-4343-9BE0-6974EC0CD834}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{38548057-6E62-400C-9E42-08E9E7AA6958}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.Tests", "CookBook.Tests\CookBook.Tests.csproj", "{EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,8 +19,15 @@ Global {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Debug|Any CPU.Build.0 = Debug|Any CPU {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Release|Any CPU.ActiveCfg = Release|Any CPU {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Release|Any CPU.Build.0 = Release|Any CPU + {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC} = {38548057-6E62-400C-9E42-08E9E7AA6958} + EndGlobalSection EndGlobal From b95ca489d701f5a123e0782a09a6ee5f4d2ac423 Mon Sep 17 00:00:00 2001 From: Martin Dybal Date: Wed, 8 Mar 2017 10:30:47 +0100 Subject: [PATCH 24/41] Add CleanCode sample --- Labs/IW5-Excercise-03/CleanCode.pptx | 3 + .../CleanCodeSample/CleanCodeSample.sln | 22 ++++++ .../CleanCodeSample/App.config | 6 ++ .../CleanCodeSample/CleanCodeSample.csproj | 58 ++++++++++++++++ .../CleanCodeSample/Program.cs | 69 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ 6 files changed, 194 insertions(+) create mode 100644 Labs/IW5-Excercise-03/CleanCode.pptx create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample.sln create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/App.config create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/CleanCodeSample.csproj create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Properties/AssemblyInfo.cs diff --git a/Labs/IW5-Excercise-03/CleanCode.pptx b/Labs/IW5-Excercise-03/CleanCode.pptx new file mode 100644 index 00000000..4b9a3bd1 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode.pptx @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b10e3326278196c81211aa0923a1b83632fc9bc6f94cc744ba9bcee51e70faed +size 1712830 diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample.sln b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample.sln new file mode 100644 index 00000000..413137a0 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanCodeSample", "CleanCodeSample\CleanCodeSample.csproj", "{3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E9DD469-D148-4AB9-A00B-7843B6B6DC0E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/App.config b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/CleanCodeSample.csproj b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/CleanCodeSample.csproj new file mode 100644 index 00000000..c7443a27 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/CleanCodeSample.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {3E9DD469-D148-4AB9-A00B-7843B6B6DC0E} + Exe + Properties + CleanCodeSample + CleanCodeSample + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs new file mode 100644 index 00000000..a689a393 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CleanCodeSample +{ + class Program + { + static void Main(string[] args) + { + TestAddition(); + + // Waiting for input from user + Console.ReadKey(); + } + + private static void TestAddition() + { + var firstInputForAddition = ReadNumberInput("Zadejte 1. číslo pro sčítání: "); + var secondInputForAddition = ReadNumberInput("Zadejte 2. číslo pro sčítání: "); + var userAnswer = ReadNumberInput("Zadejte Vaši odpověď: "); + + var result = firstInputForAddition + secondInputForAddition; + + WriteResultMessage(result, userAnswer); + } + + private static void WriteResultMessage(int result, int userAnswer) + { + string message = $"Vaše odpověď \"{userAnswer}\""; + + if (result == userAnswer) + { + WriteColorLine(ConsoleColor.Green, $"{message} byla správná"); + } + else + { + WriteColorLine(ConsoleColor.Red, $"{message} nebyla správná"); + } + } + + private static int ReadNumberInput(string message) + { + Console.Write(message); + return ReadNumberInput(); + } + + private static int ReadNumberInput() + { + int input; + // Reading number from console + while (!int.TryParse(Console.ReadLine(), out input)) + { + } + return input; + } + + private static void WriteColorLine(ConsoleColor foregroundColor, string message) + { + var previouslyForegroundColor = Console.ForegroundColor; + Console.ForegroundColor = foregroundColor; + Console.WriteLine(message); + Console.ForegroundColor = previouslyForegroundColor; + } + } +} diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..0afb147c --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CleanCodeSample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CleanCodeSample")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("39b2ae37-4084-4a0a-9f83-938ea370bb67")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] From 897533aebedcb0b2f59ce2d67803534a952d8595 Mon Sep 17 00:00:00 2001 From: martindybal Date: Wed, 8 Mar 2017 12:53:32 +0100 Subject: [PATCH 25/41] FIX: there was refactored version of Program --- .../CleanCodeSample/Program.cs | 90 +++++++++++-------- 1 file changed, 51 insertions(+), 39 deletions(-) diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs index a689a393..563962b7 100644 --- a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -11,59 +11,71 @@ class Program { static void Main(string[] args) { - TestAddition(); - - // Waiting for input from user - Console.ReadKey(); + Stuff(); } - - private static void TestAddition() + + // Calculating addition operation + private static void Stuff() { - var firstInputForAddition = ReadNumberInput("Zadejte 1. číslo pro sčítání: "); - var secondInputForAddition = ReadNumberInput("Zadejte 2. číslo pro sčítání: "); - var userAnswer = ReadNumberInput("Zadejte Vaši odpověď: "); + // FIrst number for addition + int n1; + // Second number for addition + int n2; + // Answer from the user + int a; + // Correct answer + int r; - var result = firstInputForAddition + secondInputForAddition; + // Asking user to input a number + Console.Write("Zadejte 1. číslo pro sčítání: "); - WriteResultMessage(result, userAnswer); - } + // Reading number from console + while (!int.TryParse(Console.ReadLine(), out n1)) + { + } - private static void WriteResultMessage(int result, int userAnswer) - { - string message = $"Vaše odpověď \"{userAnswer}\""; + // Asking user to input a number + Console.Write("Zadejte 2. číslo pro sčítání: "); - if (result == userAnswer) + // Reading number from console + while (!int.TryParse(Console.ReadLine(), out n2)) { - WriteColorLine(ConsoleColor.Green, $"{message} byla správná"); } - else + + Console.Write("Zadejte Vaši odpověď: "); + + // Reading number from console + while (!int.TryParse(Console.ReadLine(), out a)) { - WriteColorLine(ConsoleColor.Red, $"{message} nebyla správná"); } - } - private static int ReadNumberInput(string message) - { - Console.Write(message); - return ReadNumberInput(); - } + // Correct answer + r = n1 + n2; - private static int ReadNumberInput() - { - int input; - // Reading number from console - while (!int.TryParse(Console.ReadLine(), out input)) + // Checking if the answer from the user was correct + if (r == a) { + // Setting color to green + Console.ForegroundColor = ConsoleColor.Green; + + // Printing the result + Console.Write("Vaše odpověď \""); + Console.Write(a); + Console.Write("\" byla správná"); } - return input; - } + else + { + // Setting color to red + Console.ForegroundColor = ConsoleColor.Red; - private static void WriteColorLine(ConsoleColor foregroundColor, string message) - { - var previouslyForegroundColor = Console.ForegroundColor; - Console.ForegroundColor = foregroundColor; - Console.WriteLine(message); - Console.ForegroundColor = previouslyForegroundColor; + // Printing the result + Console.Write("Vaše odpověď \""); + Console.Write(a); + Console.Write("\" byla nesprávná"); + } + + // Waiting for input from user + Console.ReadKey(); } } } From 357ce7c30265c1dc7d9338ffa1e521f28ad2d8a2 Mon Sep 17 00:00:00 2001 From: Martin Dybal Date: Thu, 9 Mar 2017 10:56:11 +0100 Subject: [PATCH 26/41] Add BL skeleton --- .../CookBook/CookBook.BL/App.config | 6 ++ .../CookBook/CookBook.BL/CookBook.BL.csproj | 73 +++++++++++++++++++ .../CookBook.BL/Properties/AssemblyInfo.cs | 36 +++++++++ .../CookBook/CookBook.BL/RecipeRepository.cs | 18 +++++ .../CookBook/CookBook.BL/packages.config | 4 + .../CookBook.Tests/CookBook.Tests.csproj | 5 ++ .../CookBook.Tests/RecipeRepositoryTests.cs | 18 +++++ .../CookBook/CookBook.sln | 6 ++ 8 files changed, 166 insertions(+) create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/App.config create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/CookBook.BL.csproj create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/Properties/AssemblyInfo.cs create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/RecipeRepository.cs create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/packages.config create mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/RecipeRepositoryTests.cs diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/App.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/App.config new file mode 100644 index 00000000..a8739f8d --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/CookBook.BL.csproj b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/CookBook.BL.csproj new file mode 100644 index 00000000..dfaa6f8a --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/CookBook.BL.csproj @@ -0,0 +1,73 @@ + + + + + Debug + AnyCPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779} + Library + Properties + CookBook.BL + CookBook.BL + v4.6.1 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + + + + + + + + + + + + + + + + + {9247FC0B-1D73-4343-9BE0-6974EC0CD834} + CookBook.DAL + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..e2bb0be0 --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CookBook.BL")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CookBook.BL")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f48d47ed-6003-4b97-8629-5c6bec99e779")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/RecipeRepository.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/RecipeRepository.cs new file mode 100644 index 00000000..2e49d719 --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/RecipeRepository.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CookBook.DAL; +using CookBook.DAL.Entities; + +namespace CookBook.BL +{ + public class RecipeRepository + { + public RecipeEntity FindByName(string name) + { + throw new NotImplementedException(); + } + } +} diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/packages.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/packages.config new file mode 100644 index 00000000..373cff52 --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj index d04d4545..1994f8f9 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj @@ -67,12 +67,17 @@ + + + {F48D47ED-6003-4B97-8629-5C6BEC99E779} + CookBook.BL + {9247fc0b-1d73-4343-9be0-6974ec0cd834} CookBook.DAL diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/RecipeRepositoryTests.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/RecipeRepositoryTests.cs new file mode 100644 index 00000000..fdfa1b6c --- /dev/null +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/RecipeRepositoryTests.cs @@ -0,0 +1,18 @@ +using CookBook.BL; +using Xunit; + +namespace CookBook.Tests +{ + public class RecipeRepositoryTests + { + private RecipeRepository recipeRepository = new RecipeRepository(); + + [Fact] + public void FindByName_ExistRecipe_NotNull() + { + var recipe = recipeRepository.FindByName("Čokoládová torta"); + + Assert.NotNull(recipe); + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln index 730b09b3..0a277cd6 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln @@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{38548057 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.Tests", "CookBook.Tests\CookBook.Tests.csproj", "{EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.BL", "CookBook.BL\CookBook.BL.csproj", "{F48D47ED-6003-4B97-8629-5C6BEC99E779}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,6 +25,10 @@ Global {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Debug|Any CPU.Build.0 = Debug|Any CPU {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Release|Any CPU.Build.0 = Release|Any CPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 9b9d75a8fed02ccc8112425133ddddbb947ba4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ja=C5=A1ek?= Date: Wed, 15 Mar 2017 10:36:07 +0100 Subject: [PATCH 27/41] Changed test project to use MS Test. Added SaveChanges() call to Seed method. --- .../CookBook/CookBook.DAL/CookBook.DAL.csproj | 3 +- .../CookBook.DAL/CookBookDbContext.cs | 3 +- .../CookBook.DAL/Migrations/Configuration.cs | 2 + .../CookBook/CookBook.Tests/App.config | 12 ++-- .../CookBook.Tests/CookBook.Tests.csproj | 68 +++++++++---------- .../CookBook.Tests/CookBookDbContextTests.cs | 10 ++- .../CookBook.Tests/Properties/AssemblyInfo.cs | 20 +----- .../CookBook.Tests/RecipeRepositoryTests.cs | 18 ----- .../CookBook/CookBook.Tests/packages.config | 10 +-- .../CookBook/CookBook.sln | 16 ++--- 10 files changed, 59 insertions(+), 103 deletions(-) delete mode 100644 Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/RecipeRepositoryTests.cs diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj index 2faf2d0e..8b559812 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBook.DAL.csproj @@ -30,9 +30,8 @@ 4 - + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll - True ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBookDbContext.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBookDbContext.cs index 55a16bd2..e57d993c 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBookDbContext.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/CookBookDbContext.cs @@ -1,4 +1,5 @@ -using CookBook.DAL.Entities; +using System; +using CookBook.DAL.Entities; using System.Data.Entity; namespace CookBook.DAL diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs index c0e233c9..a9f71c8d 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.DAL/Migrations/Configuration.cs @@ -89,6 +89,8 @@ protected override void Seed(CookBookDbContext context) } } }); + + context.SaveChanges(); } } } diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/App.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/App.config index 6b71cbb8..39ffc423 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/App.config +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/App.config @@ -1,16 +1,16 @@ - + -
+
- + - + - + - \ No newline at end of file + diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj index 1994f8f9..4b6525ad 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj @@ -1,16 +1,25 @@  - - + + Debug AnyCPU - {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC} + {3CF47F1F-6A2B-480F-B95D-403BE8079A49} Library Properties CookBook.Tests CookBook.Tests v4.6.1 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + true @@ -32,63 +41,48 @@ ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll - True ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll - True + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - - - - - - - ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll - True - - - ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll - True - - - ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll - True - - - ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll - True - - - + + Designer + - {F48D47ED-6003-4B97-8629-5C6BEC99E779} + {f48d47ed-6003-4b97-8629-5c6bec99e779} CookBook.BL - {9247fc0b-1d73-4343-9be0-6974ec0cd834} + {9247FC0B-1D73-4343-9BE0-6974EC0CD834} CookBook.DAL + - + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs index 67d5207e..e5f7a4b2 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs @@ -1,17 +1,15 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CookBook.BL; using CookBook.DAL; -using CookBook.DAL.Migrations; -using Xunit; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace CookBook.Tests { + [TestClass] public class CookBookDbContextTests { - [Fact] + [TestMethod] public void DbConnectionTest() { using (var cookBookDbContext = new CookBookDbContext()) diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/Properties/AssemblyInfo.cs index 003c66ca..a45d1758 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/Properties/AssemblyInfo.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/Properties/AssemblyInfo.cs @@ -1,10 +1,7 @@ -using System.Reflection; +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. [assembly: AssemblyTitle("CookBook.Tests")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] @@ -14,23 +11,10 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("ee318c24-4329-4ed1-8960-9fc4dc9eb6fc")] +[assembly: Guid("3cf47f1f-6a2b-480f-b95d-403be8079a49")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/RecipeRepositoryTests.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/RecipeRepositoryTests.cs deleted file mode 100644 index fdfa1b6c..00000000 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/RecipeRepositoryTests.cs +++ /dev/null @@ -1,18 +0,0 @@ -using CookBook.BL; -using Xunit; - -namespace CookBook.Tests -{ - public class RecipeRepositoryTests - { - private RecipeRepository recipeRepository = new RecipeRepository(); - - [Fact] - public void FindByName_ExistRecipe_NotNull() - { - var recipe = recipeRepository.FindByName("Čokoládová torta"); - - Assert.NotNull(recipe); - } - } -} \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config index 04c620cb..652da8ec 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config @@ -1,10 +1,6 @@  - - - - - - - + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln index 0a277cd6..e4536eb6 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.sln @@ -5,11 +5,11 @@ VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.DAL", "CookBook.DAL\CookBook.DAL.csproj", "{9247FC0B-1D73-4343-9BE0-6974EC0CD834}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{38548057-6E62-400C-9E42-08E9E7AA6958}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.BL", "CookBook.BL\CookBook.BL.csproj", "{F48D47ED-6003-4B97-8629-5C6BEC99E779}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.Tests", "CookBook.Tests\CookBook.Tests.csproj", "{EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F6262EAF-DFD7-40EF-A155-6A4C85E6943D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.BL", "CookBook.BL\CookBook.BL.csproj", "{F48D47ED-6003-4B97-8629-5C6BEC99E779}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.Tests", "CookBook.Tests\CookBook.Tests.csproj", "{3CF47F1F-6A2B-480F-B95D-403BE8079A49}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,19 +21,19 @@ Global {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Debug|Any CPU.Build.0 = Debug|Any CPU {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Release|Any CPU.ActiveCfg = Release|Any CPU {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Release|Any CPU.Build.0 = Release|Any CPU - {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC}.Release|Any CPU.Build.0 = Release|Any CPU {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Debug|Any CPU.Build.0 = Debug|Any CPU {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Release|Any CPU.ActiveCfg = Release|Any CPU {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Release|Any CPU.Build.0 = Release|Any CPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {EE318C24-4329-4ED1-8960-9FC4DC9EB6FC} = {38548057-6E62-400C-9E42-08E9E7AA6958} + {3CF47F1F-6A2B-480F-B95D-403BE8079A49} = {F6262EAF-DFD7-40EF-A155-6A4C85E6943D} EndGlobalSection EndGlobal From a0e0d04a1aadad9bba22e5511daf730654d09eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ja=C5=A1ek?= Date: Wed, 15 Mar 2017 14:51:41 +0100 Subject: [PATCH 28/41] Tests reverted back to XUnit (because of issues with MS Test in labs) --- .../CookBook/CookBook.Tests/CookBook.Tests.csproj | 12 ++++++++++++ .../CookBook.Tests/CookBookDbContextTests.cs | 5 ++--- .../CookBook/CookBook.Tests/packages.config | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj index 4b6525ad..179a3cc0 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBook.Tests.csproj @@ -54,6 +54,18 @@ + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll + + + ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll + diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs index e5f7a4b2..dbe76d2f 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs @@ -2,14 +2,13 @@ using System.Linq; using CookBook.BL; using CookBook.DAL; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; namespace CookBook.Tests { - [TestClass] public class CookBookDbContextTests { - [TestMethod] + [Fact] public void DbConnectionTest() { using (var cookBookDbContext = new CookBookDbContext()) diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config index 652da8ec..e944e71c 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/packages.config @@ -3,4 +3,10 @@ + + + + + + \ No newline at end of file From 3d5aeaf375d2fc0770a6bde0bfabc84ff7eea5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ja=C5=A1ek?= Date: Wed, 22 Mar 2017 09:08:43 +0100 Subject: [PATCH 29/41] Added the solution of the 3rd excercise. --- .../CookBook/CookBook.BL/RecipeRepository.cs | 10 +++++- .../CookBook.Tests/CookBookDbContextTests.cs | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/RecipeRepository.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/RecipeRepository.cs index 2e49d719..ff467152 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/RecipeRepository.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.BL/RecipeRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data.Entity; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,7 +13,14 @@ public class RecipeRepository { public RecipeEntity FindByName(string name) { - throw new NotImplementedException(); + using (var cookBookDbContext = new CookBookDbContext()) + { + var recipe = cookBookDbContext + .Recipes + .Include(r => r.Ingredients.Select(i => i.Ingredient)) + .FirstOrDefault(r => r.Name == name); + return recipe; + } } } } diff --git a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs index dbe76d2f..6d206674 100644 --- a/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs +++ b/Labs/IW5-Excercise-CookBook/CookBook/CookBook.Tests/CookBookDbContextTests.cs @@ -8,6 +8,7 @@ namespace CookBook.Tests { public class CookBookDbContextTests { + [Fact] public void DbConnectionTest() { @@ -16,5 +17,37 @@ public void DbConnectionTest() cookBookDbContext.Recipes.Any(); } } + + private RecipeRepository recipeRepositorySUT = new RecipeRepository(); + + [Fact] + public void FindByName_ChocolateCake_NotNull() + { + var recipe = recipeRepositorySUT.FindByName("Čokoládová torta"); + Assert.NotNull(recipe); + } + + [Fact] + public void FindByName_ChocolateCake2_Null() + { + var recipe = recipeRepositorySUT.FindByName("Čokoládová torta 2"); + Assert.Null(recipe); + } + + [Fact] + public void FindByName_ChocolateCake_ContainsEgg() + { + var recipe = recipeRepositorySUT.FindByName("Čokoládová torta"); + var containsEgg = recipe.Ingredients.Any(ingredient => ingredient.Ingredient.Name == "Vajíčko"); + Assert.True(containsEgg); + } + + [Fact] + public void FindByName_Ingredient_NotNull() + { + var recipe = recipeRepositorySUT.FindByName("Čokoládová torta"); + var containsEgg = recipe.Ingredients.Any(ingredient => ingredient.Ingredient.Name == "Vajíčko"); + Assert.True(containsEgg); + } } } From cf3d15b8e117d9b36175f5c7928abb14d31b4897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Ja=C5=A1ek?= Date: Wed, 22 Mar 2017 09:53:41 +0100 Subject: [PATCH 30/41] Added solution for the Clean Code sample. --- .../CleanCodeSample/CleanCodeSample.csproj | 7 ++ .../CleanCodeSample/ConsoleHelper.cs | 27 ++++++++ .../MathExcercise/AdditionMathExcercise.cs | 13 ++++ .../MathExcercise/IMathExcercise.cs | 9 +++ .../MathExcercise/MathExcerciseRunner.cs | 41 ++++++++++++ .../MultiplicationMathExcercise.cs | 13 ++++ .../SubstractionMathExcercise.cs | 13 ++++ .../CleanCodeSample/MathExcercisesProgram.cs | 24 +++++++ .../CleanCodeSample/Program.cs | 65 +------------------ 9 files changed, 149 insertions(+), 63 deletions(-) create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/ConsoleHelper.cs create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/AdditionMathExcercise.cs create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/IMathExcercise.cs create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/MathExcerciseRunner.cs create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/MultiplicationMathExcercise.cs create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/SubstractionMathExcercise.cs create mode 100644 Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercisesProgram.cs diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/CleanCodeSample.csproj b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/CleanCodeSample.csproj index c7443a27..1d799b78 100644 --- a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/CleanCodeSample.csproj +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/CleanCodeSample.csproj @@ -41,6 +41,13 @@ + + + + + + + diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/ConsoleHelper.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/ConsoleHelper.cs new file mode 100644 index 00000000..337f019e --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/ConsoleHelper.cs @@ -0,0 +1,27 @@ +using System; + +namespace CleanCodeSample +{ + public class ConsoleHelper + { + + public int ReadNumber(string message) + { + Console.Write(message); + int input; + if (!int.TryParse(Console.ReadLine(), out input)) + { + return ReadNumber(message); + } + return input; + } + + public void WriteColorLine(ConsoleColor foregroundColor, string message) + { + var previouslyForegroundColor = Console.ForegroundColor; + Console.ForegroundColor = foregroundColor; + Console.WriteLine(message); + Console.ForegroundColor = previouslyForegroundColor; + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/AdditionMathExcercise.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/AdditionMathExcercise.cs new file mode 100644 index 00000000..a6eaad00 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/AdditionMathExcercise.cs @@ -0,0 +1,13 @@ +namespace CleanCodeSample.MathExcercise +{ + class AdditionMathExcercise : IMathExcercise + { + public char Operand { get; } = '+'; + public string OperationName { get; } = "sčítání"; + + public int GetCorrectResult(int leftOperand, int rightOperand) + { + return leftOperand + rightOperand; + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/IMathExcercise.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/IMathExcercise.cs new file mode 100644 index 00000000..17697997 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/IMathExcercise.cs @@ -0,0 +1,9 @@ +namespace CleanCodeSample.MathExcercise +{ + public interface IMathExcercise + { + char Operand { get; } + string OperationName { get; } + int GetCorrectResult(int leftOperand, int rightOperand); + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/MathExcerciseRunner.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/MathExcerciseRunner.cs new file mode 100644 index 00000000..19560141 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/MathExcerciseRunner.cs @@ -0,0 +1,41 @@ +using System; + +namespace CleanCodeSample.MathExcercise +{ + class MathExcerciseRunner + { + protected ConsoleHelper consoleHelper = new ConsoleHelper(); + + public void Test(IMathExcercise mathExcercise) + { + var leftOperand = consoleHelper.ReadNumber($"Zadejte 1. číslo pro {mathExcercise.OperationName}: "); + var rightOperand = consoleHelper.ReadNumber($"Zadejte 2. číslo pro {mathExcercise.OperationName}: "); + + var askForSolution = $"{leftOperand} {mathExcercise.Operand} {rightOperand} = "; + var userAnswer = consoleHelper.ReadNumber(askForSolution); + + var correctResult = mathExcercise.GetCorrectResult(leftOperand, rightOperand); + WriteResultMessage(correctResult, userAnswer); + } + + private void WriteResultMessage(int correctResult, int userAnswer) + { + var wasUserAnswerCorrect = correctResult == userAnswer; + var wasAnswerCorrectMessage = GetWasAnswerCorrectMessage(wasUserAnswerCorrect); + var messageColor = GetMessageColor(wasUserAnswerCorrect); + + string message = $"Vaše odpověď \"{userAnswer}\" {wasAnswerCorrectMessage}"; + consoleHelper.WriteColorLine(messageColor, message); + } + + private static ConsoleColor GetMessageColor(bool wasUserAnswerCorrect) + { + return wasUserAnswerCorrect ? ConsoleColor.Green : ConsoleColor.Red; + } + + private static string GetWasAnswerCorrectMessage(bool wasUserAnswerCorrect) + { + return wasUserAnswerCorrect ? "byla správná" : "nebyla správná"; + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/MultiplicationMathExcercise.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/MultiplicationMathExcercise.cs new file mode 100644 index 00000000..910547d4 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/MultiplicationMathExcercise.cs @@ -0,0 +1,13 @@ +namespace CleanCodeSample.MathExcercise +{ + class MultiplicationMathExcercise : IMathExcercise + { + public char Operand { get; } = '*'; + public string OperationName { get; } = "násobení"; + + public int GetCorrectResult(int leftOperand, int rightOperand) + { + return leftOperand * rightOperand; + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/SubstractionMathExcercise.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/SubstractionMathExcercise.cs new file mode 100644 index 00000000..8e8c7212 --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercise/SubstractionMathExcercise.cs @@ -0,0 +1,13 @@ +namespace CleanCodeSample.MathExcercise +{ + class SubstractionMathExcercise : IMathExcercise + { + public char Operand { get; } = '-'; + public string OperationName { get; } = "odčítání"; + + public int GetCorrectResult(int leftOperand, int rightOperand) + { + return leftOperand - rightOperand; + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercisesProgram.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercisesProgram.cs new file mode 100644 index 00000000..a42534fb --- /dev/null +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/MathExcercisesProgram.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using CleanCodeSample.MathExcercise; + +namespace CleanCodeSample +{ + class MathExcercisesProgram + { + private readonly List mathExcercises = new List + { + new AdditionMathExcercise(), + new SubstractionMathExcercise(), + new MultiplicationMathExcercise() + }; + + public void Run() + { + var mathExcerciseRunner = new MathExcerciseRunner(); + foreach (var mathExcercise in mathExcercises) + { + mathExcerciseRunner.Test(mathExcercise); + } + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs index 563962b7..a332d150 100644 --- a/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs +++ b/Labs/IW5-Excercise-03/CleanCode/CleanCodeSample/CleanCodeSample/Program.cs @@ -11,70 +11,9 @@ class Program { static void Main(string[] args) { - Stuff(); - } - - // Calculating addition operation - private static void Stuff() - { - // FIrst number for addition - int n1; - // Second number for addition - int n2; - // Answer from the user - int a; - // Correct answer - int r; - - // Asking user to input a number - Console.Write("Zadejte 1. číslo pro sčítání: "); - - // Reading number from console - while (!int.TryParse(Console.ReadLine(), out n1)) - { - } - - // Asking user to input a number - Console.Write("Zadejte 2. číslo pro sčítání: "); - - // Reading number from console - while (!int.TryParse(Console.ReadLine(), out n2)) - { - } - - Console.Write("Zadejte Vaši odpověď: "); - - // Reading number from console - while (!int.TryParse(Console.ReadLine(), out a)) - { - } - - // Correct answer - r = n1 + n2; - - // Checking if the answer from the user was correct - if (r == a) - { - // Setting color to green - Console.ForegroundColor = ConsoleColor.Green; - - // Printing the result - Console.Write("Vaše odpověď \""); - Console.Write(a); - Console.Write("\" byla správná"); - } - else - { - // Setting color to red - Console.ForegroundColor = ConsoleColor.Red; - - // Printing the result - Console.Write("Vaše odpověď \""); - Console.Write(a); - Console.Write("\" byla nesprávná"); - } + var mathExcercisesProgram = new MathExcercisesProgram(); + mathExcercisesProgram.Run(); - // Waiting for input from user Console.ReadKey(); } } From 1ae5b25e100c850b16159765da50cfc26993aa91 Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Tue, 4 Apr 2017 22:26:24 +0200 Subject: [PATCH 31/41] Added before solution for Excercise05 --- Labs/IW5-Excercise-05/CookBook.App/App.config | 23 + Labs/IW5-Excercise-05/CookBook.App/App.xaml | 11 + .../IW5-Excercise-05/CookBook.App/App.xaml.cs | 11 + .../CookBook.App/Commands/RelayCommand.cs | 42 + .../Commands/SaveRecipeCommand.cs | 46 + .../Converters/TimeSpanToMinutesConverter.cs | 32 + .../CookBook.App/CookBook.App.csproj | 153 +++ .../CookBook.App/Properties/Annotations.cs | 1048 +++++++++++++++++ .../CookBook.App/Properties/AssemblyInfo.cs | 55 + .../Properties/Resources.Designer.cs | 63 + .../CookBook.App/Properties/Resources.resx | 117 ++ .../Properties/Settings.Designer.cs | 26 + .../CookBook.App/Properties/Settings.settings | 7 + .../CookBook.App/ViewModelLocator.cs | 35 + .../CookBook.App/ViewModels/MainViewModel.cs | 21 + .../ViewModels/RecipeDetailViewModel.cs | 59 + .../ViewModels/RecipeListViewModel.cs | 46 + .../CookBook.App/ViewModels/ViewModelBase.cs | 18 + .../CookBook.App/Views/MainWindow.xaml | 37 + .../CookBook.App/Views/MainWindow.xaml.cs | 15 + .../CookBook.App/Views/RecipeDetailView.xaml | 52 + .../Views/RecipeDetailView.xaml.cs | 15 + .../CookBook.App/Views/RecipeListView.xaml | 25 + .../CookBook.App/Views/RecipeListView.xaml.cs | 15 + .../CookBook.App/packages.config | 4 + Labs/IW5-Excercise-05/CookBook.BL/App.config | 6 + .../CookBook.BL/CookBook.BL.csproj | 82 ++ .../CookBook.BL/IMessenger.cs | 11 + Labs/IW5-Excercise-05/CookBook.BL/Mapper.cs | 50 + .../Messages/DeletedRecipeMessage.cs | 15 + .../CookBook.BL/Messages/NewRecipeMessage.cs | 6 + .../Messages/SelectedRecipeMessage.cs | 9 + .../Messages/UpdatedRecipeMessage.cs | 16 + .../IW5-Excercise-05/CookBook.BL/Messenger.cs | 58 + .../CookBook.BL/Models/RecipeDetailModel.cs | 16 + .../CookBook.BL/Models/RecipesListModel.cs | 17 + .../CookBook.BL/Properties/AssemblyInfo.cs | 36 + .../Repositories/RecipeRepository.cs | 89 ++ .../CookBook.BL/packages.config | 4 + Labs/IW5-Excercise-05/CookBook.DAL/App.config | 20 + .../CookBook.DAL/CookBook.DAL.csproj | 91 ++ .../CookBook.DAL/CookBookDbContext.cs | 17 + .../Base/Implementation/EntityBase.cs | 10 + .../Entities/Base/Interface/IEntity.cs | 9 + .../CookBook.DAL/Entities/FoodType.cs | 10 + .../Entities/IngredientAmountEntity.cs | 22 + .../CookBook.DAL/Entities/IngredientEntity.cs | 14 + .../CookBook.DAL/Entities/RecipeEntity.cs | 17 + .../CookBook.DAL/Entities/Unit.cs | 18 + ...0839276_IngredientAmountEntity.Designer.cs | 29 + .../201703060839276_IngredientAmountEntity.cs | 39 + ...01703060839276_IngredientAmountEntity.resx | 126 ++ ...ddedPropertiesIngredientEntity.Designer.cs | 29 + ...0851297_AddedPropertiesIngredientEntity.cs | 22 + ...51297_AddedPropertiesIngredientEntity.resx | 126 ++ .../201703061916184_Init.Designer.cs | 29 + .../Migrations/201703061916184_Init.cs | 62 + .../Migrations/201703061916184_Init.resx | 126 ++ ...080209034_PrepareForExcercise3.Designer.cs | 29 + .../201703080209034_PrepareForExcercise3.cs | 26 + .../201703080209034_PrepareForExcercise3.resx | 126 ++ .../CookBook.DAL/Migrations/Configuration.cs | 96 ++ .../CookBook.DAL/Properties/AssemblyInfo.cs | 36 + .../CookBook.DAL/packages.config | 4 + .../CookBook.Tests/App.config | 16 + .../CookBook.Tests/CookBook.Tests.csproj | 100 ++ .../CookBook.Tests/CookBookDbContextTests.cs | 54 + .../CookBook.Tests/Properties/AssemblyInfo.cs | 20 + .../CookBook.Tests/packages.config | 12 + Labs/IW5-Excercise-05/CookBook.sln | 45 + 70 files changed, 3771 insertions(+) create mode 100644 Labs/IW5-Excercise-05/CookBook.App/App.config create mode 100644 Labs/IW5-Excercise-05/CookBook.App/App.xaml create mode 100644 Labs/IW5-Excercise-05/CookBook.App/App.xaml.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Commands/RelayCommand.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Commands/SaveRecipeCommand.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Converters/TimeSpanToMinutesConverter.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Properties/Annotations.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Properties/AssemblyInfo.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Properties/Resources.Designer.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Properties/Resources.resx create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Properties/Settings.Designer.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Properties/Settings.settings create mode 100644 Labs/IW5-Excercise-05/CookBook.App/ViewModelLocator.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.App/packages.config create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/App.config create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/CookBook.BL.csproj create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/IMessenger.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Mapper.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Messages/DeletedRecipeMessage.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Messages/NewRecipeMessage.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Messages/SelectedRecipeMessage.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Messages/UpdatedRecipeMessage.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Messenger.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Models/RecipeDetailModel.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Models/RecipesListModel.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Properties/AssemblyInfo.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/Repositories/RecipeRepository.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.BL/packages.config create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/App.config create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/CookBook.DAL.csproj create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/CookBookDbContext.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Entities/Base/Interface/IEntity.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Entities/FoodType.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Entities/IngredientAmountEntity.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Entities/IngredientEntity.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Entities/RecipeEntity.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Entities/Unit.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.resx create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.Designer.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.resx create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Migrations/Configuration.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/Properties/AssemblyInfo.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.DAL/packages.config create mode 100644 Labs/IW5-Excercise-05/CookBook.Tests/App.config create mode 100644 Labs/IW5-Excercise-05/CookBook.Tests/CookBook.Tests.csproj create mode 100644 Labs/IW5-Excercise-05/CookBook.Tests/CookBookDbContextTests.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.Tests/Properties/AssemblyInfo.cs create mode 100644 Labs/IW5-Excercise-05/CookBook.Tests/packages.config create mode 100644 Labs/IW5-Excercise-05/CookBook.sln diff --git a/Labs/IW5-Excercise-05/CookBook.App/App.config b/Labs/IW5-Excercise-05/CookBook.App/App.config new file mode 100644 index 00000000..dbc55e69 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/App.config @@ -0,0 +1,23 @@ + + + + +
+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/App.xaml b/Labs/IW5-Excercise-05/CookBook.App/App.xaml new file mode 100644 index 00000000..193b9fec --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/App.xaml @@ -0,0 +1,11 @@ + + + + + + diff --git a/Labs/IW5-Excercise-05/CookBook.App/App.xaml.cs b/Labs/IW5-Excercise-05/CookBook.App/App.xaml.cs new file mode 100644 index 00000000..6c1c6057 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/App.xaml.cs @@ -0,0 +1,11 @@ +using System.Windows; + +namespace CookBook.App +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.App/Commands/RelayCommand.cs b/Labs/IW5-Excercise-05/CookBook.App/Commands/RelayCommand.cs new file mode 100644 index 00000000..540b548c --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Commands/RelayCommand.cs @@ -0,0 +1,42 @@ +using System; +using System.Windows.Input; + +namespace CookBook.App.Commands +{ + public class RelayCommand : ICommand + { + private readonly Action _executeAction; + private readonly Func _canExecuteAction; + + public RelayCommand(Action executeAction, Func canExecuteAction = null) + { + _executeAction = executeAction; + _canExecuteAction = canExecuteAction; + } + + public RelayCommand(Action executeAction, Func canExecuteAction = null) + : this(p => executeAction(), p => canExecuteAction?.Invoke() ?? true) + { + + } + + public bool CanExecute(object parameter) + { + return _canExecuteAction?.Invoke(parameter) ?? true; + } + + public void Execute(object parameter) + { + _executeAction?.Invoke(parameter); + } + + public void RaiseCanExecuteChanged() + { + CanExecuteChanged?.Invoke(this, EventArgs.Empty); + } + + public event EventHandler CanExecuteChanged; + } + + +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/Commands/SaveRecipeCommand.cs b/Labs/IW5-Excercise-05/CookBook.App/Commands/SaveRecipeCommand.cs new file mode 100644 index 00000000..ef3f8dc1 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Commands/SaveRecipeCommand.cs @@ -0,0 +1,46 @@ +using System; +using System.Windows.Input; +using CookBook.App.ViewModels; +using CookBook.BL; +using CookBook.BL.Models; +using CookBook.BL.Repositories; + +namespace CookBook.App.Commands +{ + public class SaveRecipeCommand : ICommand + { + private readonly RecipeRepository _recipeRepository; + private readonly RecipeDetailViewModel _viewModel; + private readonly IMessenger _messenger; + + public SaveRecipeCommand(RecipeRepository recipeRepository, RecipeDetailViewModel viewModel, IMessenger messenger) + { + _recipeRepository = recipeRepository; + _viewModel = viewModel; + _messenger = messenger; + } + + public bool CanExecute(object parameter) + { + var detail = parameter as RecipeDetailModel; + + if (detail != null) + { + return detail.Duration.TotalMinutes > 0; + } + + return false; + } + + public void Execute(object parameter) + { + // ToDo + } + + public event EventHandler CanExecuteChanged + { + add { CommandManager.RequerySuggested += value; } + remove { CommandManager.RequerySuggested -= value; } + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/Converters/TimeSpanToMinutesConverter.cs b/Labs/IW5-Excercise-05/CookBook.App/Converters/TimeSpanToMinutesConverter.cs new file mode 100644 index 00000000..96caf469 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Converters/TimeSpanToMinutesConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace CookBook.App.Converters +{ + public class TimeSpanToMinutesConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var time = value as TimeSpan?; + + return time?.TotalMinutes; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + var minutes = value?.ToString(); + + if (minutes != null) + { + int minutesCount = 0; + if (int.TryParse(minutes, out minutesCount)) + { + return TimeSpan.FromMinutes(minutesCount); + } + } + + return null; + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj b/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj new file mode 100644 index 00000000..1d7d5f3a --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj @@ -0,0 +1,153 @@ + + + + + Debug + AnyCPU + {9FE5CEF4-1AD0-4B7E-984C-AE908F7B5F3A} + WinExe + Properties + CookBook.App + CookBook.App + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + + + RecipeDetailView.xaml + + + RecipeListView.xaml + + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + + {F48D47ED-6003-4B97-8629-5C6BEC99E779} + CookBook.BL + + + {9247FC0B-1D73-4343-9BE0-6974EC0CD834} + CookBook.DAL + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/Properties/Annotations.cs b/Labs/IW5-Excercise-05/CookBook.App/Properties/Annotations.cs new file mode 100644 index 00000000..e40e819e --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Properties/Annotations.cs @@ -0,0 +1,1048 @@ +/* MIT License + +Copyright (c) 2016 JetBrains http://www.jetbrains.com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. */ + +using System; + +#pragma warning disable 1591 +// ReSharper disable UnusedMember.Global +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable IntroduceOptionalParameters.Global +// ReSharper disable MemberCanBeProtected.Global +// ReSharper disable InconsistentNaming + +namespace CookBook.App.Properties +{ + /// + /// Indicates that the value of the marked element could be null sometimes, + /// so the check for null is necessary before its usage. + /// + /// + /// [CanBeNull] object Test() => null; + /// + /// void UseTest() { + /// var p = Test(); + /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException' + /// } + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | + AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] + public sealed class CanBeNullAttribute : Attribute { } + + /// + /// Indicates that the value of the marked element could never be null. + /// + /// + /// [NotNull] object Foo() { + /// return null; // Warning: Possible 'null' assignment + /// } + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | + AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] + public sealed class NotNullAttribute : Attribute { } + + /// + /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task + /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property + /// or of the Lazy.Value property can never be null. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | + AttributeTargets.Delegate | AttributeTargets.Field)] + public sealed class ItemNotNullAttribute : Attribute { } + + /// + /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task + /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property + /// or of the Lazy.Value property can be null. + /// + [AttributeUsage( + AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | + AttributeTargets.Delegate | AttributeTargets.Field)] + public sealed class ItemCanBeNullAttribute : Attribute { } + + /// + /// Indicates that the marked method builds string by format pattern and (optional) arguments. + /// Parameter, which contains format string, should be given in constructor. The format string + /// should be in -like form. + /// + /// + /// [StringFormatMethod("message")] + /// void ShowError(string message, params object[] args) { /* do something */ } + /// + /// void Foo() { + /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string + /// } + /// + [AttributeUsage( + AttributeTargets.Constructor | AttributeTargets.Method | + AttributeTargets.Property | AttributeTargets.Delegate)] + public sealed class StringFormatMethodAttribute : Attribute + { + /// + /// Specifies which parameter of an annotated method should be treated as format-string + /// + public StringFormatMethodAttribute([NotNull] string formatParameterName) + { + FormatParameterName = formatParameterName; + } + + [NotNull] public string FormatParameterName { get; private set; } + } + + /// + /// For a parameter that is expected to be one of the limited set of values. + /// Specify fields of which type should be used as values for this parameter. + /// + [AttributeUsage( + AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field, + AllowMultiple = true)] + public sealed class ValueProviderAttribute : Attribute + { + public ValueProviderAttribute([NotNull] string name) + { + Name = name; + } + + [NotNull] public string Name { get; private set; } + } + + /// + /// Indicates that the function argument should be string literal and match one + /// of the parameters of the caller function. For example, ReSharper annotates + /// the parameter of . + /// + /// + /// void Foo(string param) { + /// if (param == null) + /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol + /// } + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class InvokerParameterNameAttribute : Attribute { } + + /// + /// Indicates that the method is contained in a type that implements + /// System.ComponentModel.INotifyPropertyChanged interface and this method + /// is used to notify that some property value changed. + /// + /// + /// The method should be non-static and conform to one of the supported signatures: + /// + /// NotifyChanged(string) + /// NotifyChanged(params string[]) + /// NotifyChanged{T}(Expression{Func{T}}) + /// NotifyChanged{T,U}(Expression{Func{T,U}}) + /// SetProperty{T}(ref T, T, string) + /// + /// + /// + /// public class Foo : INotifyPropertyChanged { + /// public event PropertyChangedEventHandler PropertyChanged; + /// + /// [NotifyPropertyChangedInvocator] + /// protected virtual void NotifyChanged(string propertyName) { ... } + /// + /// string _name; + /// + /// public string Name { + /// get { return _name; } + /// set { _name = value; NotifyChanged("LastName"); /* Warning */ } + /// } + /// } + /// + /// Examples of generated notifications: + /// + /// NotifyChanged("Property") + /// NotifyChanged(() => Property) + /// NotifyChanged((VM x) => x.Property) + /// SetProperty(ref myField, value, "Property") + /// + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class NotifyPropertyChangedInvocatorAttribute : Attribute + { + public NotifyPropertyChangedInvocatorAttribute() { } + public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) + { + ParameterName = parameterName; + } + + [CanBeNull] public string ParameterName { get; private set; } + } + + /// + /// Describes dependency between method input and output. + /// + /// + ///

Function Definition Table syntax:

+ /// + /// FDT ::= FDTRow [;FDTRow]* + /// FDTRow ::= Input => Output | Output <= Input + /// Input ::= ParameterName: Value [, Input]* + /// Output ::= [ParameterName: Value]* {halt|stop|void|nothing|Value} + /// Value ::= true | false | null | notnull | canbenull + /// + /// If method has single input parameter, it's name could be omitted.
+ /// Using halt (or void/nothing, which is the same) for method output + /// means that the methos doesn't return normally (throws or terminates the process).
+ /// Value canbenull is only applicable for output parameters.
+ /// You can use multiple [ContractAnnotation] for each FDT row, or use single attribute + /// with rows separated by semicolon. There is no notion of order rows, all rows are checked + /// for applicability and applied per each program state tracked by R# analysis.
+ ///
+ /// + /// + /// [ContractAnnotation("=> halt")] + /// public void TerminationMethod() + /// + /// + /// [ContractAnnotation("halt <= condition: false")] + /// public void Assert(bool condition, string text) // regular assertion method + /// + /// + /// [ContractAnnotation("s:null => true")] + /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty() + /// + /// + /// // A method that returns null if the parameter is null, + /// // and not null if the parameter is not null + /// [ContractAnnotation("null => null; notnull => notnull")] + /// public object Transform(object data) + /// + /// + /// [ContractAnnotation("=> true, result: notnull; => false, result: null")] + /// public bool TryParse(string s, out Person result) + /// + /// + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public sealed class ContractAnnotationAttribute : Attribute + { + public ContractAnnotationAttribute([NotNull] string contract) + : this(contract, false) { } + + public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates) + { + Contract = contract; + ForceFullStates = forceFullStates; + } + + [NotNull] public string Contract { get; private set; } + + public bool ForceFullStates { get; private set; } + } + + /// + /// Indicates that marked element should be localized or not. + /// + /// + /// [LocalizationRequiredAttribute(true)] + /// class Foo { + /// string str = "my string"; // Warning: Localizable string + /// } + /// + [AttributeUsage(AttributeTargets.All)] + public sealed class LocalizationRequiredAttribute : Attribute + { + public LocalizationRequiredAttribute() : this(true) { } + + public LocalizationRequiredAttribute(bool required) + { + Required = required; + } + + public bool Required { get; private set; } + } + + /// + /// Indicates that the value of the marked type (or its derivatives) + /// cannot be compared using '==' or '!=' operators and Equals() + /// should be used instead. However, using '==' or '!=' for comparison + /// with null is always permitted. + /// + /// + /// [CannotApplyEqualityOperator] + /// class NoEquality { } + /// + /// class UsesNoEquality { + /// void Test() { + /// var ca1 = new NoEquality(); + /// var ca2 = new NoEquality(); + /// if (ca1 != null) { // OK + /// bool condition = ca1 == ca2; // Warning + /// } + /// } + /// } + /// + [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct)] + public sealed class CannotApplyEqualityOperatorAttribute : Attribute { } + + /// + /// When applied to a target attribute, specifies a requirement for any type marked + /// with the target attribute to implement or inherit specific type or types. + /// + /// + /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement + /// class ComponentAttribute : Attribute { } + /// + /// [Component] // ComponentAttribute requires implementing IComponent interface + /// class MyComponent : IComponent { } + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + [BaseTypeRequired(typeof(Attribute))] + public sealed class BaseTypeRequiredAttribute : Attribute + { + public BaseTypeRequiredAttribute([NotNull] Type baseType) + { + BaseType = baseType; + } + + [NotNull] public Type BaseType { get; private set; } + } + + /// + /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library), + /// so this symbol will not be marked as unused (as well as by other usage inspections). + /// + [AttributeUsage(AttributeTargets.All)] + public sealed class UsedImplicitlyAttribute : Attribute + { + public UsedImplicitlyAttribute() + : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } + + public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags) + : this(useKindFlags, ImplicitUseTargetFlags.Default) { } + + public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags) + : this(ImplicitUseKindFlags.Default, targetFlags) { } + + public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) + { + UseKindFlags = useKindFlags; + TargetFlags = targetFlags; + } + + public ImplicitUseKindFlags UseKindFlags { get; private set; } + + public ImplicitUseTargetFlags TargetFlags { get; private set; } + } + + /// + /// Should be used on attributes and causes ReSharper to not mark symbols marked with such attributes + /// as unused (as well as by other usage inspections) + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter)] + public sealed class MeansImplicitUseAttribute : Attribute + { + public MeansImplicitUseAttribute() + : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } + + public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) + : this(useKindFlags, ImplicitUseTargetFlags.Default) { } + + public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) + : this(ImplicitUseKindFlags.Default, targetFlags) { } + + public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) + { + UseKindFlags = useKindFlags; + TargetFlags = targetFlags; + } + + [UsedImplicitly] public ImplicitUseKindFlags UseKindFlags { get; private set; } + + [UsedImplicitly] public ImplicitUseTargetFlags TargetFlags { get; private set; } + } + + [Flags] + public enum ImplicitUseKindFlags + { + Default = Access | Assign | InstantiatedWithFixedConstructorSignature, + /// Only entity marked with attribute considered used. + Access = 1, + /// Indicates implicit assignment to a member. + Assign = 2, + /// + /// Indicates implicit instantiation of a type with fixed constructor signature. + /// That means any unused constructor parameters won't be reported as such. + /// + InstantiatedWithFixedConstructorSignature = 4, + /// Indicates implicit instantiation of a type. + InstantiatedNoFixedConstructorSignature = 8, + } + + /// + /// Specify what is considered used implicitly when marked + /// with or . + /// + [Flags] + public enum ImplicitUseTargetFlags + { + Default = Itself, + Itself = 1, + /// Members of entity marked with attribute are considered used. + Members = 2, + /// Entity marked with attribute and all its members considered used. + WithMembers = Itself | Members + } + + /// + /// This attribute is intended to mark publicly available API + /// which should not be removed and so is treated as used. + /// + [MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)] + public sealed class PublicAPIAttribute : Attribute + { + public PublicAPIAttribute() { } + + public PublicAPIAttribute([NotNull] string comment) + { + Comment = comment; + } + + [CanBeNull] public string Comment { get; private set; } + } + + /// + /// Tells code analysis engine if the parameter is completely handled when the invoked method is on stack. + /// If the parameter is a delegate, indicates that delegate is executed while the method is executed. + /// If the parameter is an enumerable, indicates that it is enumerated while the method is executed. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class InstantHandleAttribute : Attribute { } + + /// + /// Indicates that a method does not make any observable state changes. + /// The same as System.Diagnostics.Contracts.PureAttribute. + /// + /// + /// [Pure] int Multiply(int x, int y) => x * y; + /// + /// void M() { + /// Multiply(123, 42); // Waring: Return value of pure method is not used + /// } + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class PureAttribute : Attribute { } + + /// + /// Indicates that the return value of method invocation must be used. + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class MustUseReturnValueAttribute : Attribute + { + public MustUseReturnValueAttribute() { } + + public MustUseReturnValueAttribute([NotNull] string justification) + { + Justification = justification; + } + + [CanBeNull] public string Justification { get; private set; } + } + + /// + /// Indicates the type member or parameter of some type, that should be used instead of all other ways + /// to get the value that type. This annotation is useful when you have some "context" value evaluated + /// and stored somewhere, meaning that all other ways to get this value must be consolidated with existing one. + /// + /// + /// class Foo { + /// [ProvidesContext] IBarService _barService = ...; + /// + /// void ProcessNode(INode node) { + /// DoSomething(node, node.GetGlobalServices().Bar); + /// // ^ Warning: use value of '_barService' field + /// } + /// } + /// + [AttributeUsage( + AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.Method | + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.GenericParameter)] + public sealed class ProvidesContextAttribute : Attribute { } + + /// + /// Indicates that a parameter is a path to a file or a folder within a web project. + /// Path can be relative or absolute, starting from web root (~). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class PathReferenceAttribute : Attribute + { + public PathReferenceAttribute() { } + + public PathReferenceAttribute([NotNull, PathReference] string basePath) + { + BasePath = basePath; + } + + [CanBeNull] public string BasePath { get; private set; } + } + + /// + /// An extension method marked with this attribute is processed by ReSharper code completion + /// as a 'Source Template'. When extension method is completed over some expression, it's source code + /// is automatically expanded like a template at call site. + /// + /// + /// Template method body can contain valid source code and/or special comments starting with '$'. + /// Text inside these comments is added as source code when the template is applied. Template parameters + /// can be used either as additional method parameters or as identifiers wrapped in two '$' signs. + /// Use the attribute to specify macros for parameters. + /// + /// + /// In this example, the 'forEach' method is a source template available over all values + /// of enumerable types, producing ordinary C# 'foreach' statement and placing caret inside block: + /// + /// [SourceTemplate] + /// public static void forEach<T>(this IEnumerable<T> xs) { + /// foreach (var x in xs) { + /// //$ $END$ + /// } + /// } + /// + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class SourceTemplateAttribute : Attribute { } + + /// + /// Allows specifying a macro for a parameter of a source template. + /// + /// + /// You can apply the attribute on the whole method or on any of its additional parameters. The macro expression + /// is defined in the property. When applied on a method, the target + /// template parameter is defined in the property. To apply the macro silently + /// for the parameter, set the property value = -1. + /// + /// + /// Applying the attribute on a source template method: + /// + /// [SourceTemplate, Macro(Target = "item", Expression = "suggestVariableName()")] + /// public static void forEach<T>(this IEnumerable<T> collection) { + /// foreach (var item in collection) { + /// //$ $END$ + /// } + /// } + /// + /// Applying the attribute on a template method parameter: + /// + /// [SourceTemplate] + /// public static void something(this Entity x, [Macro(Expression = "guid()", Editable = -1)] string newguid) { + /// /*$ var $x$Id = "$newguid$" + x.ToString(); + /// x.DoSomething($x$Id); */ + /// } + /// + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = true)] + public sealed class MacroAttribute : Attribute + { + /// + /// Allows specifying a macro that will be executed for a source template + /// parameter when the template is expanded. + /// + [CanBeNull] public string Expression { get; set; } + + /// + /// Allows specifying which occurrence of the target parameter becomes editable when the template is deployed. + /// + /// + /// If the target parameter is used several times in the template, only one occurrence becomes editable; + /// other occurrences are changed synchronously. To specify the zero-based index of the editable occurrence, + /// use values >= 0. To make the parameter non-editable when the template is expanded, use -1. + /// > + public int Editable { get; set; } + + /// + /// Identifies the target parameter of a source template if the + /// is applied on a template method. + /// + [CanBeNull] public string Target { get; set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute + { + public AspMvcAreaMasterLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute + { + public AspMvcAreaPartialViewLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class AspMvcAreaViewLocationFormatAttribute : Attribute + { + public AspMvcAreaViewLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class AspMvcMasterLocationFormatAttribute : Attribute + { + public AspMvcMasterLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class AspMvcPartialViewLocationFormatAttribute : Attribute + { + public AspMvcPartialViewLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class AspMvcViewLocationFormatAttribute : Attribute + { + public AspMvcViewLocationFormatAttribute([NotNull] string format) + { + Format = format; + } + + [NotNull] public string Format { get; private set; } + } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter + /// is an MVC action. If applied to a method, the MVC action name is calculated + /// implicitly from the context. Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcActionAttribute : Attribute + { + public AspMvcActionAttribute() { } + + public AspMvcActionAttribute([NotNull] string anonymousProperty) + { + AnonymousProperty = anonymousProperty; + } + + [CanBeNull] public string AnonymousProperty { get; private set; } + } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC area. + /// Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcAreaAttribute : Attribute + { + public AspMvcAreaAttribute() { } + + public AspMvcAreaAttribute([NotNull] string anonymousProperty) + { + AnonymousProperty = anonymousProperty; + } + + [CanBeNull] public string AnonymousProperty { get; private set; } + } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is + /// an MVC controller. If applied to a method, the MVC controller name is calculated + /// implicitly from the context. Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String, String). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcControllerAttribute : Attribute + { + public AspMvcControllerAttribute() { } + + public AspMvcControllerAttribute([NotNull] string anonymousProperty) + { + AnonymousProperty = anonymousProperty; + } + + [CanBeNull] public string AnonymousProperty { get; private set; } + } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC Master. Use this attribute + /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcMasterAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC model type. Use this attribute + /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, Object). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcModelTypeAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is an MVC + /// partial view. If applied to a method, the MVC partial view name is calculated implicitly + /// from the context. Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcPartialViewAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Allows disabling inspections for MVC views within a class or a method. + /// + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] + public sealed class AspMvcSuppressViewErrorAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC display template. + /// Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.DisplayExtensions.DisplayForModel(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcDisplayTemplateAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC editor template. + /// Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper, String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcEditorTemplateAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. Indicates that a parameter is an MVC template. + /// Use this attribute for custom wrappers similar to + /// System.ComponentModel.DataAnnotations.UIHintAttribute(System.String). + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcTemplateAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter + /// is an MVC view component. If applied to a method, the MVC view name is calculated implicitly + /// from the context. Use this attribute for custom wrappers similar to + /// System.Web.Mvc.Controller.View(Object). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcViewAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter + /// is an MVC view component name. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AspMvcViewComponentAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter + /// is an MVC view component view. If applied to a method, the MVC view component view name is default. + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class AspMvcViewComponentViewAttribute : Attribute { } + + /// + /// ASP.NET MVC attribute. When applied to a parameter of an attribute, + /// indicates that this parameter is an MVC action name. + /// + /// + /// [ActionName("Foo")] + /// public ActionResult Login(string returnUrl) { + /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK + /// return RedirectToAction("Bar"); // Error: Cannot resolve action + /// } + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)] + public sealed class AspMvcActionSelectorAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field)] + public sealed class HtmlElementAttributesAttribute : Attribute + { + public HtmlElementAttributesAttribute() { } + + public HtmlElementAttributesAttribute([NotNull] string name) + { + Name = name; + } + + [CanBeNull] public string Name { get; private set; } + } + + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] + public sealed class HtmlAttributeValueAttribute : Attribute + { + public HtmlAttributeValueAttribute([NotNull] string name) + { + Name = name; + } + + [NotNull] public string Name { get; private set; } + } + + /// + /// Razor attribute. Indicates that a parameter or a method is a Razor section. + /// Use this attribute for custom wrappers similar to + /// System.Web.WebPages.WebPageBase.RenderSection(String). + /// + [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] + public sealed class RazorSectionAttribute : Attribute { } + + /// + /// Indicates how method, constructor invocation or property access + /// over collection type affects content of the collection. + /// + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)] + public sealed class CollectionAccessAttribute : Attribute + { + public CollectionAccessAttribute(CollectionAccessType collectionAccessType) + { + CollectionAccessType = collectionAccessType; + } + + public CollectionAccessType CollectionAccessType { get; private set; } + } + + [Flags] + public enum CollectionAccessType + { + /// Method does not use or modify content of the collection. + None = 0, + /// Method only reads content of the collection but does not modify it. + Read = 1, + /// Method can change content of the collection but does not add new elements. + ModifyExistingContent = 2, + /// Method can add new elements to the collection. + UpdatedContent = ModifyExistingContent | 4 + } + + /// + /// Indicates that the marked method is assertion method, i.e. it halts control flow if + /// one of the conditions is satisfied. To set the condition, mark one of the parameters with + /// attribute. + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class AssertionMethodAttribute : Attribute { } + + /// + /// Indicates the condition parameter of the assertion method. The method itself should be + /// marked by attribute. The mandatory argument of + /// the attribute is the assertion type. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class AssertionConditionAttribute : Attribute + { + public AssertionConditionAttribute(AssertionConditionType conditionType) + { + ConditionType = conditionType; + } + + public AssertionConditionType ConditionType { get; private set; } + } + + /// + /// Specifies assertion type. If the assertion method argument satisfies the condition, + /// then the execution continues. Otherwise, execution is assumed to be halted. + /// + public enum AssertionConditionType + { + /// Marked parameter should be evaluated to true. + IS_TRUE = 0, + /// Marked parameter should be evaluated to false. + IS_FALSE = 1, + /// Marked parameter should be evaluated to null value. + IS_NULL = 2, + /// Marked parameter should be evaluated to not null value. + IS_NOT_NULL = 3, + } + + /// + /// Indicates that the marked method unconditionally terminates control flow execution. + /// For example, it could unconditionally throw exception. + /// + [Obsolete("Use [ContractAnnotation('=> halt')] instead")] + [AttributeUsage(AttributeTargets.Method)] + public sealed class TerminatesProgramAttribute : Attribute { } + + /// + /// Indicates that method is pure LINQ method, with postponed enumeration (like Enumerable.Select, + /// .Where). This annotation allows inference of [InstantHandle] annotation for parameters + /// of delegate type by analyzing LINQ method chains. + /// + [AttributeUsage(AttributeTargets.Method)] + public sealed class LinqTunnelAttribute : Attribute { } + + /// + /// Indicates that IEnumerable, passed as parameter, is not enumerated. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class NoEnumerationAttribute : Attribute { } + + /// + /// Indicates that parameter is regular expression pattern. + /// + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class RegexPatternAttribute : Attribute { } + + /// + /// Prevents the Member Reordering feature from tossing members of the marked class. + /// + /// + /// The attribute must be mentioned in your member reordering patterns + /// + [AttributeUsage( + AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum)] + public sealed class NoReorderAttribute : Attribute { } + + /// + /// XAML attribute. Indicates the type that has ItemsSource property and should be treated + /// as ItemsControl-derived type, to enable inner items DataContext type resolve. + /// + [AttributeUsage(AttributeTargets.Class)] + public sealed class XamlItemsControlAttribute : Attribute { } + + /// + /// XAML attribute. Indicates the property of some BindingBase-derived type, that + /// is used to bind some item of ItemsControl-derived type. This annotation will + /// enable the DataContext type resolve for XAML bindings for such properties. + /// + /// + /// Property should have the tree ancestor of the ItemsControl type or + /// marked with the attribute. + /// + [AttributeUsage(AttributeTargets.Property)] + public sealed class XamlItemBindingOfItemsControlAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public sealed class AspChildControlTypeAttribute : Attribute + { + public AspChildControlTypeAttribute([NotNull] string tagName, [NotNull] Type controlType) + { + TagName = tagName; + ControlType = controlType; + } + + [NotNull] public string TagName { get; private set; } + + [NotNull] public Type ControlType { get; private set; } + } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] + public sealed class AspDataFieldAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] + public sealed class AspDataFieldsAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Property)] + public sealed class AspMethodPropertyAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public sealed class AspRequiredAttributeAttribute : Attribute + { + public AspRequiredAttributeAttribute([NotNull] string attribute) + { + Attribute = attribute; + } + + [NotNull] public string Attribute { get; private set; } + } + + [AttributeUsage(AttributeTargets.Property)] + public sealed class AspTypePropertyAttribute : Attribute + { + public bool CreateConstructorReferences { get; private set; } + + public AspTypePropertyAttribute(bool createConstructorReferences) + { + CreateConstructorReferences = createConstructorReferences; + } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class RazorImportNamespaceAttribute : Attribute + { + public RazorImportNamespaceAttribute([NotNull] string name) + { + Name = name; + } + + [NotNull] public string Name { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class RazorInjectionAttribute : Attribute + { + public RazorInjectionAttribute([NotNull] string type, [NotNull] string fieldName) + { + Type = type; + FieldName = fieldName; + } + + [NotNull] public string Type { get; private set; } + + [NotNull] public string FieldName { get; private set; } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class RazorDirectiveAttribute : Attribute + { + public RazorDirectiveAttribute([NotNull] string directive) + { + Directive = directive; + } + + [NotNull] public string Directive { get; private set; } + } + + [AttributeUsage(AttributeTargets.Method)] + public sealed class RazorHelperCommonAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Property)] + public sealed class RazorLayoutAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Method)] + public sealed class RazorWriteLiteralMethodAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Method)] + public sealed class RazorWriteMethodAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class RazorWriteMethodParameterAttribute : Attribute { } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-05/CookBook.App/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..5d58bc89 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CookBook.App04")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CookBook.App04")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labs/IW5-Excercise-05/CookBook.App/Properties/Resources.Designer.cs b/Labs/IW5-Excercise-05/CookBook.App/Properties/Resources.Designer.cs new file mode 100644 index 00000000..5b1d84e5 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CookBook.App.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CookBook.App.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.App/Properties/Resources.resx b/Labs/IW5-Excercise-05/CookBook.App/Properties/Resources.resx new file mode 100644 index 00000000..af7dbebb --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/Properties/Settings.Designer.cs b/Labs/IW5-Excercise-05/CookBook.App/Properties/Settings.Designer.cs new file mode 100644 index 00000000..f1ff1d28 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CookBook.App.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.0.1.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.App/Properties/Settings.settings b/Labs/IW5-Excercise-05/CookBook.App/Properties/Settings.settings new file mode 100644 index 00000000..033d7a5e --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModelLocator.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModelLocator.cs new file mode 100644 index 00000000..1bdf381f --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModelLocator.cs @@ -0,0 +1,35 @@ +using CookBook.App.ViewModels; +using CookBook.BL; +using CookBook.BL.Repositories; + +namespace CookBook.App +{ + public class ViewModelLocator + { + private readonly Messenger _messenger = new Messenger(); + private readonly RecipeRepository _recipeRepository = new RecipeRepository(); + + public MainViewModel MainViewModel => CreateMainViewModel(); + + public RecipeListViewModel RecipeListViewModel => CreateRecipeListViewModel(); + + public RecipeDetailViewModel RecipeDetailViewModel => CreateRecipeDetailViewModel(); + + + private MainViewModel CreateMainViewModel() + { + return new MainViewModel(_messenger); + } + + private RecipeDetailViewModel CreateRecipeDetailViewModel() + { + return new RecipeDetailViewModel(_recipeRepository, _messenger); + } + + private RecipeListViewModel CreateRecipeListViewModel() + { + + return new RecipeListViewModel(_recipeRepository, _messenger); + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs new file mode 100644 index 00000000..019cc956 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs @@ -0,0 +1,21 @@ +using System.Windows.Input; +using CookBook.App.Commands; +using CookBook.BL; +using CookBook.BL.Messages; + +namespace CookBook.App.ViewModels +{ + public class MainViewModel : ViewModelBase + { + private readonly IMessenger _messenger; + + public ICommand CreateRecipeCommand { get; } + + public MainViewModel(IMessenger messenger) + { + _messenger = messenger; + + CreateRecipeCommand = new RelayCommand(() => _messenger.Send(new NewRecipeMessage())); + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs new file mode 100644 index 00000000..e6f5b208 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using CookBook.BL; +using CookBook.BL.Messages; +using CookBook.BL.Models; +using CookBook.BL.Repositories; +using CookBook.DAL.Entities; + +namespace CookBook.App.ViewModels +{ + public class RecipeDetailViewModel : ViewModelBase + { + private readonly RecipeRepository _recipeRepository; + private readonly IMessenger _messenger; + private RecipeDetailModel _detail; + + public RecipeDetailModel Detail + { + get { return _detail; } + set + { + if (Equals(value, Detail)) return; + + _detail = value; + OnPropertyChanged(); + } + } + + public IList FoodTypes => Enum.GetValues(typeof(FoodType)).Cast().ToList(); + + public RecipeDetailViewModel(RecipeRepository recipeRepository, IMessenger messenger) + { + _recipeRepository = recipeRepository; + _messenger = messenger; + + _messenger.Register(SelectedRecipe); + _messenger.Register(NewRecipeMessageReceived); + + // ToDo: Add commands to save and delete + + } + + private void NewRecipeMessageReceived(NewRecipeMessage message) + { + Detail = new RecipeDetailModel(); + } + + private void SelectedRecipe(SelectedRecipeMessage message) + { + Detail = _recipeRepository.GetById(message.Id); + } + + private bool IsSavedRecipe() + { + return Detail.Id != Guid.Empty; + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs new file mode 100644 index 00000000..b9435d00 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs @@ -0,0 +1,46 @@ +using System; +using System.Windows.Input; +using CookBook.App.Commands; +using CookBook.BL; +using CookBook.BL.Messages; +using CookBook.BL.Repositories; + +namespace CookBook.App.ViewModels +{ + public class RecipeListViewModel : ViewModelBase + { + private readonly RecipeRepository _recipeRepository; + private readonly IMessenger _messenger; + + // ToDo Add Recipes + + + public ICommand SelectRecipeCommand { get; } + + public RecipeListViewModel(RecipeRepository recipeRepository, IMessenger messenger) + { + _recipeRepository = recipeRepository; + _messenger = messenger; + + SelectRecipeCommand = new RelayCommand(RecipeSelectionChanged); + // ToDo Add Action on message + } + + public void OnLoad() + { + // ToDo Load Data + } + + public void RecipeSelectionChanged(object parameter) + { + var recipeId = (Guid?)parameter; + + if (!recipeId.HasValue) + { + return; + } + + _messenger.Send(new SelectedRecipeMessage() { Id = recipeId.Value}); + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs new file mode 100644 index 00000000..02ffc2fe --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs @@ -0,0 +1,18 @@ +using System.ComponentModel; +using System.Runtime.CompilerServices; +using CookBook.App.Properties; + +namespace CookBook.App.ViewModels +{ + public abstract class ViewModelBase : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml new file mode 100644 index 00000000..8f63a86a --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs new file mode 100644 index 00000000..4b1dfba6 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows; + +namespace CookBook.App.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml new file mode 100644 index 00000000..0d69940f --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml.cs b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml.cs new file mode 100644 index 00000000..e89caec1 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows.Controls; + +namespace CookBook.App.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class RecipeDetailView : UserControl + { + public RecipeDetailView() + { + InitializeComponent(); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml new file mode 100644 index 00000000..f20af3f7 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml.cs b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml.cs new file mode 100644 index 00000000..af09f8c2 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows.Controls; + +namespace CookBook.App.Views +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class RecipeListView : UserControl + { + public RecipeListView() + { + InitializeComponent(); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.App/packages.config b/Labs/IW5-Excercise-05/CookBook.App/packages.config new file mode 100644 index 00000000..373cff52 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/App.config b/Labs/IW5-Excercise-05/CookBook.BL/App.config new file mode 100644 index 00000000..a8739f8d --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/CookBook.BL.csproj b/Labs/IW5-Excercise-05/CookBook.BL/CookBook.BL.csproj new file mode 100644 index 00000000..91d686ea --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/CookBook.BL.csproj @@ -0,0 +1,82 @@ + + + + + Debug + AnyCPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779} + Library + Properties + CookBook.BL + CookBook.BL + v4.6.1 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + True + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + {9247FC0B-1D73-4343-9BE0-6974EC0CD834} + CookBook.DAL + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/IMessenger.cs b/Labs/IW5-Excercise-05/CookBook.BL/IMessenger.cs new file mode 100644 index 00000000..10cc29fc --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/IMessenger.cs @@ -0,0 +1,11 @@ +using System; + +namespace CookBook.BL +{ + public interface IMessenger + { + void Register(Action action); + void Send(TMessage message); + void UnRegister(Action action); + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Mapper.cs b/Labs/IW5-Excercise-05/CookBook.BL/Mapper.cs new file mode 100644 index 00000000..5e5822cd --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Mapper.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CookBook.BL.Models; +using CookBook.DAL.Entities; + +namespace CookBook.BL +{ + class Mapper + { + public RecipeListModel MapEntityToListModel(RecipeEntity entity) + { + return new RecipeListModel() + { + Id = entity.Id, + Name = entity.Name, + Type = entity.Type, + Duration = entity.Duration + }; + } + + public RecipeDetailModel MapEntityToDetailModel(RecipeEntity entity) + { + return new RecipeDetailModel() + { + Id = entity.Id, + Name = entity.Name, + Type = entity.Type, + Description = entity.Description, + Duration = entity.Duration, + Ingredients = entity.Ingredients + }; + } + + public RecipeEntity MapDetailModelToEntity(RecipeDetailModel entity) + { + return new RecipeEntity() + { + Id = entity.Id, + Name = entity.Name, + Type = entity.Type, + Description = entity.Description, + Duration = entity.Duration, + Ingredients = entity.Ingredients + }; + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Messages/DeletedRecipeMessage.cs b/Labs/IW5-Excercise-05/CookBook.BL/Messages/DeletedRecipeMessage.cs new file mode 100644 index 00000000..391d8f75 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Messages/DeletedRecipeMessage.cs @@ -0,0 +1,15 @@ +using System; +using CookBook.BL.Models; + +namespace CookBook.BL.Messages +{ + public class DeletedRecipeMessage + { + public DeletedRecipeMessage(Guid recipeId) + { + RecipeId = recipeId; + } + + public Guid RecipeId { get; set; } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Messages/NewRecipeMessage.cs b/Labs/IW5-Excercise-05/CookBook.BL/Messages/NewRecipeMessage.cs new file mode 100644 index 00000000..6f5c5872 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Messages/NewRecipeMessage.cs @@ -0,0 +1,6 @@ +namespace CookBook.BL.Messages +{ + public class NewRecipeMessage + { + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Messages/SelectedRecipeMessage.cs b/Labs/IW5-Excercise-05/CookBook.BL/Messages/SelectedRecipeMessage.cs new file mode 100644 index 00000000..8fa97181 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Messages/SelectedRecipeMessage.cs @@ -0,0 +1,9 @@ +using System; + +namespace CookBook.BL.Messages +{ + public class SelectedRecipeMessage + { + public Guid Id { get; set; } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Messages/UpdatedRecipeMessage.cs b/Labs/IW5-Excercise-05/CookBook.BL/Messages/UpdatedRecipeMessage.cs new file mode 100644 index 00000000..b3c58299 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Messages/UpdatedRecipeMessage.cs @@ -0,0 +1,16 @@ +using System; +using CookBook.BL.Models; + +namespace CookBook.BL.Messages +{ + public class UpdatedRecipeMessage + { + public RecipeDetailModel Model { get; set; } + public UpdatedRecipeMessage(RecipeDetailModel model) + { + Model = model; + } + + + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Messenger.cs b/Labs/IW5-Excercise-05/CookBook.BL/Messenger.cs new file mode 100644 index 00000000..5f76078f --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Messenger.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Concurrent; +using System.Linq; + +namespace CookBook.BL +{ + public class Messenger : IMessenger + { + private readonly ConcurrentDictionary> registeredActions = new ConcurrentDictionary>(); + private readonly Object bagLock = new Object(); + + public void Register(Action action) + { + var key = typeof(TMessage); + + lock (bagLock) + { + ConcurrentBag actions; + if (!registeredActions.TryGetValue(typeof(TMessage), out actions)) + { + actions = new ConcurrentBag(); + registeredActions[key] = actions; + } + + actions.Add(action); + } + + } + + public void Send(TMessage message) + { + ConcurrentBag actions; + if (registeredActions.TryGetValue(typeof(TMessage), out actions)) + { + foreach (var action in actions.Select(a => a as Action).Where(a => a != null)) + { + action(message); + } + } + } + + public void UnRegister(Action action) + { + var key = typeof(TMessage); + + ConcurrentBag actions; + if (registeredActions.TryGetValue(typeof(TMessage), out actions)) + { + lock (bagLock) + { + var actionsList = actions.ToList(); + actionsList.Remove(action); + registeredActions[key] = new ConcurrentBag(actionsList); + } + } + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Models/RecipeDetailModel.cs b/Labs/IW5-Excercise-05/CookBook.BL/Models/RecipeDetailModel.cs new file mode 100644 index 00000000..1aed0734 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Models/RecipeDetailModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using CookBook.DAL.Entities; + +namespace CookBook.BL.Models +{ + public class RecipeDetailModel + { + public Guid Id { get; set; } + public string Name { get; set; } + public FoodType Type { get; set; } + public string Description { get; set; } + public TimeSpan Duration { get; set; } + public virtual ICollection Ingredients { get; set; } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Models/RecipesListModel.cs b/Labs/IW5-Excercise-05/CookBook.BL/Models/RecipesListModel.cs new file mode 100644 index 00000000..caf02967 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Models/RecipesListModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CookBook.DAL.Entities; + +namespace CookBook.BL.Models +{ + public class RecipeListModel + { + public Guid Id { get; set; } + public string Name { get; set; } + public FoodType Type { get; set; } + public TimeSpan Duration { get; set; } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-05/CookBook.BL/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..e2bb0be0 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CookBook.BL")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CookBook.BL")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f48d47ed-6003-4b97-8629-5c6bec99e779")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Repositories/RecipeRepository.cs b/Labs/IW5-Excercise-05/CookBook.BL/Repositories/RecipeRepository.cs new file mode 100644 index 00000000..d38cde3e --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/Repositories/RecipeRepository.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using CookBook.BL.Models; +using CookBook.DAL; +using CookBook.DAL.Entities; + +namespace CookBook.BL.Repositories +{ + public class RecipeRepository + { + private Mapper mapper = new Mapper(); + public RecipeEntity FindByName(string name) + { + using (var cookBookDbContext = new CookBookDbContext()) + { + var recipe = cookBookDbContext + .Recipes + .Include(r => r.Ingredients.Select(i => i.Ingredient)) + .FirstOrDefault(r => r.Name == name); + return recipe; + } + } + + public List GetAll() + { + using (var cookBookDbContext = new CookBookDbContext()) + { + return cookBookDbContext.Recipes + .Select(mapper.MapEntityToListModel) + .ToList(); + } + } + + public RecipeDetailModel GetById(Guid id) + { + using (var cookBookDbContext = new CookBookDbContext()) + { + var recipeEntity = cookBookDbContext.Recipes + .FirstOrDefault(r => r.Id == id); + + return mapper.MapEntityToDetailModel(recipeEntity); + } + } + + + public RecipeDetailModel Insert(RecipeDetailModel detail) + { + using (var cookBookDbContext = new CookBookDbContext()) + { + var entity = mapper.MapDetailModelToEntity(detail); + entity.Id = Guid.NewGuid(); + + cookBookDbContext.Recipes.Add(entity); + cookBookDbContext.SaveChanges(); + + return mapper.MapEntityToDetailModel(entity); + } + } + + public void Update(RecipeDetailModel detail) + { + using (var cookBookDbContext = new CookBookDbContext()) + { + var entity = cookBookDbContext.Recipes.First(r => r.Id == detail.Id); + + entity.Name = detail.Name; + entity.Description = detail.Description; + entity.Duration = detail.Duration; + entity.Type = detail.Type; + + cookBookDbContext.SaveChanges(); + } + } + + public void Remove(Guid id) + { + using (var cookBookDbContext = new CookBookDbContext()) + { + var entity = new RecipeEntity() { Id = id }; + cookBookDbContext.Recipes.Attach(entity); + + cookBookDbContext.Recipes.Remove(entity); + cookBookDbContext.SaveChanges(); + } + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.BL/packages.config b/Labs/IW5-Excercise-05/CookBook.BL/packages.config new file mode 100644 index 00000000..373cff52 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.BL/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/App.config b/Labs/IW5-Excercise-05/CookBook.DAL/App.config new file mode 100644 index 00000000..1878bf4c --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/App.config @@ -0,0 +1,20 @@ + + + + +
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/CookBook.DAL.csproj b/Labs/IW5-Excercise-05/CookBook.DAL/CookBook.DAL.csproj new file mode 100644 index 00000000..8b559812 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/CookBook.DAL.csproj @@ -0,0 +1,91 @@ + + + + + Debug + AnyCPU + {9247FC0B-1D73-4343-9BE0-6974EC0CD834} + Library + Properties + CookBook.DAL + CookBook.DAL + v4.5.2 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + True + + + + + + + + + + + + + + + + + + + + + + + + 201703061916184_Init.cs + + + + 201703080209034_PrepareForExcercise3.cs + + + + + + + + + + + 201703061916184_Init.cs + + + 201703080209034_PrepareForExcercise3.cs + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/CookBookDbContext.cs b/Labs/IW5-Excercise-05/CookBook.DAL/CookBookDbContext.cs new file mode 100644 index 00000000..e57d993c --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/CookBookDbContext.cs @@ -0,0 +1,17 @@ +using System; +using CookBook.DAL.Entities; +using System.Data.Entity; + +namespace CookBook.DAL +{ + public class CookBookDbContext : DbContext + { + public IDbSet Recipes { get; set; } + public IDbSet Ingredients { get; set; } + + public CookBookDbContext() + : base("CookBookContext") + { + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs new file mode 100644 index 00000000..83a0de70 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Base/Implementation/EntityBase.cs @@ -0,0 +1,10 @@ +using System; +using CookBook.DAL.Entities.Base.Interface; + +namespace CookBook.DAL.Entities.Base.Implementation +{ + public abstract class EntityBase : IEntity + { + public Guid Id { get; set; } = Guid.NewGuid(); + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Base/Interface/IEntity.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Base/Interface/IEntity.cs new file mode 100644 index 00000000..0e7330f0 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Base/Interface/IEntity.cs @@ -0,0 +1,9 @@ +using System; + +namespace CookBook.DAL.Entities.Base.Interface +{ + public interface IEntity + { + Guid Id { get; } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Entities/FoodType.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/FoodType.cs new file mode 100644 index 00000000..949642e8 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/FoodType.cs @@ -0,0 +1,10 @@ +namespace CookBook.DAL.Entities +{ + public enum FoodType + { + Soup, + MainCourse, + Dessert, + Other + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Entities/IngredientAmountEntity.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/IngredientAmountEntity.cs new file mode 100644 index 00000000..a403bd21 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/IngredientAmountEntity.cs @@ -0,0 +1,22 @@ +using System; +using System.ComponentModel.DataAnnotations; +using CookBook.DAL.Entities.Base.Implementation; + +namespace CookBook.DAL.Entities +{ + public class IngredientAmountEntity : EntityBase + { + [Required] + public double Amount { get; set; } + [Required] + public Unit Unit { get; set; } + + [Required] + public Guid IngredientId { get; set; } + public virtual IngredientEntity Ingredient { get; set; } + + [Required] + public Guid RecipeId { get; set; } + public virtual RecipeEntity Recipe { get; set; } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Entities/IngredientEntity.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/IngredientEntity.cs new file mode 100644 index 00000000..f2d95a8e --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/IngredientEntity.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; +using CookBook.DAL.Entities.Base.Implementation; +using CookBook.DAL.Entities.Base.Interface; + +namespace CookBook.DAL.Entities +{ + public class IngredientEntity : EntityBase, IEntity + { + [Required] + public string Name { get; set; } + + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Entities/RecipeEntity.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/RecipeEntity.cs new file mode 100644 index 00000000..d0759b42 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/RecipeEntity.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using CookBook.DAL.Entities.Base.Implementation; + +namespace CookBook.DAL.Entities +{ + public class RecipeEntity : EntityBase + { + [Required] + public string Name { get; set; } + public FoodType Type { get; set; } + public string Description { get; set; } + public TimeSpan Duration { get; set; } + public virtual ICollection Ingredients { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Unit.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Unit.cs new file mode 100644 index 00000000..648651d5 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Entities/Unit.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; + +namespace CookBook.DAL.Entities +{ + public enum Unit + { + Kg = 1, + L = 2, + Pound = 3, + Spoon = 4, + LittleSpoon = 5, + Pieces = 6, + G = 7, + Ml = 8, + Piece = 9, + TeaSpoon = 10 + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs new file mode 100644 index 00000000..45daae85 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.Designer.cs @@ -0,0 +1,29 @@ +// +namespace CookBook.DAL.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] + public sealed partial class IngredientAmountEntity : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(IngredientAmountEntity)); + + string IMigrationMetadata.Id + { + get { return "201703060839276_IngredientAmountEntity"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs new file mode 100644 index 00000000..6dd8bf18 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.cs @@ -0,0 +1,39 @@ +namespace CookBook.DAL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class IngredientAmountEntity : DbMigration + { + public override void Up() + { + CreateTable( + "dbo.IngredientAmountEntities", + c => new + { + Id = c.Guid(nullable: false), + Amount = c.Double(nullable: false), + Unit = c.Int(nullable: false), + Ingredient_Id = c.Guid(nullable: false), + RecipeEntity_Id = c.Guid(nullable: false), + }) + .PrimaryKey(t => t.Id) + .ForeignKey("dbo.IngredientEntities", t => t.Ingredient_Id, cascadeDelete: true) + .ForeignKey("dbo.RecipeEntities", t => t.RecipeEntity_Id, cascadeDelete: true) + .Index(t => t.Ingredient_Id) + .Index(t => t.RecipeEntity_Id); + + AlterColumn("dbo.RecipeEntities", "Name", c => c.String(nullable: false)); + } + + public override void Down() + { + DropForeignKey("dbo.IngredientAmountEntities", "RecipeEntity_Id", "dbo.RecipeEntities"); + DropForeignKey("dbo.IngredientAmountEntities", "Ingredient_Id", "dbo.IngredientEntities"); + DropIndex("dbo.IngredientAmountEntities", new[] { "RecipeEntity_Id" }); + DropIndex("dbo.IngredientAmountEntities", new[] { "Ingredient_Id" }); + AlterColumn("dbo.RecipeEntities", "Name", c => c.String()); + DropTable("dbo.IngredientAmountEntities"); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx new file mode 100644 index 00000000..cde3b765 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060839276_IngredientAmountEntity.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs new file mode 100644 index 00000000..5c54e7dc --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.Designer.cs @@ -0,0 +1,29 @@ +// +namespace CookBook.DAL.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] + public sealed partial class AddedPropertiesIngredientEntity : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(AddedPropertiesIngredientEntity)); + + string IMigrationMetadata.Id + { + get { return "201703060851297_AddedPropertiesIngredientEntity"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs new file mode 100644 index 00000000..302ae9da --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.cs @@ -0,0 +1,22 @@ +namespace CookBook.DAL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class AddedPropertiesIngredientEntity : DbMigration + { + public override void Up() + { + AddColumn("dbo.IngredientEntities", "Description", c => c.String()); + AddColumn("dbo.IngredientEntities", "Argb", c => c.Int(nullable: false)); + AlterColumn("dbo.IngredientEntities", "Name", c => c.String(nullable: false)); + } + + public override void Down() + { + AlterColumn("dbo.IngredientEntities", "Name", c => c.String()); + DropColumn("dbo.IngredientEntities", "Argb"); + DropColumn("dbo.IngredientEntities", "Description"); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx new file mode 100644 index 00000000..efe1400e --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703060851297_AddedPropertiesIngredientEntity.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs new file mode 100644 index 00000000..74227743 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.Designer.cs @@ -0,0 +1,29 @@ +// +namespace CookBook.DAL.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] + public sealed partial class Init : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(Init)); + + string IMigrationMetadata.Id + { + get { return "201703061916184_Init"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.cs new file mode 100644 index 00000000..0681f659 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.cs @@ -0,0 +1,62 @@ +namespace CookBook.DAL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class Init : DbMigration + { + public override void Up() + { + CreateTable( + "dbo.IngredientEntities", + c => new + { + Id = c.Guid(nullable: false), + Name = c.String(nullable: false), + Description = c.String(), + Argb = c.Int(nullable: false), + }) + .PrimaryKey(t => t.Id); + + CreateTable( + "dbo.RecipeEntities", + c => new + { + Id = c.Guid(nullable: false), + Name = c.String(nullable: false), + Type = c.Int(nullable: false), + Description = c.String(), + Duration = c.Time(nullable: false, precision: 7), + }) + .PrimaryKey(t => t.Id); + + CreateTable( + "dbo.IngredientAmountEntities", + c => new + { + Id = c.Guid(nullable: false), + Amount = c.Double(nullable: false), + Unit = c.Int(nullable: false), + Ingredient_Id = c.Guid(nullable: false), + RecipeEntity_Id = c.Guid(nullable: false), + }) + .PrimaryKey(t => t.Id) + .ForeignKey("dbo.IngredientEntities", t => t.Ingredient_Id, cascadeDelete: true) + .ForeignKey("dbo.RecipeEntities", t => t.RecipeEntity_Id, cascadeDelete: true) + .Index(t => t.Ingredient_Id) + .Index(t => t.RecipeEntity_Id); + + } + + public override void Down() + { + DropForeignKey("dbo.IngredientAmountEntities", "RecipeEntity_Id", "dbo.RecipeEntities"); + DropForeignKey("dbo.IngredientAmountEntities", "Ingredient_Id", "dbo.IngredientEntities"); + DropIndex("dbo.IngredientAmountEntities", new[] { "RecipeEntity_Id" }); + DropIndex("dbo.IngredientAmountEntities", new[] { "Ingredient_Id" }); + DropTable("dbo.IngredientAmountEntities"); + DropTable("dbo.RecipeEntities"); + DropTable("dbo.IngredientEntities"); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.resx b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.resx new file mode 100644 index 00000000..cef7af14 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703061916184_Init.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.Designer.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.Designer.cs new file mode 100644 index 00000000..0ec51c14 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.Designer.cs @@ -0,0 +1,29 @@ +// +namespace CookBook.DAL.Migrations +{ + using System.CodeDom.Compiler; + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + using System.Resources; + + [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] + public sealed partial class PrepareForExcercise3 : IMigrationMetadata + { + private readonly ResourceManager Resources = new ResourceManager(typeof(PrepareForExcercise3)); + + string IMigrationMetadata.Id + { + get { return "201703080209034_PrepareForExcercise3"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return Resources.GetString("Target"); } + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.cs new file mode 100644 index 00000000..ab178318 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.cs @@ -0,0 +1,26 @@ +namespace CookBook.DAL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class PrepareForExcercise3 : DbMigration + { + public override void Up() + { + RenameColumn(table: "dbo.IngredientAmountEntities", name: "RecipeEntity_Id", newName: "RecipeId"); + RenameColumn(table: "dbo.IngredientAmountEntities", name: "Ingredient_Id", newName: "IngredientId"); + RenameIndex(table: "dbo.IngredientAmountEntities", name: "IX_Ingredient_Id", newName: "IX_IngredientId"); + RenameIndex(table: "dbo.IngredientAmountEntities", name: "IX_RecipeEntity_Id", newName: "IX_RecipeId"); + DropColumn("dbo.IngredientEntities", "Argb"); + } + + public override void Down() + { + AddColumn("dbo.IngredientEntities", "Argb", c => c.Int(nullable: false)); + RenameIndex(table: "dbo.IngredientAmountEntities", name: "IX_RecipeId", newName: "IX_RecipeEntity_Id"); + RenameIndex(table: "dbo.IngredientAmountEntities", name: "IX_IngredientId", newName: "IX_Ingredient_Id"); + RenameColumn(table: "dbo.IngredientAmountEntities", name: "IngredientId", newName: "Ingredient_Id"); + RenameColumn(table: "dbo.IngredientAmountEntities", name: "RecipeId", newName: "RecipeEntity_Id"); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.resx b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.resx new file mode 100644 index 00000000..6e91a6b0 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/201703080209034_PrepareForExcercise3.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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 + + + dbo + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/Configuration.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/Configuration.cs new file mode 100644 index 00000000..a9f71c8d --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/Configuration.cs @@ -0,0 +1,96 @@ +namespace CookBook.DAL.Migrations +{ + using Entities; + using System; + using System.Data.Entity.Migrations; + using System.Drawing; + + internal sealed class Configuration : DbMigrationsConfiguration + { + public Configuration() + { + AutomaticMigrationsEnabled = false; + } + + protected override void Seed(CookBookDbContext context) + { + var darkChocolate = new IngredientEntity + { + Id = new Guid("5abdfee1-c970-4afd-aff8-aa3cfef8b1ac"), + Name = "Tmavá čokoláda", + Description = "Tmavá čokoláda s 80% kakaa.", + }; + + var wholeMilk = new IngredientEntity + { + Id = new Guid("83041385-cb60-401b-bf11-cc5ffb8bc570"), + Name = "Plnotučné mlieko", + Description = "Plnotučné mlieko so 4% tuku.", + }; + + var almondFlour = new IngredientEntity + { + Id = new Guid("cb181669-4e02-449f-bf02-ab6020dfecb4"), + Name = "Mandlová múka", + Description = "Najemno umletá mandlová múka", + }; + + var egg = new IngredientEntity + { + Id = new Guid("012ac89a-94e3-4bc2-94b5-c9b05fc83375"), + Name = "Vajíčko", + Description = "Slepačie vajíčko.", + }; + + context.Ingredients.AddOrUpdate(i => i.Id, wholeMilk, darkChocolate, almondFlour, egg); + + var chocolateCakeId = new Guid("cb8db9b3-799c-4ef2-9d85-ce32a9ffa843"); + context.Recipes.AddOrUpdate( + r => r.Id, + new RecipeEntity + { + Id = chocolateCakeId, + Name = "Čokoládová torta", + Duration = TimeSpan.FromMinutes(30), + Type = FoodType.Dessert, + Ingredients = + { + new IngredientAmountEntity + { + Id = new Guid("1d2e7873-3e35-4d40-877c-a3d0d78de3c0"), + Amount = 0.5, + Unit = Unit.Kg, + RecipeId = chocolateCakeId, + IngredientId = darkChocolate.Id + }, + new IngredientAmountEntity + { + Id = new Guid("2711f535-3566-446c-9ac6-58261efe3fa3"), + Amount = 0.3, + Unit = Unit.L, + RecipeId = chocolateCakeId, + IngredientId = wholeMilk.Id + }, + new IngredientAmountEntity + { + Id = new Guid("c8cdbff9-6692-42ad-93aa-69cb56f95019"), + Amount = 5, + Unit = Unit.Pieces, + RecipeId = chocolateCakeId, + IngredientId = egg.Id + }, + new IngredientAmountEntity + { + Id = new Guid("b417ad46-b94c-487e-8cc1-97ebd7551b13"), + Amount = 7, + Unit = Unit.Spoon, + RecipeId = chocolateCakeId, + IngredientId = almondFlour.Id + } + } + }); + + context.SaveChanges(); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..31f08efb --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CookBook.DAL")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CookBook.DAL")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("707fc4d3-fcb6-4686-84a6-6abf270243ad")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/packages.config b/Labs/IW5-Excercise-05/CookBook.DAL/packages.config new file mode 100644 index 00000000..44091730 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.DAL/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.Tests/App.config b/Labs/IW5-Excercise-05/CookBook.Tests/App.config new file mode 100644 index 00000000..39ffc423 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.Tests/App.config @@ -0,0 +1,16 @@ + + + + +
+ + + + + + + + + + + diff --git a/Labs/IW5-Excercise-05/CookBook.Tests/CookBook.Tests.csproj b/Labs/IW5-Excercise-05/CookBook.Tests/CookBook.Tests.csproj new file mode 100644 index 00000000..179a3cc0 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.Tests/CookBook.Tests.csproj @@ -0,0 +1,100 @@ + + + + + Debug + AnyCPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49} + Library + Properties + CookBook.Tests + CookBook.Tests + v4.6.1 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.1.1.11\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + + + + ..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll + + + ..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll + + + ..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll + + + ..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll + + + + + + + + + + Designer + + + + + {f48d47ed-6003-4b97-8629-5c6bec99e779} + CookBook.BL + + + {9247FC0B-1D73-4343-9BE0-6974EC0CD834} + CookBook.DAL + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.Tests/CookBookDbContextTests.cs b/Labs/IW5-Excercise-05/CookBook.Tests/CookBookDbContextTests.cs new file mode 100644 index 00000000..96da3757 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.Tests/CookBookDbContextTests.cs @@ -0,0 +1,54 @@ +using System; +using System.Linq; +using CookBook.BL; +using CookBook.BL.Repositories; +using CookBook.DAL; +using Xunit; + +namespace CookBook.Tests +{ + public class CookBookDbContextTests + { + + [Fact] + public void DbConnectionTest() + { + using (var cookBookDbContext = new CookBookDbContext()) + { + cookBookDbContext.Recipes.Any(); + } + } + + private RecipeRepository recipeRepositorySUT = new RecipeRepository(); + + [Fact] + public void FindByName_ChocolateCake_NotNull() + { + var recipe = recipeRepositorySUT.FindByName("Čokoládová torta"); + Assert.NotNull(recipe); + } + + [Fact] + public void FindByName_ChocolateCake2_Null() + { + var recipe = recipeRepositorySUT.FindByName("Čokoládová torta 2"); + Assert.Null(recipe); + } + + [Fact] + public void FindByName_ChocolateCake_ContainsEgg() + { + var recipe = recipeRepositorySUT.FindByName("Čokoládová torta"); + var containsEgg = recipe.Ingredients.Any(ingredient => ingredient.Ingredient.Name == "Vajíčko"); + Assert.True(containsEgg); + } + + [Fact] + public void FindByName_Ingredient_NotNull() + { + var recipe = recipeRepositorySUT.FindByName("Čokoládová torta"); + var containsEgg = recipe.Ingredients.Any(ingredient => ingredient.Ingredient.Name == "Vajíčko"); + Assert.True(containsEgg); + } + } +} diff --git a/Labs/IW5-Excercise-05/CookBook.Tests/Properties/AssemblyInfo.cs b/Labs/IW5-Excercise-05/CookBook.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..a45d1758 --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("CookBook.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CookBook.Tests")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("3cf47f1f-6a2b-480f-b95d-403be8079a49")] + +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Labs/IW5-Excercise-05/CookBook.Tests/packages.config b/Labs/IW5-Excercise-05/CookBook.Tests/packages.config new file mode 100644 index 00000000..e944e71c --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.Tests/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.sln b/Labs/IW5-Excercise-05/CookBook.sln new file mode 100644 index 00000000..dd5e218c --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.sln @@ -0,0 +1,45 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.4 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.DAL", "CookBook.DAL\CookBook.DAL.csproj", "{9247FC0B-1D73-4343-9BE0-6974EC0CD834}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.BL", "CookBook.BL\CookBook.BL.csproj", "{F48D47ED-6003-4B97-8629-5C6BEC99E779}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F6262EAF-DFD7-40EF-A155-6A4C85E6943D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.Tests", "CookBook.Tests\CookBook.Tests.csproj", "{3CF47F1F-6A2B-480F-B95D-403BE8079A49}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CookBook.App", "CookBook.App\CookBook.App.csproj", "{9FE5CEF4-1AD0-4B7E-984C-AE908F7B5F3A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9247FC0B-1D73-4343-9BE0-6974EC0CD834}.Release|Any CPU.Build.0 = Release|Any CPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F48D47ED-6003-4B97-8629-5C6BEC99E779}.Release|Any CPU.Build.0 = Release|Any CPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3CF47F1F-6A2B-480F-B95D-403BE8079A49}.Release|Any CPU.Build.0 = Release|Any CPU + {9FE5CEF4-1AD0-4B7E-984C-AE908F7B5F3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9FE5CEF4-1AD0-4B7E-984C-AE908F7B5F3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9FE5CEF4-1AD0-4B7E-984C-AE908F7B5F3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9FE5CEF4-1AD0-4B7E-984C-AE908F7B5F3A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {3CF47F1F-6A2B-480F-B95D-403BE8079A49} = {F6262EAF-DFD7-40EF-A155-6A4C85E6943D} + EndGlobalSection +EndGlobal From 73865f8c808fc7ca0d2cbb4bf35a21e8923c74bc Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Tue, 4 Apr 2017 23:52:12 +0200 Subject: [PATCH 32/41] solution cleanup --- .../CookBook.App/CookBook.App.csproj | 1 - .../CookBook.App/Properties/Annotations.cs | 1048 ----------------- .../ViewModels/RecipeListViewModel.cs | 7 +- .../CookBook.App/ViewModels/ViewModelBase.cs | 1 - .../CookBook.App/Views/RecipeDetailView.xaml | 3 +- .../CookBook.App/Views/RecipeListView.xaml | 3 +- 6 files changed, 8 insertions(+), 1055 deletions(-) delete mode 100644 Labs/IW5-Excercise-05/CookBook.App/Properties/Annotations.cs diff --git a/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj b/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj index 1d7d5f3a..41ff969b 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj +++ b/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj @@ -76,7 +76,6 @@ RecipeListView.xaml - diff --git a/Labs/IW5-Excercise-05/CookBook.App/Properties/Annotations.cs b/Labs/IW5-Excercise-05/CookBook.App/Properties/Annotations.cs deleted file mode 100644 index e40e819e..00000000 --- a/Labs/IW5-Excercise-05/CookBook.App/Properties/Annotations.cs +++ /dev/null @@ -1,1048 +0,0 @@ -/* MIT License - -Copyright (c) 2016 JetBrains http://www.jetbrains.com - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. */ - -using System; - -#pragma warning disable 1591 -// ReSharper disable UnusedMember.Global -// ReSharper disable MemberCanBePrivate.Global -// ReSharper disable UnusedAutoPropertyAccessor.Global -// ReSharper disable IntroduceOptionalParameters.Global -// ReSharper disable MemberCanBeProtected.Global -// ReSharper disable InconsistentNaming - -namespace CookBook.App.Properties -{ - /// - /// Indicates that the value of the marked element could be null sometimes, - /// so the check for null is necessary before its usage. - /// - /// - /// [CanBeNull] object Test() => null; - /// - /// void UseTest() { - /// var p = Test(); - /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException' - /// } - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] - public sealed class CanBeNullAttribute : Attribute { } - - /// - /// Indicates that the value of the marked element could never be null. - /// - /// - /// [NotNull] object Foo() { - /// return null; // Warning: Possible 'null' assignment - /// } - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)] - public sealed class NotNullAttribute : Attribute { } - - /// - /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task - /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property - /// or of the Lazy.Value property can never be null. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field)] - public sealed class ItemNotNullAttribute : Attribute { } - - /// - /// Can be appplied to symbols of types derived from IEnumerable as well as to symbols of Task - /// and Lazy classes to indicate that the value of a collection item, of the Task.Result property - /// or of the Lazy.Value property can be null. - /// - [AttributeUsage( - AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | - AttributeTargets.Delegate | AttributeTargets.Field)] - public sealed class ItemCanBeNullAttribute : Attribute { } - - /// - /// Indicates that the marked method builds string by format pattern and (optional) arguments. - /// Parameter, which contains format string, should be given in constructor. The format string - /// should be in -like form. - /// - /// - /// [StringFormatMethod("message")] - /// void ShowError(string message, params object[] args) { /* do something */ } - /// - /// void Foo() { - /// ShowError("Failed: {0}"); // Warning: Non-existing argument in format string - /// } - /// - [AttributeUsage( - AttributeTargets.Constructor | AttributeTargets.Method | - AttributeTargets.Property | AttributeTargets.Delegate)] - public sealed class StringFormatMethodAttribute : Attribute - { - /// - /// Specifies which parameter of an annotated method should be treated as format-string - /// - public StringFormatMethodAttribute([NotNull] string formatParameterName) - { - FormatParameterName = formatParameterName; - } - - [NotNull] public string FormatParameterName { get; private set; } - } - - /// - /// For a parameter that is expected to be one of the limited set of values. - /// Specify fields of which type should be used as values for this parameter. - /// - [AttributeUsage( - AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field, - AllowMultiple = true)] - public sealed class ValueProviderAttribute : Attribute - { - public ValueProviderAttribute([NotNull] string name) - { - Name = name; - } - - [NotNull] public string Name { get; private set; } - } - - /// - /// Indicates that the function argument should be string literal and match one - /// of the parameters of the caller function. For example, ReSharper annotates - /// the parameter of . - /// - /// - /// void Foo(string param) { - /// if (param == null) - /// throw new ArgumentNullException("par"); // Warning: Cannot resolve symbol - /// } - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class InvokerParameterNameAttribute : Attribute { } - - /// - /// Indicates that the method is contained in a type that implements - /// System.ComponentModel.INotifyPropertyChanged interface and this method - /// is used to notify that some property value changed. - /// - /// - /// The method should be non-static and conform to one of the supported signatures: - /// - /// NotifyChanged(string) - /// NotifyChanged(params string[]) - /// NotifyChanged{T}(Expression{Func{T}}) - /// NotifyChanged{T,U}(Expression{Func{T,U}}) - /// SetProperty{T}(ref T, T, string) - /// - /// - /// - /// public class Foo : INotifyPropertyChanged { - /// public event PropertyChangedEventHandler PropertyChanged; - /// - /// [NotifyPropertyChangedInvocator] - /// protected virtual void NotifyChanged(string propertyName) { ... } - /// - /// string _name; - /// - /// public string Name { - /// get { return _name; } - /// set { _name = value; NotifyChanged("LastName"); /* Warning */ } - /// } - /// } - /// - /// Examples of generated notifications: - /// - /// NotifyChanged("Property") - /// NotifyChanged(() => Property) - /// NotifyChanged((VM x) => x.Property) - /// SetProperty(ref myField, value, "Property") - /// - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class NotifyPropertyChangedInvocatorAttribute : Attribute - { - public NotifyPropertyChangedInvocatorAttribute() { } - public NotifyPropertyChangedInvocatorAttribute([NotNull] string parameterName) - { - ParameterName = parameterName; - } - - [CanBeNull] public string ParameterName { get; private set; } - } - - /// - /// Describes dependency between method input and output. - /// - /// - ///

Function Definition Table syntax:

- /// - /// FDT ::= FDTRow [;FDTRow]* - /// FDTRow ::= Input => Output | Output <= Input - /// Input ::= ParameterName: Value [, Input]* - /// Output ::= [ParameterName: Value]* {halt|stop|void|nothing|Value} - /// Value ::= true | false | null | notnull | canbenull - /// - /// If method has single input parameter, it's name could be omitted.
- /// Using halt (or void/nothing, which is the same) for method output - /// means that the methos doesn't return normally (throws or terminates the process).
- /// Value canbenull is only applicable for output parameters.
- /// You can use multiple [ContractAnnotation] for each FDT row, or use single attribute - /// with rows separated by semicolon. There is no notion of order rows, all rows are checked - /// for applicability and applied per each program state tracked by R# analysis.
- ///
- /// - /// - /// [ContractAnnotation("=> halt")] - /// public void TerminationMethod() - /// - /// - /// [ContractAnnotation("halt <= condition: false")] - /// public void Assert(bool condition, string text) // regular assertion method - /// - /// - /// [ContractAnnotation("s:null => true")] - /// public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty() - /// - /// - /// // A method that returns null if the parameter is null, - /// // and not null if the parameter is not null - /// [ContractAnnotation("null => null; notnull => notnull")] - /// public object Transform(object data) - /// - /// - /// [ContractAnnotation("=> true, result: notnull; => false, result: null")] - /// public bool TryParse(string s, out Person result) - /// - /// - [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public sealed class ContractAnnotationAttribute : Attribute - { - public ContractAnnotationAttribute([NotNull] string contract) - : this(contract, false) { } - - public ContractAnnotationAttribute([NotNull] string contract, bool forceFullStates) - { - Contract = contract; - ForceFullStates = forceFullStates; - } - - [NotNull] public string Contract { get; private set; } - - public bool ForceFullStates { get; private set; } - } - - /// - /// Indicates that marked element should be localized or not. - /// - /// - /// [LocalizationRequiredAttribute(true)] - /// class Foo { - /// string str = "my string"; // Warning: Localizable string - /// } - /// - [AttributeUsage(AttributeTargets.All)] - public sealed class LocalizationRequiredAttribute : Attribute - { - public LocalizationRequiredAttribute() : this(true) { } - - public LocalizationRequiredAttribute(bool required) - { - Required = required; - } - - public bool Required { get; private set; } - } - - /// - /// Indicates that the value of the marked type (or its derivatives) - /// cannot be compared using '==' or '!=' operators and Equals() - /// should be used instead. However, using '==' or '!=' for comparison - /// with null is always permitted. - /// - /// - /// [CannotApplyEqualityOperator] - /// class NoEquality { } - /// - /// class UsesNoEquality { - /// void Test() { - /// var ca1 = new NoEquality(); - /// var ca2 = new NoEquality(); - /// if (ca1 != null) { // OK - /// bool condition = ca1 == ca2; // Warning - /// } - /// } - /// } - /// - [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct)] - public sealed class CannotApplyEqualityOperatorAttribute : Attribute { } - - /// - /// When applied to a target attribute, specifies a requirement for any type marked - /// with the target attribute to implement or inherit specific type or types. - /// - /// - /// [BaseTypeRequired(typeof(IComponent)] // Specify requirement - /// class ComponentAttribute : Attribute { } - /// - /// [Component] // ComponentAttribute requires implementing IComponent interface - /// class MyComponent : IComponent { } - /// - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - [BaseTypeRequired(typeof(Attribute))] - public sealed class BaseTypeRequiredAttribute : Attribute - { - public BaseTypeRequiredAttribute([NotNull] Type baseType) - { - BaseType = baseType; - } - - [NotNull] public Type BaseType { get; private set; } - } - - /// - /// Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library), - /// so this symbol will not be marked as unused (as well as by other usage inspections). - /// - [AttributeUsage(AttributeTargets.All)] - public sealed class UsedImplicitlyAttribute : Attribute - { - public UsedImplicitlyAttribute() - : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } - - public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags) - : this(useKindFlags, ImplicitUseTargetFlags.Default) { } - - public UsedImplicitlyAttribute(ImplicitUseTargetFlags targetFlags) - : this(ImplicitUseKindFlags.Default, targetFlags) { } - - public UsedImplicitlyAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) - { - UseKindFlags = useKindFlags; - TargetFlags = targetFlags; - } - - public ImplicitUseKindFlags UseKindFlags { get; private set; } - - public ImplicitUseTargetFlags TargetFlags { get; private set; } - } - - /// - /// Should be used on attributes and causes ReSharper to not mark symbols marked with such attributes - /// as unused (as well as by other usage inspections) - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.GenericParameter)] - public sealed class MeansImplicitUseAttribute : Attribute - { - public MeansImplicitUseAttribute() - : this(ImplicitUseKindFlags.Default, ImplicitUseTargetFlags.Default) { } - - public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags) - : this(useKindFlags, ImplicitUseTargetFlags.Default) { } - - public MeansImplicitUseAttribute(ImplicitUseTargetFlags targetFlags) - : this(ImplicitUseKindFlags.Default, targetFlags) { } - - public MeansImplicitUseAttribute(ImplicitUseKindFlags useKindFlags, ImplicitUseTargetFlags targetFlags) - { - UseKindFlags = useKindFlags; - TargetFlags = targetFlags; - } - - [UsedImplicitly] public ImplicitUseKindFlags UseKindFlags { get; private set; } - - [UsedImplicitly] public ImplicitUseTargetFlags TargetFlags { get; private set; } - } - - [Flags] - public enum ImplicitUseKindFlags - { - Default = Access | Assign | InstantiatedWithFixedConstructorSignature, - /// Only entity marked with attribute considered used. - Access = 1, - /// Indicates implicit assignment to a member. - Assign = 2, - /// - /// Indicates implicit instantiation of a type with fixed constructor signature. - /// That means any unused constructor parameters won't be reported as such. - /// - InstantiatedWithFixedConstructorSignature = 4, - /// Indicates implicit instantiation of a type. - InstantiatedNoFixedConstructorSignature = 8, - } - - /// - /// Specify what is considered used implicitly when marked - /// with or . - /// - [Flags] - public enum ImplicitUseTargetFlags - { - Default = Itself, - Itself = 1, - /// Members of entity marked with attribute are considered used. - Members = 2, - /// Entity marked with attribute and all its members considered used. - WithMembers = Itself | Members - } - - /// - /// This attribute is intended to mark publicly available API - /// which should not be removed and so is treated as used. - /// - [MeansImplicitUse(ImplicitUseTargetFlags.WithMembers)] - public sealed class PublicAPIAttribute : Attribute - { - public PublicAPIAttribute() { } - - public PublicAPIAttribute([NotNull] string comment) - { - Comment = comment; - } - - [CanBeNull] public string Comment { get; private set; } - } - - /// - /// Tells code analysis engine if the parameter is completely handled when the invoked method is on stack. - /// If the parameter is a delegate, indicates that delegate is executed while the method is executed. - /// If the parameter is an enumerable, indicates that it is enumerated while the method is executed. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class InstantHandleAttribute : Attribute { } - - /// - /// Indicates that a method does not make any observable state changes. - /// The same as System.Diagnostics.Contracts.PureAttribute. - /// - /// - /// [Pure] int Multiply(int x, int y) => x * y; - /// - /// void M() { - /// Multiply(123, 42); // Waring: Return value of pure method is not used - /// } - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class PureAttribute : Attribute { } - - /// - /// Indicates that the return value of method invocation must be used. - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class MustUseReturnValueAttribute : Attribute - { - public MustUseReturnValueAttribute() { } - - public MustUseReturnValueAttribute([NotNull] string justification) - { - Justification = justification; - } - - [CanBeNull] public string Justification { get; private set; } - } - - /// - /// Indicates the type member or parameter of some type, that should be used instead of all other ways - /// to get the value that type. This annotation is useful when you have some "context" value evaluated - /// and stored somewhere, meaning that all other ways to get this value must be consolidated with existing one. - /// - /// - /// class Foo { - /// [ProvidesContext] IBarService _barService = ...; - /// - /// void ProcessNode(INode node) { - /// DoSomething(node, node.GetGlobalServices().Bar); - /// // ^ Warning: use value of '_barService' field - /// } - /// } - /// - [AttributeUsage( - AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.Method | - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.GenericParameter)] - public sealed class ProvidesContextAttribute : Attribute { } - - /// - /// Indicates that a parameter is a path to a file or a folder within a web project. - /// Path can be relative or absolute, starting from web root (~). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class PathReferenceAttribute : Attribute - { - public PathReferenceAttribute() { } - - public PathReferenceAttribute([NotNull, PathReference] string basePath) - { - BasePath = basePath; - } - - [CanBeNull] public string BasePath { get; private set; } - } - - /// - /// An extension method marked with this attribute is processed by ReSharper code completion - /// as a 'Source Template'. When extension method is completed over some expression, it's source code - /// is automatically expanded like a template at call site. - /// - /// - /// Template method body can contain valid source code and/or special comments starting with '$'. - /// Text inside these comments is added as source code when the template is applied. Template parameters - /// can be used either as additional method parameters or as identifiers wrapped in two '$' signs. - /// Use the attribute to specify macros for parameters. - /// - /// - /// In this example, the 'forEach' method is a source template available over all values - /// of enumerable types, producing ordinary C# 'foreach' statement and placing caret inside block: - /// - /// [SourceTemplate] - /// public static void forEach<T>(this IEnumerable<T> xs) { - /// foreach (var x in xs) { - /// //$ $END$ - /// } - /// } - /// - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class SourceTemplateAttribute : Attribute { } - - /// - /// Allows specifying a macro for a parameter of a source template. - /// - /// - /// You can apply the attribute on the whole method or on any of its additional parameters. The macro expression - /// is defined in the property. When applied on a method, the target - /// template parameter is defined in the property. To apply the macro silently - /// for the parameter, set the property value = -1. - /// - /// - /// Applying the attribute on a source template method: - /// - /// [SourceTemplate, Macro(Target = "item", Expression = "suggestVariableName()")] - /// public static void forEach<T>(this IEnumerable<T> collection) { - /// foreach (var item in collection) { - /// //$ $END$ - /// } - /// } - /// - /// Applying the attribute on a template method parameter: - /// - /// [SourceTemplate] - /// public static void something(this Entity x, [Macro(Expression = "guid()", Editable = -1)] string newguid) { - /// /*$ var $x$Id = "$newguid$" + x.ToString(); - /// x.DoSomething($x$Id); */ - /// } - /// - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method, AllowMultiple = true)] - public sealed class MacroAttribute : Attribute - { - /// - /// Allows specifying a macro that will be executed for a source template - /// parameter when the template is expanded. - /// - [CanBeNull] public string Expression { get; set; } - - /// - /// Allows specifying which occurrence of the target parameter becomes editable when the template is deployed. - /// - /// - /// If the target parameter is used several times in the template, only one occurrence becomes editable; - /// other occurrences are changed synchronously. To specify the zero-based index of the editable occurrence, - /// use values >= 0. To make the parameter non-editable when the template is expanded, use -1. - /// > - public int Editable { get; set; } - - /// - /// Identifies the target parameter of a source template if the - /// is applied on a template method. - /// - [CanBeNull] public string Target { get; set; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class AspMvcAreaMasterLocationFormatAttribute : Attribute - { - public AspMvcAreaMasterLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] public string Format { get; private set; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class AspMvcAreaPartialViewLocationFormatAttribute : Attribute - { - public AspMvcAreaPartialViewLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] public string Format { get; private set; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class AspMvcAreaViewLocationFormatAttribute : Attribute - { - public AspMvcAreaViewLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] public string Format { get; private set; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class AspMvcMasterLocationFormatAttribute : Attribute - { - public AspMvcMasterLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] public string Format { get; private set; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class AspMvcPartialViewLocationFormatAttribute : Attribute - { - public AspMvcPartialViewLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] public string Format { get; private set; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class AspMvcViewLocationFormatAttribute : Attribute - { - public AspMvcViewLocationFormatAttribute([NotNull] string format) - { - Format = format; - } - - [NotNull] public string Format { get; private set; } - } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter - /// is an MVC action. If applied to a method, the MVC action name is calculated - /// implicitly from the context. Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcActionAttribute : Attribute - { - public AspMvcActionAttribute() { } - - public AspMvcActionAttribute([NotNull] string anonymousProperty) - { - AnonymousProperty = anonymousProperty; - } - - [CanBeNull] public string AnonymousProperty { get; private set; } - } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC area. - /// Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcAreaAttribute : Attribute - { - public AspMvcAreaAttribute() { } - - public AspMvcAreaAttribute([NotNull] string anonymousProperty) - { - AnonymousProperty = anonymousProperty; - } - - [CanBeNull] public string AnonymousProperty { get; private set; } - } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is - /// an MVC controller. If applied to a method, the MVC controller name is calculated - /// implicitly from the context. Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.ChildActionExtensions.RenderAction(HtmlHelper, String, String). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcControllerAttribute : Attribute - { - public AspMvcControllerAttribute() { } - - public AspMvcControllerAttribute([NotNull] string anonymousProperty) - { - AnonymousProperty = anonymousProperty; - } - - [CanBeNull] public string AnonymousProperty { get; private set; } - } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC Master. Use this attribute - /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcMasterAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC model type. Use this attribute - /// for custom wrappers similar to System.Web.Mvc.Controller.View(String, Object). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcModelTypeAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter is an MVC - /// partial view. If applied to a method, the MVC partial view name is calculated implicitly - /// from the context. Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.RenderPartialExtensions.RenderPartial(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcPartialViewAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. Allows disabling inspections for MVC views within a class or a method. - /// - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] - public sealed class AspMvcSuppressViewErrorAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC display template. - /// Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.DisplayExtensions.DisplayForModel(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcDisplayTemplateAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC editor template. - /// Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Html.EditorExtensions.EditorForModel(HtmlHelper, String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcEditorTemplateAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. Indicates that a parameter is an MVC template. - /// Use this attribute for custom wrappers similar to - /// System.ComponentModel.DataAnnotations.UIHintAttribute(System.String). - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcTemplateAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter - /// is an MVC view component. If applied to a method, the MVC view name is calculated implicitly - /// from the context. Use this attribute for custom wrappers similar to - /// System.Web.Mvc.Controller.View(Object). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcViewAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter - /// is an MVC view component name. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AspMvcViewComponentAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. If applied to a parameter, indicates that the parameter - /// is an MVC view component view. If applied to a method, the MVC view component view name is default. - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class AspMvcViewComponentViewAttribute : Attribute { } - - /// - /// ASP.NET MVC attribute. When applied to a parameter of an attribute, - /// indicates that this parameter is an MVC action name. - /// - /// - /// [ActionName("Foo")] - /// public ActionResult Login(string returnUrl) { - /// ViewBag.ReturnUrl = Url.Action("Foo"); // OK - /// return RedirectToAction("Bar"); // Error: Cannot resolve action - /// } - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)] - public sealed class AspMvcActionSelectorAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Field)] - public sealed class HtmlElementAttributesAttribute : Attribute - { - public HtmlElementAttributesAttribute() { } - - public HtmlElementAttributesAttribute([NotNull] string name) - { - Name = name; - } - - [CanBeNull] public string Name { get; private set; } - } - - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property)] - public sealed class HtmlAttributeValueAttribute : Attribute - { - public HtmlAttributeValueAttribute([NotNull] string name) - { - Name = name; - } - - [NotNull] public string Name { get; private set; } - } - - /// - /// Razor attribute. Indicates that a parameter or a method is a Razor section. - /// Use this attribute for custom wrappers similar to - /// System.Web.WebPages.WebPageBase.RenderSection(String). - /// - [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Method)] - public sealed class RazorSectionAttribute : Attribute { } - - /// - /// Indicates how method, constructor invocation or property access - /// over collection type affects content of the collection. - /// - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property)] - public sealed class CollectionAccessAttribute : Attribute - { - public CollectionAccessAttribute(CollectionAccessType collectionAccessType) - { - CollectionAccessType = collectionAccessType; - } - - public CollectionAccessType CollectionAccessType { get; private set; } - } - - [Flags] - public enum CollectionAccessType - { - /// Method does not use or modify content of the collection. - None = 0, - /// Method only reads content of the collection but does not modify it. - Read = 1, - /// Method can change content of the collection but does not add new elements. - ModifyExistingContent = 2, - /// Method can add new elements to the collection. - UpdatedContent = ModifyExistingContent | 4 - } - - /// - /// Indicates that the marked method is assertion method, i.e. it halts control flow if - /// one of the conditions is satisfied. To set the condition, mark one of the parameters with - /// attribute. - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class AssertionMethodAttribute : Attribute { } - - /// - /// Indicates the condition parameter of the assertion method. The method itself should be - /// marked by attribute. The mandatory argument of - /// the attribute is the assertion type. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class AssertionConditionAttribute : Attribute - { - public AssertionConditionAttribute(AssertionConditionType conditionType) - { - ConditionType = conditionType; - } - - public AssertionConditionType ConditionType { get; private set; } - } - - /// - /// Specifies assertion type. If the assertion method argument satisfies the condition, - /// then the execution continues. Otherwise, execution is assumed to be halted. - /// - public enum AssertionConditionType - { - /// Marked parameter should be evaluated to true. - IS_TRUE = 0, - /// Marked parameter should be evaluated to false. - IS_FALSE = 1, - /// Marked parameter should be evaluated to null value. - IS_NULL = 2, - /// Marked parameter should be evaluated to not null value. - IS_NOT_NULL = 3, - } - - /// - /// Indicates that the marked method unconditionally terminates control flow execution. - /// For example, it could unconditionally throw exception. - /// - [Obsolete("Use [ContractAnnotation('=> halt')] instead")] - [AttributeUsage(AttributeTargets.Method)] - public sealed class TerminatesProgramAttribute : Attribute { } - - /// - /// Indicates that method is pure LINQ method, with postponed enumeration (like Enumerable.Select, - /// .Where). This annotation allows inference of [InstantHandle] annotation for parameters - /// of delegate type by analyzing LINQ method chains. - /// - [AttributeUsage(AttributeTargets.Method)] - public sealed class LinqTunnelAttribute : Attribute { } - - /// - /// Indicates that IEnumerable, passed as parameter, is not enumerated. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class NoEnumerationAttribute : Attribute { } - - /// - /// Indicates that parameter is regular expression pattern. - /// - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class RegexPatternAttribute : Attribute { } - - /// - /// Prevents the Member Reordering feature from tossing members of the marked class. - /// - /// - /// The attribute must be mentioned in your member reordering patterns - /// - [AttributeUsage( - AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Struct | AttributeTargets.Enum)] - public sealed class NoReorderAttribute : Attribute { } - - /// - /// XAML attribute. Indicates the type that has ItemsSource property and should be treated - /// as ItemsControl-derived type, to enable inner items DataContext type resolve. - /// - [AttributeUsage(AttributeTargets.Class)] - public sealed class XamlItemsControlAttribute : Attribute { } - - /// - /// XAML attribute. Indicates the property of some BindingBase-derived type, that - /// is used to bind some item of ItemsControl-derived type. This annotation will - /// enable the DataContext type resolve for XAML bindings for such properties. - /// - /// - /// Property should have the tree ancestor of the ItemsControl type or - /// marked with the attribute. - /// - [AttributeUsage(AttributeTargets.Property)] - public sealed class XamlItemBindingOfItemsControlAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - public sealed class AspChildControlTypeAttribute : Attribute - { - public AspChildControlTypeAttribute([NotNull] string tagName, [NotNull] Type controlType) - { - TagName = tagName; - ControlType = controlType; - } - - [NotNull] public string TagName { get; private set; } - - [NotNull] public Type ControlType { get; private set; } - } - - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] - public sealed class AspDataFieldAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] - public sealed class AspDataFieldsAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Property)] - public sealed class AspMethodPropertyAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] - public sealed class AspRequiredAttributeAttribute : Attribute - { - public AspRequiredAttributeAttribute([NotNull] string attribute) - { - Attribute = attribute; - } - - [NotNull] public string Attribute { get; private set; } - } - - [AttributeUsage(AttributeTargets.Property)] - public sealed class AspTypePropertyAttribute : Attribute - { - public bool CreateConstructorReferences { get; private set; } - - public AspTypePropertyAttribute(bool createConstructorReferences) - { - CreateConstructorReferences = createConstructorReferences; - } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class RazorImportNamespaceAttribute : Attribute - { - public RazorImportNamespaceAttribute([NotNull] string name) - { - Name = name; - } - - [NotNull] public string Name { get; private set; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class RazorInjectionAttribute : Attribute - { - public RazorInjectionAttribute([NotNull] string type, [NotNull] string fieldName) - { - Type = type; - FieldName = fieldName; - } - - [NotNull] public string Type { get; private set; } - - [NotNull] public string FieldName { get; private set; } - } - - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class RazorDirectiveAttribute : Attribute - { - public RazorDirectiveAttribute([NotNull] string directive) - { - Directive = directive; - } - - [NotNull] public string Directive { get; private set; } - } - - [AttributeUsage(AttributeTargets.Method)] - public sealed class RazorHelperCommonAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Property)] - public sealed class RazorLayoutAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Method)] - public sealed class RazorWriteLiteralMethodAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Method)] - public sealed class RazorWriteMethodAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class RazorWriteMethodParameterAttribute : Attribute { } -} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs index b9435d00..5be32fce 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs @@ -3,6 +3,7 @@ using CookBook.App.Commands; using CookBook.BL; using CookBook.BL.Messages; +using CookBook.BL.Models; using CookBook.BL.Repositories; namespace CookBook.App.ViewModels @@ -33,14 +34,14 @@ public void OnLoad() public void RecipeSelectionChanged(object parameter) { - var recipeId = (Guid?)parameter; + var recipe = parameter as RecipeListModel; - if (!recipeId.HasValue) + if (recipe == null) { return; } - _messenger.Send(new SelectedRecipeMessage() { Id = recipeId.Value}); + _messenger.Send(new SelectedRecipeMessage() { Id = recipe.Id }); } } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs index 02ffc2fe..3753dafd 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs @@ -8,7 +8,6 @@ public abstract class ViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; - [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml index 0d69940f..366833a6 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml @@ -3,7 +3,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" + xmlns:viewModels="clr-namespace:CookBook.App.ViewModels" + mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:RecipeDetailViewModel, IsDesignTimeCreatable=False}" d:DesignWidth="400" d:DesignHeight="600"> diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml index f20af3f7..affca740 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml @@ -5,7 +5,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" - mc:Ignorable="d" + xmlns:viewModels="clr-namespace:CookBook.App.ViewModels" + mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:RecipeListViewModel, IsDesignTimeCreatable=False}" d:DesignWidth="200" d:DesignHeight="600"> From 1e05d805d5ce7e7928453d1cbc90500dbada0306 Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Wed, 5 Apr 2017 09:43:35 +0200 Subject: [PATCH 33/41] final touch lab05 --- Labs/IW5-Excercise-05/CookBook.App/App.xaml | 2 +- .../CookBook.App/ViewModels/MainViewModel.cs | 4 ++++ .../CookBook.App/Views/MainWindow.xaml | 12 +++++++----- .../CookBook.App/Views/RecipeDetailView.xaml | 1 + .../CookBook.App/Views/RecipeListView.xaml | 1 + 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Labs/IW5-Excercise-05/CookBook.App/App.xaml b/Labs/IW5-Excercise-05/CookBook.App/App.xaml index 193b9fec..f905704f 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/App.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/App.xaml @@ -6,6 +6,6 @@ StartupUri="Views/MainWindow.xaml"> - + diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs index 019cc956..0a68fb76 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs @@ -11,6 +11,10 @@ public class MainViewModel : ViewModelBase public ICommand CreateRecipeCommand { get; } + public string Name { get; set; } + public string Description { get; set; } + + public MainViewModel(IMessenger messenger) { _messenger = messenger; diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml index 8f63a86a..78164f1b 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml @@ -3,15 +3,17 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:viewModels1="clr-namespace:CookBook.App.ViewModels" + xmlns:viewModels="clr-namespace:CookBook.App.ViewModels" xmlns:views="clr-namespace:CookBook.App.Views" mc:Ignorable="d" Title="MainWindow" - DataContext="{Binding MainViewModel, Source={StaticResource ViewModelLocator}}" - d:DataContext="{d:DesignInstance viewModels1:MainViewModel, IsDesignTimeCreatable=False}"> + d:DataContext="{d:DesignInstance viewModels:MainViewModel, IsDesignTimeCreatable=False}"> - + + + + diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml index 366833a6..0260c7a9 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewModels="clr-namespace:CookBook.App.ViewModels" mc:Ignorable="d" + DataContext="{Binding RecipeDetailViewModel, Source={StaticResource ViewModelLocator}}" d:DataContext="{d:DesignInstance viewModels:RecipeDetailViewModel, IsDesignTimeCreatable=False}" d:DesignWidth="400" d:DesignHeight="600"> diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml index affca740..ddaef71c 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml @@ -7,6 +7,7 @@ xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" xmlns:viewModels="clr-namespace:CookBook.App.ViewModels" mc:Ignorable="d" + DataContext="{Binding RecipeListViewModel, Source={StaticResource ViewModelLocator}}" d:DataContext="{d:DesignInstance viewModels:RecipeListViewModel, IsDesignTimeCreatable=False}" d:DesignWidth="200" d:DesignHeight="600"> From f52974fd2dacd0ba5ed0e9d58135618386886984 Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Wed, 5 Apr 2017 15:25:59 +0200 Subject: [PATCH 34/41] bug fix --- Labs/IW5-Excercise-05/CookBook.App/App.config | 2 +- .../CookBook.App/ViewModels/MainViewModel.cs | 11 ++++++++--- .../CookBook.App/Views/MainWindow.xaml | 1 - .../CookBook.App/Views/MainWindow.xaml.cs | 3 +++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Labs/IW5-Excercise-05/CookBook.App/App.config b/Labs/IW5-Excercise-05/CookBook.App/App.config index dbc55e69..217b89a0 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/App.config +++ b/Labs/IW5-Excercise-05/CookBook.App/App.config @@ -18,6 +18,6 @@ - + \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs index 0a68fb76..99309d44 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs @@ -1,4 +1,6 @@ -using System.Windows.Input; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Input; using CookBook.App.Commands; using CookBook.BL; using CookBook.BL.Messages; @@ -12,14 +14,17 @@ public class MainViewModel : ViewModelBase public ICommand CreateRecipeCommand { get; } public string Name { get; set; } - public string Description { get; set; } - public MainViewModel(IMessenger messenger) { _messenger = messenger; CreateRecipeCommand = new RelayCommand(() => _messenger.Send(new NewRecipeMessage())); + + } + + public void OnLoad() + { } } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml index 78164f1b..1ca5376d 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml @@ -11,7 +11,6 @@ - - + @@ -26,9 +26,9 @@ - - + + @@ -39,7 +39,8 @@ - + + + + + + + + + diff --git a/Labs/IW5-Excercise-05/CookBook.BL/Repositories/RecipeRepository.cs b/Labs/IW5-Excercise-05/CookBook.BL/Repositories/RecipeRepository.cs index d38cde3e..56160e5f 100644 --- a/Labs/IW5-Excercise-05/CookBook.BL/Repositories/RecipeRepository.cs +++ b/Labs/IW5-Excercise-05/CookBook.BL/Repositories/RecipeRepository.cs @@ -38,6 +38,7 @@ public RecipeDetailModel GetById(Guid id) using (var cookBookDbContext = new CookBookDbContext()) { var recipeEntity = cookBookDbContext.Recipes + .Include(r => r.Ingredients.Select(i => i.Ingredient)) .FirstOrDefault(r => r.Id == id); return mapper.MapEntityToDetailModel(recipeEntity); diff --git a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/Configuration.cs b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/Configuration.cs index a9f71c8d..ad13a4ba 100644 --- a/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/Configuration.cs +++ b/Labs/IW5-Excercise-05/CookBook.DAL/Migrations/Configuration.cs @@ -53,6 +53,11 @@ protected override void Seed(CookBookDbContext context) Name = "Čokoládová torta", Duration = TimeSpan.FromMinutes(30), Type = FoodType.Dessert, + Description = "Hovězí maso dobře nasolíme a obalíme v zázvoru, pak v hladké mouce a necháme asi hodinu odležet. " + + "V hrnci si osmažíme na pokrájeném špeku s trochou oleje cibuli dosklovata. Pak vložíme hovězí maso, " + + "které ze všech stran osmažíme dozlatova. Ke konci smažení přidáme orestovat buď plátky čerstvých " + + "hub (200 g) nebo přidáme hrst předem namočených sušených hub a vše zalijeme vývarem nebo vodou " + + "s kostkou bujonu. Dusíme pod poklicí, než bude maso měkké, dle potřeby podléváme a občas maso otočíme.", Ingredients = { new IngredientAmountEntity From 2906ffb866c5e8c4f0b7ce6dfcb13f5ed5c4cefe Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Thu, 6 Apr 2017 09:54:09 +0200 Subject: [PATCH 37/41] hotfix --- .../CookBook.App/ViewModels/RecipeDetailViewModel.cs | 1 - Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs index 431f926d..d5bd8516 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs @@ -35,7 +35,6 @@ public RecipeDetailViewModel(RecipeRepository recipeRepository, IMessenger messe _messenger = messenger; _messenger.Register(SelectedRecipe); - Detail = _recipeRepository.GetById(new Guid("cb8db9b3-799c-4ef2-9d85-ce32a9ffa843")); } private void SelectedRecipe(SelectedRecipeMessage message) diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml index 797f977f..95e6556b 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml @@ -17,7 +17,7 @@ - + From 2cd243f7b6e25ac89525f8f6a85be1d5dbed61f5 Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Thu, 6 Apr 2017 11:50:16 +0200 Subject: [PATCH 38/41] small cleanup --- .../CookBook.App/ViewModels/RecipeListViewModel.cs | 1 - .../CookBook.App/Views/RecipeListView.xaml | 7 ------- 2 files changed, 8 deletions(-) diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs index 5be32fce..dbe413e7 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs @@ -24,7 +24,6 @@ public RecipeListViewModel(RecipeRepository recipeRepository, IMessenger messeng _messenger = messenger; SelectRecipeCommand = new RelayCommand(RecipeSelectionChanged); - // ToDo Add Action on message } public void OnLoad() diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml index ddaef71c..13ea69e0 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml @@ -12,13 +12,6 @@ d:DesignWidth="200" d:DesignHeight="600"> - - - - From 107a7eda874d4ed0ac71af82617317c410ffb89b Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Sun, 9 Apr 2017 12:30:49 +0200 Subject: [PATCH 39/41] Added excercise05-after --- Labs/IW5-Excercise-05/CookBook.App/App.xaml | 3 +- .../Commands/SaveRecipeCommand.cs | 22 ++++++++++-- .../Converters/NullToVisibilityConverter.cs | 20 +++++++++++ .../CookBook.App/CookBook.App.csproj | 1 + .../CookBook.App/ViewModels/MainViewModel.cs | 11 ++---- .../ViewModels/RecipeDetailViewModel.cs | 30 ++++++++++++++++ .../ViewModels/RecipeListViewModel.cs | 35 ++++++++++++++---- .../CookBook.App/ViewModels/ViewModelBase.cs | 1 - .../CookBook.App/Views/MainWindow.xaml | 18 ++++++---- .../CookBook.App/Views/RecipeDetailView.xaml | 23 ++++++------ .../CookBook.App/Views/RecipeListView.xaml | 36 ++++++++++++++++++- 11 files changed, 164 insertions(+), 36 deletions(-) create mode 100644 Labs/IW5-Excercise-05/CookBook.App/Converters/NullToVisibilityConverter.cs diff --git a/Labs/IW5-Excercise-05/CookBook.App/App.xaml b/Labs/IW5-Excercise-05/CookBook.App/App.xaml index f905704f..49993fab 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/App.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/App.xaml @@ -6,6 +6,7 @@ StartupUri="Views/MainWindow.xaml"> - + + diff --git a/Labs/IW5-Excercise-05/CookBook.App/Commands/SaveRecipeCommand.cs b/Labs/IW5-Excercise-05/CookBook.App/Commands/SaveRecipeCommand.cs index ef3f8dc1..76979252 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Commands/SaveRecipeCommand.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/Commands/SaveRecipeCommand.cs @@ -2,6 +2,7 @@ using System.Windows.Input; using CookBook.App.ViewModels; using CookBook.BL; +using CookBook.BL.Messages; using CookBook.BL.Models; using CookBook.BL.Repositories; @@ -26,7 +27,8 @@ public bool CanExecute(object parameter) if (detail != null) { - return detail.Duration.TotalMinutes > 0; + return detail.Duration.TotalMinutes > 0 + && !string.IsNullOrWhiteSpace(detail.Name); } return false; @@ -34,7 +36,23 @@ public bool CanExecute(object parameter) public void Execute(object parameter) { - // ToDo + var detail = parameter as RecipeDetailModel; + + if (detail == null) + { + return; + } + + if (detail.Id != Guid.Empty) + { + _recipeRepository.Update(detail); + } + else + { + _viewModel.Detail = _recipeRepository.Insert(detail); + } + + _messenger.Send(new UpdatedRecipeMessage(detail)); } public event EventHandler CanExecuteChanged diff --git a/Labs/IW5-Excercise-05/CookBook.App/Converters/NullToVisibilityConverter.cs b/Labs/IW5-Excercise-05/CookBook.App/Converters/NullToVisibilityConverter.cs new file mode 100644 index 00000000..4057c4cf --- /dev/null +++ b/Labs/IW5-Excercise-05/CookBook.App/Converters/NullToVisibilityConverter.cs @@ -0,0 +1,20 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace CookBook.App.Converters +{ + public class NullToVisibilityConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value == null ? Visibility.Collapsed : Visibility.Visible; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj b/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj index 41ff969b..45e56372 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj +++ b/Labs/IW5-Excercise-05/CookBook.App/CookBook.App.csproj @@ -69,6 +69,7 @@ + RecipeDetailView.xaml diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs index cdf4bc63..019cc956 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/MainViewModel.cs @@ -1,7 +1,4 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using System.Windows.Input; +using System.Windows.Input; using CookBook.App.Commands; using CookBook.BL; using CookBook.BL.Messages; @@ -12,15 +9,13 @@ public class MainViewModel : ViewModelBase { private readonly IMessenger _messenger; - public string Name { get; set; } = "Nenacteno"; + public ICommand CreateRecipeCommand { get; } public MainViewModel(IMessenger messenger) { _messenger = messenger; - } - public void OnLoad() - { + CreateRecipeCommand = new RelayCommand(() => _messenger.Send(new NewRecipeMessage())); } } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs index d5bd8516..b14a7d35 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeDetailViewModel.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Windows.Input; +using CookBook.App.Commands; using CookBook.BL; using CookBook.BL.Messages; using CookBook.BL.Models; @@ -29,17 +31,45 @@ public RecipeDetailModel Detail public IList FoodTypes => Enum.GetValues(typeof(FoodType)).Cast().ToList(); + public ICommand DeleteCommand { get; } + + public ICommand SaveCommand { get; } + public RecipeDetailViewModel(RecipeRepository recipeRepository, IMessenger messenger) { _recipeRepository = recipeRepository; _messenger = messenger; + DeleteCommand = new RelayCommand(Delete); + SaveCommand = new SaveRecipeCommand(recipeRepository, this, messenger); _messenger.Register(SelectedRecipe); + _messenger.Register(NewRecipeMessageReceived); + } + + private void NewRecipeMessageReceived(NewRecipeMessage message) + { + Detail = new RecipeDetailModel(); } private void SelectedRecipe(SelectedRecipeMessage message) { Detail = _recipeRepository.GetById(message.Id); } + + public void Delete() + { + if (IsSavedRecipe()) + { + _recipeRepository.Remove(Detail.Id); + _messenger.Send(new DeletedRecipeMessage(Detail.Id)); + } + + Detail = null; + } + + private bool IsSavedRecipe() + { + return Detail.Id != Guid.Empty; + } } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs index dbe413e7..85cb0a3a 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/RecipeListViewModel.cs @@ -1,4 +1,5 @@ -using System; +using System.Collections.ObjectModel; +using System.Linq; using System.Windows.Input; using CookBook.App.Commands; using CookBook.BL; @@ -10,11 +11,20 @@ namespace CookBook.App.ViewModels { public class RecipeListViewModel : ViewModelBase { + private ObservableCollection _recipes; private readonly RecipeRepository _recipeRepository; private readonly IMessenger _messenger; - // ToDo Add Recipes - + public ObservableCollection Recipes + { + get { return _recipes; } + set + { + if (Equals(value, _recipes)) return; + _recipes = value; + OnPropertyChanged(); + } + } public ICommand SelectRecipeCommand { get; } @@ -23,24 +33,35 @@ public RecipeListViewModel(RecipeRepository recipeRepository, IMessenger messeng _recipeRepository = recipeRepository; _messenger = messenger; + _messenger.Register(DeletedRecipeMessageReceived); + _messenger.Register((p) => OnLoad()); SelectRecipeCommand = new RelayCommand(RecipeSelectionChanged); } public void OnLoad() { - // ToDo Load Data + Recipes = new ObservableCollection(_recipeRepository.GetAll()); } public void RecipeSelectionChanged(object parameter) { - var recipe = parameter as RecipeListModel; + var recipeId = (RecipeListModel)parameter; - if (recipe == null) + if (recipeId == null) { return; } - _messenger.Send(new SelectedRecipeMessage() { Id = recipe.Id }); + _messenger.Send(new SelectedRecipeMessage() { Id = recipeId.Id }); + } + + private void DeletedRecipeMessageReceived(DeletedRecipeMessage message) + { + var deletedRecipe = Recipes.FirstOrDefault(r => r.Id == message.RecipeId); + if (deletedRecipe != null) + { + Recipes.Remove(deletedRecipe); + } } } } \ No newline at end of file diff --git a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs index 3753dafd..9a035521 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/ViewModels/ViewModelBase.cs @@ -1,6 +1,5 @@ using System.ComponentModel; using System.Runtime.CompilerServices; -using CookBook.App.Properties; namespace CookBook.App.ViewModels { diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml index 95e6556b..bb59219d 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml @@ -7,24 +7,30 @@ xmlns:views="clr-namespace:CookBook.App.Views" mc:Ignorable="d" Title="MainWindow" + DataContext="{Binding Source={StaticResource ViewModelLocator}, Path=MainViewModel}" d:DataContext="{d:DesignInstance viewModels:MainViewModel, IsDesignTimeCreatable=False}"> - - - + diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml index 6cde65f3..e10791f1 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeDetailView.xaml @@ -8,18 +8,18 @@ DataContext="{Binding RecipeDetailViewModel, Source={StaticResource ViewModelLocator}}" d:DataContext="{d:DesignInstance viewModels:RecipeDetailViewModel, IsDesignTimeCreatable=False}" d:DesignWidth="400" - d:DesignHeight="600"> + d:DesignHeight="600" + x:Name="Root"> - - + - - + + @@ -36,19 +36,22 @@ - + - + + Text="{Binding Duration, Converter={StaticResource TimeSpanToMinutesConverter}, UpdateSourceTrigger=PropertyChanged}"> + - + diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml index 13ea69e0..433c59fa 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/RecipeListView.xaml @@ -13,8 +13,42 @@ d:DesignHeight="600"> + + + + + + + + + + - + + + + + + + + + + + + + + + + + Délka přípravy: minut + + + + From a2b50f461824f0a44d4c0cab7315d8d0c2b2867d Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Wed, 12 Apr 2017 20:53:43 +0200 Subject: [PATCH 40/41] Removed unnecessary creation of viewmodel --- Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs index d79ce332..c2799f59 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml.cs @@ -12,7 +12,6 @@ public partial class MainWindow : Window public MainWindow() { InitializeComponent(); - DataContext = new MainViewModel(new Messenger()); } } } From 9e5e05e938eb94edce7495b62d5bc948f7e67f1c Mon Sep 17 00:00:00 2001 From: Adam Jez Date: Wed, 12 Apr 2017 21:13:14 +0200 Subject: [PATCH 41/41] Bug fix of recipedetailview over the entire window --- Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml index bb59219d..5cba881d 100644 --- a/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml +++ b/Labs/IW5-Excercise-05/CookBook.App/Views/MainWindow.xaml @@ -18,7 +18,7 @@ - + @@ -26,7 +26,7 @@ - +