├── .gitattributes ├── .gitignore ├── README.md ├── csproj_msbuild_core1 └── start-end │ └── Library │ ├── Library.sln │ └── src │ └── Library.API │ ├── Entities │ ├── Author.cs │ ├── Book.cs │ ├── LibraryContext.cs │ └── LibraryContextExtensions.cs │ ├── Helpers │ └── DateTimeOffsetExtensions.cs │ ├── Library.API.csproj │ ├── Migrations │ ├── InitialMigration.Designer.cs │ ├── InitialMigration.cs │ └── LibraryContextModelSnapshot.cs │ ├── Program.cs │ ├── Project_Readme.html │ ├── Properties │ └── launchSettings.json │ ├── Services │ ├── ILibraryRepository.cs │ └── LibraryRepository.cs │ ├── Startup.cs │ ├── appsettings.json │ └── web.config ├── csproj_msbuild_core2 └── start-end │ └── Library │ ├── Library.sln │ └── src │ └── Library.API │ ├── Entities │ ├── Author.cs │ ├── Book.cs │ ├── LibraryContext.cs │ └── LibraryContextExtensions.cs │ ├── Helpers │ └── DateTimeOffsetExtensions.cs │ ├── Library.API.csproj │ ├── Migrations │ ├── InitialMigration.Designer.cs │ ├── InitialMigration.cs │ └── LibraryContextModelSnapshot.cs │ ├── Program.cs │ ├── Project_Readme.html │ ├── Properties │ └── launchSettings.json │ ├── Services │ ├── ILibraryRepository.cs │ └── LibraryRepository.cs │ ├── Startup.cs │ ├── appsettings.json │ └── web.config └── xproj_project_json_core1 └── start-end └── Library ├── Library.sln ├── global.json └── src └── Library.API ├── Entities ├── Author.cs ├── Book.cs ├── LibraryContext.cs └── LibraryContextExtensions.cs ├── Helpers └── DateTimeOffsetExtensions.cs ├── Library.API.xproj ├── Migrations ├── InitialMigration.Designer.cs ├── InitialMigration.cs └── LibraryContextModelSnapshot.cs ├── Program.cs ├── Project_Readme.html ├── Properties └── launchSettings.json ├── Services ├── ILibraryRepository.cs └── LibraryRepository.cs ├── Startup.cs ├── appsettings.json ├── project.json └── web.config /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Microsoft Azure ApplicationInsights config file 170 | ApplicationInsights.config 171 | 172 | # Windows Store app package directory 173 | AppPackages/ 174 | BundleArtifacts/ 175 | 176 | # Visual Studio cache files 177 | # files ending in .cache can be ignored 178 | *.[Cc]ache 179 | # but keep track of directories ending in .cache 180 | !*.[Cc]ache/ 181 | 182 | # Others 183 | ClientBin/ 184 | [Ss]tyle[Cc]op.* 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # RIA/Silverlight projects 195 | Generated_Code/ 196 | 197 | # Backup & report files from converting an old project file 198 | # to a newer Visual Studio version. Backup files are not needed, 199 | # because we have git ;-) 200 | _UpgradeReport_Files/ 201 | Backup*/ 202 | UpgradeLog*.XML 203 | UpgradeLog*.htm 204 | 205 | # SQL Server files 206 | *.mdf 207 | *.ldf 208 | 209 | # Business Intelligence projects 210 | *.rdl.data 211 | *.bim.layout 212 | *.bim_*.settings 213 | 214 | # Microsoft Fakes 215 | FakesAssemblies/ 216 | 217 | # GhostDoc plugin setting file 218 | *.GhostDoc.xml 219 | 220 | # Node.js Tools for Visual Studio 221 | .ntvs_analysis.dat 222 | 223 | # Visual Studio 6 build log 224 | *.plg 225 | 226 | # Visual Studio 6 workspace options file 227 | *.opt 228 | 229 | # Visual Studio LightSwitch build output 230 | **/*.HTMLClient/GeneratedArtifacts 231 | **/*.DesktopClient/GeneratedArtifacts 232 | **/*.DesktopClient/ModelManifest.xml 233 | **/*.Server/GeneratedArtifacts 234 | **/*.Server/ModelManifest.xml 235 | _Pvt_Extensions 236 | 237 | # LightSwitch generated files 238 | GeneratedArtifacts/ 239 | ModelManifest.xml 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | 244 | # FAKE - F# Make 245 | .fake/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Building a RESTful API with ASP.NET Core 2 | Starter files for my Building a RESTful API with ASP.NET Core course at Pluralsight: https://app.pluralsight.com/library/courses/asp-dot-net-core-restful-api-building 3 | 4 | NOTE: this repository has been archived - the new one can be found here: https://github.com/KevinDockx/BuildingRESTfulAPIAspNetCore3 5 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/Library.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.3 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FB41072F-53FC-4AF6-8838-89CF1FFCAE5B}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{52859A54-50D0-4BBF-935D-FD2EC134E2DC}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library.API", "src\Library.API\Library.API.csproj", "{25AAC737-21A7-4BEE-A3BC-8539AFDB931B}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(NestedProjects) = preSolution 27 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B} = {FB41072F-53FC-4AF6-8838-89CF1FFCAE5B} 28 | EndGlobalSection 29 | GlobalSection(ExtensibilityGlobals) = postSolution 30 | SolutionGuid = {8B29F935-E7DD-43CB-BECA-4CA62E47AA9F} 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Entities/Author.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace Library.API.Entities 6 | { 7 | public class Author 8 | { 9 | [Key] 10 | public Guid Id { get; set; } 11 | 12 | [Required] 13 | [MaxLength(50)] 14 | public string FirstName { get; set; } 15 | 16 | [Required] 17 | [MaxLength(50)] 18 | public string LastName { get; set; } 19 | 20 | [Required] 21 | public DateTimeOffset DateOfBirth { get; set; } 22 | 23 | [Required] 24 | [MaxLength(50)] 25 | public string Genre { get; set; } 26 | 27 | public ICollection Books { get; set; } 28 | = new List(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Entities/Book.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | 5 | namespace Library.API.Entities 6 | { 7 | public class Book 8 | { 9 | [Key] 10 | public Guid Id { get; set; } 11 | 12 | [Required] 13 | [MaxLength(100)] 14 | public string Title { get; set; } 15 | 16 | [MaxLength(500)] 17 | public string Description { get; set; } 18 | 19 | [ForeignKey("AuthorId")] 20 | public Author Author { get; set; } 21 | 22 | public Guid AuthorId { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Entities/LibraryContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace Library.API.Entities 4 | { 5 | public class LibraryContext : DbContext 6 | { 7 | public LibraryContext(DbContextOptions options) 8 | : base(options) 9 | { 10 | Database.Migrate(); 11 | } 12 | 13 | public DbSet Authors { get; set; } 14 | public DbSet Books { get; set; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Entities/LibraryContextExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Library.API.Entities 5 | { 6 | public static class LibraryContextExtensions 7 | { 8 | public static void EnsureSeedDataForContext(this LibraryContext context) 9 | { 10 | // first, clear the database. This ensures we can always start 11 | // fresh with each demo. Not advised for production environments, obviously :-) 12 | 13 | context.Authors.RemoveRange(context.Authors); 14 | context.SaveChanges(); 15 | 16 | // init seed data 17 | var authors = new List() 18 | { 19 | new Author() 20 | { 21 | Id = new Guid("25320c5e-f58a-4b1f-b63a-8ee07a840bdf"), 22 | FirstName = "Stephen", 23 | LastName = "King", 24 | Genre = "Horror", 25 | DateOfBirth = new DateTimeOffset(new DateTime(1947, 9, 21)), 26 | Books = new List() 27 | { 28 | new Book() 29 | { 30 | Id = new Guid("c7ba6add-09c4-45f8-8dd0-eaca221e5d93"), 31 | Title = "The Shining", 32 | Description = "The Shining is a horror novel by American author Stephen King. Published in 1977, it is King's third published novel and first hardback bestseller: the success of the book firmly established King as a preeminent author in the horror genre. " 33 | }, 34 | new Book() 35 | { 36 | Id = new Guid("a3749477-f823-4124-aa4a-fc9ad5e79cd6"), 37 | Title = "Misery", 38 | Description = "Misery is a 1987 psychological horror novel by Stephen King. This novel was nominated for the World Fantasy Award for Best Novel in 1988, and was later made into a Hollywood film and an off-Broadway play of the same name." 39 | }, 40 | new Book() 41 | { 42 | Id = new Guid("70a1f9b9-0a37-4c1a-99b1-c7709fc64167"), 43 | Title = "It", 44 | Description = "It is a 1986 horror novel by American author Stephen King. The story follows the exploits of seven children as they are terrorized by the eponymous being, which exploits the fears and phobias of its victims in order to disguise itself while hunting its prey. 'It' primarily appears in the form of a clown in order to attract its preferred prey of young children." 45 | }, 46 | new Book() 47 | { 48 | Id = new Guid("60188a2b-2784-4fc4-8df8-8919ff838b0b"), 49 | Title = "The Stand", 50 | Description = "The Stand is a post-apocalyptic horror/fantasy novel by American author Stephen King. It expands upon the scenario of his earlier short story 'Night Surf' and outlines the total breakdown of society after the accidental release of a strain of influenza that had been modified for biological warfare causes an apocalyptic pandemic which kills off the majority of the world's human population." 51 | } 52 | } 53 | }, 54 | new Author() 55 | { 56 | Id = new Guid("76053df4-6687-4353-8937-b45556748abe"), 57 | FirstName = "George", 58 | LastName = "RR Martin", 59 | Genre = "Fantasy", 60 | DateOfBirth = new DateTimeOffset(new DateTime(1948, 9, 20)), 61 | Books = new List() 62 | { 63 | new Book() 64 | { 65 | Id = new Guid("447eb762-95e9-4c31-95e1-b20053fbe215"), 66 | Title = "A Game of Thrones", 67 | Description = "A Game of Thrones is the first novel in A Song of Ice and Fire, a series of fantasy novels by American author George R. R. Martin. It was first published on August 1, 1996." 68 | }, 69 | new Book() 70 | { 71 | Id = new Guid("bc4c35c3-3857-4250-9449-155fcf5109ec"), 72 | Title = "The Winds of Winter", 73 | Description = "Forthcoming 6th novel in A Song of Ice and Fire." 74 | }, 75 | new Book() 76 | { 77 | Id = new Guid("09af5a52-9421-44e8-a2bb-a6b9ccbc8239"), 78 | Title = "A Dance with Dragons", 79 | Description = "A Dance with Dragons is the fifth of seven planned novels in the epic fantasy series A Song of Ice and Fire by American author George R. R. Martin." 80 | } 81 | } 82 | }, 83 | new Author() 84 | { 85 | Id = new Guid("412c3012-d891-4f5e-9613-ff7aa63e6bb3"), 86 | FirstName = "Neil", 87 | LastName = "Gaiman", 88 | Genre = "Fantasy", 89 | DateOfBirth = new DateTimeOffset(new DateTime(1960, 11, 10)), 90 | Books = new List() 91 | { 92 | new Book() 93 | { 94 | Id = new Guid("9edf91ee-ab77-4521-a402-5f188bc0c577"), 95 | Title = "American Gods", 96 | Description = "American Gods is a Hugo and Nebula Award-winning novel by English author Neil Gaiman. The novel is a blend of Americana, fantasy, and various strands of ancient and modern mythology, all centering on the mysterious and taciturn Shadow." 97 | } 98 | } 99 | }, 100 | new Author() 101 | { 102 | Id = new Guid("578359b7-1967-41d6-8b87-64ab7605587e"), 103 | FirstName = "Tom", 104 | LastName = "Lanoye", 105 | Genre = "Various", 106 | DateOfBirth = new DateTimeOffset(new DateTime(1958, 8, 27)), 107 | Books = new List() 108 | { 109 | new Book() 110 | { 111 | Id = new Guid("01457142-358f-495f-aafa-fb23de3d67e9"), 112 | Title = "Speechless", 113 | Description = "Good-natured and often humorous, Speechless is at times a 'song of curses', as Lanoye describes the conflicts with his beloved diva of a mother and her brave struggle with decline and death." 114 | } 115 | } 116 | }, 117 | new Author() 118 | { 119 | Id = new Guid("f74d6899-9ed2-4137-9876-66b070553f8f"), 120 | FirstName = "Douglas", 121 | LastName = "Adams", 122 | Genre = "Science fiction", 123 | DateOfBirth = new DateTimeOffset(new DateTime(1952, 3, 11)), 124 | Books = new List() 125 | { 126 | new Book() 127 | { 128 | Id = new Guid("e57b605f-8b3c-4089-b672-6ce9e6d6c23f"), 129 | Title = "The Hitchhiker's Guide to the Galaxy", 130 | Description = "The Hitchhiker's Guide to the Galaxy is the first of five books in the Hitchhiker's Guide to the Galaxy comedy science fiction 'trilogy' by Douglas Adams." 131 | } 132 | } 133 | }, 134 | new Author() 135 | { 136 | Id = new Guid("a1da1d8e-1988-4634-b538-a01709477b77"), 137 | FirstName = "Jens", 138 | LastName = "Lapidus", 139 | Genre = "Thriller", 140 | DateOfBirth = new DateTimeOffset(new DateTime(1974, 5, 24)), 141 | Books = new List() 142 | { 143 | new Book() 144 | { 145 | Id = new Guid("1325360c-8253-473a-a20f-55c269c20407"), 146 | Title = "Easy Money", 147 | Description = "Easy Money or Snabba cash is a novel from 2006 by Jens Lapidus. It has been a success in term of sales, and the paperback was the fourth best seller of Swedish novels in 2007." 148 | } 149 | } 150 | } 151 | }; 152 | 153 | context.Authors.AddRange(authors); 154 | context.SaveChanges(); 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Helpers/DateTimeOffsetExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Library.API.Helpers 7 | { 8 | public static class DateTimeOffsetExtensions 9 | { 10 | public static int GetCurrentAge(this DateTimeOffset dateTimeOffset) 11 | { 12 | var currentDate = DateTime.UtcNow; 13 | int age = currentDate.Year - dateTimeOffset.Year; 14 | 15 | if (currentDate < dateTimeOffset.AddYears(age)) 16 | { 17 | age--; 18 | } 19 | 20 | return age; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Library.API.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.0 5 | true 6 | Library.API 7 | Exe 8 | Library.API 9 | 1.0.4 10 | $(PackageTargetFallback);dotnet5.6;portable-net45+win8 11 | 12 | 13 | 14 | 15 | PreserveNewest 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Migrations/InitialMigration.Designer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Library.API.Entities; 7 | 8 | namespace Library.API.Migrations 9 | { 10 | [DbContext(typeof(LibraryContext))] 11 | [Migration("20161007150914_InitialMigration")] 12 | partial class InitialMigration 13 | { 14 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 15 | { 16 | modelBuilder 17 | .HasAnnotation("ProductVersion", "1.0.1") 18 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 19 | 20 | modelBuilder.Entity("Library.API.Entities.Author", b => 21 | { 22 | b.Property("Id") 23 | .ValueGeneratedOnAdd(); 24 | 25 | b.Property("DateOfBirth"); 26 | 27 | b.Property("FirstName") 28 | .IsRequired() 29 | .HasAnnotation("MaxLength", 50); 30 | 31 | b.Property("Genre") 32 | .IsRequired() 33 | .HasAnnotation("MaxLength", 50); 34 | 35 | b.Property("LastName") 36 | .IsRequired() 37 | .HasAnnotation("MaxLength", 50); 38 | 39 | b.HasKey("Id"); 40 | 41 | b.ToTable("Authors"); 42 | }); 43 | 44 | modelBuilder.Entity("Library.API.Entities.Book", b => 45 | { 46 | b.Property("Id") 47 | .ValueGeneratedOnAdd(); 48 | 49 | b.Property("AuthorId"); 50 | 51 | b.Property("Description") 52 | .HasAnnotation("MaxLength", 500); 53 | 54 | b.Property("Title") 55 | .IsRequired() 56 | .HasAnnotation("MaxLength", 100); 57 | 58 | b.HasKey("Id"); 59 | 60 | b.HasIndex("AuthorId"); 61 | 62 | b.ToTable("Books"); 63 | }); 64 | 65 | modelBuilder.Entity("Library.API.Entities.Book", b => 66 | { 67 | b.HasOne("Library.API.Entities.Author", "Author") 68 | .WithMany("Books") 69 | .HasForeignKey("AuthorId") 70 | .OnDelete(DeleteBehavior.Cascade); 71 | }); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Migrations/InitialMigration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | using System; 3 | 4 | namespace Library.API.Migrations 5 | { 6 | public partial class InitialMigration : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "Authors", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false), 15 | DateOfBirth = table.Column(nullable: false), 16 | FirstName = table.Column(maxLength: 50, nullable: false), 17 | Genre = table.Column(maxLength: 50, nullable: false), 18 | LastName = table.Column(maxLength: 50, nullable: false) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_Authors", x => x.Id); 23 | }); 24 | 25 | migrationBuilder.CreateTable( 26 | name: "Books", 27 | columns: table => new 28 | { 29 | Id = table.Column(nullable: false), 30 | AuthorId = table.Column(nullable: false), 31 | Description = table.Column(maxLength: 500, nullable: true), 32 | Title = table.Column(maxLength: 100, nullable: false) 33 | }, 34 | constraints: table => 35 | { 36 | table.PrimaryKey("PK_Books", x => x.Id); 37 | table.ForeignKey( 38 | name: "FK_Books_Authors_AuthorId", 39 | column: x => x.AuthorId, 40 | principalTable: "Authors", 41 | principalColumn: "Id", 42 | onDelete: ReferentialAction.Cascade); 43 | }); 44 | 45 | migrationBuilder.CreateIndex( 46 | name: "IX_Books_AuthorId", 47 | table: "Books", 48 | column: "AuthorId"); 49 | } 50 | 51 | protected override void Down(MigrationBuilder migrationBuilder) 52 | { 53 | migrationBuilder.DropTable( 54 | name: "Books"); 55 | 56 | migrationBuilder.DropTable( 57 | name: "Authors"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Migrations/LibraryContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using System; 6 | 7 | namespace Library.API.Migrations 8 | { 9 | [DbContext(typeof(LibraryContext))] 10 | partial class LibraryContextModelSnapshot : ModelSnapshot 11 | { 12 | protected override void BuildModel(ModelBuilder modelBuilder) 13 | { 14 | modelBuilder 15 | .HasAnnotation("ProductVersion", "1.0.1") 16 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 17 | 18 | modelBuilder.Entity("Library.API.Entities.Author", b => 19 | { 20 | b.Property("Id") 21 | .ValueGeneratedOnAdd(); 22 | 23 | b.Property("DateOfBirth"); 24 | 25 | b.Property("FirstName") 26 | .IsRequired() 27 | .HasAnnotation("MaxLength", 50); 28 | 29 | b.Property("Genre") 30 | .IsRequired() 31 | .HasAnnotation("MaxLength", 50); 32 | 33 | b.Property("LastName") 34 | .IsRequired() 35 | .HasAnnotation("MaxLength", 50); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Authors"); 40 | }); 41 | 42 | modelBuilder.Entity("Library.API.Entities.Book", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("AuthorId"); 48 | 49 | b.Property("Description") 50 | .HasAnnotation("MaxLength", 500); 51 | 52 | b.Property("Title") 53 | .IsRequired() 54 | .HasAnnotation("MaxLength", 100); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.HasIndex("AuthorId"); 59 | 60 | b.ToTable("Books"); 61 | }); 62 | 63 | modelBuilder.Entity("Library.API.Entities.Book", b => 64 | { 65 | b.HasOne("Library.API.Entities.Author", "Author") 66 | .WithMany("Books") 67 | .HasForeignKey("AuthorId") 68 | .OnDelete(DeleteBehavior.Cascade); 69 | }); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Hosting; 7 | 8 | namespace Library.API 9 | { 10 | public class Program 11 | { 12 | public static void Main(string[] args) 13 | { 14 | var host = new WebHostBuilder() 15 | .UseKestrel() 16 | .UseContentRoot(Directory.GetCurrentDirectory()) 17 | .UseIISIntegration() 18 | .UseStartup() 19 | .Build(); 20 | 21 | host.Run(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Project_Readme.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Welcome to ASP.NET Core 6 | 127 | 128 | 129 | 130 | 138 | 139 |
140 |
141 |

