├── .gitattributes ├── .gitignore ├── BlazorInvoiceApp ├── .cr │ └── personal │ │ └── FavoritesList │ │ └── List.xml ├── App.razor ├── Areas │ └── Identity │ │ ├── Pages │ │ ├── Account │ │ │ └── LogOut.cshtml │ │ └── Shared │ │ │ └── _LoginPartial.cshtml │ │ └── RevalidatingIdentityAuthenticationStateProvider.cs ├── BlazorInvoiceApp.csproj ├── BlazorInvoiceApp.sln ├── DTOS │ ├── CustomerDTO.cs │ ├── IDTO.cs │ ├── IOwnedDTO.cs │ ├── InvoiceDTO.cs │ ├── InvoiceLineItemDTO.cs │ └── InvoiceTermsDTO.cs ├── Data │ ├── ApplicationDbContext.cs │ ├── Customer.cs │ ├── IEntity.cs │ ├── IOwnedEntity.cs │ ├── Invoice.cs │ ├── InvoiceLineItem.cs │ ├── InvoiceTerms.cs │ └── Migrations │ │ ├── 00000000000000_CreateIdentitySchema.Designer.cs │ │ ├── 00000000000000_CreateIdentitySchema.cs │ │ ├── 20230926013249_db1.Designer.cs │ │ ├── 20230926013249_db1.cs │ │ └── ApplicationDbContextModelSnapshot.cs ├── Pages │ ├── Components │ │ ├── CustomerSetupComponent.razor │ │ ├── InvoiceDetailComponent.razor │ │ ├── InvoiceTermsSetupComponent.razor │ │ └── InvoicesComponent.razor │ ├── CustomerSetup.razor │ ├── EntityTest.razor │ ├── Error.cshtml │ ├── Error.cshtml.cs │ ├── Index.razor │ ├── InvoiceDetail.razor │ ├── InvoiceTermsSetup.razor │ └── _Host.cshtml ├── Program.cs ├── Properties │ ├── launchSettings.json │ ├── serviceDependencies.json │ └── serviceDependencies.local.json ├── Repository │ ├── AutoMapperProfile.cs │ ├── CustomerRepository.cs │ ├── GenericOwnedRepository.cs │ ├── ICustomerRepository.cs │ ├── IGenericOwnedRepository.cs │ ├── IInvoiceLineItemRepository.cs │ ├── IInvoiceRepository.cs │ ├── IInvoiceTermsRepository.cs │ ├── IRepositoryCollection.cs │ ├── InvoiceLineItemRepository.cs │ ├── InvoiceRepository.cs │ ├── InvoiceTermsRepository.cs │ ├── RepositoryAddException.cs │ ├── RepositoryCollection.cs │ ├── RepositoryDeleteException.cs │ └── RepositoryUpdateException.cs ├── Shared │ ├── LoginDisplay.razor │ ├── MainLayout.razor │ ├── MainLayout.razor.css │ ├── NavMenu.razor │ └── NavMenu.razor.css ├── _Imports.razor ├── appsettings.Development.json ├── appsettings.json └── wwwroot │ ├── css │ ├── bootstrap │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ ├── open-iconic │ │ ├── FONT-LICENSE │ │ ├── ICON-LICENSE │ │ ├── README.md │ │ └── font │ │ │ ├── css │ │ │ └── open-iconic-bootstrap.min.css │ │ │ └── fonts │ │ │ ├── open-iconic.eot │ │ │ ├── open-iconic.otf │ │ │ ├── open-iconic.svg │ │ │ ├── open-iconic.ttf │ │ │ └── open-iconic.woff │ └── site.css │ └── favicon.png ├── BlazorInvoiceAppTests ├── BlazorInvoiceAppTests.csproj ├── GlobalUsings.cs ├── SetupCustomersComponentTests.cs └── UnitTest1.cs └── LICENSE /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/.cr/personal/FavoritesList/List.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/App.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | Not found 9 | 10 |

Sorry, there's nothing at this address.