This application consists of:

142 |
    143 |
  • Sample pages using ASP.NET Core MVC
  • 144 |
  • Bower for managing client-side libraries
  • 145 |
  • Theming using Bootstrap
  • 146 |
147 |
148 | 160 | 172 |
173 |

Run & Deploy

174 | 179 |
180 | 181 | 184 |
185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:6058/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "Library.API": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "launchUrl": "http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Services/ILibraryRepository.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Library.API.Services 6 | { 7 | public interface ILibraryRepository 8 | { 9 | IEnumerable GetAuthors(); 10 | Author GetAuthor(Guid authorId); 11 | IEnumerable GetAuthors(IEnumerable authorIds); 12 | void AddAuthor(Author author); 13 | void DeleteAuthor(Author author); 14 | void UpdateAuthor(Author author); 15 | bool AuthorExists(Guid authorId); 16 | IEnumerable GetBooksForAuthor(Guid authorId); 17 | Book GetBookForAuthor(Guid authorId, Guid bookId); 18 | void AddBookForAuthor(Guid authorId, Book book); 19 | void UpdateBookForAuthor(Book book); 20 | void DeleteBook(Book book); 21 | bool Save(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Services/LibraryRepository.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Library.API.Services 7 | { 8 | public class LibraryRepository : ILibraryRepository 9 | { 10 | private LibraryContext _context; 11 | 12 | public LibraryRepository(LibraryContext context) 13 | { 14 | _context = context; 15 | } 16 | 17 | public void AddAuthor(Author author) 18 | { 19 | author.Id = Guid.NewGuid(); 20 | _context.Authors.Add(author); 21 | 22 | // the repository fills the id (instead of using identity columns) 23 | if (author.Books.Any()) 24 | { 25 | foreach (var book in author.Books) 26 | { 27 | book.Id = Guid.NewGuid(); 28 | } 29 | } 30 | } 31 | 32 | public void AddBookForAuthor(Guid authorId, Book book) 33 | { 34 | var author = GetAuthor(authorId); 35 | if (author != null) 36 | { 37 | // if there isn't an id filled out (ie: we're not upserting), 38 | // we should generate one 39 | if (book.Id == Guid.Empty) 40 | { 41 | book.Id = Guid.NewGuid(); 42 | } 43 | author.Books.Add(book); 44 | } 45 | } 46 | 47 | public bool AuthorExists(Guid authorId) 48 | { 49 | return _context.Authors.Any(a => a.Id == authorId); 50 | } 51 | 52 | public void DeleteAuthor(Author author) 53 | { 54 | _context.Authors.Remove(author); 55 | } 56 | 57 | public void DeleteBook(Book book) 58 | { 59 | _context.Books.Remove(book); 60 | } 61 | 62 | public Author GetAuthor(Guid authorId) 63 | { 64 | return _context.Authors.FirstOrDefault(a => a.Id == authorId); 65 | } 66 | 67 | public IEnumerable GetAuthors() 68 | { 69 | return _context.Authors.OrderBy(a => a.FirstName).ThenBy(a => a.LastName); 70 | } 71 | 72 | public IEnumerable GetAuthors(IEnumerable authorIds) 73 | { 74 | return _context.Authors.Where(a => authorIds.Contains(a.Id)) 75 | .OrderBy(a => a.FirstName) 76 | .OrderBy(a => a.LastName) 77 | .ToList(); 78 | } 79 | 80 | public void UpdateAuthor(Author author) 81 | { 82 | // no code in this implementation 83 | } 84 | 85 | public Book GetBookForAuthor(Guid authorId, Guid bookId) 86 | { 87 | return _context.Books 88 | .Where(b => b.AuthorId == authorId && b.Id == bookId).FirstOrDefault(); 89 | } 90 | 91 | public IEnumerable GetBooksForAuthor(Guid authorId) 92 | { 93 | return _context.Books 94 | .Where(b => b.AuthorId == authorId).OrderBy(b => b.Title).ToList(); 95 | } 96 | 97 | public void UpdateBookForAuthor(Book book) 98 | { 99 | // no code in this implementation 100 | } 101 | 102 | public bool Save() 103 | { 104 | return (_context.SaveChanges() >= 0); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Configuration; 11 | using Library.API.Services; 12 | using Library.API.Entities; 13 | using Microsoft.EntityFrameworkCore; 14 | 15 | namespace Library.API 16 | { 17 | public class Startup 18 | { 19 | public static IConfigurationRoot Configuration; 20 | 21 | public Startup(IHostingEnvironment env) 22 | { 23 | var builder = new ConfigurationBuilder() 24 | .SetBasePath(env.ContentRootPath) 25 | .AddJsonFile("appSettings.json", optional: false, reloadOnChange: true) 26 | .AddJsonFile($"appSettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) 27 | .AddEnvironmentVariables(); 28 | 29 | Configuration = builder.Build(); 30 | } 31 | 32 | // This method gets called by the runtime. Use this method to add services to the container. 33 | // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 34 | public void ConfigureServices(IServiceCollection services) 35 | { 36 | services.AddMvc(); 37 | 38 | // register the DbContext on the container, getting the connection string from 39 | // appSettings (note: use this during development; in a production environment, 40 | // it's better to store the connection string in an environment variable) 41 | var connectionString = Configuration["connectionStrings:libraryDBConnectionString"]; 42 | services.AddDbContext(o => o.UseSqlServer(connectionString)); 43 | 44 | // register the repository 45 | services.AddScoped(); 46 | } 47 | 48 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 49 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, 50 | ILoggerFactory loggerFactory, LibraryContext libraryContext) 51 | { 52 | loggerFactory.AddConsole(); 53 | 54 | if (env.IsDevelopment()) 55 | { 56 | app.UseDeveloperExceptionPage(); 57 | } 58 | else 59 | { 60 | app.UseExceptionHandler(); 61 | } 62 | 63 | libraryContext.EnsureSeedDataForContext(); 64 | 65 | app.UseMvc(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "connectionStrings": { 3 | "libraryDBConnectionString": "Server=(localdb)\\mssqllocaldb;Database=LibraryDB;Trusted_Connection=True;" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /csproj_msbuild_core1/start-end/Library/src/Library.API/web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/Library.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.3 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FB41072F-53FC-4AF6-8838-89CF1FFCAE5B}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{52859A54-50D0-4BBF-935D-FD2EC134E2DC}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library.API", "src\Library.API\Library.API.csproj", "{25AAC737-21A7-4BEE-A3BC-8539AFDB931B}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(NestedProjects) = preSolution 27 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B} = {FB41072F-53FC-4AF6-8838-89CF1FFCAE5B} 28 | EndGlobalSection 29 | GlobalSection(ExtensibilityGlobals) = postSolution 30 | SolutionGuid = {8B29F935-E7DD-43CB-BECA-4CA62E47AA9F} 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Entities/Author.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace Library.API.Entities 6 | { 7 | public class Author 8 | { 9 | [Key] 10 | public Guid Id { get; set; } 11 | 12 | [Required] 13 | [MaxLength(50)] 14 | public string FirstName { get; set; } 15 | 16 | [Required] 17 | [MaxLength(50)] 18 | public string LastName { get; set; } 19 | 20 | [Required] 21 | public DateTimeOffset DateOfBirth { get; set; } 22 | 23 | [Required] 24 | [MaxLength(50)] 25 | public string Genre { get; set; } 26 | 27 | public ICollection Books { get; set; } 28 | = new List(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Entities/Book.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | 5 | namespace Library.API.Entities 6 | { 7 | public class Book 8 | { 9 | [Key] 10 | public Guid Id { get; set; } 11 | 12 | [Required] 13 | [MaxLength(100)] 14 | public string Title { get; set; } 15 | 16 | [MaxLength(500)] 17 | public string Description { get; set; } 18 | 19 | [ForeignKey("AuthorId")] 20 | public Author Author { get; set; } 21 | 22 | public Guid AuthorId { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Entities/LibraryContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace Library.API.Entities 4 | { 5 | public class LibraryContext : DbContext 6 | { 7 | public LibraryContext(DbContextOptions options) 8 | : base(options) 9 | { 10 | Database.Migrate(); 11 | } 12 | 13 | public DbSet Authors { get; set; } 14 | public DbSet Books { get; set; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Entities/LibraryContextExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Library.API.Entities 5 | { 6 | public static class LibraryContextExtensions 7 | { 8 | public static void EnsureSeedDataForContext(this LibraryContext context) 9 | { 10 | // first, clear the database. This ensures we can always start 11 | // fresh with each demo. Not advised for production environments, obviously :-) 12 | 13 | context.Authors.RemoveRange(context.Authors); 14 | context.SaveChanges(); 15 | 16 | // init seed data 17 | var authors = new List() 18 | { 19 | new Author() 20 | { 21 | Id = new Guid("25320c5e-f58a-4b1f-b63a-8ee07a840bdf"), 22 | FirstName = "Stephen", 23 | LastName = "King", 24 | Genre = "Horror", 25 | DateOfBirth = new DateTimeOffset(new DateTime(1947, 9, 21)), 26 | Books = new List() 27 | { 28 | new Book() 29 | { 30 | Id = new Guid("c7ba6add-09c4-45f8-8dd0-eaca221e5d93"), 31 | Title = "The Shining", 32 | Description = "The Shining is a horror novel by American author Stephen King. Published in 1977, it is King's third published novel and first hardback bestseller: the success of the book firmly established King as a preeminent author in the horror genre. " 33 | }, 34 | new Book() 35 | { 36 | Id = new Guid("a3749477-f823-4124-aa4a-fc9ad5e79cd6"), 37 | Title = "Misery", 38 | Description = "Misery is a 1987 psychological horror novel by Stephen King. This novel was nominated for the World Fantasy Award for Best Novel in 1988, and was later made into a Hollywood film and an off-Broadway play of the same name." 39 | }, 40 | new Book() 41 | { 42 | Id = new Guid("70a1f9b9-0a37-4c1a-99b1-c7709fc64167"), 43 | Title = "It", 44 | Description = "It is a 1986 horror novel by American author Stephen King. The story follows the exploits of seven children as they are terrorized by the eponymous being, which exploits the fears and phobias of its victims in order to disguise itself while hunting its prey. 'It' primarily appears in the form of a clown in order to attract its preferred prey of young children." 45 | }, 46 | new Book() 47 | { 48 | Id = new Guid("60188a2b-2784-4fc4-8df8-8919ff838b0b"), 49 | Title = "The Stand", 50 | Description = "The Stand is a post-apocalyptic horror/fantasy novel by American author Stephen King. It expands upon the scenario of his earlier short story 'Night Surf' and outlines the total breakdown of society after the accidental release of a strain of influenza that had been modified for biological warfare causes an apocalyptic pandemic which kills off the majority of the world's human population." 51 | } 52 | } 53 | }, 54 | new Author() 55 | { 56 | Id = new Guid("76053df4-6687-4353-8937-b45556748abe"), 57 | FirstName = "George", 58 | LastName = "RR Martin", 59 | Genre = "Fantasy", 60 | DateOfBirth = new DateTimeOffset(new DateTime(1948, 9, 20)), 61 | Books = new List() 62 | { 63 | new Book() 64 | { 65 | Id = new Guid("447eb762-95e9-4c31-95e1-b20053fbe215"), 66 | Title = "A Game of Thrones", 67 | Description = "A Game of Thrones is the first novel in A Song of Ice and Fire, a series of fantasy novels by American author George R. R. Martin. It was first published on August 1, 1996." 68 | }, 69 | new Book() 70 | { 71 | Id = new Guid("bc4c35c3-3857-4250-9449-155fcf5109ec"), 72 | Title = "The Winds of Winter", 73 | Description = "Forthcoming 6th novel in A Song of Ice and Fire." 74 | }, 75 | new Book() 76 | { 77 | Id = new Guid("09af5a52-9421-44e8-a2bb-a6b9ccbc8239"), 78 | Title = "A Dance with Dragons", 79 | Description = "A Dance with Dragons is the fifth of seven planned novels in the epic fantasy series A Song of Ice and Fire by American author George R. R. Martin." 80 | } 81 | } 82 | }, 83 | new Author() 84 | { 85 | Id = new Guid("412c3012-d891-4f5e-9613-ff7aa63e6bb3"), 86 | FirstName = "Neil", 87 | LastName = "Gaiman", 88 | Genre = "Fantasy", 89 | DateOfBirth = new DateTimeOffset(new DateTime(1960, 11, 10)), 90 | Books = new List() 91 | { 92 | new Book() 93 | { 94 | Id = new Guid("9edf91ee-ab77-4521-a402-5f188bc0c577"), 95 | Title = "American Gods", 96 | Description = "American Gods is a Hugo and Nebula Award-winning novel by English author Neil Gaiman. The novel is a blend of Americana, fantasy, and various strands of ancient and modern mythology, all centering on the mysterious and taciturn Shadow." 97 | } 98 | } 99 | }, 100 | new Author() 101 | { 102 | Id = new Guid("578359b7-1967-41d6-8b87-64ab7605587e"), 103 | FirstName = "Tom", 104 | LastName = "Lanoye", 105 | Genre = "Various", 106 | DateOfBirth = new DateTimeOffset(new DateTime(1958, 8, 27)), 107 | Books = new List() 108 | { 109 | new Book() 110 | { 111 | Id = new Guid("01457142-358f-495f-aafa-fb23de3d67e9"), 112 | Title = "Speechless", 113 | Description = "Good-natured and often humorous, Speechless is at times a 'song of curses', as Lanoye describes the conflicts with his beloved diva of a mother and her brave struggle with decline and death." 114 | } 115 | } 116 | }, 117 | new Author() 118 | { 119 | Id = new Guid("f74d6899-9ed2-4137-9876-66b070553f8f"), 120 | FirstName = "Douglas", 121 | LastName = "Adams", 122 | Genre = "Science fiction", 123 | DateOfBirth = new DateTimeOffset(new DateTime(1952, 3, 11)), 124 | Books = new List() 125 | { 126 | new Book() 127 | { 128 | Id = new Guid("e57b605f-8b3c-4089-b672-6ce9e6d6c23f"), 129 | Title = "The Hitchhiker's Guide to the Galaxy", 130 | Description = "The Hitchhiker's Guide to the Galaxy is the first of five books in the Hitchhiker's Guide to the Galaxy comedy science fiction 'trilogy' by Douglas Adams." 131 | } 132 | } 133 | }, 134 | new Author() 135 | { 136 | Id = new Guid("a1da1d8e-1988-4634-b538-a01709477b77"), 137 | FirstName = "Jens", 138 | LastName = "Lapidus", 139 | Genre = "Thriller", 140 | DateOfBirth = new DateTimeOffset(new DateTime(1974, 5, 24)), 141 | Books = new List() 142 | { 143 | new Book() 144 | { 145 | Id = new Guid("1325360c-8253-473a-a20f-55c269c20407"), 146 | Title = "Easy Money", 147 | Description = "Easy Money or Snabba cash is a novel from 2006 by Jens Lapidus. It has been a success in term of sales, and the paperback was the fourth best seller of Swedish novels in 2007." 148 | } 149 | } 150 | } 151 | }; 152 | 153 | context.Authors.AddRange(authors); 154 | context.SaveChanges(); 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Helpers/DateTimeOffsetExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Library.API.Helpers 7 | { 8 | public static class DateTimeOffsetExtensions 9 | { 10 | public static int GetCurrentAge(this DateTimeOffset dateTimeOffset) 11 | { 12 | var currentDate = DateTime.UtcNow; 13 | int age = currentDate.Year - dateTimeOffset.Year; 14 | 15 | if (currentDate < dateTimeOffset.AddYears(age)) 16 | { 17 | age--; 18 | } 19 | 20 | return age; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Library.API.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Migrations/InitialMigration.Designer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Library.API.Entities; 7 | 8 | namespace Library.API.Migrations 9 | { 10 | [DbContext(typeof(LibraryContext))] 11 | [Migration("20161007150914_InitialMigration")] 12 | partial class InitialMigration 13 | { 14 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 15 | { 16 | modelBuilder 17 | .HasAnnotation("ProductVersion", "1.0.1") 18 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 19 | 20 | modelBuilder.Entity("Library.API.Entities.Author", b => 21 | { 22 | b.Property("Id") 23 | .ValueGeneratedOnAdd(); 24 | 25 | b.Property("DateOfBirth"); 26 | 27 | b.Property("FirstName") 28 | .IsRequired() 29 | .HasAnnotation("MaxLength", 50); 30 | 31 | b.Property("Genre") 32 | .IsRequired() 33 | .HasAnnotation("MaxLength", 50); 34 | 35 | b.Property("LastName") 36 | .IsRequired() 37 | .HasAnnotation("MaxLength", 50); 38 | 39 | b.HasKey("Id"); 40 | 41 | b.ToTable("Authors"); 42 | }); 43 | 44 | modelBuilder.Entity("Library.API.Entities.Book", b => 45 | { 46 | b.Property("Id") 47 | .ValueGeneratedOnAdd(); 48 | 49 | b.Property("AuthorId"); 50 | 51 | b.Property("Description") 52 | .HasAnnotation("MaxLength", 500); 53 | 54 | b.Property("Title") 55 | .IsRequired() 56 | .HasAnnotation("MaxLength", 100); 57 | 58 | b.HasKey("Id"); 59 | 60 | b.HasIndex("AuthorId"); 61 | 62 | b.ToTable("Books"); 63 | }); 64 | 65 | modelBuilder.Entity("Library.API.Entities.Book", b => 66 | { 67 | b.HasOne("Library.API.Entities.Author", "Author") 68 | .WithMany("Books") 69 | .HasForeignKey("AuthorId") 70 | .OnDelete(DeleteBehavior.Cascade); 71 | }); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Migrations/InitialMigration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | using System; 3 | 4 | namespace Library.API.Migrations 5 | { 6 | public partial class InitialMigration : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "Authors", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false), 15 | DateOfBirth = table.Column(nullable: false), 16 | FirstName = table.Column(maxLength: 50, nullable: false), 17 | Genre = table.Column(maxLength: 50, nullable: false), 18 | LastName = table.Column(maxLength: 50, nullable: false) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_Authors", x => x.Id); 23 | }); 24 | 25 | migrationBuilder.CreateTable( 26 | name: "Books", 27 | columns: table => new 28 | { 29 | Id = table.Column(nullable: false), 30 | AuthorId = table.Column(nullable: false), 31 | Description = table.Column(maxLength: 500, nullable: true), 32 | Title = table.Column(maxLength: 100, nullable: false) 33 | }, 34 | constraints: table => 35 | { 36 | table.PrimaryKey("PK_Books", x => x.Id); 37 | table.ForeignKey( 38 | name: "FK_Books_Authors_AuthorId", 39 | column: x => x.AuthorId, 40 | principalTable: "Authors", 41 | principalColumn: "Id", 42 | onDelete: ReferentialAction.Cascade); 43 | }); 44 | 45 | migrationBuilder.CreateIndex( 46 | name: "IX_Books_AuthorId", 47 | table: "Books", 48 | column: "AuthorId"); 49 | } 50 | 51 | protected override void Down(MigrationBuilder migrationBuilder) 52 | { 53 | migrationBuilder.DropTable( 54 | name: "Books"); 55 | 56 | migrationBuilder.DropTable( 57 | name: "Authors"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Migrations/LibraryContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using System; 6 | 7 | namespace Library.API.Migrations 8 | { 9 | [DbContext(typeof(LibraryContext))] 10 | partial class LibraryContextModelSnapshot : ModelSnapshot 11 | { 12 | protected override void BuildModel(ModelBuilder modelBuilder) 13 | { 14 | modelBuilder 15 | .HasAnnotation("ProductVersion", "1.0.1") 16 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 17 | 18 | modelBuilder.Entity("Library.API.Entities.Author", b => 19 | { 20 | b.Property("Id") 21 | .ValueGeneratedOnAdd(); 22 | 23 | b.Property("DateOfBirth"); 24 | 25 | b.Property("FirstName") 26 | .IsRequired() 27 | .HasAnnotation("MaxLength", 50); 28 | 29 | b.Property("Genre") 30 | .IsRequired() 31 | .HasAnnotation("MaxLength", 50); 32 | 33 | b.Property("LastName") 34 | .IsRequired() 35 | .HasAnnotation("MaxLength", 50); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Authors"); 40 | }); 41 | 42 | modelBuilder.Entity("Library.API.Entities.Book", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("AuthorId"); 48 | 49 | b.Property("Description") 50 | .HasAnnotation("MaxLength", 500); 51 | 52 | b.Property("Title") 53 | .IsRequired() 54 | .HasAnnotation("MaxLength", 100); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.HasIndex("AuthorId"); 59 | 60 | b.ToTable("Books"); 61 | }); 62 | 63 | modelBuilder.Entity("Library.API.Entities.Book", b => 64 | { 65 | b.HasOne("Library.API.Entities.Author", "Author") 66 | .WithMany("Books") 67 | .HasForeignKey("AuthorId") 68 | .OnDelete(DeleteBehavior.Cascade); 69 | }); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore; 8 | 9 | namespace Library.API 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | BuildWebHost(args).Run(); 16 | } 17 | 18 | public static IWebHost BuildWebHost(string[] args) => 19 | WebHost.CreateDefaultBuilder(args) 20 | .UseStartup() 21 | .Build(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Project_Readme.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Welcome to ASP.NET Core 6 | 127 | 128 | 129 | 130 | 138 | 139 |
140 |
141 |

This application consists of:

142 |
    143 |
  • Sample pages using ASP.NET Core MVC
  • 144 |
  • Bower for managing client-side libraries
  • 145 |
  • Theming using Bootstrap
  • 146 |
147 |
148 | 160 | 172 |
173 |

Run & Deploy

174 | 179 |
180 | 181 | 184 |
185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:6058/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "Library.API": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "launchUrl": "http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Services/ILibraryRepository.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Library.API.Services 6 | { 7 | public interface ILibraryRepository 8 | { 9 | IEnumerable GetAuthors(); 10 | Author GetAuthor(Guid authorId); 11 | IEnumerable GetAuthors(IEnumerable authorIds); 12 | void AddAuthor(Author author); 13 | void DeleteAuthor(Author author); 14 | void UpdateAuthor(Author author); 15 | bool AuthorExists(Guid authorId); 16 | IEnumerable GetBooksForAuthor(Guid authorId); 17 | Book GetBookForAuthor(Guid authorId, Guid bookId); 18 | void AddBookForAuthor(Guid authorId, Book book); 19 | void UpdateBookForAuthor(Book book); 20 | void DeleteBook(Book book); 21 | bool Save(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Services/LibraryRepository.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Library.API.Services 7 | { 8 | public class LibraryRepository : ILibraryRepository 9 | { 10 | private LibraryContext _context; 11 | 12 | public LibraryRepository(LibraryContext context) 13 | { 14 | _context = context; 15 | } 16 | 17 | public void AddAuthor(Author author) 18 | { 19 | author.Id = Guid.NewGuid(); 20 | _context.Authors.Add(author); 21 | 22 | // the repository fills the id (instead of using identity columns) 23 | if (author.Books.Any()) 24 | { 25 | foreach (var book in author.Books) 26 | { 27 | book.Id = Guid.NewGuid(); 28 | } 29 | } 30 | } 31 | 32 | public void AddBookForAuthor(Guid authorId, Book book) 33 | { 34 | var author = GetAuthor(authorId); 35 | if (author != null) 36 | { 37 | // if there isn't an id filled out (ie: we're not upserting), 38 | // we should generate one 39 | if (book.Id == Guid.Empty) 40 | { 41 | book.Id = Guid.NewGuid(); 42 | } 43 | author.Books.Add(book); 44 | } 45 | } 46 | 47 | public bool AuthorExists(Guid authorId) 48 | { 49 | return _context.Authors.Any(a => a.Id == authorId); 50 | } 51 | 52 | public void DeleteAuthor(Author author) 53 | { 54 | _context.Authors.Remove(author); 55 | } 56 | 57 | public void DeleteBook(Book book) 58 | { 59 | _context.Books.Remove(book); 60 | } 61 | 62 | public Author GetAuthor(Guid authorId) 63 | { 64 | return _context.Authors.FirstOrDefault(a => a.Id == authorId); 65 | } 66 | 67 | public IEnumerable GetAuthors() 68 | { 69 | return _context.Authors.OrderBy(a => a.FirstName).ThenBy(a => a.LastName); 70 | } 71 | 72 | public IEnumerable GetAuthors(IEnumerable authorIds) 73 | { 74 | return _context.Authors.Where(a => authorIds.Contains(a.Id)) 75 | .OrderBy(a => a.FirstName) 76 | .OrderBy(a => a.LastName) 77 | .ToList(); 78 | } 79 | 80 | public void UpdateAuthor(Author author) 81 | { 82 | // no code in this implementation 83 | } 84 | 85 | public Book GetBookForAuthor(Guid authorId, Guid bookId) 86 | { 87 | return _context.Books 88 | .Where(b => b.AuthorId == authorId && b.Id == bookId).FirstOrDefault(); 89 | } 90 | 91 | public IEnumerable GetBooksForAuthor(Guid authorId) 92 | { 93 | return _context.Books 94 | .Where(b => b.AuthorId == authorId).OrderBy(b => b.Title).ToList(); 95 | } 96 | 97 | public void UpdateBookForAuthor(Book book) 98 | { 99 | // no code in this implementation 100 | } 101 | 102 | public bool Save() 103 | { 104 | return (_context.SaveChanges() >= 0); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Configuration; 11 | using Library.API.Services; 12 | using Library.API.Entities; 13 | using Microsoft.EntityFrameworkCore; 14 | 15 | namespace Library.API 16 | { 17 | public class Startup 18 | { 19 | public static IConfiguration Configuration; 20 | 21 | public Startup(IConfiguration configuration) 22 | { 23 | Configuration = configuration; 24 | } 25 | 26 | // This method gets called by the runtime. Use this method to add services to the container. 27 | // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 28 | public void ConfigureServices(IServiceCollection services) 29 | { 30 | services.AddMvc(); 31 | 32 | // register the DbContext on the container, getting the connection string from 33 | // appSettings (note: use this during development; in a production environment, 34 | // it's better to store the connection string in an environment variable) 35 | var connectionString = Configuration["connectionStrings:libraryDBConnectionString"]; 36 | services.AddDbContext(o => o.UseSqlServer(connectionString)); 37 | 38 | // register the repository 39 | services.AddScoped(); 40 | } 41 | 42 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 43 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, 44 | ILoggerFactory loggerFactory, LibraryContext libraryContext) 45 | { 46 | if (env.IsDevelopment()) 47 | { 48 | app.UseDeveloperExceptionPage(); 49 | } 50 | else 51 | { 52 | app.UseExceptionHandler(); 53 | } 54 | 55 | libraryContext.EnsureSeedDataForContext(); 56 | 57 | app.UseMvc(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "connectionStrings": { 3 | "libraryDBConnectionString": "Server=(localdb)\\mssqllocaldb;Database=LibraryDB;Trusted_Connection=True;" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /csproj_msbuild_core2/start-end/Library/src/Library.API/web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/Library.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{FB41072F-53FC-4AF6-8838-89CF1FFCAE5B}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{52859A54-50D0-4BBF-935D-FD2EC134E2DC}" 9 | ProjectSection(SolutionItems) = preProject 10 | global.json = global.json 11 | EndProjectSection 12 | EndProject 13 | Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Library.API", "src\Library.API\Library.API.xproj", "{25AAC737-21A7-4BEE-A3BC-8539AFDB931B}" 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B}.Release|Any CPU.Build.0 = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | GlobalSection(NestedProjects) = preSolution 30 | {25AAC737-21A7-4BEE-A3BC-8539AFDB931B} = {FB41072F-53FC-4AF6-8838-89CF1FFCAE5B} 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ "src", "test" ], 3 | "sdk": { 4 | "version": "1.0.0-preview2-003131" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Entities/Author.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace Library.API.Entities 6 | { 7 | public class Author 8 | { 9 | [Key] 10 | public Guid Id { get; set; } 11 | 12 | [Required] 13 | [MaxLength(50)] 14 | public string FirstName { get; set; } 15 | 16 | [Required] 17 | [MaxLength(50)] 18 | public string LastName { get; set; } 19 | 20 | [Required] 21 | public DateTimeOffset DateOfBirth { get; set; } 22 | 23 | [Required] 24 | [MaxLength(50)] 25 | public string Genre { get; set; } 26 | 27 | public ICollection Books { get; set; } 28 | = new List(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Entities/Book.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | 5 | namespace Library.API.Entities 6 | { 7 | public class Book 8 | { 9 | [Key] 10 | public Guid Id { get; set; } 11 | 12 | [Required] 13 | [MaxLength(100)] 14 | public string Title { get; set; } 15 | 16 | [MaxLength(500)] 17 | public string Description { get; set; } 18 | 19 | [ForeignKey("AuthorId")] 20 | public Author Author { get; set; } 21 | 22 | public Guid AuthorId { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Entities/LibraryContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | 3 | namespace Library.API.Entities 4 | { 5 | public class LibraryContext : DbContext 6 | { 7 | public LibraryContext(DbContextOptions options) 8 | : base(options) 9 | { 10 | Database.Migrate(); 11 | } 12 | 13 | public DbSet Authors { get; set; } 14 | public DbSet Books { get; set; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Entities/LibraryContextExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Library.API.Entities 5 | { 6 | public static class LibraryContextExtensions 7 | { 8 | public static void EnsureSeedDataForContext(this LibraryContext context) 9 | { 10 | // first, clear the database. This ensures we can always start 11 | // fresh with each demo. Not advised for production environments, obviously :-) 12 | 13 | context.Authors.RemoveRange(context.Authors); 14 | context.SaveChanges(); 15 | 16 | // init seed data 17 | var authors = new List() 18 | { 19 | new Author() 20 | { 21 | Id = new Guid("25320c5e-f58a-4b1f-b63a-8ee07a840bdf"), 22 | FirstName = "Stephen", 23 | LastName = "King", 24 | Genre = "Horror", 25 | DateOfBirth = new DateTimeOffset(new DateTime(1947, 9, 21)), 26 | Books = new List() 27 | { 28 | new Book() 29 | { 30 | Id = new Guid("c7ba6add-09c4-45f8-8dd0-eaca221e5d93"), 31 | Title = "The Shining", 32 | Description = "The Shining is a horror novel by American author Stephen King. Published in 1977, it is King's third published novel and first hardback bestseller: the success of the book firmly established King as a preeminent author in the horror genre. " 33 | }, 34 | new Book() 35 | { 36 | Id = new Guid("a3749477-f823-4124-aa4a-fc9ad5e79cd6"), 37 | Title = "Misery", 38 | Description = "Misery is a 1987 psychological horror novel by Stephen King. This novel was nominated for the World Fantasy Award for Best Novel in 1988, and was later made into a Hollywood film and an off-Broadway play of the same name." 39 | }, 40 | new Book() 41 | { 42 | Id = new Guid("70a1f9b9-0a37-4c1a-99b1-c7709fc64167"), 43 | Title = "It", 44 | Description = "It is a 1986 horror novel by American author Stephen King. The story follows the exploits of seven children as they are terrorized by the eponymous being, which exploits the fears and phobias of its victims in order to disguise itself while hunting its prey. 'It' primarily appears in the form of a clown in order to attract its preferred prey of young children." 45 | }, 46 | new Book() 47 | { 48 | Id = new Guid("60188a2b-2784-4fc4-8df8-8919ff838b0b"), 49 | Title = "The Stand", 50 | Description = "The Stand is a post-apocalyptic horror/fantasy novel by American author Stephen King. It expands upon the scenario of his earlier short story 'Night Surf' and outlines the total breakdown of society after the accidental release of a strain of influenza that had been modified for biological warfare causes an apocalyptic pandemic which kills off the majority of the world's human population." 51 | } 52 | } 53 | }, 54 | new Author() 55 | { 56 | Id = new Guid("76053df4-6687-4353-8937-b45556748abe"), 57 | FirstName = "George", 58 | LastName = "RR Martin", 59 | Genre = "Fantasy", 60 | DateOfBirth = new DateTimeOffset(new DateTime(1948, 9, 20)), 61 | Books = new List() 62 | { 63 | new Book() 64 | { 65 | Id = new Guid("447eb762-95e9-4c31-95e1-b20053fbe215"), 66 | Title = "A Game of Thrones", 67 | Description = "A Game of Thrones is the first novel in A Song of Ice and Fire, a series of fantasy novels by American author George R. R. Martin. It was first published on August 1, 1996." 68 | }, 69 | new Book() 70 | { 71 | Id = new Guid("bc4c35c3-3857-4250-9449-155fcf5109ec"), 72 | Title = "The Winds of Winter", 73 | Description = "Forthcoming 6th novel in A Song of Ice and Fire." 74 | }, 75 | new Book() 76 | { 77 | Id = new Guid("09af5a52-9421-44e8-a2bb-a6b9ccbc8239"), 78 | Title = "A Dance with Dragons", 79 | Description = "A Dance with Dragons is the fifth of seven planned novels in the epic fantasy series A Song of Ice and Fire by American author George R. R. Martin." 80 | } 81 | } 82 | }, 83 | new Author() 84 | { 85 | Id = new Guid("412c3012-d891-4f5e-9613-ff7aa63e6bb3"), 86 | FirstName = "Neil", 87 | LastName = "Gaiman", 88 | Genre = "Fantasy", 89 | DateOfBirth = new DateTimeOffset(new DateTime(1960, 11, 10)), 90 | Books = new List() 91 | { 92 | new Book() 93 | { 94 | Id = new Guid("9edf91ee-ab77-4521-a402-5f188bc0c577"), 95 | Title = "American Gods", 96 | Description = "American Gods is a Hugo and Nebula Award-winning novel by English author Neil Gaiman. The novel is a blend of Americana, fantasy, and various strands of ancient and modern mythology, all centering on the mysterious and taciturn Shadow." 97 | } 98 | } 99 | }, 100 | new Author() 101 | { 102 | Id = new Guid("578359b7-1967-41d6-8b87-64ab7605587e"), 103 | FirstName = "Tom", 104 | LastName = "Lanoye", 105 | Genre = "Various", 106 | DateOfBirth = new DateTimeOffset(new DateTime(1958, 8, 27)), 107 | Books = new List() 108 | { 109 | new Book() 110 | { 111 | Id = new Guid("01457142-358f-495f-aafa-fb23de3d67e9"), 112 | Title = "Speechless", 113 | Description = "Good-natured and often humorous, Speechless is at times a 'song of curses', as Lanoye describes the conflicts with his beloved diva of a mother and her brave struggle with decline and death." 114 | } 115 | } 116 | }, 117 | new Author() 118 | { 119 | Id = new Guid("f74d6899-9ed2-4137-9876-66b070553f8f"), 120 | FirstName = "Douglas", 121 | LastName = "Adams", 122 | Genre = "Science fiction", 123 | DateOfBirth = new DateTimeOffset(new DateTime(1952, 3, 11)), 124 | Books = new List() 125 | { 126 | new Book() 127 | { 128 | Id = new Guid("e57b605f-8b3c-4089-b672-6ce9e6d6c23f"), 129 | Title = "The Hitchhiker's Guide to the Galaxy", 130 | Description = "The Hitchhiker's Guide to the Galaxy is the first of five books in the Hitchhiker's Guide to the Galaxy comedy science fiction 'trilogy' by Douglas Adams." 131 | } 132 | } 133 | }, 134 | new Author() 135 | { 136 | Id = new Guid("a1da1d8e-1988-4634-b538-a01709477b77"), 137 | FirstName = "Jens", 138 | LastName = "Lapidus", 139 | Genre = "Thriller", 140 | DateOfBirth = new DateTimeOffset(new DateTime(1974, 5, 24)), 141 | Books = new List() 142 | { 143 | new Book() 144 | { 145 | Id = new Guid("1325360c-8253-473a-a20f-55c269c20407"), 146 | Title = "Easy Money", 147 | Description = "Easy Money or Snabba cash is a novel from 2006 by Jens Lapidus. It has been a success in term of sales, and the paperback was the fourth best seller of Swedish novels in 2007." 148 | } 149 | } 150 | } 151 | }; 152 | 153 | context.Authors.AddRange(authors); 154 | context.SaveChanges(); 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Helpers/DateTimeOffsetExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Library.API.Helpers 7 | { 8 | public static class DateTimeOffsetExtensions 9 | { 10 | public static int GetCurrentAge(this DateTimeOffset dateTimeOffset) 11 | { 12 | var currentDate = DateTime.UtcNow; 13 | int age = currentDate.Year - dateTimeOffset.Year; 14 | 15 | if (currentDate < dateTimeOffset.AddYears(age)) 16 | { 17 | age--; 18 | } 19 | 20 | return age; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Library.API.xproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 25aac737-21a7-4bee-a3bc-8539afdb931b 11 | Library.API 12 | .\obj 13 | .\bin\ 14 | v4.5.2 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Migrations/InitialMigration.Designer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Library.API.Entities; 7 | 8 | namespace Library.API.Migrations 9 | { 10 | [DbContext(typeof(LibraryContext))] 11 | [Migration("20161007150914_InitialMigration")] 12 | partial class InitialMigration 13 | { 14 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 15 | { 16 | modelBuilder 17 | .HasAnnotation("ProductVersion", "1.0.1") 18 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 19 | 20 | modelBuilder.Entity("Library.API.Entities.Author", b => 21 | { 22 | b.Property("Id") 23 | .ValueGeneratedOnAdd(); 24 | 25 | b.Property("DateOfBirth"); 26 | 27 | b.Property("FirstName") 28 | .IsRequired() 29 | .HasAnnotation("MaxLength", 50); 30 | 31 | b.Property("Genre") 32 | .IsRequired() 33 | .HasAnnotation("MaxLength", 50); 34 | 35 | b.Property("LastName") 36 | .IsRequired() 37 | .HasAnnotation("MaxLength", 50); 38 | 39 | b.HasKey("Id"); 40 | 41 | b.ToTable("Authors"); 42 | }); 43 | 44 | modelBuilder.Entity("Library.API.Entities.Book", b => 45 | { 46 | b.Property("Id") 47 | .ValueGeneratedOnAdd(); 48 | 49 | b.Property("AuthorId"); 50 | 51 | b.Property("Description") 52 | .HasAnnotation("MaxLength", 500); 53 | 54 | b.Property("Title") 55 | .IsRequired() 56 | .HasAnnotation("MaxLength", 100); 57 | 58 | b.HasKey("Id"); 59 | 60 | b.HasIndex("AuthorId"); 61 | 62 | b.ToTable("Books"); 63 | }); 64 | 65 | modelBuilder.Entity("Library.API.Entities.Book", b => 66 | { 67 | b.HasOne("Library.API.Entities.Author", "Author") 68 | .WithMany("Books") 69 | .HasForeignKey("AuthorId") 70 | .OnDelete(DeleteBehavior.Cascade); 71 | }); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Migrations/InitialMigration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | using System; 3 | 4 | namespace Library.API.Migrations 5 | { 6 | public partial class InitialMigration : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "Authors", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false), 15 | DateOfBirth = table.Column(nullable: false), 16 | FirstName = table.Column(maxLength: 50, nullable: false), 17 | Genre = table.Column(maxLength: 50, nullable: false), 18 | LastName = table.Column(maxLength: 50, nullable: false) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_Authors", x => x.Id); 23 | }); 24 | 25 | migrationBuilder.CreateTable( 26 | name: "Books", 27 | columns: table => new 28 | { 29 | Id = table.Column(nullable: false), 30 | AuthorId = table.Column(nullable: false), 31 | Description = table.Column(maxLength: 500, nullable: true), 32 | Title = table.Column(maxLength: 100, nullable: false) 33 | }, 34 | constraints: table => 35 | { 36 | table.PrimaryKey("PK_Books", x => x.Id); 37 | table.ForeignKey( 38 | name: "FK_Books_Authors_AuthorId", 39 | column: x => x.AuthorId, 40 | principalTable: "Authors", 41 | principalColumn: "Id", 42 | onDelete: ReferentialAction.Cascade); 43 | }); 44 | 45 | migrationBuilder.CreateIndex( 46 | name: "IX_Books_AuthorId", 47 | table: "Books", 48 | column: "AuthorId"); 49 | } 50 | 51 | protected override void Down(MigrationBuilder migrationBuilder) 52 | { 53 | migrationBuilder.DropTable( 54 | name: "Books"); 55 | 56 | migrationBuilder.DropTable( 57 | name: "Authors"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Migrations/LibraryContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using System; 6 | 7 | namespace Library.API.Migrations 8 | { 9 | [DbContext(typeof(LibraryContext))] 10 | partial class LibraryContextModelSnapshot : ModelSnapshot 11 | { 12 | protected override void BuildModel(ModelBuilder modelBuilder) 13 | { 14 | modelBuilder 15 | .HasAnnotation("ProductVersion", "1.0.1") 16 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 17 | 18 | modelBuilder.Entity("Library.API.Entities.Author", b => 19 | { 20 | b.Property("Id") 21 | .ValueGeneratedOnAdd(); 22 | 23 | b.Property("DateOfBirth"); 24 | 25 | b.Property("FirstName") 26 | .IsRequired() 27 | .HasAnnotation("MaxLength", 50); 28 | 29 | b.Property("Genre") 30 | .IsRequired() 31 | .HasAnnotation("MaxLength", 50); 32 | 33 | b.Property("LastName") 34 | .IsRequired() 35 | .HasAnnotation("MaxLength", 50); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Authors"); 40 | }); 41 | 42 | modelBuilder.Entity("Library.API.Entities.Book", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("AuthorId"); 48 | 49 | b.Property("Description") 50 | .HasAnnotation("MaxLength", 500); 51 | 52 | b.Property("Title") 53 | .IsRequired() 54 | .HasAnnotation("MaxLength", 100); 55 | 56 | b.HasKey("Id"); 57 | 58 | b.HasIndex("AuthorId"); 59 | 60 | b.ToTable("Books"); 61 | }); 62 | 63 | modelBuilder.Entity("Library.API.Entities.Book", b => 64 | { 65 | b.HasOne("Library.API.Entities.Author", "Author") 66 | .WithMany("Books") 67 | .HasForeignKey("AuthorId") 68 | .OnDelete(DeleteBehavior.Cascade); 69 | }); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Hosting; 7 | 8 | namespace Library.API 9 | { 10 | public class Program 11 | { 12 | public static void Main(string[] args) 13 | { 14 | var host = new WebHostBuilder() 15 | .UseKestrel() 16 | .UseContentRoot(Directory.GetCurrentDirectory()) 17 | .UseIISIntegration() 18 | .UseStartup() 19 | .Build(); 20 | 21 | host.Run(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Project_Readme.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Welcome to ASP.NET Core 6 | 127 | 128 | 129 | 130 | 138 | 139 |
140 |
141 |