11 |
12 |
13 |
14 |
15 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Areas/Identity/Pages/Account/LogOut.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @using Microsoft.AspNetCore.Identity 3 | @attribute [IgnoreAntiforgeryToken] 4 | @inject SignInManager SignInManager 5 | @functions { 6 | public async Task OnPost() 7 | { 8 | if (SignInManager.IsSignedIn(User)) 9 | { 10 | await SignInManager.SignOutAsync(); 11 | } 12 | 13 | return Redirect("~/"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Areas/Identity/Pages/Shared/_LoginPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Identity 2 | @inject SignInManager SignInManager 3 | @inject UserManager UserManager 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | 6 | 28 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Areas/Identity/RevalidatingIdentityAuthenticationStateProvider.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using Microsoft.AspNetCore.Components.Authorization; 3 | using Microsoft.AspNetCore.Components.Server; 4 | using Microsoft.AspNetCore.Identity; 5 | using Microsoft.Extensions.Options; 6 | using System.Security.Claims; 7 | 8 | namespace BlazorInvoiceApp.Areas.Identity 9 | { 10 | public class RevalidatingIdentityAuthenticationStateProvider 11 | : RevalidatingServerAuthenticationStateProvider where TUser : class 12 | { 13 | private readonly IServiceScopeFactory _scopeFactory; 14 | private readonly IdentityOptions _options; 15 | 16 | public RevalidatingIdentityAuthenticationStateProvider( 17 | ILoggerFactory loggerFactory, 18 | IServiceScopeFactory scopeFactory, 19 | IOptions optionsAccessor) 20 | : base(loggerFactory) 21 | { 22 | _scopeFactory = scopeFactory; 23 | _options = optionsAccessor.Value; 24 | } 25 | 26 | protected override TimeSpan RevalidationInterval => TimeSpan.FromMinutes(30); 27 | 28 | protected override async Task ValidateAuthenticationStateAsync( 29 | AuthenticationState authenticationState, CancellationToken cancellationToken) 30 | { 31 | // Get the user manager from a new scope to ensure it fetches fresh data 32 | var scope = _scopeFactory.CreateScope(); 33 | try 34 | { 35 | var userManager = scope.ServiceProvider.GetRequiredService>(); 36 | return await ValidateSecurityStampAsync(userManager, authenticationState.User); 37 | } 38 | finally 39 | { 40 | if (scope is IAsyncDisposable asyncDisposable) 41 | { 42 | await asyncDisposable.DisposeAsync(); 43 | } 44 | else 45 | { 46 | scope.Dispose(); 47 | } 48 | } 49 | } 50 | 51 | private async Task ValidateSecurityStampAsync(UserManager userManager, ClaimsPrincipal principal) 52 | { 53 | var user = await userManager.GetUserAsync(principal); 54 | if (user == null) 55 | { 56 | return false; 57 | } 58 | else if (!userManager.SupportsUserSecurityStamp) 59 | { 60 | return true; 61 | } 62 | else 63 | { 64 | var principalStamp = principal.FindFirstValue(_options.ClaimsIdentity.SecurityStampClaimType); 65 | var userStamp = await userManager.GetSecurityStampAsync(user); 66 | return principalStamp == userStamp; 67 | } 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/BlazorInvoiceApp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | aspnet-BlazorInvoiceApp-8e925f58-da5d-47fd-9e7c-ff5ca569d2e8 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/BlazorInvoiceApp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34031.279 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorInvoiceApp", "BlazorInvoiceApp.csproj", "{04ECF5AC-129F-4728-B7E8-A1F49DEFAB6B}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorInvoiceAppTests", "..\BlazorInvoiceAppTests\BlazorInvoiceAppTests.csproj", "{58379BFD-86CE-4391-B65C-539EF0406048}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {04ECF5AC-129F-4728-B7E8-A1F49DEFAB6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {04ECF5AC-129F-4728-B7E8-A1F49DEFAB6B}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {04ECF5AC-129F-4728-B7E8-A1F49DEFAB6B}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {04ECF5AC-129F-4728-B7E8-A1F49DEFAB6B}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {58379BFD-86CE-4391-B65C-539EF0406048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {58379BFD-86CE-4391-B65C-539EF0406048}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {58379BFD-86CE-4391-B65C-539EF0406048}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {58379BFD-86CE-4391-B65C-539EF0406048}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {CF5A584D-06CA-435B-8FB3-686BB09CD309} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/DTOS/CustomerDTO.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.DTOS 2 | { 3 | public class CustomerDTO : IDTO, IOwnedDTO 4 | { 5 | public string Id { get; set; } = string.Empty; 6 | public string Name { get; set; } = String.Empty; 7 | public string UserId { get; set; } = null!; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/DTOS/IDTO.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.DTOS 2 | { 3 | public interface IDTO 4 | { 5 | public string Id { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/DTOS/IOwnedDTO.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.DTOS 2 | { 3 | public interface IOwnedDTO 4 | { 5 | public string UserId { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/DTOS/InvoiceDTO.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.DTOS 2 | { 3 | public class InvoiceDTO : IDTO, IOwnedDTO 4 | { 5 | public string Id { get; set; } = string.Empty; 6 | public DateTime CreateDate { get; set; } = DateTime.Now; 7 | public int InvoiceNumber { get; set; } 8 | public string Description { get; set; } = string.Empty; 9 | public string CustomerId { get; set; } = string.Empty; 10 | public string CustomerName { get; set; } = string.Empty; 11 | public string InvoiceTermsId { get; set; } = string.Empty; 12 | public string InvoiceTermsName { get; set; } = string.Empty; 13 | public double Paid { get; set; } = 0; 14 | public double Credit { get; set; } = 0; 15 | public double TaxRate { get; set; } = 0; 16 | public double InvoiceTotal { get; set; } = 0; 17 | public string UserId { get; set; } = null!; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/DTOS/InvoiceLineItemDTO.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.DTOS 2 | { 3 | public class InvoiceLineItemDTO : IDTO, IOwnedDTO 4 | { 5 | public string Id { get; set; } = Guid.NewGuid().ToString(); 6 | public string InvoiceId { get; set; } = String.Empty; 7 | public string Description { get; set; } = String.Empty; 8 | public double UnitPrice { get; set; } 9 | public double Quantity { get; set; } 10 | public string UserId { get; set; } = null!; 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/DTOS/InvoiceTermsDTO.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.DTOS 2 | { 3 | public class InvoiceTermsDTO : IDTO, IOwnedDTO 4 | { 5 | public string Id { get; set; } = string.Empty; 6 | public string Name { get; set; } = String.Empty; 7 | public string UserId { get; set; } = null!; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata; 4 | 5 | namespace BlazorInvoiceApp.Data 6 | { 7 | public class ApplicationDbContext : IdentityDbContext 8 | { 9 | public DbSet Invoices { get; set; } 10 | public DbSet Customers { get; set; } 11 | public DbSet InvoiceTerms { get; set; } 12 | public DbSet InvoicesLineItems { get; set; } 13 | 14 | 15 | public ApplicationDbContext(DbContextOptions options) 16 | : base(options) 17 | { 18 | 19 | 20 | } 21 | 22 | protected void RemoveFixups(ModelBuilder modelBuilder, Type type) 23 | { 24 | foreach (var relationship in modelBuilder.Model.FindEntityType(type)!.GetForeignKeys()) 25 | { 26 | relationship.DeleteBehavior = DeleteBehavior.ClientNoAction; 27 | } 28 | } 29 | 30 | protected override void OnModelCreating(ModelBuilder modelBuilder) 31 | { 32 | // customizations 33 | RemoveFixups(modelBuilder, typeof(Invoice)); 34 | RemoveFixups(modelBuilder, typeof(InvoiceTerms)); 35 | RemoveFixups(modelBuilder, typeof(Customer)); 36 | RemoveFixups(modelBuilder, typeof(InvoiceLineItem)); 37 | 38 | modelBuilder.Entity().Property(u => u.InvoiceNumber).Metadata.SetAfterSaveBehavior(PropertySaveBehavior.Ignore); 39 | 40 | modelBuilder.Entity() 41 | .Property(u => u.TotalPrice) 42 | .HasComputedColumnSql("[UnitPrice] * [Quantity]"); 43 | 44 | base.OnModelCreating(modelBuilder); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/Customer.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace BlazorInvoiceApp.Data 5 | { 6 | public class Customer : IEntity, IOwnedEntity 7 | { 8 | [DatabaseGenerated(DatabaseGeneratedOption.None)] 9 | public string Id { get; set; } = Guid.NewGuid().ToString(); 10 | 11 | public string UserId { get; set; } = null!; 12 | public IdentityUser? User { get; set; } = null!; 13 | 14 | 15 | public string Name { get; set; } = String.Empty; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/IEntity.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.Data 2 | { 3 | public interface IEntity 4 | { 5 | public string Id { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/IOwnedEntity.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.Data 2 | { 3 | public interface IOwnedEntity 4 | { 5 | public string UserId { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/Invoice.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace BlazorInvoiceApp.Data 5 | { 6 | public class Invoice : IEntity, IOwnedEntity 7 | { 8 | [DatabaseGenerated(DatabaseGeneratedOption.None)] 9 | public string Id { get; set; } = Guid.NewGuid().ToString(); 10 | 11 | public string UserId { get; set; } = null!; 12 | public IdentityUser? User { get; set; } = null!; 13 | 14 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 15 | public int InvoiceNumber { get; set; } 16 | 17 | public DateTime CreateDate { get; set; } = DateTime.Now; 18 | 19 | public string Description { get; set; } = String.Empty; 20 | 21 | public string CustomerId { get; set; } = String.Empty; 22 | public Customer? Customer { get; set; } = null!; 23 | 24 | public string InvoiceTermsId { get; set; } = String.Empty; 25 | public InvoiceTerms? InvoiceTerms { get; set; } = null!; 26 | 27 | public double Paid { get; set; } = 0; 28 | public double Credit { get; set; } = 0; 29 | 30 | public double TaxRate { get; set; } = 0; 31 | 32 | public ICollection InvoiceLineItems { get; set; } = new List(); 33 | 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/InvoiceLineItem.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace BlazorInvoiceApp.Data 5 | { 6 | public class InvoiceLineItem : IEntity, IOwnedEntity 7 | { 8 | [DatabaseGenerated(DatabaseGeneratedOption.None)] 9 | public string Id { get; set; } = Guid.NewGuid().ToString(); 10 | 11 | public string InvoiceId { get; set; } = String.Empty; 12 | public Invoice? Invoice { get; set; } = null!; 13 | 14 | public string Description { get; set; } = String.Empty; 15 | public double UnitPrice { get; set; } 16 | public double Quantity { get; set; } 17 | public double TotalPrice { get; private set; } 18 | 19 | public string UserId { get; set; } = null!; 20 | public IdentityUser? User { get; set; } = null!; 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/InvoiceTerms.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace BlazorInvoiceApp.Data 5 | { 6 | public class InvoiceTerms : IEntity, IOwnedEntity 7 | { 8 | [DatabaseGenerated(DatabaseGeneratedOption.None)] 9 | public string Id { get; set; } = Guid.NewGuid().ToString(); 10 | 11 | public string UserId { get; set; } = null!; 12 | public IdentityUser? User { get; set; } = null!; 13 | 14 | public string Name { get; set; } = String.Empty; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using BlazorInvoiceApp.Data; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Metadata; 6 | using Microsoft.EntityFrameworkCore.Migrations; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | using System; 9 | 10 | namespace BlazorInvoiceApp.Data.Migrations 11 | { 12 | [DbContext(typeof(ApplicationDbContext))] 13 | [Migration("00000000000000_CreateIdentitySchema")] 14 | partial class CreateIdentitySchema 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "3.0.0") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 25 | { 26 | b.Property("Id") 27 | .HasColumnType("nvarchar(450)"); 28 | 29 | b.Property("ConcurrencyStamp") 30 | .IsConcurrencyToken() 31 | .HasColumnType("nvarchar(max)"); 32 | 33 | b.Property("Name") 34 | .HasColumnType("nvarchar(256)") 35 | .HasMaxLength(256); 36 | 37 | b.Property("NormalizedName") 38 | .HasColumnType("nvarchar(256)") 39 | .HasMaxLength(256); 40 | 41 | b.HasKey("Id"); 42 | 43 | b.HasIndex("NormalizedName") 44 | .IsUnique() 45 | .HasName("RoleNameIndex") 46 | .HasFilter("[NormalizedName] IS NOT NULL"); 47 | 48 | b.ToTable("AspNetRoles"); 49 | }); 50 | 51 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 52 | { 53 | b.Property("Id") 54 | .ValueGeneratedOnAdd() 55 | .HasColumnType("int") 56 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 57 | 58 | b.Property("ClaimType") 59 | .HasColumnType("nvarchar(max)"); 60 | 61 | b.Property("ClaimValue") 62 | .HasColumnType("nvarchar(max)"); 63 | 64 | b.Property("RoleId") 65 | .IsRequired() 66 | .HasColumnType("nvarchar(450)"); 67 | 68 | b.HasKey("Id"); 69 | 70 | b.HasIndex("RoleId"); 71 | 72 | b.ToTable("AspNetRoleClaims"); 73 | }); 74 | 75 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => 76 | { 77 | b.Property("Id") 78 | .HasColumnType("nvarchar(450)"); 79 | 80 | b.Property("AccessFailedCount") 81 | .HasColumnType("int"); 82 | 83 | b.Property("ConcurrencyStamp") 84 | .IsConcurrencyToken() 85 | .HasColumnType("nvarchar(max)"); 86 | 87 | b.Property("Email") 88 | .HasColumnType("nvarchar(256)") 89 | .HasMaxLength(256); 90 | 91 | b.Property("EmailConfirmed") 92 | .HasColumnType("bit"); 93 | 94 | b.Property("LockoutEnabled") 95 | .HasColumnType("bit"); 96 | 97 | b.Property("LockoutEnd") 98 | .HasColumnType("datetimeoffset"); 99 | 100 | b.Property("NormalizedEmail") 101 | .HasColumnType("nvarchar(256)") 102 | .HasMaxLength(256); 103 | 104 | b.Property("NormalizedUserName") 105 | .HasColumnType("nvarchar(256)") 106 | .HasMaxLength(256); 107 | 108 | b.Property("PasswordHash") 109 | .HasColumnType("nvarchar(max)"); 110 | 111 | b.Property("PhoneNumber") 112 | .HasColumnType("nvarchar(max)"); 113 | 114 | b.Property("PhoneNumberConfirmed") 115 | .HasColumnType("bit"); 116 | 117 | b.Property("SecurityStamp") 118 | .HasColumnType("nvarchar(max)"); 119 | 120 | b.Property("TwoFactorEnabled") 121 | .HasColumnType("bit"); 122 | 123 | b.Property("UserName") 124 | .HasColumnType("nvarchar(256)") 125 | .HasMaxLength(256); 126 | 127 | b.HasKey("Id"); 128 | 129 | b.HasIndex("NormalizedEmail") 130 | .HasName("EmailIndex"); 131 | 132 | b.HasIndex("NormalizedUserName") 133 | .IsUnique() 134 | .HasName("UserNameIndex") 135 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 136 | 137 | b.ToTable("AspNetUsers"); 138 | }); 139 | 140 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 141 | { 142 | b.Property("Id") 143 | .ValueGeneratedOnAdd() 144 | .HasColumnType("int") 145 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 146 | 147 | b.Property("ClaimType") 148 | .HasColumnType("nvarchar(max)"); 149 | 150 | b.Property("ClaimValue") 151 | .HasColumnType("nvarchar(max)"); 152 | 153 | b.Property("UserId") 154 | .IsRequired() 155 | .HasColumnType("nvarchar(450)"); 156 | 157 | b.HasKey("Id"); 158 | 159 | b.HasIndex("UserId"); 160 | 161 | b.ToTable("AspNetUserClaims"); 162 | }); 163 | 164 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 165 | { 166 | b.Property("LoginProvider") 167 | .HasColumnType("nvarchar(128)") 168 | .HasMaxLength(128); 169 | 170 | b.Property("ProviderKey") 171 | .HasColumnType("nvarchar(128)") 172 | .HasMaxLength(128); 173 | 174 | b.Property("ProviderDisplayName") 175 | .HasColumnType("nvarchar(max)"); 176 | 177 | b.Property("UserId") 178 | .IsRequired() 179 | .HasColumnType("nvarchar(450)"); 180 | 181 | b.HasKey("LoginProvider", "ProviderKey"); 182 | 183 | b.HasIndex("UserId"); 184 | 185 | b.ToTable("AspNetUserLogins"); 186 | }); 187 | 188 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 189 | { 190 | b.Property("UserId") 191 | .HasColumnType("nvarchar(450)"); 192 | 193 | b.Property("RoleId") 194 | .HasColumnType("nvarchar(450)"); 195 | 196 | b.HasKey("UserId", "RoleId"); 197 | 198 | b.HasIndex("RoleId"); 199 | 200 | b.ToTable("AspNetUserRoles"); 201 | }); 202 | 203 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 204 | { 205 | b.Property("UserId") 206 | .HasColumnType("nvarchar(450)"); 207 | 208 | b.Property("LoginProvider") 209 | .HasColumnType("nvarchar(128)") 210 | .HasMaxLength(128); 211 | 212 | b.Property("Name") 213 | .HasColumnType("nvarchar(128)") 214 | .HasMaxLength(128); 215 | 216 | b.Property("Value") 217 | .HasColumnType("nvarchar(max)"); 218 | 219 | b.HasKey("UserId", "LoginProvider", "Name"); 220 | 221 | b.ToTable("AspNetUserTokens"); 222 | }); 223 | 224 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 225 | { 226 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 227 | .WithMany() 228 | .HasForeignKey("RoleId") 229 | .OnDelete(DeleteBehavior.Cascade) 230 | .IsRequired(); 231 | }); 232 | 233 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 234 | { 235 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 236 | .WithMany() 237 | .HasForeignKey("UserId") 238 | .OnDelete(DeleteBehavior.Cascade) 239 | .IsRequired(); 240 | }); 241 | 242 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 243 | { 244 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 245 | .WithMany() 246 | .HasForeignKey("UserId") 247 | .OnDelete(DeleteBehavior.Cascade) 248 | .IsRequired(); 249 | }); 250 | 251 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 252 | { 253 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 254 | .WithMany() 255 | .HasForeignKey("RoleId") 256 | .OnDelete(DeleteBehavior.Cascade) 257 | .IsRequired(); 258 | 259 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 260 | .WithMany() 261 | .HasForeignKey("UserId") 262 | .OnDelete(DeleteBehavior.Cascade) 263 | .IsRequired(); 264 | }); 265 | 266 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 267 | { 268 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 269 | .WithMany() 270 | .HasForeignKey("UserId") 271 | .OnDelete(DeleteBehavior.Cascade) 272 | .IsRequired(); 273 | }); 274 | #pragma warning restore 612, 618 275 | } 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/Migrations/00000000000000_CreateIdentitySchema.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | using System; 4 | 5 | namespace BlazorInvoiceApp.Data.Migrations 6 | { 7 | public partial class CreateIdentitySchema : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.CreateTable( 12 | name: "AspNetRoles", 13 | columns: table => new 14 | { 15 | Id = table.Column(nullable: false), 16 | Name = table.Column(maxLength: 256, nullable: true), 17 | NormalizedName = table.Column(maxLength: 256, nullable: true), 18 | ConcurrencyStamp = table.Column(nullable: true) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_AspNetRoles", x => x.Id); 23 | }); 24 | 25 | migrationBuilder.CreateTable( 26 | name: "AspNetUsers", 27 | columns: table => new 28 | { 29 | Id = table.Column(nullable: false), 30 | UserName = table.Column(maxLength: 256, nullable: true), 31 | NormalizedUserName = table.Column(maxLength: 256, nullable: true), 32 | Email = table.Column(maxLength: 256, nullable: true), 33 | NormalizedEmail = table.Column(maxLength: 256, nullable: true), 34 | EmailConfirmed = table.Column(nullable: false), 35 | PasswordHash = table.Column(nullable: true), 36 | SecurityStamp = table.Column(nullable: true), 37 | ConcurrencyStamp = table.Column(nullable: true), 38 | PhoneNumber = table.Column(nullable: true), 39 | PhoneNumberConfirmed = table.Column(nullable: false), 40 | TwoFactorEnabled = table.Column(nullable: false), 41 | LockoutEnd = table.Column(nullable: true), 42 | LockoutEnabled = table.Column(nullable: false), 43 | AccessFailedCount = table.Column(nullable: false) 44 | }, 45 | constraints: table => 46 | { 47 | table.PrimaryKey("PK_AspNetUsers", x => x.Id); 48 | }); 49 | 50 | migrationBuilder.CreateTable( 51 | name: "AspNetRoleClaims", 52 | columns: table => new 53 | { 54 | Id = table.Column(nullable: false) 55 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 56 | RoleId = table.Column(nullable: false), 57 | ClaimType = table.Column(nullable: true), 58 | ClaimValue = table.Column(nullable: true) 59 | }, 60 | constraints: table => 61 | { 62 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); 63 | table.ForeignKey( 64 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", 65 | column: x => x.RoleId, 66 | principalTable: "AspNetRoles", 67 | principalColumn: "Id", 68 | onDelete: ReferentialAction.Cascade); 69 | }); 70 | 71 | migrationBuilder.CreateTable( 72 | name: "AspNetUserClaims", 73 | columns: table => new 74 | { 75 | Id = table.Column(nullable: false) 76 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 77 | UserId = table.Column(nullable: false), 78 | ClaimType = table.Column(nullable: true), 79 | ClaimValue = table.Column(nullable: true) 80 | }, 81 | constraints: table => 82 | { 83 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); 84 | table.ForeignKey( 85 | name: "FK_AspNetUserClaims_AspNetUsers_UserId", 86 | column: x => x.UserId, 87 | principalTable: "AspNetUsers", 88 | principalColumn: "Id", 89 | onDelete: ReferentialAction.Cascade); 90 | }); 91 | 92 | migrationBuilder.CreateTable( 93 | name: "AspNetUserLogins", 94 | columns: table => new 95 | { 96 | LoginProvider = table.Column(maxLength: 128, nullable: false), 97 | ProviderKey = table.Column(maxLength: 128, nullable: false), 98 | ProviderDisplayName = table.Column(nullable: true), 99 | UserId = table.Column(nullable: false) 100 | }, 101 | constraints: table => 102 | { 103 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); 104 | table.ForeignKey( 105 | name: "FK_AspNetUserLogins_AspNetUsers_UserId", 106 | column: x => x.UserId, 107 | principalTable: "AspNetUsers", 108 | principalColumn: "Id", 109 | onDelete: ReferentialAction.Cascade); 110 | }); 111 | 112 | migrationBuilder.CreateTable( 113 | name: "AspNetUserRoles", 114 | columns: table => new 115 | { 116 | UserId = table.Column(nullable: false), 117 | RoleId = table.Column(nullable: false) 118 | }, 119 | constraints: table => 120 | { 121 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); 122 | table.ForeignKey( 123 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId", 124 | column: x => x.RoleId, 125 | principalTable: "AspNetRoles", 126 | principalColumn: "Id", 127 | onDelete: ReferentialAction.Cascade); 128 | table.ForeignKey( 129 | name: "FK_AspNetUserRoles_AspNetUsers_UserId", 130 | column: x => x.UserId, 131 | principalTable: "AspNetUsers", 132 | principalColumn: "Id", 133 | onDelete: ReferentialAction.Cascade); 134 | }); 135 | 136 | migrationBuilder.CreateTable( 137 | name: "AspNetUserTokens", 138 | columns: table => new 139 | { 140 | UserId = table.Column(nullable: false), 141 | LoginProvider = table.Column(maxLength: 128, nullable: false), 142 | Name = table.Column(maxLength: 128, nullable: false), 143 | Value = table.Column(nullable: true) 144 | }, 145 | constraints: table => 146 | { 147 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); 148 | table.ForeignKey( 149 | name: "FK_AspNetUserTokens_AspNetUsers_UserId", 150 | column: x => x.UserId, 151 | principalTable: "AspNetUsers", 152 | principalColumn: "Id", 153 | onDelete: ReferentialAction.Cascade); 154 | }); 155 | 156 | migrationBuilder.CreateIndex( 157 | name: "IX_AspNetRoleClaims_RoleId", 158 | table: "AspNetRoleClaims", 159 | column: "RoleId"); 160 | 161 | migrationBuilder.CreateIndex( 162 | name: "RoleNameIndex", 163 | table: "AspNetRoles", 164 | column: "NormalizedName", 165 | unique: true, 166 | filter: "[NormalizedName] IS NOT NULL"); 167 | 168 | migrationBuilder.CreateIndex( 169 | name: "IX_AspNetUserClaims_UserId", 170 | table: "AspNetUserClaims", 171 | column: "UserId"); 172 | 173 | migrationBuilder.CreateIndex( 174 | name: "IX_AspNetUserLogins_UserId", 175 | table: "AspNetUserLogins", 176 | column: "UserId"); 177 | 178 | migrationBuilder.CreateIndex( 179 | name: "IX_AspNetUserRoles_RoleId", 180 | table: "AspNetUserRoles", 181 | column: "RoleId"); 182 | 183 | migrationBuilder.CreateIndex( 184 | name: "EmailIndex", 185 | table: "AspNetUsers", 186 | column: "NormalizedEmail"); 187 | 188 | migrationBuilder.CreateIndex( 189 | name: "UserNameIndex", 190 | table: "AspNetUsers", 191 | column: "NormalizedUserName", 192 | unique: true, 193 | filter: "[NormalizedUserName] IS NOT NULL"); 194 | } 195 | 196 | protected override void Down(MigrationBuilder migrationBuilder) 197 | { 198 | migrationBuilder.DropTable( 199 | name: "AspNetRoleClaims"); 200 | 201 | migrationBuilder.DropTable( 202 | name: "AspNetUserClaims"); 203 | 204 | migrationBuilder.DropTable( 205 | name: "AspNetUserLogins"); 206 | 207 | migrationBuilder.DropTable( 208 | name: "AspNetUserRoles"); 209 | 210 | migrationBuilder.DropTable( 211 | name: "AspNetUserTokens"); 212 | 213 | migrationBuilder.DropTable( 214 | name: "AspNetRoles"); 215 | 216 | migrationBuilder.DropTable( 217 | name: "AspNetUsers"); 218 | } 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/Migrations/20230926013249_db1.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using BlazorInvoiceApp.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace BlazorInvoiceApp.Data.Migrations 13 | { 14 | [DbContext(typeof(ApplicationDbContext))] 15 | [Migration("20230926013249_db1")] 16 | partial class db1 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "7.0.11") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 25 | 26 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("BlazorInvoiceApp.Data.Customer", b => 29 | { 30 | b.Property("Id") 31 | .HasColumnType("nvarchar(450)"); 32 | 33 | b.Property("Name") 34 | .IsRequired() 35 | .HasColumnType("nvarchar(max)"); 36 | 37 | b.Property("UserId") 38 | .IsRequired() 39 | .HasColumnType("nvarchar(450)"); 40 | 41 | b.HasKey("Id"); 42 | 43 | b.HasIndex("UserId"); 44 | 45 | b.ToTable("Customers"); 46 | }); 47 | 48 | modelBuilder.Entity("BlazorInvoiceApp.Data.Invoice", b => 49 | { 50 | b.Property("Id") 51 | .HasColumnType("nvarchar(450)"); 52 | 53 | b.Property("CreateDate") 54 | .HasColumnType("datetime2"); 55 | 56 | b.Property("Credit") 57 | .HasColumnType("float"); 58 | 59 | b.Property("CustomerId") 60 | .IsRequired() 61 | .HasColumnType("nvarchar(450)"); 62 | 63 | b.Property("Description") 64 | .IsRequired() 65 | .HasColumnType("nvarchar(max)"); 66 | 67 | b.Property("InvoiceNumber") 68 | .ValueGeneratedOnAdd() 69 | .HasColumnType("int"); 70 | 71 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("InvoiceNumber")); 72 | 73 | b.Property("InvoiceTermsId") 74 | .IsRequired() 75 | .HasColumnType("nvarchar(450)"); 76 | 77 | b.Property("Paid") 78 | .HasColumnType("float"); 79 | 80 | b.Property("TaxRate") 81 | .HasColumnType("float"); 82 | 83 | b.Property("UserId") 84 | .IsRequired() 85 | .HasColumnType("nvarchar(450)"); 86 | 87 | b.HasKey("Id"); 88 | 89 | b.HasIndex("CustomerId"); 90 | 91 | b.HasIndex("InvoiceTermsId"); 92 | 93 | b.HasIndex("UserId"); 94 | 95 | b.ToTable("Invoices"); 96 | }); 97 | 98 | modelBuilder.Entity("BlazorInvoiceApp.Data.InvoiceLineItem", b => 99 | { 100 | b.Property("Id") 101 | .HasColumnType("nvarchar(450)"); 102 | 103 | b.Property("Description") 104 | .IsRequired() 105 | .HasColumnType("nvarchar(max)"); 106 | 107 | b.Property("InvoiceId") 108 | .IsRequired() 109 | .HasColumnType("nvarchar(450)"); 110 | 111 | b.Property("Quantity") 112 | .HasColumnType("float"); 113 | 114 | b.Property("TotalPrice") 115 | .ValueGeneratedOnAddOrUpdate() 116 | .HasColumnType("float") 117 | .HasComputedColumnSql("[UnitPrice] * [Quantity]"); 118 | 119 | b.Property("UnitPrice") 120 | .HasColumnType("float"); 121 | 122 | b.Property("UserId") 123 | .IsRequired() 124 | .HasColumnType("nvarchar(450)"); 125 | 126 | b.HasKey("Id"); 127 | 128 | b.HasIndex("InvoiceId"); 129 | 130 | b.HasIndex("UserId"); 131 | 132 | b.ToTable("InvoicesLineItems"); 133 | }); 134 | 135 | modelBuilder.Entity("BlazorInvoiceApp.Data.InvoiceTerms", b => 136 | { 137 | b.Property("Id") 138 | .HasColumnType("nvarchar(450)"); 139 | 140 | b.Property("Name") 141 | .IsRequired() 142 | .HasColumnType("nvarchar(max)"); 143 | 144 | b.Property("UserId") 145 | .IsRequired() 146 | .HasColumnType("nvarchar(450)"); 147 | 148 | b.HasKey("Id"); 149 | 150 | b.HasIndex("UserId"); 151 | 152 | b.ToTable("InvoiceTerms"); 153 | }); 154 | 155 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 156 | { 157 | b.Property("Id") 158 | .HasColumnType("nvarchar(450)"); 159 | 160 | b.Property("ConcurrencyStamp") 161 | .IsConcurrencyToken() 162 | .HasColumnType("nvarchar(max)"); 163 | 164 | b.Property("Name") 165 | .HasMaxLength(256) 166 | .HasColumnType("nvarchar(256)"); 167 | 168 | b.Property("NormalizedName") 169 | .HasMaxLength(256) 170 | .HasColumnType("nvarchar(256)"); 171 | 172 | b.HasKey("Id"); 173 | 174 | b.HasIndex("NormalizedName") 175 | .IsUnique() 176 | .HasDatabaseName("RoleNameIndex") 177 | .HasFilter("[NormalizedName] IS NOT NULL"); 178 | 179 | b.ToTable("AspNetRoles", (string)null); 180 | }); 181 | 182 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 183 | { 184 | b.Property("Id") 185 | .ValueGeneratedOnAdd() 186 | .HasColumnType("int"); 187 | 188 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 189 | 190 | b.Property("ClaimType") 191 | .HasColumnType("nvarchar(max)"); 192 | 193 | b.Property("ClaimValue") 194 | .HasColumnType("nvarchar(max)"); 195 | 196 | b.Property("RoleId") 197 | .IsRequired() 198 | .HasColumnType("nvarchar(450)"); 199 | 200 | b.HasKey("Id"); 201 | 202 | b.HasIndex("RoleId"); 203 | 204 | b.ToTable("AspNetRoleClaims", (string)null); 205 | }); 206 | 207 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => 208 | { 209 | b.Property("Id") 210 | .HasColumnType("nvarchar(450)"); 211 | 212 | b.Property("AccessFailedCount") 213 | .HasColumnType("int"); 214 | 215 | b.Property("ConcurrencyStamp") 216 | .IsConcurrencyToken() 217 | .HasColumnType("nvarchar(max)"); 218 | 219 | b.Property("Email") 220 | .HasMaxLength(256) 221 | .HasColumnType("nvarchar(256)"); 222 | 223 | b.Property("EmailConfirmed") 224 | .HasColumnType("bit"); 225 | 226 | b.Property("LockoutEnabled") 227 | .HasColumnType("bit"); 228 | 229 | b.Property("LockoutEnd") 230 | .HasColumnType("datetimeoffset"); 231 | 232 | b.Property("NormalizedEmail") 233 | .HasMaxLength(256) 234 | .HasColumnType("nvarchar(256)"); 235 | 236 | b.Property("NormalizedUserName") 237 | .HasMaxLength(256) 238 | .HasColumnType("nvarchar(256)"); 239 | 240 | b.Property("PasswordHash") 241 | .HasColumnType("nvarchar(max)"); 242 | 243 | b.Property("PhoneNumber") 244 | .HasColumnType("nvarchar(max)"); 245 | 246 | b.Property("PhoneNumberConfirmed") 247 | .HasColumnType("bit"); 248 | 249 | b.Property("SecurityStamp") 250 | .HasColumnType("nvarchar(max)"); 251 | 252 | b.Property("TwoFactorEnabled") 253 | .HasColumnType("bit"); 254 | 255 | b.Property("UserName") 256 | .HasMaxLength(256) 257 | .HasColumnType("nvarchar(256)"); 258 | 259 | b.HasKey("Id"); 260 | 261 | b.HasIndex("NormalizedEmail") 262 | .HasDatabaseName("EmailIndex"); 263 | 264 | b.HasIndex("NormalizedUserName") 265 | .IsUnique() 266 | .HasDatabaseName("UserNameIndex") 267 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 268 | 269 | b.ToTable("AspNetUsers", (string)null); 270 | }); 271 | 272 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 273 | { 274 | b.Property("Id") 275 | .ValueGeneratedOnAdd() 276 | .HasColumnType("int"); 277 | 278 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 279 | 280 | b.Property("ClaimType") 281 | .HasColumnType("nvarchar(max)"); 282 | 283 | b.Property("ClaimValue") 284 | .HasColumnType("nvarchar(max)"); 285 | 286 | b.Property("UserId") 287 | .IsRequired() 288 | .HasColumnType("nvarchar(450)"); 289 | 290 | b.HasKey("Id"); 291 | 292 | b.HasIndex("UserId"); 293 | 294 | b.ToTable("AspNetUserClaims", (string)null); 295 | }); 296 | 297 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 298 | { 299 | b.Property("LoginProvider") 300 | .HasMaxLength(128) 301 | .HasColumnType("nvarchar(128)"); 302 | 303 | b.Property("ProviderKey") 304 | .HasMaxLength(128) 305 | .HasColumnType("nvarchar(128)"); 306 | 307 | b.Property("ProviderDisplayName") 308 | .HasColumnType("nvarchar(max)"); 309 | 310 | b.Property("UserId") 311 | .IsRequired() 312 | .HasColumnType("nvarchar(450)"); 313 | 314 | b.HasKey("LoginProvider", "ProviderKey"); 315 | 316 | b.HasIndex("UserId"); 317 | 318 | b.ToTable("AspNetUserLogins", (string)null); 319 | }); 320 | 321 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 322 | { 323 | b.Property("UserId") 324 | .HasColumnType("nvarchar(450)"); 325 | 326 | b.Property("RoleId") 327 | .HasColumnType("nvarchar(450)"); 328 | 329 | b.HasKey("UserId", "RoleId"); 330 | 331 | b.HasIndex("RoleId"); 332 | 333 | b.ToTable("AspNetUserRoles", (string)null); 334 | }); 335 | 336 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 337 | { 338 | b.Property("UserId") 339 | .HasColumnType("nvarchar(450)"); 340 | 341 | b.Property("LoginProvider") 342 | .HasMaxLength(128) 343 | .HasColumnType("nvarchar(128)"); 344 | 345 | b.Property("Name") 346 | .HasMaxLength(128) 347 | .HasColumnType("nvarchar(128)"); 348 | 349 | b.Property("Value") 350 | .HasColumnType("nvarchar(max)"); 351 | 352 | b.HasKey("UserId", "LoginProvider", "Name"); 353 | 354 | b.ToTable("AspNetUserTokens", (string)null); 355 | }); 356 | 357 | modelBuilder.Entity("BlazorInvoiceApp.Data.Customer", b => 358 | { 359 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") 360 | .WithMany() 361 | .HasForeignKey("UserId") 362 | .OnDelete(DeleteBehavior.ClientNoAction) 363 | .IsRequired(); 364 | 365 | b.Navigation("User"); 366 | }); 367 | 368 | modelBuilder.Entity("BlazorInvoiceApp.Data.Invoice", b => 369 | { 370 | b.HasOne("BlazorInvoiceApp.Data.Customer", "Customer") 371 | .WithMany() 372 | .HasForeignKey("CustomerId") 373 | .OnDelete(DeleteBehavior.ClientNoAction) 374 | .IsRequired(); 375 | 376 | b.HasOne("BlazorInvoiceApp.Data.InvoiceTerms", "InvoiceTerms") 377 | .WithMany() 378 | .HasForeignKey("InvoiceTermsId") 379 | .OnDelete(DeleteBehavior.ClientNoAction) 380 | .IsRequired(); 381 | 382 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") 383 | .WithMany() 384 | .HasForeignKey("UserId") 385 | .OnDelete(DeleteBehavior.ClientNoAction) 386 | .IsRequired(); 387 | 388 | b.Navigation("Customer"); 389 | 390 | b.Navigation("InvoiceTerms"); 391 | 392 | b.Navigation("User"); 393 | }); 394 | 395 | modelBuilder.Entity("BlazorInvoiceApp.Data.InvoiceLineItem", b => 396 | { 397 | b.HasOne("BlazorInvoiceApp.Data.Invoice", "Invoice") 398 | .WithMany("InvoiceLineItems") 399 | .HasForeignKey("InvoiceId") 400 | .OnDelete(DeleteBehavior.ClientNoAction) 401 | .IsRequired(); 402 | 403 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") 404 | .WithMany() 405 | .HasForeignKey("UserId") 406 | .OnDelete(DeleteBehavior.ClientNoAction) 407 | .IsRequired(); 408 | 409 | b.Navigation("Invoice"); 410 | 411 | b.Navigation("User"); 412 | }); 413 | 414 | modelBuilder.Entity("BlazorInvoiceApp.Data.InvoiceTerms", b => 415 | { 416 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") 417 | .WithMany() 418 | .HasForeignKey("UserId") 419 | .OnDelete(DeleteBehavior.ClientNoAction) 420 | .IsRequired(); 421 | 422 | b.Navigation("User"); 423 | }); 424 | 425 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 426 | { 427 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 428 | .WithMany() 429 | .HasForeignKey("RoleId") 430 | .OnDelete(DeleteBehavior.Cascade) 431 | .IsRequired(); 432 | }); 433 | 434 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 435 | { 436 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 437 | .WithMany() 438 | .HasForeignKey("UserId") 439 | .OnDelete(DeleteBehavior.Cascade) 440 | .IsRequired(); 441 | }); 442 | 443 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 444 | { 445 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 446 | .WithMany() 447 | .HasForeignKey("UserId") 448 | .OnDelete(DeleteBehavior.Cascade) 449 | .IsRequired(); 450 | }); 451 | 452 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 453 | { 454 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 455 | .WithMany() 456 | .HasForeignKey("RoleId") 457 | .OnDelete(DeleteBehavior.Cascade) 458 | .IsRequired(); 459 | 460 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 461 | .WithMany() 462 | .HasForeignKey("UserId") 463 | .OnDelete(DeleteBehavior.Cascade) 464 | .IsRequired(); 465 | }); 466 | 467 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 468 | { 469 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 470 | .WithMany() 471 | .HasForeignKey("UserId") 472 | .OnDelete(DeleteBehavior.Cascade) 473 | .IsRequired(); 474 | }); 475 | 476 | modelBuilder.Entity("BlazorInvoiceApp.Data.Invoice", b => 477 | { 478 | b.Navigation("InvoiceLineItems"); 479 | }); 480 | #pragma warning restore 612, 618 481 | } 482 | } 483 | } 484 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/Migrations/20230926013249_db1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace BlazorInvoiceApp.Data.Migrations 7 | { 8 | /// 9 | public partial class db1 : Migration 10 | { 11 | /// 12 | protected override void Up(MigrationBuilder migrationBuilder) 13 | { 14 | migrationBuilder.CreateTable( 15 | name: "Customers", 16 | columns: table => new 17 | { 18 | Id = table.Column(type: "nvarchar(450)", nullable: false), 19 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 20 | Name = table.Column(type: "nvarchar(max)", nullable: false) 21 | }, 22 | constraints: table => 23 | { 24 | table.PrimaryKey("PK_Customers", x => x.Id); 25 | table.ForeignKey( 26 | name: "FK_Customers_AspNetUsers_UserId", 27 | column: x => x.UserId, 28 | principalTable: "AspNetUsers", 29 | principalColumn: "Id"); 30 | }); 31 | 32 | migrationBuilder.CreateTable( 33 | name: "InvoiceTerms", 34 | columns: table => new 35 | { 36 | Id = table.Column(type: "nvarchar(450)", nullable: false), 37 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 38 | Name = table.Column(type: "nvarchar(max)", nullable: false) 39 | }, 40 | constraints: table => 41 | { 42 | table.PrimaryKey("PK_InvoiceTerms", x => x.Id); 43 | table.ForeignKey( 44 | name: "FK_InvoiceTerms_AspNetUsers_UserId", 45 | column: x => x.UserId, 46 | principalTable: "AspNetUsers", 47 | principalColumn: "Id"); 48 | }); 49 | 50 | migrationBuilder.CreateTable( 51 | name: "Invoices", 52 | columns: table => new 53 | { 54 | Id = table.Column(type: "nvarchar(450)", nullable: false), 55 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 56 | InvoiceNumber = table.Column(type: "int", nullable: false) 57 | .Annotation("SqlServer:Identity", "1, 1"), 58 | CreateDate = table.Column(type: "datetime2", nullable: false), 59 | Description = table.Column(type: "nvarchar(max)", nullable: false), 60 | CustomerId = table.Column(type: "nvarchar(450)", nullable: false), 61 | InvoiceTermsId = table.Column(type: "nvarchar(450)", nullable: false), 62 | Paid = table.Column(type: "float", nullable: false), 63 | Credit = table.Column(type: "float", nullable: false), 64 | TaxRate = table.Column(type: "float", nullable: false) 65 | }, 66 | constraints: table => 67 | { 68 | table.PrimaryKey("PK_Invoices", x => x.Id); 69 | table.ForeignKey( 70 | name: "FK_Invoices_AspNetUsers_UserId", 71 | column: x => x.UserId, 72 | principalTable: "AspNetUsers", 73 | principalColumn: "Id"); 74 | table.ForeignKey( 75 | name: "FK_Invoices_Customers_CustomerId", 76 | column: x => x.CustomerId, 77 | principalTable: "Customers", 78 | principalColumn: "Id"); 79 | table.ForeignKey( 80 | name: "FK_Invoices_InvoiceTerms_InvoiceTermsId", 81 | column: x => x.InvoiceTermsId, 82 | principalTable: "InvoiceTerms", 83 | principalColumn: "Id"); 84 | }); 85 | 86 | migrationBuilder.CreateTable( 87 | name: "InvoicesLineItems", 88 | columns: table => new 89 | { 90 | Id = table.Column(type: "nvarchar(450)", nullable: false), 91 | InvoiceId = table.Column(type: "nvarchar(450)", nullable: false), 92 | Description = table.Column(type: "nvarchar(max)", nullable: false), 93 | UnitPrice = table.Column(type: "float", nullable: false), 94 | Quantity = table.Column(type: "float", nullable: false), 95 | TotalPrice = table.Column(type: "float", nullable: false, computedColumnSql: "[UnitPrice] * [Quantity]"), 96 | UserId = table.Column(type: "nvarchar(450)", nullable: false) 97 | }, 98 | constraints: table => 99 | { 100 | table.PrimaryKey("PK_InvoicesLineItems", x => x.Id); 101 | table.ForeignKey( 102 | name: "FK_InvoicesLineItems_AspNetUsers_UserId", 103 | column: x => x.UserId, 104 | principalTable: "AspNetUsers", 105 | principalColumn: "Id"); 106 | table.ForeignKey( 107 | name: "FK_InvoicesLineItems_Invoices_InvoiceId", 108 | column: x => x.InvoiceId, 109 | principalTable: "Invoices", 110 | principalColumn: "Id"); 111 | }); 112 | 113 | migrationBuilder.CreateIndex( 114 | name: "IX_Customers_UserId", 115 | table: "Customers", 116 | column: "UserId"); 117 | 118 | migrationBuilder.CreateIndex( 119 | name: "IX_Invoices_CustomerId", 120 | table: "Invoices", 121 | column: "CustomerId"); 122 | 123 | migrationBuilder.CreateIndex( 124 | name: "IX_Invoices_InvoiceTermsId", 125 | table: "Invoices", 126 | column: "InvoiceTermsId"); 127 | 128 | migrationBuilder.CreateIndex( 129 | name: "IX_Invoices_UserId", 130 | table: "Invoices", 131 | column: "UserId"); 132 | 133 | migrationBuilder.CreateIndex( 134 | name: "IX_InvoicesLineItems_InvoiceId", 135 | table: "InvoicesLineItems", 136 | column: "InvoiceId"); 137 | 138 | migrationBuilder.CreateIndex( 139 | name: "IX_InvoicesLineItems_UserId", 140 | table: "InvoicesLineItems", 141 | column: "UserId"); 142 | 143 | migrationBuilder.CreateIndex( 144 | name: "IX_InvoiceTerms_UserId", 145 | table: "InvoiceTerms", 146 | column: "UserId"); 147 | } 148 | 149 | /// 150 | protected override void Down(MigrationBuilder migrationBuilder) 151 | { 152 | migrationBuilder.DropTable( 153 | name: "InvoicesLineItems"); 154 | 155 | migrationBuilder.DropTable( 156 | name: "Invoices"); 157 | 158 | migrationBuilder.DropTable( 159 | name: "Customers"); 160 | 161 | migrationBuilder.DropTable( 162 | name: "InvoiceTerms"); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Data/Migrations/ApplicationDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using BlazorInvoiceApp.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | #nullable disable 10 | 11 | namespace BlazorInvoiceApp.Data.Migrations 12 | { 13 | [DbContext(typeof(ApplicationDbContext))] 14 | partial class ApplicationDbContextModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "7.0.11") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 22 | 23 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 24 | 25 | modelBuilder.Entity("BlazorInvoiceApp.Data.Customer", b => 26 | { 27 | b.Property("Id") 28 | .HasColumnType("nvarchar(450)"); 29 | 30 | b.Property("Name") 31 | .IsRequired() 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("UserId") 35 | .IsRequired() 36 | .HasColumnType("nvarchar(450)"); 37 | 38 | b.HasKey("Id"); 39 | 40 | b.HasIndex("UserId"); 41 | 42 | b.ToTable("Customers"); 43 | }); 44 | 45 | modelBuilder.Entity("BlazorInvoiceApp.Data.Invoice", b => 46 | { 47 | b.Property("Id") 48 | .HasColumnType("nvarchar(450)"); 49 | 50 | b.Property("CreateDate") 51 | .HasColumnType("datetime2"); 52 | 53 | b.Property("Credit") 54 | .HasColumnType("float"); 55 | 56 | b.Property("CustomerId") 57 | .IsRequired() 58 | .HasColumnType("nvarchar(450)"); 59 | 60 | b.Property("Description") 61 | .IsRequired() 62 | .HasColumnType("nvarchar(max)"); 63 | 64 | b.Property("InvoiceNumber") 65 | .ValueGeneratedOnAdd() 66 | .HasColumnType("int"); 67 | 68 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("InvoiceNumber")); 69 | 70 | b.Property("InvoiceTermsId") 71 | .IsRequired() 72 | .HasColumnType("nvarchar(450)"); 73 | 74 | b.Property("Paid") 75 | .HasColumnType("float"); 76 | 77 | b.Property("TaxRate") 78 | .HasColumnType("float"); 79 | 80 | b.Property("UserId") 81 | .IsRequired() 82 | .HasColumnType("nvarchar(450)"); 83 | 84 | b.HasKey("Id"); 85 | 86 | b.HasIndex("CustomerId"); 87 | 88 | b.HasIndex("InvoiceTermsId"); 89 | 90 | b.HasIndex("UserId"); 91 | 92 | b.ToTable("Invoices"); 93 | }); 94 | 95 | modelBuilder.Entity("BlazorInvoiceApp.Data.InvoiceLineItem", b => 96 | { 97 | b.Property("Id") 98 | .HasColumnType("nvarchar(450)"); 99 | 100 | b.Property("Description") 101 | .IsRequired() 102 | .HasColumnType("nvarchar(max)"); 103 | 104 | b.Property("InvoiceId") 105 | .IsRequired() 106 | .HasColumnType("nvarchar(450)"); 107 | 108 | b.Property("Quantity") 109 | .HasColumnType("float"); 110 | 111 | b.Property("TotalPrice") 112 | .ValueGeneratedOnAddOrUpdate() 113 | .HasColumnType("float") 114 | .HasComputedColumnSql("[UnitPrice] * [Quantity]"); 115 | 116 | b.Property("UnitPrice") 117 | .HasColumnType("float"); 118 | 119 | b.Property("UserId") 120 | .IsRequired() 121 | .HasColumnType("nvarchar(450)"); 122 | 123 | b.HasKey("Id"); 124 | 125 | b.HasIndex("InvoiceId"); 126 | 127 | b.HasIndex("UserId"); 128 | 129 | b.ToTable("InvoicesLineItems"); 130 | }); 131 | 132 | modelBuilder.Entity("BlazorInvoiceApp.Data.InvoiceTerms", b => 133 | { 134 | b.Property("Id") 135 | .HasColumnType("nvarchar(450)"); 136 | 137 | b.Property("Name") 138 | .IsRequired() 139 | .HasColumnType("nvarchar(max)"); 140 | 141 | b.Property("UserId") 142 | .IsRequired() 143 | .HasColumnType("nvarchar(450)"); 144 | 145 | b.HasKey("Id"); 146 | 147 | b.HasIndex("UserId"); 148 | 149 | b.ToTable("InvoiceTerms"); 150 | }); 151 | 152 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 153 | { 154 | b.Property("Id") 155 | .HasColumnType("nvarchar(450)"); 156 | 157 | b.Property("ConcurrencyStamp") 158 | .IsConcurrencyToken() 159 | .HasColumnType("nvarchar(max)"); 160 | 161 | b.Property("Name") 162 | .HasMaxLength(256) 163 | .HasColumnType("nvarchar(256)"); 164 | 165 | b.Property("NormalizedName") 166 | .HasMaxLength(256) 167 | .HasColumnType("nvarchar(256)"); 168 | 169 | b.HasKey("Id"); 170 | 171 | b.HasIndex("NormalizedName") 172 | .IsUnique() 173 | .HasDatabaseName("RoleNameIndex") 174 | .HasFilter("[NormalizedName] IS NOT NULL"); 175 | 176 | b.ToTable("AspNetRoles", (string)null); 177 | }); 178 | 179 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 180 | { 181 | b.Property("Id") 182 | .ValueGeneratedOnAdd() 183 | .HasColumnType("int"); 184 | 185 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 186 | 187 | b.Property("ClaimType") 188 | .HasColumnType("nvarchar(max)"); 189 | 190 | b.Property("ClaimValue") 191 | .HasColumnType("nvarchar(max)"); 192 | 193 | b.Property("RoleId") 194 | .IsRequired() 195 | .HasColumnType("nvarchar(450)"); 196 | 197 | b.HasKey("Id"); 198 | 199 | b.HasIndex("RoleId"); 200 | 201 | b.ToTable("AspNetRoleClaims", (string)null); 202 | }); 203 | 204 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => 205 | { 206 | b.Property("Id") 207 | .HasColumnType("nvarchar(450)"); 208 | 209 | b.Property("AccessFailedCount") 210 | .HasColumnType("int"); 211 | 212 | b.Property("ConcurrencyStamp") 213 | .IsConcurrencyToken() 214 | .HasColumnType("nvarchar(max)"); 215 | 216 | b.Property("Email") 217 | .HasMaxLength(256) 218 | .HasColumnType("nvarchar(256)"); 219 | 220 | b.Property("EmailConfirmed") 221 | .HasColumnType("bit"); 222 | 223 | b.Property("LockoutEnabled") 224 | .HasColumnType("bit"); 225 | 226 | b.Property("LockoutEnd") 227 | .HasColumnType("datetimeoffset"); 228 | 229 | b.Property("NormalizedEmail") 230 | .HasMaxLength(256) 231 | .HasColumnType("nvarchar(256)"); 232 | 233 | b.Property("NormalizedUserName") 234 | .HasMaxLength(256) 235 | .HasColumnType("nvarchar(256)"); 236 | 237 | b.Property("PasswordHash") 238 | .HasColumnType("nvarchar(max)"); 239 | 240 | b.Property("PhoneNumber") 241 | .HasColumnType("nvarchar(max)"); 242 | 243 | b.Property("PhoneNumberConfirmed") 244 | .HasColumnType("bit"); 245 | 246 | b.Property("SecurityStamp") 247 | .HasColumnType("nvarchar(max)"); 248 | 249 | b.Property("TwoFactorEnabled") 250 | .HasColumnType("bit"); 251 | 252 | b.Property("UserName") 253 | .HasMaxLength(256) 254 | .HasColumnType("nvarchar(256)"); 255 | 256 | b.HasKey("Id"); 257 | 258 | b.HasIndex("NormalizedEmail") 259 | .HasDatabaseName("EmailIndex"); 260 | 261 | b.HasIndex("NormalizedUserName") 262 | .IsUnique() 263 | .HasDatabaseName("UserNameIndex") 264 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 265 | 266 | b.ToTable("AspNetUsers", (string)null); 267 | }); 268 | 269 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 270 | { 271 | b.Property("Id") 272 | .ValueGeneratedOnAdd() 273 | .HasColumnType("int"); 274 | 275 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 276 | 277 | b.Property("ClaimType") 278 | .HasColumnType("nvarchar(max)"); 279 | 280 | b.Property("ClaimValue") 281 | .HasColumnType("nvarchar(max)"); 282 | 283 | b.Property("UserId") 284 | .IsRequired() 285 | .HasColumnType("nvarchar(450)"); 286 | 287 | b.HasKey("Id"); 288 | 289 | b.HasIndex("UserId"); 290 | 291 | b.ToTable("AspNetUserClaims", (string)null); 292 | }); 293 | 294 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 295 | { 296 | b.Property("LoginProvider") 297 | .HasMaxLength(128) 298 | .HasColumnType("nvarchar(128)"); 299 | 300 | b.Property("ProviderKey") 301 | .HasMaxLength(128) 302 | .HasColumnType("nvarchar(128)"); 303 | 304 | b.Property("ProviderDisplayName") 305 | .HasColumnType("nvarchar(max)"); 306 | 307 | b.Property("UserId") 308 | .IsRequired() 309 | .HasColumnType("nvarchar(450)"); 310 | 311 | b.HasKey("LoginProvider", "ProviderKey"); 312 | 313 | b.HasIndex("UserId"); 314 | 315 | b.ToTable("AspNetUserLogins", (string)null); 316 | }); 317 | 318 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 319 | { 320 | b.Property("UserId") 321 | .HasColumnType("nvarchar(450)"); 322 | 323 | b.Property("RoleId") 324 | .HasColumnType("nvarchar(450)"); 325 | 326 | b.HasKey("UserId", "RoleId"); 327 | 328 | b.HasIndex("RoleId"); 329 | 330 | b.ToTable("AspNetUserRoles", (string)null); 331 | }); 332 | 333 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 334 | { 335 | b.Property("UserId") 336 | .HasColumnType("nvarchar(450)"); 337 | 338 | b.Property("LoginProvider") 339 | .HasMaxLength(128) 340 | .HasColumnType("nvarchar(128)"); 341 | 342 | b.Property("Name") 343 | .HasMaxLength(128) 344 | .HasColumnType("nvarchar(128)"); 345 | 346 | b.Property("Value") 347 | .HasColumnType("nvarchar(max)"); 348 | 349 | b.HasKey("UserId", "LoginProvider", "Name"); 350 | 351 | b.ToTable("AspNetUserTokens", (string)null); 352 | }); 353 | 354 | modelBuilder.Entity("BlazorInvoiceApp.Data.Customer", b => 355 | { 356 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") 357 | .WithMany() 358 | .HasForeignKey("UserId") 359 | .OnDelete(DeleteBehavior.ClientNoAction) 360 | .IsRequired(); 361 | 362 | b.Navigation("User"); 363 | }); 364 | 365 | modelBuilder.Entity("BlazorInvoiceApp.Data.Invoice", b => 366 | { 367 | b.HasOne("BlazorInvoiceApp.Data.Customer", "Customer") 368 | .WithMany() 369 | .HasForeignKey("CustomerId") 370 | .OnDelete(DeleteBehavior.ClientNoAction) 371 | .IsRequired(); 372 | 373 | b.HasOne("BlazorInvoiceApp.Data.InvoiceTerms", "InvoiceTerms") 374 | .WithMany() 375 | .HasForeignKey("InvoiceTermsId") 376 | .OnDelete(DeleteBehavior.ClientNoAction) 377 | .IsRequired(); 378 | 379 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") 380 | .WithMany() 381 | .HasForeignKey("UserId") 382 | .OnDelete(DeleteBehavior.ClientNoAction) 383 | .IsRequired(); 384 | 385 | b.Navigation("Customer"); 386 | 387 | b.Navigation("InvoiceTerms"); 388 | 389 | b.Navigation("User"); 390 | }); 391 | 392 | modelBuilder.Entity("BlazorInvoiceApp.Data.InvoiceLineItem", b => 393 | { 394 | b.HasOne("BlazorInvoiceApp.Data.Invoice", "Invoice") 395 | .WithMany("InvoiceLineItems") 396 | .HasForeignKey("InvoiceId") 397 | .OnDelete(DeleteBehavior.ClientNoAction) 398 | .IsRequired(); 399 | 400 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") 401 | .WithMany() 402 | .HasForeignKey("UserId") 403 | .OnDelete(DeleteBehavior.ClientNoAction) 404 | .IsRequired(); 405 | 406 | b.Navigation("Invoice"); 407 | 408 | b.Navigation("User"); 409 | }); 410 | 411 | modelBuilder.Entity("BlazorInvoiceApp.Data.InvoiceTerms", b => 412 | { 413 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", "User") 414 | .WithMany() 415 | .HasForeignKey("UserId") 416 | .OnDelete(DeleteBehavior.ClientNoAction) 417 | .IsRequired(); 418 | 419 | b.Navigation("User"); 420 | }); 421 | 422 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 423 | { 424 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 425 | .WithMany() 426 | .HasForeignKey("RoleId") 427 | .OnDelete(DeleteBehavior.Cascade) 428 | .IsRequired(); 429 | }); 430 | 431 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 432 | { 433 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 434 | .WithMany() 435 | .HasForeignKey("UserId") 436 | .OnDelete(DeleteBehavior.Cascade) 437 | .IsRequired(); 438 | }); 439 | 440 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 441 | { 442 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 443 | .WithMany() 444 | .HasForeignKey("UserId") 445 | .OnDelete(DeleteBehavior.Cascade) 446 | .IsRequired(); 447 | }); 448 | 449 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 450 | { 451 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 452 | .WithMany() 453 | .HasForeignKey("RoleId") 454 | .OnDelete(DeleteBehavior.Cascade) 455 | .IsRequired(); 456 | 457 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 458 | .WithMany() 459 | .HasForeignKey("UserId") 460 | .OnDelete(DeleteBehavior.Cascade) 461 | .IsRequired(); 462 | }); 463 | 464 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 465 | { 466 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) 467 | .WithMany() 468 | .HasForeignKey("UserId") 469 | .OnDelete(DeleteBehavior.Cascade) 470 | .IsRequired(); 471 | }); 472 | 473 | modelBuilder.Entity("BlazorInvoiceApp.Data.Invoice", b => 474 | { 475 | b.Navigation("InvoiceLineItems"); 476 | }); 477 | #pragma warning restore 612, 618 478 | } 479 | } 480 | } 481 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/Components/CustomerSetupComponent.razor: -------------------------------------------------------------------------------- 1 | @inject IRepositoryCollection repo 2 | @inject AuthenticationStateProvider authstate 3 | 4 |

Customers

5 | 6 | 7 |
@Message
8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
39 |
40 | 41 | @code { 42 | 43 | List customers = new(); 44 | RadzenDataGrid? customersGrid; 45 | 46 | string Message = string.Empty; 47 | CustomerDTO? customerToInsert; 48 | CustomerDTO? customerToUpdate; 49 | 50 | protected override async Task OnInitializedAsync() 51 | { 52 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 53 | await repo.Customer.Seed(auth.User); 54 | await repo.Save(); 55 | customers = await repo.Customer.GetAllMine(auth.User); 56 | } 57 | 58 | async Task EditRow(CustomerDTO customer) 59 | { 60 | Message = ""; 61 | customerToUpdate = customer; 62 | await customersGrid!.EditRow(customer); 63 | } 64 | 65 | async Task OnUpdateRow(CustomerDTO customer) 66 | { 67 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 68 | Reset(); 69 | await repo.Customer.UpdateMine(auth.User, customer); 70 | await repo.Save(); 71 | } 72 | 73 | async Task SaveRow(CustomerDTO customer) 74 | { 75 | Message = ""; 76 | await customersGrid!.UpdateRow(customer); 77 | } 78 | 79 | void CancelEdit(CustomerDTO customer) 80 | { 81 | Reset(); 82 | customersGrid!.CancelEditRow(customer); 83 | } 84 | 85 | async Task DeleteRow(CustomerDTO customer) 86 | { 87 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 88 | Reset(); 89 | try 90 | { 91 | bool found = await repo.Customer.DeleteMine(auth.User, customer.Id); 92 | if (found) 93 | { 94 | await repo.Save(); 95 | await repo.Customer.Seed(auth.User); 96 | await repo.Save(); 97 | 98 | this.customers = await repo.Customer.GetAllMine(auth.User); 99 | await customersGrid!.Reload(); 100 | } 101 | else 102 | { 103 | customersGrid!.CancelEditRow(customer); 104 | await customersGrid!.Reload(); 105 | } 106 | } 107 | catch (RepositoryDeleteException) 108 | { 109 | // can't delete because would break integrity! 110 | Message = "Can't delete selected Customer, it is being used by an invoice."; 111 | } 112 | } 113 | 114 | async Task InsertRow() 115 | { 116 | Message = ""; 117 | customerToInsert = new CustomerDTO(); 118 | await customersGrid!.InsertRow(customerToInsert); 119 | } 120 | 121 | async Task OnCreateRow(CustomerDTO customer) 122 | { 123 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 124 | customer.Id = await repo.Customer.AddMine(auth.User, customer); 125 | await repo.Save(); 126 | this.customers = await repo.Customer.GetAllMine(auth.User); 127 | customerToInsert = null; 128 | } 129 | 130 | void Reset() 131 | { 132 | Message = ""; 133 | customerToInsert = null; 134 | customerToUpdate = null; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/Components/InvoiceDetailComponent.razor: -------------------------------------------------------------------------------- 1 | @inject IRepositoryCollection repo 2 | @inject NavigationManager navManager 3 | @inject DialogService DialogService 4 | @inject AuthenticationStateProvider authstate 5 |
@Message
6 |
7 | 8 |
9 | @invoice.InvoiceNumber 10 |
11 |
12 |
13 | 14 |
15 | 16 |
17 |
18 |
19 | 20 |
21 | 22 |
23 |
24 |
25 | 26 |
27 | 28 |
29 |
30 |
31 | 32 |
33 | 34 |
35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 |
43 | 44 |
45 | 46 |
47 |
48 |
49 | 50 |
51 | 52 |
53 |
54 | 55 | 56 |

Line Items:

57 | 58 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 83 | 84 | 85 | 86 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 |

Total: @string.Format("{0:c}",InvoiceTotal)

105 |

Tax: @string.Format("{0:c}",InvoiceTax)

106 |

Total with Tax: @string.Format("{0:c}",InvoiceTotalWithTax)

107 |

Amount Due: @string.Format("{0:c}",AmountDue)

108 | 109 |
110 |
111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | @code { 119 | [Parameter] 120 | public string Id { get; set; } = String.Empty; 121 | 122 | List customers = new(); 123 | List terms = new(); 124 | InvoiceDTO invoice = new(); 125 | List lineitems = new(); 126 | RadzenDataGrid? lineitemsGrid; 127 | InvoiceLineItemDTO? lineitemToInsert; 128 | InvoiceLineItemDTO? lineitemToUpdate; 129 | 130 | double InvoiceTotal = 0; 131 | double InvoiceTax = 0; 132 | double InvoiceTotalWithTax = 0; 133 | double AmountDue = 0; 134 | 135 | string Message = string.Empty; 136 | 137 | bool savedisabled = true; 138 | 139 | public void OnChange() 140 | { 141 | savedisabled = false; 142 | } 143 | 144 | async Task DeleteInvoice() 145 | { 146 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 147 | bool? result = await DialogService.Confirm("Are you sure?", "Remove Invoice", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" }); ; 148 | if (result == true) 149 | { 150 | await repo.Invoice.DeleteWithLineItems(auth.User, Id); 151 | await repo.Save(); 152 | navManager.NavigateTo("/"); 153 | } 154 | } 155 | 156 | 157 | public async Task OnSaveChanges() 158 | { 159 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 160 | await repo.Invoice.UpdateMine(auth.User, invoice); 161 | await repo.Save(); 162 | UpdateTotals(); 163 | } 164 | 165 | protected override async Task OnInitializedAsync() 166 | { 167 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 168 | customers = await repo.Customer.GetAllMine(auth.User); 169 | terms = await repo.InvoiceTerms.GetAllMine(auth.User); 170 | invoice = await repo.Invoice.GetMineById(auth.User, Id); 171 | lineitems = await repo.InvoiceLineItem.GetAllByInvoiceId(auth.User, Id); 172 | UpdateTotals(); 173 | } 174 | 175 | public void UpdateTotals() 176 | { 177 | InvoiceTotal = 0; 178 | foreach (InvoiceLineItemDTO line in lineitems) 179 | { 180 | InvoiceTotal = InvoiceTotal + line.UnitPrice * line.Quantity; 181 | } 182 | InvoiceTax = InvoiceTotal * invoice.TaxRate / 100; 183 | InvoiceTotalWithTax = InvoiceTotal + InvoiceTax; 184 | AmountDue = InvoiceTotalWithTax - invoice.Paid - invoice.Credit; 185 | 186 | } 187 | 188 | 189 | void Reset() 190 | { 191 | Message = ""; 192 | lineitemToInsert = null; 193 | lineitemToUpdate = null; 194 | } 195 | 196 | async Task EditRow(InvoiceLineItemDTO lineitem) 197 | { 198 | Message = ""; 199 | lineitemToUpdate = lineitem; 200 | await lineitemsGrid!.EditRow(lineitem); 201 | } 202 | 203 | async Task OnUpdateRow(InvoiceLineItemDTO lineitem) 204 | { 205 | Reset(); 206 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 207 | await repo.InvoiceLineItem.UpdateMine(auth.User, lineitem); 208 | await repo.Save(); 209 | UpdateTotals(); 210 | } 211 | 212 | async Task SaveRow(InvoiceLineItemDTO lineitem) 213 | { 214 | await lineitemsGrid!.UpdateRow(lineitem); 215 | } 216 | void CancelEdit(InvoiceLineItemDTO lineitem) 217 | { 218 | Reset(); 219 | 220 | lineitemsGrid!.CancelEditRow(lineitem); 221 | 222 | } 223 | 224 | async Task DeleteRow(InvoiceLineItemDTO lineitem) 225 | { 226 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 227 | Reset(); 228 | try 229 | { 230 | bool found = await repo.InvoiceLineItem.DeleteMine(auth.User, lineitem.Id); 231 | if (found) 232 | { 233 | await repo.Save(); 234 | this.lineitems = await repo.InvoiceLineItem.GetAllMine(auth.User); 235 | await lineitemsGrid!.Reload(); 236 | } 237 | else 238 | { 239 | lineitemsGrid!.CancelEditRow(lineitem); 240 | await lineitemsGrid!.Reload(); 241 | } 242 | } 243 | catch (RepositoryDeleteException) 244 | { 245 | // can't delete because would break integrity! 246 | Message = "Can't delete selected Line Item, it is being used by an invoice."; 247 | } 248 | UpdateTotals(); 249 | 250 | } 251 | 252 | 253 | async Task InsertRow() 254 | { 255 | Message = ""; 256 | lineitemToInsert = new InvoiceLineItemDTO(); 257 | await lineitemsGrid!.InsertRow(lineitemToInsert); 258 | 259 | } 260 | 261 | async Task OnCreateRow(InvoiceLineItemDTO lineitem) 262 | { 263 | Reset(); 264 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 265 | lineitem.InvoiceId = Id; 266 | lineitem.Id = await repo.InvoiceLineItem.AddMine(auth.User, lineitem); 267 | await repo.Save(); 268 | this.lineitems = await repo.InvoiceLineItem.GetAllByInvoiceId(auth.User, Id); 269 | UpdateTotals(); 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/Components/InvoiceTermsSetupComponent.razor: -------------------------------------------------------------------------------- 1 | @inject IRepositoryCollection repo 2 | @inject AuthenticationStateProvider authstate 3 | 4 |

Invoice Terms

5 | 6 | 7 | 8 |
@Message
9 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
39 |
40 | 41 | 42 | @code { 43 | List terms = new(); 44 | RadzenDataGrid? termsGrid; 45 | 46 | 47 | InvoiceTermsDTO? termsToInsert; 48 | InvoiceTermsDTO? termsToUpdate; 49 | 50 | string Message = string.Empty; 51 | 52 | protected override async Task OnInitializedAsync() 53 | { 54 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 55 | await repo.InvoiceTerms.Seed(auth.User); 56 | await repo.Save(); 57 | terms = await repo.InvoiceTerms.GetAllMine(auth.User); 58 | } 59 | 60 | void Reset() 61 | { 62 | Message = ""; 63 | termsToInsert = null; 64 | termsToUpdate = null; 65 | } 66 | 67 | async Task EditRow(InvoiceTermsDTO terms) 68 | { 69 | Message = ""; 70 | termsToUpdate = terms; 71 | await termsGrid!.EditRow(terms); 72 | } 73 | 74 | async Task OnUpdateRow(InvoiceTermsDTO terms) 75 | { 76 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 77 | Reset(); 78 | await repo.InvoiceTerms.UpdateMine(auth.User, terms); 79 | await repo.Save(); 80 | } 81 | 82 | async Task SaveRow(InvoiceTermsDTO terms) 83 | { 84 | await termsGrid!.UpdateRow(terms); 85 | } 86 | 87 | void CancelEdit(InvoiceTermsDTO terms) 88 | { 89 | Reset(); 90 | termsGrid!.CancelEditRow(terms); 91 | } 92 | 93 | async Task DeleteRow(InvoiceTermsDTO terms) 94 | { 95 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 96 | Reset(); 97 | try 98 | { 99 | bool found = await repo.InvoiceTerms.DeleteMine(auth.User, terms.Id); 100 | if (found) 101 | { 102 | await repo.Save(); 103 | await repo.InvoiceTerms.Seed(auth.User); 104 | await repo.Save(); 105 | this.terms = await repo.InvoiceTerms.GetAllMine(auth.User); 106 | await termsGrid!.Reload(); 107 | } 108 | else 109 | { 110 | termsGrid!.CancelEditRow(terms); 111 | await termsGrid!.Reload(); 112 | } 113 | } 114 | catch (RepositoryDeleteException) 115 | { 116 | // can't delete because would break integrity! 117 | Message = "Can't delete selected Invoice Terms, it is being used by an invoice."; 118 | } 119 | } 120 | 121 | async Task InsertRow() 122 | { 123 | Message = ""; 124 | termsToInsert = new InvoiceTermsDTO(); 125 | await termsGrid!.InsertRow(termsToInsert); 126 | } 127 | 128 | async Task OnCreateRow(InvoiceTermsDTO terms) 129 | { 130 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 131 | terms.Id = await repo.InvoiceTerms.AddMine(auth.User, terms); 132 | await repo.Save(); 133 | this.terms = await repo.InvoiceTerms.GetAllMine(auth.User); 134 | termsToInsert = null; 135 | } 136 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/Components/InvoicesComponent.razor: -------------------------------------------------------------------------------- 1 | @inject IRepositoryCollection repo 2 | @inject NavigationManager nav 3 | @inject AuthenticationStateProvider authstate 4 |
@Message
5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 22 | 23 | 24 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 39 | 40 | 41 | 42 | 43 | 46 | 47 | 48 | 51 | 52 | 53 | 54 | 55 | 56 | @code { 57 | 58 | List invoices = new(); 59 | List customers = new(); 60 | List invoiceterms = new(); 61 | RadzenDataGrid? invoicesGrid; 62 | 63 | string Message = string.Empty; 64 | string dropdownvalue = string.Empty; 65 | 66 | IEnumerable? selectedCustomerNames; 67 | List customernames = new List(); 68 | void OnSelectedCustomerNameChange(object value) 69 | { 70 | if (selectedCustomerNames != null && !selectedCustomerNames.Any()) 71 | { 72 | selectedCustomerNames = null; 73 | } 74 | } 75 | 76 | IEnumerable? selectedInvoiceTerms; 77 | List invoicetermsvalues = new List(); 78 | void OnSelectedInvoiceTermsChange(object value) 79 | { 80 | if (selectedInvoiceTerms != null && !selectedInvoiceTerms.Any()) 81 | { 82 | selectedInvoiceTerms = null; 83 | } 84 | } 85 | 86 | protected override async Task OnInitializedAsync() 87 | { 88 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 89 | 90 | await repo.Customer.Seed(auth.User); 91 | await repo.InvoiceTerms.Seed(auth.User); 92 | await repo.Save(); 93 | 94 | customers = await repo.Customer.GetAllMine(auth.User); 95 | foreach (CustomerDTO c in customers) 96 | customernames.Add(c.Name!); 97 | 98 | invoiceterms = await repo.InvoiceTerms.GetAllMine(auth.User); 99 | foreach (InvoiceTermsDTO i in invoiceterms) 100 | invoicetermsvalues.Add(i.Name); 101 | 102 | if (customers.Count > 0) 103 | dropdownvalue = customers[0].Id; 104 | invoices = await repo.Invoice.GetAllMineFlat(auth.User); 105 | 106 | } 107 | 108 | 109 | public void OpenInvoice(string Id) 110 | { 111 | nav.NavigateTo("/invoicedetail/" + Id); 112 | } 113 | 114 | public async Task AddInvoice() 115 | { 116 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 117 | // create an invoice and redirect to it 118 | List terms = await repo.InvoiceTerms.GetAllMine(auth.User); 119 | string id = await repo.Invoice.AddMine(auth.User, new InvoiceDTO 120 | { 121 | Description = "New Invoice", 122 | CreateDate = DateTime.Now, 123 | Credit = 0, 124 | Paid = 0, 125 | CustomerId = dropdownvalue, 126 | TaxRate = 0, 127 | InvoiceTermsId = terms[0].Id 128 | }); 129 | await repo.Save(); 130 | nav.NavigateTo("/invoicedetail/" + id); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/CustomerSetup.razor: -------------------------------------------------------------------------------- 1 | @page "/customersetup" 2 | 3 | Customers Setup 4 | 5 | 6 | 7 | 8 | 9 | Please log in to see your customers. 10 | 11 | 12 | 13 | @code { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/EntityTest.razor: -------------------------------------------------------------------------------- 1 | @page "/entitytest" 2 | @using System.Security.Claims; 3 | @inject AuthenticationStateProvider authstate 4 | @inject IDbContextFactory dbFactory 5 |

EntityTest

6 | 7 | @if (invoices != null) 8 | { 9 |
    10 | @foreach (Invoice i in invoices) 11 | { 12 |
  • 13 |
      14 |
    • Id: @i.Id
    • 15 |
    • Invoice Number: @i.InvoiceNumber
    • 16 |
    • Customer Id: @i.CustomerId
    • 17 |
    • Customer Name: @i.Customer?.Name
    • 18 |
    • Invoice Terms Id: @i.InvoiceTermsId
    • 19 |
    • Invoice Terms Id: @i.InvoiceTerms?.Name
    • 20 |
    • Paid Amount: @i.Paid
    • 21 |
    • Credit Amount: @i.Credit
    • 22 |
    • Tax Rate: @i.TaxRate
    • 23 | @foreach (InvoiceLineItem ili in i.InvoiceLineItems) 24 | { 25 |
    • 26 | Line Item: 27 |
        28 |
      • Id: @ili.Id
      • 29 |
      • Description: @ili.Description
      • 30 |
      • Unit Price: @ili.UnitPrice
      • 31 |
      • Quantity: @ili.Quantity
      • 32 |
      • Total Price: @ili.TotalPrice
      • 33 |
      34 |
    • 35 | } 36 |
    37 |
  • 38 | } 39 |
40 | } 41 | 42 | 43 | 44 | @code { 45 | 46 | private List? invoices = null; 47 | 48 | protected override async Task OnInitializedAsync() 49 | { 50 | AuthenticationState auth = await authstate.GetAuthenticationStateAsync(); 51 | Claim? uid = 52 | auth.User?.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"); 53 | if (uid is not null) 54 | { 55 | var context = await dbFactory.CreateDbContextAsync(); 56 | string userid = uid.Value; 57 | 58 | // DELETE (clear out the tables) 59 | var customers_to_delete 60 | = await context.Customers.Where(c => c.UserId == userid).ToListAsync(); 61 | foreach (Customer c in customers_to_delete) 62 | context.Customers.Remove(c); 63 | 64 | var invoiceterms_to_delete 65 | = await context.InvoiceTerms.Where(it => it.UserId == userid).ToListAsync(); 66 | foreach (InvoiceTerms it in invoiceterms_to_delete) 67 | context.InvoiceTerms.Remove(it); 68 | 69 | var invoicelineitems_to_delete 70 | = await context.InvoicesLineItems.Where(ili => ili.UserId == userid).ToListAsync(); 71 | foreach (InvoiceLineItem ili in invoicelineitems_to_delete) 72 | context.InvoicesLineItems.Remove(ili); 73 | 74 | var invoices_to_delete 75 | = await context.Invoices.Where(i => i.UserId == userid).ToListAsync(); 76 | foreach (Invoice i in invoices_to_delete) 77 | context.Invoices.Remove(i); 78 | await context.SaveChangesAsync(); 79 | 80 | 81 | Customer c1 = new Customer() 82 | { 83 | UserId = userid, 84 | Name = "Customer 1" 85 | }; 86 | Customer c2 = new Customer() 87 | { 88 | UserId = userid, 89 | Name = "Customer 2" 90 | }; 91 | Customer c3 = new Customer() 92 | { 93 | UserId = userid, 94 | Name = "Customer 3" 95 | }; 96 | context.Customers.Add(c1); 97 | context.Customers.Add(c2); 98 | context.Customers.Add(c3); 99 | 100 | 101 | InvoiceTerms terms1 = new InvoiceTerms() 102 | { 103 | UserId = userid, 104 | Name = "Net 45" 105 | }; 106 | context.InvoiceTerms.Add(terms1); 107 | 108 | 109 | Invoice i1 = new Invoice() 110 | { 111 | InvoiceTermsId = terms1.Id, 112 | UserId = userid, 113 | Credit = 0.0, 114 | CustomerId = c1.Id, 115 | Paid = 0.0, 116 | Description = "First Invoice", 117 | TaxRate = 5.0, 118 | }; 119 | Invoice i2 = new Invoice() 120 | { 121 | InvoiceTermsId = terms1.Id, 122 | UserId = userid, 123 | Credit = 0.0, 124 | CustomerId = c2.Id, 125 | Paid = 0.0, 126 | Description = "Second Invoice", 127 | TaxRate = 5.0 128 | }; 129 | 130 | Invoice i3 = new Invoice() 131 | { 132 | InvoiceTermsId = terms1.Id, 133 | UserId = userid, 134 | Credit = 0.0, 135 | CustomerId = c2.Id, 136 | Paid = 0.0, 137 | Description = "Third Invoice", 138 | TaxRate = 5.0 139 | }; 140 | context.Invoices.Add(i1); 141 | context.Invoices.Add(i2); 142 | context.Invoices.Add(i3); 143 | 144 | 145 | InvoiceLineItem ili1 = new InvoiceLineItem() 146 | { 147 | InvoiceId = i1.Id, 148 | UserId = userid, 149 | Quantity = 4, 150 | Description = "Computers", 151 | UnitPrice = 555 152 | }; 153 | InvoiceLineItem ili2 = new InvoiceLineItem() 154 | { 155 | InvoiceId = i1.Id, 156 | UserId = userid, 157 | Quantity = 2, 158 | Description = "Printers", 159 | UnitPrice = 250, 160 | }; 161 | InvoiceLineItem ili3 = new InvoiceLineItem() 162 | { 163 | InvoiceId = i2.Id, 164 | UserId = userid, 165 | Quantity = 12, 166 | Description = "Apples", 167 | UnitPrice = 0.79 168 | }; 169 | InvoiceLineItem ili4 = new InvoiceLineItem() 170 | { 171 | InvoiceId = i2.Id, 172 | UserId = userid, 173 | Quantity = 5, 174 | Description = "Oranges", 175 | UnitPrice = 1.25 176 | }; 177 | 178 | InvoiceLineItem ili5 = new InvoiceLineItem() 179 | { 180 | InvoiceId = i3.Id, 181 | UserId = userid, 182 | Quantity = 20, 183 | Description = "Stapler", 184 | UnitPrice = 12.95 185 | }; 186 | 187 | context.InvoicesLineItems.Add(ili1); 188 | context.InvoicesLineItems.Add(ili2); 189 | context.InvoicesLineItems.Add(ili3); 190 | context.InvoicesLineItems.Add(ili4); 191 | context.InvoicesLineItems.Add(ili5); 192 | await context.SaveChangesAsync(); 193 | 194 | // change all of invoices for customer 2, adjust the tax rate 195 | List customer2invoices = 196 | await context.Invoices.Where(i => i.CustomerId == c2.Id).ToListAsync(); 197 | 198 | foreach (Invoice i in customer2invoices) 199 | { 200 | i.TaxRate = 10; 201 | } 202 | await context.SaveChangesAsync(); 203 | 204 | Customer? customer_to_change = 205 | await context.Customers.Where(c => c.Name == "Customer 2").FirstOrDefaultAsync(); 206 | if (customer_to_change is not null) 207 | { 208 | customer_to_change.Name = "Test Customer 2"; 209 | await context.SaveChangesAsync(); 210 | } 211 | 212 | invoices = 213 | await context.Invoices.Where(i => i.CustomerId == c2.Id) 214 | .Include("Customer").Include("InvoiceTerms").Include("InvoiceLineItems") 215 | .ToListAsync(); 216 | 217 | 218 | 219 | } 220 | } 221 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model BlazorInvoiceApp.Pages.ErrorModel 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Error 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |

Error.

19 |

An error occurred while processing your request.

20 | 21 | @if (Model.ShowRequestId) 22 | { 23 |

24 | Request ID: @Model.RequestId 25 |

26 | } 27 | 28 |

Development Mode

29 |

30 | Swapping to the Development environment displays detailed information about the error that occurred. 31 |

32 |

33 | The Development environment shouldn't be enabled for deployed applications. 34 | It can result in displaying sensitive information from exceptions to end users. 35 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 36 | and restarting the app. 37 |

38 |
39 |
40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.AspNetCore.Mvc.RazorPages; 3 | using System.Diagnostics; 4 | 5 | namespace BlazorInvoiceApp.Pages 6 | { 7 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 8 | [IgnoreAntiforgeryToken] 9 | public class ErrorModel : PageModel 10 | { 11 | public string? RequestId { get; set; } 12 | 13 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 14 | 15 | private readonly ILogger _logger; 16 | 17 | public ErrorModel(ILogger logger) 18 | { 19 | _logger = logger; 20 | } 21 | 22 | public void OnGet() 23 | { 24 | RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | 3 | @inject IRepositoryCollection repo 4 | @inject AuthenticationStateProvider authstate 5 | 6 | My Page 7 | 8 |

Invoices

9 | Invoices 10 | 11 | 12 | 13 | 14 | 15 | Please log in to see your invoices. 16 | 17 | 18 | 19 | @code { 20 | 21 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/InvoiceDetail.razor: -------------------------------------------------------------------------------- 1 | @page "/invoicedetail/{id}" 2 |

InvoiceDetail

3 | 4 | @code { 5 | [Parameter] 6 | public string? id { get; set; } 7 | } 8 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/InvoiceTermsSetup.razor: -------------------------------------------------------------------------------- 1 | @page "/invoicetermssetup" 2 | Invoice Terms Setup 3 | 4 | 5 | 6 | 7 | 8 | Please log in to see your invoice terms. 9 | 10 | 11 | @code { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Pages/_Host.cshtml: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @using Microsoft.AspNetCore.Components.Web 3 | @namespace BlazorInvoiceApp.Pages 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | An error has occurred. This application may no longer respond until reloaded. 25 | 26 | 27 | An unhandled exception has occurred. See browser dev tools for details. 28 | 29 | Reload 30 | 🗙 31 |
32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Program.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Areas.Identity; 3 | using BlazorInvoiceApp.Data; 4 | using BlazorInvoiceApp.Repository; 5 | using Microsoft.AspNetCore.Components; 6 | using Microsoft.AspNetCore.Components.Authorization; 7 | using Microsoft.AspNetCore.Components.Web; 8 | using Microsoft.AspNetCore.Identity; 9 | using Microsoft.AspNetCore.Identity.UI; 10 | using Microsoft.EntityFrameworkCore; 11 | using Radzen; 12 | 13 | namespace BlazorInvoiceApp 14 | { 15 | public class Program 16 | { 17 | public static void Main(string[] args) 18 | { 19 | var builder = WebApplication.CreateBuilder(args); 20 | 21 | // Add services to the container. 22 | var connectionString 23 | = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); 24 | builder.Services.AddDbContextFactory(options => 25 | options.UseSqlServer(connectionString), ServiceLifetime.Transient); 26 | builder.Services.AddDatabaseDeveloperPageExceptionFilter(); 27 | builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) 28 | .AddEntityFrameworkStores(); 29 | builder.Services.AddRazorPages(); 30 | builder.Services.AddServerSideBlazor(); 31 | builder.Services.AddScoped>(); 32 | builder.Services.AddScoped(); 33 | builder.Services.AddTransient(); 34 | 35 | var mapperConfig = new MapperConfiguration(mc => 36 | { 37 | mc.AddProfile(new AutoMapperProfile()); 38 | }); 39 | 40 | IMapper mapper = mapperConfig.CreateMapper(); 41 | builder.Services.AddSingleton(mapper); 42 | 43 | 44 | 45 | var app = builder.Build(); 46 | 47 | // Configure the HTTP request pipeline. 48 | if (app.Environment.IsDevelopment()) 49 | { 50 | app.UseMigrationsEndPoint(); 51 | } 52 | else 53 | { 54 | app.UseExceptionHandler("/Error"); 55 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. 56 | app.UseHsts(); 57 | } 58 | 59 | app.UseHttpsRedirection(); 60 | 61 | app.UseStaticFiles(); 62 | 63 | app.UseRouting(); 64 | 65 | app.UseAuthorization(); 66 | 67 | app.MapControllers(); 68 | app.MapBlazorHub(); 69 | app.MapFallbackToPage("/_Host"); 70 | 71 | app.Run(); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:30156", 7 | "sslPort": 44342 8 | } 9 | }, 10 | "profiles": { 11 | "http": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "applicationUrl": "http://localhost:5143", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "https": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": true, 23 | "launchBrowser": true, 24 | "applicationUrl": "https://localhost:7202;http://localhost:5143", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | }, 29 | "IIS Express": { 30 | "commandName": "IISExpress", 31 | "launchBrowser": true, 32 | "environmentVariables": { 33 | "ASPNETCORE_ENVIRONMENT": "Development" 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Properties/serviceDependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Properties/serviceDependencies.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql.local", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/AutoMapperProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Data; 3 | using BlazorInvoiceApp.DTOS; 4 | 5 | 6 | namespace BlazorInvoiceApp.Repository 7 | { 8 | public class AutoMapperProfile : Profile 9 | { 10 | public AutoMapperProfile() { 11 | CreateMap(); 12 | CreateMap() 13 | .ForMember(dest => dest.Id, opt => opt.Ignore()); 14 | CreateMap(); 15 | CreateMap() 16 | .ForMember(dest => dest.Id, opt => opt.Ignore()); 17 | CreateMap(); 18 | CreateMap() 19 | .ForMember(dest => dest.Id, opt => opt.Ignore()); 20 | CreateMap() 21 | .ForMember(dest => dest.CustomerName, opt => opt.MapFrom(src => src.Customer!.Name)) 22 | .ForMember(dest => dest.InvoiceTermsName, opt => opt.MapFrom(src => src.InvoiceTerms!.Name)); 23 | CreateMap() 24 | .ForMember(dest => dest.Id, opt => opt.Ignore()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/CustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Data; 3 | using BlazorInvoiceApp.DTOS; 4 | using Microsoft.EntityFrameworkCore; 5 | using System.Security.Claims; 6 | 7 | namespace BlazorInvoiceApp.Repository 8 | { 9 | public class CustomerRepository : GenericOwnedRepository, ICustomerRepository 10 | { 11 | public CustomerRepository(ApplicationDbContext context, IMapper mapper) 12 | : base(context, mapper) { } 13 | 14 | public async Task Seed(ClaimsPrincipal User) 15 | { 16 | string? userid = getMyUserId(User); 17 | if (userid is not null) 18 | { 19 | int count = await context.Customers.Where(c => c.UserId == userid).CountAsync(); 20 | if (count == 0) 21 | { 22 | // seed some data. 23 | CustomerDTO defaultCustomer = new CustomerDTO 24 | { 25 | Name = "My First Customer" 26 | }; 27 | await AddMine(User, defaultCustomer); 28 | } 29 | } 30 | return; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/GenericOwnedRepository.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Data; 3 | using BlazorInvoiceApp.DTOS; 4 | using Microsoft.EntityFrameworkCore; 5 | using System.Linq.Expressions; 6 | using System.Linq; 7 | using System.Security.Claims; 8 | 9 | namespace BlazorInvoiceApp.Repository 10 | { 11 | public class GenericOwnedRepository : IGenericOwnedRepository 12 | where TEntity : class, IEntity, IOwnedEntity 13 | where TDTO : class, IDTO, IOwnedDTO 14 | { 15 | public readonly ApplicationDbContext context; 16 | public readonly IMapper mapper; 17 | public GenericOwnedRepository(ApplicationDbContext context, IMapper mapper) 18 | { 19 | this.context = context; 20 | this.mapper = mapper; 21 | } 22 | 23 | 24 | protected string? getMyUserId(ClaimsPrincipal User) 25 | { 26 | Claim? uid = User?.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"); 27 | if (uid is not null) 28 | return uid.Value; 29 | else 30 | return null; 31 | } 32 | public virtual async Task> GetAllMine(ClaimsPrincipal User) 33 | { 34 | string? userid = getMyUserId(User); 35 | if (userid is not null) 36 | { 37 | List entities = 38 | await context.Set().Where(e => e.UserId == userid).ToListAsync(); 39 | List result = mapper.Map>(entities); 40 | return result; 41 | } 42 | else 43 | { 44 | return new List(); 45 | } 46 | } 47 | 48 | public virtual async Task GetMineById(ClaimsPrincipal User, string id) 49 | { 50 | string? userid = getMyUserId(User); 51 | if (userid is not null) 52 | { 53 | TEntity? entity = await 54 | context.Set().Where(entity => entity.Id == id && entity.UserId == userid).FirstOrDefaultAsync(); ; 55 | TDTO result = mapper.Map(entity); 56 | return result; 57 | } 58 | else 59 | { 60 | return null!; 61 | } 62 | 63 | } 64 | 65 | public virtual async Task UpdateMine(ClaimsPrincipal User, TDTO dto) 66 | { 67 | string? userid = getMyUserId(User); 68 | if (userid is not null) 69 | { 70 | TEntity? toupdate = 71 | await context.Set().Where(entity => entity.Id == dto.Id && entity.UserId == userid).FirstOrDefaultAsync(); 72 | 73 | if (toupdate is not null) 74 | { 75 | mapper.Map(dto, toupdate); 76 | context.Entry(toupdate).State = EntityState.Modified; 77 | TDTO result = mapper.Map(toupdate); 78 | return result; 79 | 80 | } 81 | else 82 | { 83 | return null!; 84 | } 85 | } 86 | else 87 | { 88 | return null!; 89 | } 90 | } 91 | 92 | public virtual async Task DeleteMine(ClaimsPrincipal User, string id) 93 | { 94 | string? userid = getMyUserId(User); 95 | if (userid is not null) 96 | { 97 | TEntity? entity = await context.Set().Where(entity => entity.Id == id && entity.UserId == userid).FirstOrDefaultAsync(); 98 | if (entity is not null) 99 | { 100 | context.Remove(entity); 101 | return true; 102 | } 103 | else 104 | { 105 | return false; 106 | } 107 | } 108 | else 109 | { 110 | return false; 111 | } 112 | 113 | } 114 | 115 | public virtual async Task AddMine(ClaimsPrincipal User, TDTO dto) 116 | { 117 | string? userid = getMyUserId(User); 118 | if (userid is not null) 119 | { 120 | dto.UserId = userid; 121 | dto.Id = System.Guid.NewGuid().ToString(); 122 | TEntity toadd = mapper.Map(dto); 123 | await context.Set().AddAsync(toadd); 124 | 125 | return toadd.Id; 126 | } 127 | else 128 | { 129 | return null!; 130 | } 131 | } 132 | 133 | protected async Task> GenericQuery(ClaimsPrincipal User, Expression>? expression, List>> includes) 134 | { 135 | string? userid = getMyUserId(User); 136 | if (userid is not null) 137 | { 138 | IQueryable query = context.Set().Where(e => e.UserId == userid); 139 | if (expression is not null) 140 | query = query.Where(expression); 141 | 142 | if (includes is not null) 143 | { 144 | foreach (var include in includes) 145 | { 146 | query = query.Include(include); 147 | } 148 | } 149 | List entities = await query.ToListAsync(); 150 | 151 | List result = mapper.Map>(entities); 152 | return result; 153 | } 154 | else 155 | { 156 | return new List(); 157 | } 158 | } 159 | 160 | 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/ICustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using BlazorInvoiceApp.Data; 2 | using BlazorInvoiceApp.DTOS; 3 | using System.Security.Claims; 4 | 5 | namespace BlazorInvoiceApp.Repository 6 | { 7 | public interface ICustomerRepository : IGenericOwnedRepository 8 | { 9 | public Task Seed(ClaimsPrincipal User); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/IGenericOwnedRepository.cs: -------------------------------------------------------------------------------- 1 | using BlazorInvoiceApp.Data; 2 | using BlazorInvoiceApp.DTOS; 3 | using System.Security.Claims; 4 | 5 | namespace BlazorInvoiceApp.Repository 6 | { 7 | public interface IGenericOwnedRepository 8 | where TEntity : class, IEntity, IOwnedEntity 9 | where TDTO : class, IDTO, IOwnedDTO 10 | { 11 | Task GetMineById(ClaimsPrincipal User, string id); 12 | Task> GetAllMine(ClaimsPrincipal User); 13 | Task AddMine(ClaimsPrincipal User, TDTO dto); 14 | Task UpdateMine(ClaimsPrincipal User, TDTO dto); 15 | Task DeleteMine(ClaimsPrincipal User, string id); 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/IInvoiceLineItemRepository.cs: -------------------------------------------------------------------------------- 1 | using BlazorInvoiceApp.Data; 2 | using BlazorInvoiceApp.DTOS; 3 | using System.Security.Claims; 4 | 5 | namespace BlazorInvoiceApp.Repository 6 | { 7 | public interface IInvoiceLineItemRepository : IGenericOwnedRepository 8 | { 9 | public Task> GetAllByInvoiceId(ClaimsPrincipal User, string invoiceid); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/IInvoiceRepository.cs: -------------------------------------------------------------------------------- 1 | using BlazorInvoiceApp.Data; 2 | using BlazorInvoiceApp.DTOS; 3 | using System.Security.Claims; 4 | 5 | namespace BlazorInvoiceApp.Repository 6 | { 7 | public interface IInvoiceRepository : IGenericOwnedRepository 8 | { 9 | public Task> GetAllMineFlat(ClaimsPrincipal User); 10 | public Task DeleteWithLineItems(ClaimsPrincipal User, string invoiceid); 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/IInvoiceTermsRepository.cs: -------------------------------------------------------------------------------- 1 | using BlazorInvoiceApp.Data; 2 | using BlazorInvoiceApp.DTOS; 3 | using System.Security.Claims; 4 | 5 | namespace BlazorInvoiceApp.Repository 6 | { 7 | public interface IInvoiceTermsRepository : IGenericOwnedRepository 8 | { 9 | public Task Seed(ClaimsPrincipal User); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/IRepositoryCollection.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.Repository 2 | { 3 | public interface IRepositoryCollection : IDisposable 4 | { 5 | IInvoiceRepository Invoice { get; } 6 | ICustomerRepository Customer { get; } 7 | IInvoiceTermsRepository InvoiceTerms { get; } 8 | IInvoiceLineItemRepository InvoiceLineItem { get; } 9 | 10 | Task Save(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/InvoiceLineItemRepository.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Data; 3 | using BlazorInvoiceApp.DTOS; 4 | using System.Security.Claims; 5 | 6 | namespace BlazorInvoiceApp.Repository 7 | { 8 | public class InvoiceLineItemRepository : GenericOwnedRepository, IInvoiceLineItemRepository 9 | { 10 | public InvoiceLineItemRepository(ApplicationDbContext context, IMapper mapper) : base(context, mapper) { } 11 | 12 | public async Task> GetAllByInvoiceId(ClaimsPrincipal User, string invoiceid) 13 | { 14 | return await GenericQuery(User, l => l.InvoiceId == invoiceid, null!); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/InvoiceRepository.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Data; 3 | using BlazorInvoiceApp.DTOS; 4 | using Microsoft.EntityFrameworkCore; 5 | using System.Security.Claims; 6 | 7 | namespace BlazorInvoiceApp.Repository 8 | { 9 | public class InvoiceRepository : GenericOwnedRepository, IInvoiceRepository 10 | { 11 | public InvoiceRepository(ApplicationDbContext context, IMapper mapper) : base(context, mapper) { } 12 | 13 | public async Task DeleteWithLineItems(ClaimsPrincipal User, string invoiceid) 14 | { 15 | string? userid = getMyUserId(User); 16 | var lineitems = await context.InvoicesLineItems.Where(i => i.InvoiceId == invoiceid && i.UserId == userid).ToListAsync(); 17 | foreach (InvoiceLineItem lineitem in lineitems) 18 | { 19 | context.InvoicesLineItems.Remove(lineitem); 20 | } 21 | Invoice? invoice = await context.Invoices.Where(i => i.Id == invoiceid && i.UserId == userid).FirstOrDefaultAsync(); 22 | if (invoice != null) 23 | { 24 | context.Invoices.Remove(invoice); 25 | } 26 | } 27 | 28 | public async Task> GetAllMineFlat(ClaimsPrincipal User) 29 | { 30 | string? userid = getMyUserId(User); 31 | var q = from i in context.Invoices.Where(i => i.UserId == userid).Include(i => i.InvoiceLineItems).Include(i => i.InvoiceTerms).Include(i => i.Customer) 32 | select new InvoiceDTO 33 | { 34 | Id = i.Id, 35 | CreateDate = i.CreateDate, 36 | InvoiceNumber = i.InvoiceNumber, 37 | Description = i.Description, 38 | CustomerId = i.CustomerId, 39 | CustomerName = i.Customer!.Name, 40 | InvoiceTermsId = i.InvoiceTermsId, 41 | InvoiceTermsName = i.InvoiceTerms!.Name, 42 | Paid = i.Paid, 43 | Credit = i.Credit, 44 | TaxRate = i.TaxRate, 45 | UserId = i.UserId, 46 | InvoiceTotal = i.InvoiceLineItems.Sum(a => a.TotalPrice) 47 | }; 48 | 49 | 50 | List? results = await q.ToListAsync(); 51 | return results; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/InvoiceTermsRepository.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Data; 3 | using BlazorInvoiceApp.DTOS; 4 | using Microsoft.EntityFrameworkCore; 5 | using System.Security.Claims; 6 | 7 | namespace BlazorInvoiceApp.Repository 8 | { 9 | public class InvoiceTermsRepository : GenericOwnedRepository, IInvoiceTermsRepository 10 | { 11 | public InvoiceTermsRepository(ApplicationDbContext context, IMapper mapper) : base(context, mapper) { } 12 | 13 | public async Task Seed(ClaimsPrincipal User) 14 | { 15 | string? userid = getMyUserId(User); 16 | if (userid is not null) 17 | { 18 | int count = await context.InvoiceTerms.Where(it => it.UserId == userid).CountAsync(); 19 | if (count == 0) 20 | { 21 | // seed some data. 22 | InvoiceTermsDTO terms1 = new InvoiceTermsDTO 23 | { 24 | Name = "Net 30" 25 | }; 26 | InvoiceTermsDTO terms2 = new InvoiceTermsDTO 27 | { 28 | Name = "Net 60" 29 | }; 30 | InvoiceTermsDTO terms3 = new InvoiceTermsDTO 31 | { 32 | Name = "Net 90" 33 | }; 34 | await AddMine(User, terms1); 35 | await AddMine(User, terms2); 36 | await AddMine(User, terms3); 37 | 38 | } 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/RepositoryAddException.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.Repository 2 | { 3 | public class RepositoryAddException : Exception 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/RepositoryCollection.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Data; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.ChangeTracking; 5 | 6 | namespace BlazorInvoiceApp.Repository 7 | { 8 | public class RepositoryCollection : IRepositoryCollection 9 | { 10 | private readonly ApplicationDbContext context; 11 | private readonly IMapper mapper; 12 | 13 | public IInvoiceRepository Invoice { get; private set; } 14 | public ICustomerRepository Customer { get; private set; } 15 | public IInvoiceTermsRepository InvoiceTerms { get; private set; } 16 | public IInvoiceLineItemRepository InvoiceLineItem { get; private set; } 17 | 18 | 19 | public RepositoryCollection(IDbContextFactory dbFactory, IMapper mapper) 20 | { 21 | this.context = dbFactory.CreateDbContext(); 22 | this.mapper = mapper; 23 | this.Invoice = new InvoiceRepository(context, mapper); 24 | this.Customer = new CustomerRepository(context, mapper); 25 | this.InvoiceTerms = new InvoiceTermsRepository(context, mapper); 26 | this.InvoiceLineItem = new InvoiceLineItemRepository(context, mapper); 27 | } 28 | 29 | public void Dispose() 30 | { 31 | context.Dispose(); 32 | } 33 | 34 | public async Task Save() 35 | { 36 | try 37 | { 38 | return await context.SaveChangesAsync(); 39 | } 40 | catch (DbUpdateException ex) 41 | { 42 | foreach (EntityEntry item in ex.Entries) 43 | { 44 | if (item.State == EntityState.Modified) 45 | { 46 | item.CurrentValues.SetValues(item.OriginalValues); 47 | item.State = EntityState.Unchanged; 48 | throw new RepositoryUpdateException(); 49 | } 50 | else if (item.State == EntityState.Deleted) 51 | { 52 | item.State = EntityState.Unchanged; 53 | throw new RepositoryDeleteException(); 54 | } 55 | else if (item.State == EntityState.Added) 56 | { 57 | throw new RepositoryAddException(); 58 | } 59 | 60 | } 61 | } 62 | return 0; 63 | } 64 | 65 | } 66 | } -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/RepositoryDeleteException.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.Repository 2 | { 3 | public class RepositoryDeleteException : Exception 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Repository/RepositoryUpdateException.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceApp.Repository 2 | { 3 | public class RepositoryUpdateException : Exception 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Shared/LoginDisplay.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | Hello, @context.User.Identity?.Name! 4 |
5 | 6 |
7 |
8 | 9 | Register 10 | Log in 11 | 12 |
13 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 | BlazorInvoiceApp 4 | 5 |
6 | 9 | 10 |
11 |
12 | 13 | About 14 |
15 | 16 |
17 | @Body 18 | 19 |
20 |
21 |
22 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Shared/MainLayout.razor.css: -------------------------------------------------------------------------------- 1 | .page { 2 | position: relative; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | 7 | main { 8 | flex: 1; 9 | } 10 | 11 | .sidebar { 12 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 13 | } 14 | 15 | .top-row { 16 | background-color: #f7f7f7; 17 | border-bottom: 1px solid #d6d5d5; 18 | justify-content: flex-end; 19 | height: 3.5rem; 20 | display: flex; 21 | align-items: center; 22 | } 23 | 24 | .top-row ::deep a, .top-row .btn-link { 25 | white-space: nowrap; 26 | margin-left: 1.5rem; 27 | } 28 | 29 | .top-row a:first-child { 30 | overflow: hidden; 31 | text-overflow: ellipsis; 32 | } 33 | 34 | @media (max-width: 640.98px) { 35 | .top-row:not(.auth) { 36 | display: none; 37 | } 38 | 39 | .top-row.auth { 40 | justify-content: space-between; 41 | } 42 | 43 | .top-row a, .top-row .btn-link { 44 | margin-left: 0; 45 | } 46 | } 47 | 48 | @media (min-width: 641px) { 49 | .page { 50 | flex-direction: row; 51 | } 52 | 53 | .sidebar { 54 | width: 250px; 55 | height: 100vh; 56 | position: sticky; 57 | top: 0; 58 | } 59 | 60 | .top-row { 61 | position: sticky; 62 | top: 0; 63 | z-index: 1; 64 | } 65 | 66 | .top-row, article { 67 | padding-left: 2rem !important; 68 | padding-right: 1.5rem !important; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Shared/NavMenu.razor: -------------------------------------------------------------------------------- 1 |  9 | 10 | 29 | 30 | @code { 31 | private bool collapseNavMenu = true; 32 | 33 | private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null; 34 | 35 | private void ToggleNavMenu() 36 | { 37 | collapseNavMenu = !collapseNavMenu; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/Shared/NavMenu.razor.css: -------------------------------------------------------------------------------- 1 | .navbar-toggler { 2 | background-color: rgba(255, 255, 255, 0.1); 3 | } 4 | 5 | .top-row { 6 | height: 3.5rem; 7 | background-color: rgba(0,0,0,0.4); 8 | } 9 | 10 | .navbar-brand { 11 | font-size: 1.1rem; 12 | } 13 | 14 | .oi { 15 | width: 2rem; 16 | font-size: 1.1rem; 17 | vertical-align: text-top; 18 | top: -2px; 19 | } 20 | 21 | .nav-item { 22 | font-size: 0.9rem; 23 | padding-bottom: 0.5rem; 24 | } 25 | 26 | .nav-item:first-of-type { 27 | padding-top: 1rem; 28 | } 29 | 30 | .nav-item:last-of-type { 31 | padding-bottom: 1rem; 32 | } 33 | 34 | .nav-item ::deep a { 35 | color: #d7d7d7; 36 | border-radius: 4px; 37 | height: 3rem; 38 | display: flex; 39 | align-items: center; 40 | line-height: 3rem; 41 | } 42 | 43 | .nav-item ::deep a.active { 44 | background-color: rgba(255,255,255,0.25); 45 | color: white; 46 | } 47 | 48 | .nav-item ::deep a:hover { 49 | background-color: rgba(255,255,255,0.1); 50 | color: white; 51 | } 52 | 53 | @media (min-width: 641px) { 54 | .navbar-toggler { 55 | display: none; 56 | } 57 | 58 | .collapse { 59 | /* Never collapse the sidebar for wide screens */ 60 | display: block; 61 | } 62 | 63 | .nav-scrollable { 64 | /* Allow sidebar to scroll for tall menus */ 65 | height: calc(100vh - 3.5rem); 66 | overflow-y: auto; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Authorization 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.AspNetCore.Components.Web.Virtualization 8 | @using Microsoft.JSInterop 9 | @using BlazorInvoiceApp 10 | @using BlazorInvoiceApp.Shared 11 | @using BlazorInvoiceApp.Data; 12 | @using BlazorInvoiceApp.Repository; 13 | @using BlazorInvoiceApp.DTOS; 14 | @using BlazorInvoiceApp.Pages.Components; 15 | @using Radzen; 16 | @using Radzen.Blazor; 17 | @using Microsoft.EntityFrameworkCore; 18 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "DetailedErrors": true, 3 | "Logging": { 4 | "LogLevel": { 5 | "Default": "Information", 6 | "Microsoft.AspNetCore": "Warning" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-BlazorInvoiceApp-8e925f58-da5d-47fd-9e7c-ff5ca569d2e8;Trusted_Connection=True;MultipleActiveResultSets=true" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft.AspNetCore": "Warning" 9 | } 10 | }, 11 | "AllowedHosts": "*" 12 | } 13 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](https://github.com/iconic/open-iconic) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](https://github.com/iconic/open-iconic). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](https://github.com/iconic/open-iconic) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](https://github.com/iconic/open-iconic) and [Reference](https://github.com/iconic/open-iconic) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css: -------------------------------------------------------------------------------- 1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'} -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingwithtom1/BlazorFullStackCourse/2f79789b288ec67a5b6b750a5f7a823434e01505/BlazorInvoiceApp/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingwithtom1/BlazorFullStackCourse/2f79789b288ec67a5b6b750a5f7a823434e01505/BlazorInvoiceApp/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingwithtom1/BlazorFullStackCourse/2f79789b288ec67a5b6b750a5f7a823434e01505/BlazorInvoiceApp/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingwithtom1/BlazorFullStackCourse/2f79789b288ec67a5b6b750a5f7a823434e01505/BlazorInvoiceApp/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); 2 | 3 | html, body { 4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 5 | } 6 | 7 | h1:focus { 8 | outline: none; 9 | } 10 | 11 | a, .btn-link { 12 | color: #0071c1; 13 | } 14 | 15 | .btn-primary { 16 | color: #fff; 17 | background-color: #1b6ec2; 18 | border-color: #1861ac; 19 | } 20 | 21 | .btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus { 22 | box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb; 23 | } 24 | 25 | .content { 26 | padding-top: 1.1rem; 27 | } 28 | 29 | .valid.modified:not([type=checkbox]) { 30 | outline: 1px solid #26b050; 31 | } 32 | 33 | .invalid { 34 | outline: 1px solid red; 35 | } 36 | 37 | .validation-message { 38 | color: red; 39 | } 40 | 41 | #blazor-error-ui { 42 | background: lightyellow; 43 | bottom: 0; 44 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 45 | display: none; 46 | left: 0; 47 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 48 | position: fixed; 49 | width: 100%; 50 | z-index: 1000; 51 | } 52 | 53 | #blazor-error-ui .dismiss { 54 | cursor: pointer; 55 | position: absolute; 56 | right: 0.75rem; 57 | top: 0.5rem; 58 | } 59 | 60 | .blazor-error-boundary { 61 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 62 | padding: 1rem 1rem 1rem 3.7rem; 63 | color: white; 64 | } 65 | 66 | .blazor-error-boundary::after { 67 | content: "An error has occurred." 68 | } 69 | -------------------------------------------------------------------------------- /BlazorInvoiceApp/wwwroot/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingwithtom1/BlazorFullStackCourse/2f79789b288ec67a5b6b750a5f7a823434e01505/BlazorInvoiceApp/wwwroot/favicon.png -------------------------------------------------------------------------------- /BlazorInvoiceAppTests/BlazorInvoiceAppTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | false 9 | true 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | runtime; build; native; contentfiles; analyzers; buildtransitive 19 | all 20 | 21 | 22 | runtime; build; native; contentfiles; analyzers; buildtransitive 23 | all 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /BlazorInvoiceAppTests/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using Xunit; -------------------------------------------------------------------------------- /BlazorInvoiceAppTests/SetupCustomersComponentTests.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using BlazorInvoiceApp.Data; 3 | using BlazorInvoiceApp.Pages.Components; 4 | using BlazorInvoiceApp.Repository; 5 | using Bunit; 6 | using Bunit.TestDoubles; 7 | using Microsoft.AspNetCore.Identity; 8 | using Microsoft.EntityFrameworkCore; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Moq; 11 | using Radzen; 12 | using System.Security.Claims; 13 | 14 | namespace BlazorInvoiceAppTests 15 | { 16 | public class SetupCustomersComponentTests : TestContext 17 | { 18 | public SetupCustomersComponentTests() 19 | { 20 | SetupEnvironment(); 21 | } 22 | private void SetupEnvironment() 23 | { 24 | Claim[] claims = { 25 | new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", "53de24b2-187c-4a67-adac-210534db81f3") 26 | }; 27 | 28 | var authContext = this.AddTestAuthorization(); 29 | authContext.SetAuthorized("tom@test.com"); 30 | authContext.SetClaims(claims); 31 | JSInterop.SetupVoid("Radzen.preventArrows", _ => true); 32 | var mapperConfig = new MapperConfiguration(mc => 33 | { 34 | mc.AddProfile(new AutoMapperProfile()); 35 | }); 36 | IMapper mapper = mapperConfig.CreateMapper(); 37 | Services.AddSingleton(mapper); 38 | Services.AddScoped(); 39 | var mockDbFactory = new Mock>(); 40 | mockDbFactory.Setup(f => f.CreateDbContext()) 41 | .Returns(() => { 42 | var context = new ApplicationDbContext(new DbContextOptionsBuilder() 43 | .UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=testdb;Trusted_Connection=True;MultipleActiveResultSets=true") 44 | .Options); 45 | InitData(context); 46 | return context; 47 | 48 | } 49 | ); 50 | Services.AddSingleton(mockDbFactory.Object); 51 | Services.AddScoped(); 52 | 53 | } 54 | 55 | [Fact] 56 | public void SetupCustomersComponentAddTest() 57 | { 58 | 59 | 60 | var cut = RenderComponent(); 61 | 62 | cut.WaitForAssertion(() => cut.Find("span[title='Test Customer 1']")); 63 | cut.Find("span[title='Test Customer 2']"); 64 | cut.Find("span[title='Test Customer 3']"); 65 | 66 | // All initial customers rendered correctly 67 | // Try to add a customer 68 | 69 | var buttonElement = cut.Find("button"); 70 | buttonElement.Click(); 71 | 72 | var buttons = cut.FindAll("button"); 73 | var input = cut.Find("input"); 74 | input.Change("Test Customer 4"); 75 | 76 | buttons[1].Click(); 77 | cut.WaitForAssertion(() => cut.Find("span[title='Test Customer 4']")); 78 | cut.Find("span[title='Test Customer 1']"); 79 | cut.Find("span[title='Test Customer 2']"); 80 | cut.Find("span[title='Test Customer 3']"); 81 | 82 | 83 | 84 | 85 | } 86 | 87 | 88 | [Fact] 89 | public void SetupCustomersComponentModifyTest() 90 | { 91 | 92 | 93 | var cut = RenderComponent(); 94 | 95 | cut.WaitForAssertion(() => cut.Find("span[title='Test Customer 1']")); 96 | cut.Find("span[title='Test Customer 2']"); 97 | cut.Find("span[title='Test Customer 3']"); 98 | 99 | // All initial customers rendered correctly 100 | // Try to add a customer 101 | 102 | 103 | var buttons = cut.FindAll("button"); 104 | buttons[1].Click(); 105 | cut.WaitForElement("input"); 106 | 107 | 108 | var input = cut.Find("input"); 109 | input.Change("Test Customer 5"); 110 | buttons = cut.FindAll("button"); 111 | 112 | 113 | buttons[1].Click(); 114 | cut.WaitForAssertion(() => cut.Find("span[title='Test Customer 5']")); 115 | cut.Find("span[title='Test Customer 2']"); 116 | cut.Find("span[title='Test Customer 3']"); 117 | 118 | 119 | } 120 | 121 | [Fact] 122 | public void SetupCustomersComponentDeleteTest() 123 | { 124 | //SetupEnvironment(); 125 | 126 | var cut = RenderComponent(); 127 | 128 | cut.WaitForAssertion(() => cut.Find("span[title='Test Customer 1']")); 129 | cut.Find("span[title='Test Customer 2']"); 130 | cut.Find("span[title='Test Customer 3']"); 131 | 132 | var buttons = cut.FindAll("button"); 133 | buttons[2].Click(); 134 | 135 | cut.WaitForAssertion(() => Assert.DoesNotContain("Test Customer 1", cut.Markup)); 136 | cut.Find("span[title='Test Customer 2']"); 137 | cut.Find("span[title='Test Customer 3']"); 138 | } 139 | 140 | private void InitData(ApplicationDbContext context) 141 | { 142 | 143 | if (context != null) 144 | { 145 | context.Database.EnsureDeleted(); 146 | context.Database.Migrate(); 147 | 148 | context.SaveChanges(); 149 | IdentityUser user = new IdentityUser 150 | { 151 | Id = "53de24b2-187c-4a67-adac-210534db81f3", 152 | UserName = "tom@test.com", 153 | NormalizedUserName = "TOM@TEST.COM", 154 | Email = "tom@test.com", 155 | NormalizedEmail = "TOM@TEST.COM", 156 | EmailConfirmed = true, 157 | PasswordHash = "AQAAAAIAAYagAAAAEDGgJMx0qDS+ecWG2+aeD5Rzz1KTKcx362EdaFzU79vYX9/J5RjRhO0MfBpJpfnGNw==", 158 | SecurityStamp = "SEQ6T4L46XMQVNGZJTYK3YIHDHTC5N6R", 159 | ConcurrencyStamp = "3b7e9372-cbea-40ee-97aa-67a9f91d5cc8", 160 | PhoneNumber = null, 161 | PhoneNumberConfirmed = false, 162 | TwoFactorEnabled = false, 163 | LockoutEnd = null, 164 | LockoutEnabled = false, 165 | AccessFailedCount = 0, 166 | }; 167 | context.Users.Add(user); 168 | 169 | Customer customer1 = new Customer 170 | { 171 | Name = "Test Customer 1", 172 | Id = "74739f26-264b-4f7a-96ee-e29dde9f6601", 173 | UserId = "53de24b2-187c-4a67-adac-210534db81f3" 174 | 175 | }; 176 | Customer customer2 = new Customer 177 | { 178 | Name = "Test Customer 2", 179 | Id = "74739f26-264b-4f7a-96ee-e29dde9f6602", 180 | UserId = "53de24b2-187c-4a67-adac-210534db81f3" 181 | 182 | }; 183 | Customer customer3 = new Customer 184 | { 185 | Name = "Test Customer 3", 186 | Id = "74739f26-264b-4f7a-96ee-e29dde9f6603", 187 | UserId = "53de24b2-187c-4a67-adac-210534db81f3" 188 | 189 | }; 190 | context.Customers.Add(customer1); 191 | context.Customers.Add(customer2); 192 | context.Customers.Add(customer3); 193 | 194 | 195 | context.SaveChanges(); 196 | } 197 | } 198 | } 199 | } -------------------------------------------------------------------------------- /BlazorInvoiceAppTests/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | namespace BlazorInvoiceAppTests 2 | { 3 | public class UnitTest1 4 | { 5 | [Fact] 6 | public void Test1() 7 | { 8 | 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 mckennajsv 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------