This application consists of:

142 |
    143 |
  • Sample pages using ASP.NET Core MVC
  • 144 |
  • Bower for managing client-side libraries
  • 145 |
  • Theming using Bootstrap
  • 146 |
147 |
148 | 160 | 172 |
173 |

Run & Deploy

174 | 179 |
180 | 181 | 184 |
185 | 186 | 187 | 188 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:6058/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "Library.API": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "launchUrl": "http://localhost:5000", 22 | "environmentVariables": { 23 | "ASPNETCORE_ENVIRONMENT": "Development" 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Services/ILibraryRepository.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Library.API.Services 6 | { 7 | public interface ILibraryRepository 8 | { 9 | IEnumerable GetAuthors(); 10 | Author GetAuthor(Guid authorId); 11 | IEnumerable GetAuthors(IEnumerable authorIds); 12 | void AddAuthor(Author author); 13 | void DeleteAuthor(Author author); 14 | void UpdateAuthor(Author author); 15 | bool AuthorExists(Guid authorId); 16 | IEnumerable GetBooksForAuthor(Guid authorId); 17 | Book GetBookForAuthor(Guid authorId, Guid bookId); 18 | void AddBookForAuthor(Guid authorId, Book book); 19 | void UpdateBookForAuthor(Book book); 20 | void DeleteBook(Book book); 21 | bool Save(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Services/LibraryRepository.cs: -------------------------------------------------------------------------------- 1 | using Library.API.Entities; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Library.API.Services 7 | { 8 | public class LibraryRepository : ILibraryRepository 9 | { 10 | private LibraryContext _context; 11 | 12 | public LibraryRepository(LibraryContext context) 13 | { 14 | _context = context; 15 | } 16 | 17 | public void AddAuthor(Author author) 18 | { 19 | author.Id = Guid.NewGuid(); 20 | _context.Authors.Add(author); 21 | 22 | // the repository fills the id (instead of using identity columns) 23 | if (author.Books.Any()) 24 | { 25 | foreach (var book in author.Books) 26 | { 27 | book.Id = Guid.NewGuid(); 28 | } 29 | } 30 | } 31 | 32 | public void AddBookForAuthor(Guid authorId, Book book) 33 | { 34 | var author = GetAuthor(authorId); 35 | if (author != null) 36 | { 37 | // if there isn't an id filled out (ie: we're not upserting), 38 | // we should generate one 39 | if (book.Id == Guid.Empty) 40 | { 41 | book.Id = Guid.NewGuid(); 42 | } 43 | author.Books.Add(book); 44 | } 45 | } 46 | 47 | public bool AuthorExists(Guid authorId) 48 | { 49 | return _context.Authors.Any(a => a.Id == authorId); 50 | } 51 | 52 | public void DeleteAuthor(Author author) 53 | { 54 | _context.Authors.Remove(author); 55 | } 56 | 57 | public void DeleteBook(Book book) 58 | { 59 | _context.Books.Remove(book); 60 | } 61 | 62 | public Author GetAuthor(Guid authorId) 63 | { 64 | return _context.Authors.FirstOrDefault(a => a.Id == authorId); 65 | } 66 | 67 | public IEnumerable GetAuthors() 68 | { 69 | return _context.Authors.OrderBy(a => a.FirstName).ThenBy(a => a.LastName); 70 | } 71 | 72 | public IEnumerable GetAuthors(IEnumerable authorIds) 73 | { 74 | return _context.Authors.Where(a => authorIds.Contains(a.Id)) 75 | .OrderBy(a => a.FirstName) 76 | .OrderBy(a => a.LastName) 77 | .ToList(); 78 | } 79 | 80 | public void UpdateAuthor(Author author) 81 | { 82 | // no code in this implementation 83 | } 84 | 85 | public Book GetBookForAuthor(Guid authorId, Guid bookId) 86 | { 87 | return _context.Books 88 | .Where(b => b.AuthorId == authorId && b.Id == bookId).FirstOrDefault(); 89 | } 90 | 91 | public IEnumerable GetBooksForAuthor(Guid authorId) 92 | { 93 | return _context.Books 94 | .Where(b => b.AuthorId == authorId).OrderBy(b => b.Title).ToList(); 95 | } 96 | 97 | public void UpdateBookForAuthor(Book book) 98 | { 99 | // no code in this implementation 100 | } 101 | 102 | public bool Save() 103 | { 104 | return (_context.SaveChanges() >= 0); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Configuration; 11 | using Library.API.Services; 12 | using Library.API.Entities; 13 | using Microsoft.EntityFrameworkCore; 14 | 15 | namespace Library.API 16 | { 17 | public class Startup 18 | { 19 | public static IConfigurationRoot Configuration; 20 | 21 | public Startup(IHostingEnvironment env) 22 | { 23 | var builder = new ConfigurationBuilder() 24 | .SetBasePath(env.ContentRootPath) 25 | .AddJsonFile("appSettings.json", optional: false, reloadOnChange: true) 26 | .AddJsonFile($"appSettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) 27 | .AddEnvironmentVariables(); 28 | 29 | Configuration = builder.Build(); 30 | } 31 | 32 | // This method gets called by the runtime. Use this method to add services to the container. 33 | // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940 34 | public void ConfigureServices(IServiceCollection services) 35 | { 36 | services.AddMvc(); 37 | 38 | // register the DbContext on the container, getting the connection string from 39 | // appSettings (note: use this during development; in a production environment, 40 | // it's better to store the connection string in an environment variable) 41 | var connectionString = Configuration["connectionStrings:libraryDBConnectionString"]; 42 | services.AddDbContext(o => o.UseSqlServer(connectionString)); 43 | 44 | // register the repository 45 | services.AddScoped(); 46 | } 47 | 48 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 49 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, 50 | ILoggerFactory loggerFactory, LibraryContext libraryContext) 51 | { 52 | loggerFactory.AddConsole(); 53 | 54 | if (env.IsDevelopment()) 55 | { 56 | app.UseDeveloperExceptionPage(); 57 | } 58 | else 59 | { 60 | app.UseExceptionHandler(); 61 | } 62 | 63 | libraryContext.EnsureSeedDataForContext(); 64 | 65 | app.UseMvc(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "connectionStrings": { 3 | "libraryDBConnectionString": "Server=(localdb)\\mssqllocaldb;Database=LibraryDB;Trusted_Connection=True;" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "Microsoft.NETCore.App": { 4 | "version": "1.0.1", 5 | "type": "platform" 6 | }, 7 | "Microsoft.AspNetCore.Diagnostics": "1.0.1", 8 | "Microsoft.AspNetCore.Server.IISIntegration": "1.0.1", 9 | "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", 10 | "Microsoft.Extensions.Logging.Console": "1.0.1", 11 | "Microsoft.AspNetCore.Mvc": "1.0.1", 12 | "Microsoft.EntityFrameworkCore": "1.0.1", 13 | "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", 14 | "Microsoft.Extensions.Configuration.FileExtensions": "1.0.1", 15 | "Microsoft.Extensions.Configuration.Json": "1.0.1", 16 | "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1" 17 | }, 18 | 19 | "tools": { 20 | "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", 21 | "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" 22 | }, 23 | 24 | "frameworks": { 25 | "netcoreapp1.0": { 26 | "imports": [ 27 | "dotnet5.6", 28 | "portable-net45+win8" 29 | ] 30 | } 31 | }, 32 | 33 | "buildOptions": { 34 | "emitEntryPoint": true, 35 | "preserveCompilationContext": true 36 | }, 37 | 38 | "runtimeOptions": { 39 | "configProperties": { 40 | "System.GC.Server": true 41 | } 42 | }, 43 | 44 | "publishOptions": { 45 | "include": [ 46 | "wwwroot", 47 | "web.config" 48 | ] 49 | }, 50 | 51 | "scripts": { 52 | "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /xproj_project_json_core1/start-end/Library/src/Library.API/web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------