├── .gitattributes ├── .gitignore ├── ShoppingCart.sln ├── ShoppingCart ├── Areas │ └── Admin │ │ ├── Controllers │ │ └── ProductsController.cs │ │ └── Views │ │ ├── Products │ │ ├── Create.cshtml │ │ ├── Edit.cshtml │ │ └── Index.cshtml │ │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ ├── _Layout.cshtml.css │ │ ├── _NotificationPartial.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ │ ├── _ViewImports.cshtml │ │ └── _ViewStart.cshtml ├── Controllers │ ├── AccountController.cs │ ├── CartController.cs │ ├── HomeController.cs │ └── ProductsController.cs ├── Infrastructure │ ├── Components │ │ ├── CategoriesViewComponent.cs │ │ └── SmallCartViewComponent.cs │ ├── DataContext.cs │ ├── SeedData.cs │ ├── SessionExtensions.cs │ ├── TagHelpers │ │ └── PaginationTagHelper.cs │ └── Validation │ │ └── FileExtensionAttribute.cs ├── Migrations │ ├── 20220622071239_Initial.Designer.cs │ ├── 20220622071239_Initial.cs │ ├── 20220623100340_Second.Designer.cs │ ├── 20220623100340_Second.cs │ └── DataContextModelSnapshot.cs ├── Models │ ├── AppUser.cs │ ├── CartItem.cs │ ├── Category.cs │ ├── ErrorViewModel.cs │ ├── Product.cs │ ├── User.cs │ └── ViewModels │ │ ├── CartViewModel.cs │ │ ├── LoginViewModel.cs │ │ └── SmallCartViewModel.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── ShoppingCart.csproj ├── Views │ ├── Account │ │ ├── Create.cshtml │ │ └── Login.cshtml │ ├── Cart │ │ └── Index.cshtml │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Products │ │ └── Index.cshtml │ ├── Shared │ │ ├── Components │ │ │ ├── Categories │ │ │ │ └── Default.cshtml │ │ │ └── SmallCart │ │ │ │ └── Default.cshtml │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ ├── _Layout.cshtml.css │ │ ├── _NotificationPartial.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml ├── appsettings.Development.json ├── appsettings.json └── wwwroot │ ├── css │ └── site.css │ ├── favicon.ico │ ├── js │ └── site.js │ ├── lib │ ├── bootstrap │ │ ├── LICENSE │ │ └── dist │ │ │ ├── css │ │ │ ├── bootstrap-grid.css │ │ │ ├── bootstrap-grid.css.map │ │ │ ├── bootstrap-grid.min.css │ │ │ ├── bootstrap-grid.min.css.map │ │ │ ├── bootstrap-grid.rtl.css │ │ │ ├── bootstrap-grid.rtl.css.map │ │ │ ├── bootstrap-grid.rtl.min.css │ │ │ ├── bootstrap-grid.rtl.min.css.map │ │ │ ├── bootstrap-reboot.css │ │ │ ├── bootstrap-reboot.css.map │ │ │ ├── bootstrap-reboot.min.css │ │ │ ├── bootstrap-reboot.min.css.map │ │ │ ├── bootstrap-reboot.rtl.css │ │ │ ├── bootstrap-reboot.rtl.css.map │ │ │ ├── bootstrap-reboot.rtl.min.css │ │ │ ├── bootstrap-reboot.rtl.min.css.map │ │ │ ├── bootstrap-utilities.css │ │ │ ├── bootstrap-utilities.css.map │ │ │ ├── bootstrap-utilities.min.css │ │ │ ├── bootstrap-utilities.min.css.map │ │ │ ├── bootstrap-utilities.rtl.css │ │ │ ├── bootstrap-utilities.rtl.css.map │ │ │ ├── bootstrap-utilities.rtl.min.css │ │ │ ├── bootstrap-utilities.rtl.min.css.map │ │ │ ├── bootstrap.css │ │ │ ├── bootstrap.css.map │ │ │ ├── bootstrap.min.css │ │ │ ├── bootstrap.min.css.map │ │ │ ├── bootstrap.rtl.css │ │ │ ├── bootstrap.rtl.css.map │ │ │ ├── bootstrap.rtl.min.css │ │ │ └── bootstrap.rtl.min.css.map │ │ │ └── js │ │ │ ├── bootstrap.bundle.js │ │ │ ├── bootstrap.bundle.js.map │ │ │ ├── bootstrap.bundle.min.js │ │ │ ├── bootstrap.bundle.min.js.map │ │ │ ├── bootstrap.esm.js │ │ │ ├── bootstrap.esm.js.map │ │ │ ├── bootstrap.esm.min.js │ │ │ ├── bootstrap.esm.min.js.map │ │ │ ├── bootstrap.js │ │ │ ├── bootstrap.js.map │ │ │ ├── bootstrap.min.js │ │ │ └── bootstrap.min.js.map │ ├── jquery-validation-unobtrusive │ │ ├── LICENSE.txt │ │ ├── jquery.validate.unobtrusive.js │ │ └── jquery.validate.unobtrusive.min.js │ ├── jquery-validation │ │ ├── LICENSE.md │ │ └── dist │ │ │ ├── additional-methods.js │ │ │ ├── additional-methods.min.js │ │ │ ├── jquery.validate.js │ │ │ └── jquery.validate.min.js │ └── jquery │ │ ├── LICENSE.txt │ │ └── dist │ │ ├── jquery.js │ │ ├── jquery.min.js │ │ └── jquery.min.map │ └── media │ └── products │ ├── 6877f536-7580-495d-8a05-c741eeba0690_pink shirt.jpg │ ├── apples.jpg │ ├── bananas.jpg │ ├── black shirt.jpg │ ├── blue shirt.jpg │ ├── f9235e9c-6666-4077-bca7-b4eaad0f7b21_kiwi.jpg │ ├── grapefruit.jpg │ ├── grapes.jpg │ ├── grey shirt.jpg │ ├── noimage.png │ ├── watermelon.jpg │ ├── white shirt.jpg │ └── yellow shirt.jpg └── course files ├── PaginationTagHelper.cs ├── images ├── apples.jpg ├── bananas.jpg ├── black shirt.jpg ├── blue shirt.jpg ├── grapefruit.jpg ├── grapes.jpg ├── grey shirt.jpg ├── kiwi.jpg ├── noimage.png ├── pink shirt.jpg ├── watermelon.jpg ├── white shirt.jpg └── yellow shirt.jpg ├── site.js └── test.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/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 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 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 LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /ShoppingCart.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.32228.430 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShoppingCart", "ShoppingCart\ShoppingCart.csproj", "{DAE977EE-4745-49CE-9359-13328ADA9D3C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {DAE977EE-4745-49CE-9359-13328ADA9D3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {DAE977EE-4745-49CE-9359-13328ADA9D3C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {DAE977EE-4745-49CE-9359-13328ADA9D3C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {DAE977EE-4745-49CE-9359-13328ADA9D3C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {4BE335A3-AE7A-43DD-A504-6BE78D1F50E8} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.AspNetCore.Mvc.Rendering; 4 | using Microsoft.EntityFrameworkCore; 5 | using ShoppingCart.Infrastructure; 6 | using ShoppingCart.Models; 7 | 8 | namespace ShoppingCart.Areas.Admin.Controllers 9 | { 10 | [Area("Admin")] 11 | [Authorize] 12 | public class ProductsController : Controller 13 | { 14 | private readonly DataContext _context; 15 | private readonly IWebHostEnvironment _webHostEnvironment; 16 | 17 | 18 | public ProductsController(DataContext context, IWebHostEnvironment webHostEnvironment) 19 | { 20 | _context = context; 21 | _webHostEnvironment = webHostEnvironment; 22 | } 23 | 24 | public async Task Index(int p = 1) 25 | { 26 | int pageSize = 3; 27 | ViewBag.PageNumber = p; 28 | ViewBag.PageRange = pageSize; 29 | ViewBag.TotalPages = (int)Math.Ceiling((decimal)_context.Products.Count() / pageSize); 30 | 31 | return View(await _context.Products.OrderByDescending(p => p.Id) 32 | .Include(p => p.Category) 33 | .Skip((p - 1) * pageSize) 34 | .Take(pageSize) 35 | .ToListAsync()); 36 | } 37 | 38 | public IActionResult Create() 39 | { 40 | ViewBag.Categories = new SelectList(_context.Categories, "Id", "Name"); 41 | 42 | return View(); 43 | } 44 | 45 | [HttpPost] 46 | [ValidateAntiForgeryToken] 47 | public async Task Create(Product product) 48 | { 49 | ViewBag.Categories = new SelectList(_context.Categories, "Id", "Name", product.CategoryId); 50 | 51 | if (ModelState.IsValid) 52 | { 53 | product.Slug = product.Name.ToLower().Replace(" ", "-"); 54 | 55 | var slug = await _context.Products.FirstOrDefaultAsync(p => p.Slug == product.Slug); 56 | if (slug != null) 57 | { 58 | ModelState.AddModelError("", "The product already exists."); 59 | return View(product); 60 | } 61 | 62 | if (product.ImageUpload != null) 63 | { 64 | string uploadsDir = Path.Combine(_webHostEnvironment.WebRootPath, "media/products"); 65 | string imageName = Guid.NewGuid().ToString() + "_" + product.ImageUpload.FileName; 66 | 67 | string filePath = Path.Combine(uploadsDir, imageName); 68 | 69 | FileStream fs = new FileStream(filePath, FileMode.Create); 70 | await product.ImageUpload.CopyToAsync(fs); 71 | fs.Close(); 72 | 73 | product.Image = imageName; 74 | } 75 | 76 | _context.Add(product); 77 | await _context.SaveChangesAsync(); 78 | 79 | TempData["Success"] = "The product has been created!"; 80 | 81 | return RedirectToAction("Index"); 82 | } 83 | 84 | return View(product); 85 | } 86 | 87 | public async Task Edit(long id) 88 | { 89 | Product product = await _context.Products.FindAsync(id); 90 | 91 | ViewBag.Categories = new SelectList(_context.Categories, "Id", "Name", product.CategoryId); 92 | 93 | return View(product); 94 | } 95 | 96 | [HttpPost] 97 | [ValidateAntiForgeryToken] 98 | public async Task Edit(int id, Product product) 99 | { 100 | ViewBag.Categories = new SelectList(_context.Categories, "Id", "Name", product.CategoryId); 101 | 102 | if (ModelState.IsValid) 103 | { 104 | product.Slug = product.Name.ToLower().Replace(" ", "-"); 105 | 106 | var slug = await _context.Products.FirstOrDefaultAsync(p => p.Slug == product.Slug); 107 | if (slug != null) 108 | { 109 | ModelState.AddModelError("", "The product already exists."); 110 | return View(product); 111 | } 112 | 113 | if (product.ImageUpload != null) 114 | { 115 | string uploadsDir = Path.Combine(_webHostEnvironment.WebRootPath, "media/products"); 116 | string imageName = Guid.NewGuid().ToString() + "_" + product.ImageUpload.FileName; 117 | 118 | string filePath = Path.Combine(uploadsDir, imageName); 119 | 120 | FileStream fs = new FileStream(filePath, FileMode.Create); 121 | await product.ImageUpload.CopyToAsync(fs); 122 | fs.Close(); 123 | 124 | product.Image = imageName; 125 | } 126 | 127 | _context.Update(product); 128 | await _context.SaveChangesAsync(); 129 | 130 | TempData["Success"] = "The product has been edited!"; 131 | } 132 | 133 | return View(product); 134 | } 135 | 136 | public async Task Delete(long id) 137 | { 138 | Product product = await _context.Products.FindAsync(id); 139 | 140 | if (!string.Equals(product.Image, "noimage.png")) 141 | { 142 | string uploadsDir = Path.Combine(_webHostEnvironment.WebRootPath, "media/products"); 143 | string oldImagePath = Path.Combine(uploadsDir, product.Image); 144 | if (System.IO.File.Exists(oldImagePath)) 145 | { 146 | System.IO.File.Delete(oldImagePath); 147 | } 148 | } 149 | 150 | _context.Products.Remove(product); 151 | await _context.SaveChangesAsync(); 152 | 153 | TempData["Success"] = "The product has been deleted!"; 154 | 155 | return RedirectToAction("Index"); 156 | } 157 | } 158 | } -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/Products/Create.cshtml: -------------------------------------------------------------------------------- 1 | @model ShoppingCart.Models.Product 2 | 3 | @{ 4 | ViewData["Title"] = "Create"; 5 | } 6 | 7 |

Create Product

8 | 9 |
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 | 37 | 38 |
39 | 40 |
41 | 42 | 43 | 44 | 45 |
46 | 47 |
48 | 49 |
50 |
51 |
52 |
53 | 54 |
55 | Back to List 56 |
57 | 58 | @section Scripts { 59 | @{ 60 | await Html.RenderPartialAsync("_ValidationScriptsPartial"); 61 | } 62 | 63 | 64 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/Products/Edit.cshtml: -------------------------------------------------------------------------------- 1 | @model ShoppingCart.Models.Product 2 | 3 | @{ 4 | ViewData["Title"] = "Create"; 5 | } 6 | 7 |

Edit Product

8 | 9 |
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 | 39 | 40 |
41 | 42 |
43 | 44 | 45 |
46 | 47 |
48 | 49 | 50 | 51 | 52 |
53 | 54 |
55 | 56 |
57 |
58 |
59 |
60 | 61 |
62 | Back to List 63 |
64 | 65 | @section Scripts { 66 | @{ 67 | await Html.RenderPartialAsync("_ValidationScriptsPartial"); 68 | } 69 | 70 | 71 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/Products/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | 3 | @{ 4 | ViewData["Title"] = "Products"; 5 | } 6 | 7 |

Products

8 | 9 |

10 | Create New 11 |

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | @foreach (var item in Model) 25 | { 26 | 27 | 30 | 33 | 36 | 39 | 43 | 44 | } 45 | 46 |
NamePriceCategoryImage
28 | @item.Name 29 | 31 | @item.Price.ToString("C2") 32 | 34 | @item.Category.Name 35 | 37 | 38 | 40 | Edit | 41 | Delete 42 |
47 | 48 |
49 | 53 | 54 |
-------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - Admin Area 7 | 8 | 9 | 10 | 11 | 12 |
13 | 27 |
28 |
29 |
30 |
31 |
32 | 33 | @RenderBody() 34 |
35 |
36 |
37 |
38 | 39 | 40 | 41 | 42 | @await RenderSectionAsync("Scripts", required: false) 43 | 44 | 45 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/Shared/_Layout.cshtml.css: -------------------------------------------------------------------------------- 1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | for details on configuring this project to bundle and minify static web assets. */ 3 | 4 | a.navbar-brand { 5 | white-space: normal; 6 | text-align: center; 7 | word-break: break-all; 8 | } 9 | 10 | a { 11 | color: #0077cc; 12 | } 13 | 14 | .btn-primary { 15 | color: #fff; 16 | background-color: #1b6ec2; 17 | border-color: #1861ac; 18 | } 19 | 20 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link { 21 | color: #fff; 22 | background-color: #1b6ec2; 23 | border-color: #1861ac; 24 | } 25 | 26 | .border-top { 27 | border-top: 1px solid #e5e5e5; 28 | } 29 | .border-bottom { 30 | border-bottom: 1px solid #e5e5e5; 31 | } 32 | 33 | .box-shadow { 34 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); 35 | } 36 | 37 | button.accept-policy { 38 | font-size: 1rem; 39 | line-height: inherit; 40 | } 41 | 42 | .footer { 43 | position: absolute; 44 | bottom: 0; 45 | width: 100%; 46 | white-space: nowrap; 47 | line-height: 60px; 48 | } 49 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/Shared/_NotificationPartial.cshtml: -------------------------------------------------------------------------------- 1 | @if (TempData["Success"] != null) 2 | { 3 |
4 | @TempData["Success"] 5 |
6 | } 7 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using ShoppingCart 2 | @using ShoppingCart.Models 3 | @using ShoppingCart.Models.ViewModels 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | @addTagHelper *, ShoppingCart 6 | -------------------------------------------------------------------------------- /ShoppingCart/Areas/Admin/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /ShoppingCart/Controllers/AccountController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using Microsoft.AspNetCore.Mvc; 3 | using ShoppingCart.Models; 4 | using ShoppingCart.Models.ViewModels; 5 | 6 | namespace ShoppingCart.Controllers 7 | { 8 | public class AccountController : Controller 9 | { 10 | private UserManager _userManager; 11 | private SignInManager _signInManager; 12 | 13 | public AccountController(SignInManager signInManager, UserManager userManager) 14 | { 15 | _userManager = userManager; 16 | _signInManager = signInManager; 17 | } 18 | 19 | public IActionResult Create() => View(); 20 | 21 | [HttpPost] 22 | public async Task Create(User user) 23 | { 24 | if (ModelState.IsValid) 25 | { 26 | AppUser newUser = new AppUser { UserName = user.UserName, Email = user.Email }; 27 | IdentityResult result = await _userManager.CreateAsync(newUser, user.Password); 28 | 29 | if (result.Succeeded) 30 | { 31 | return Redirect("/admin/products"); 32 | } 33 | 34 | foreach (IdentityError error in result.Errors) 35 | { 36 | ModelState.AddModelError("", error.Description); 37 | } 38 | 39 | } 40 | 41 | return View(user); 42 | } 43 | 44 | public IActionResult Login(string returnUrl) => View(new LoginViewModel { ReturnUrl = returnUrl }); 45 | 46 | [HttpPost] 47 | public async Task Login(LoginViewModel loginVM) 48 | { 49 | if (ModelState.IsValid) 50 | { 51 | Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.PasswordSignInAsync(loginVM.UserName, loginVM.Password, false, false); 52 | 53 | if (result.Succeeded) 54 | { 55 | return Redirect(loginVM.ReturnUrl ?? "/"); 56 | } 57 | 58 | ModelState.AddModelError("", "Invalid username or password"); 59 | } 60 | 61 | return View(loginVM); 62 | } 63 | 64 | public async Task Logout(string returnUrl = "/") 65 | { 66 | await _signInManager.SignOutAsync(); 67 | 68 | return Redirect(returnUrl); 69 | } 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /ShoppingCart/Controllers/CartController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using ShoppingCart.Infrastructure; 3 | using ShoppingCart.Models; 4 | using ShoppingCart.Models.ViewModels; 5 | 6 | namespace ShoppingCart.Controllers 7 | { 8 | public class CartController : Controller 9 | { 10 | private readonly DataContext _context; 11 | 12 | public CartController(DataContext context) 13 | { 14 | _context = context; 15 | } 16 | 17 | public IActionResult Index() 18 | { 19 | List cart = HttpContext.Session.GetJson>("Cart") ?? new List(); 20 | 21 | CartViewModel cartVM = new() 22 | { 23 | CartItems = cart, 24 | GrandTotal = cart.Sum(x => x.Quantity * x.Price) 25 | }; 26 | 27 | return View(cartVM); 28 | } 29 | 30 | public async Task Add(long id) 31 | { 32 | Product product = await _context.Products.FindAsync(id); 33 | 34 | List cart = HttpContext.Session.GetJson>("Cart") ?? new List(); 35 | 36 | CartItem cartItem = cart.Where(c => c.ProductId == id).FirstOrDefault(); 37 | 38 | if (cartItem == null) 39 | { 40 | cart.Add(new CartItem(product)); 41 | } 42 | else 43 | { 44 | cartItem.Quantity += 1; 45 | } 46 | 47 | HttpContext.Session.SetJson("Cart", cart); 48 | 49 | TempData["Success"] = "The product has been added!"; 50 | 51 | return Redirect(Request.Headers["Referer"].ToString()); 52 | } 53 | 54 | public async Task Decrease(long id) 55 | { 56 | List cart = HttpContext.Session.GetJson>("Cart"); 57 | 58 | CartItem cartItem = cart.Where(c => c.ProductId == id).FirstOrDefault(); 59 | 60 | if (cartItem.Quantity > 1) 61 | { 62 | --cartItem.Quantity; 63 | } 64 | else 65 | { 66 | cart.RemoveAll(p => p.ProductId == id); 67 | } 68 | 69 | if (cart.Count == 0) 70 | { 71 | HttpContext.Session.Remove("Cart"); 72 | } 73 | else 74 | { 75 | HttpContext.Session.SetJson("Cart", cart); 76 | } 77 | 78 | TempData["Success"] = "The product has been removed!"; 79 | 80 | return RedirectToAction("Index"); 81 | } 82 | 83 | public async Task Remove(long id) 84 | { 85 | List cart = HttpContext.Session.GetJson>("Cart"); 86 | 87 | cart.RemoveAll(p => p.ProductId == id); 88 | 89 | if (cart.Count == 0) 90 | { 91 | HttpContext.Session.Remove("Cart"); 92 | } 93 | else 94 | { 95 | HttpContext.Session.SetJson("Cart", cart); 96 | } 97 | 98 | TempData["Success"] = "The product has been removed!"; 99 | 100 | return RedirectToAction("Index"); 101 | } 102 | 103 | public IActionResult Clear() 104 | { 105 | HttpContext.Session.Remove("Cart"); 106 | 107 | return RedirectToAction("Index"); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /ShoppingCart/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using ShoppingCart.Models; 3 | using System.Diagnostics; 4 | 5 | namespace ShoppingCart.Controllers 6 | { 7 | public class HomeController : Controller 8 | { 9 | private readonly ILogger _logger; 10 | 11 | public HomeController(ILogger logger) 12 | { 13 | _logger = logger; 14 | } 15 | 16 | public IActionResult Index() 17 | { 18 | return View(); 19 | } 20 | 21 | public IActionResult Privacy() 22 | { 23 | return View(); 24 | } 25 | 26 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 27 | public IActionResult Error() 28 | { 29 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /ShoppingCart/Controllers/ProductsController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.EntityFrameworkCore; 3 | using ShoppingCart.Infrastructure; 4 | using ShoppingCart.Models; 5 | 6 | namespace ShoppingCart.Controllers 7 | { 8 | public class ProductsController : Controller 9 | { 10 | private readonly DataContext _context; 11 | 12 | public ProductsController(DataContext context) 13 | { 14 | _context = context; 15 | } 16 | 17 | public async Task Index(string categorySlug = "", int p = 1) 18 | { 19 | int pageSize = 3; 20 | ViewBag.PageNumber = p; 21 | ViewBag.PageRange = pageSize; 22 | ViewBag.CategorySlug = categorySlug; 23 | 24 | if (categorySlug == "") 25 | { 26 | ViewBag.TotalPages = (int)Math.Ceiling((decimal)_context.Products.Count() / pageSize); 27 | 28 | return View(await _context.Products.OrderByDescending(p => p.Id).Skip((p - 1) * pageSize).Take(pageSize).ToListAsync()); 29 | } 30 | 31 | Category category = await _context.Categories.Where(c => c.Slug == categorySlug).FirstOrDefaultAsync(); 32 | if (category == null) return RedirectToAction("Index"); 33 | 34 | var productsByCategory = _context.Products.Where(p => p.CategoryId == category.Id); 35 | ViewBag.TotalPages = (int)Math.Ceiling((decimal)productsByCategory.Count() / pageSize); 36 | 37 | return View(await productsByCategory.OrderByDescending(p => p.Id).Skip((p - 1) * pageSize).Take(pageSize).ToListAsync()); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ShoppingCart/Infrastructure/Components/CategoriesViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace ShoppingCart.Infrastructure.Components 5 | { 6 | public class CategoriesViewComponent : ViewComponent 7 | { 8 | private readonly DataContext _context; 9 | 10 | public CategoriesViewComponent(DataContext context) 11 | { 12 | _context = context; 13 | } 14 | 15 | public async Task InvokeAsync() => View(await _context.Categories.ToListAsync()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ShoppingCart/Infrastructure/Components/SmallCartViewComponent.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using ShoppingCart.Models; 3 | using ShoppingCart.Models.ViewModels; 4 | 5 | namespace ShoppingCart.Infrastructure.Components 6 | { 7 | public class SmallCartViewComponent : ViewComponent 8 | { 9 | public IViewComponentResult Invoke() 10 | { 11 | List cart = HttpContext.Session.GetJson>("Cart"); 12 | SmallCartViewModel smallCartVM; 13 | 14 | if (cart == null || cart.Count == 0) 15 | { 16 | smallCartVM = null; 17 | } 18 | else 19 | { 20 | smallCartVM = new() 21 | { 22 | NumberOfItems = cart.Sum(x => x.Quantity), 23 | TotalAmount = cart.Sum(x => x.Quantity * x.Price) 24 | }; 25 | } 26 | 27 | return View(smallCartVM); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ShoppingCart/Infrastructure/DataContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore; 3 | using ShoppingCart.Models; 4 | 5 | namespace ShoppingCart.Infrastructure 6 | { 7 | public class DataContext : IdentityDbContext 8 | { 9 | public DataContext(DbContextOptions options) : base(options) 10 | { } 11 | public DbSet Products { get; set; } 12 | public DbSet Categories { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ShoppingCart/Infrastructure/SeedData.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using ShoppingCart.Models; 3 | 4 | namespace ShoppingCart.Infrastructure 5 | { 6 | public class SeedData 7 | { 8 | public static void SeedDatabase(DataContext context) 9 | { 10 | context.Database.Migrate(); 11 | 12 | if (!context.Products.Any()) 13 | { 14 | Category fruits = new Category { Name = "Fruits", Slug = "fruits" }; 15 | Category shirts = new Category { Name = "Shirts", Slug = "shirts" }; 16 | 17 | context.Products.AddRange( 18 | new Product 19 | { 20 | Name = "Apples", 21 | Slug = "apples", 22 | Description = "Juicy apples", 23 | Price = 1.50M, 24 | Category = fruits, 25 | Image = "apples.jpg" 26 | }, 27 | new Product 28 | { 29 | Name = "Bananas", 30 | Slug = "bananas", 31 | Description = "Fresh bananas", 32 | Price = 3M, 33 | Category = fruits, 34 | Image = "bananas.jpg" 35 | }, 36 | new Product 37 | { 38 | Name = "Watermelon", 39 | Slug = "watermelon", 40 | Description = "Juicy watermelon", 41 | Price = 0.50M, 42 | Category = fruits, 43 | Image = "watermelon.jpg" 44 | }, 45 | new Product 46 | { 47 | Name = "Grapefruit", 48 | Slug = "grapefruit", 49 | Description = "Juicy grapefruit", 50 | Price = 2M, 51 | Category = fruits, 52 | Image = "grapefruit.jpg" 53 | }, 54 | new Product 55 | { 56 | Name = "White shirt", 57 | Slug = "white-shirt", 58 | Description = "White shirt", 59 | Price = 5.99M, 60 | Category = shirts, 61 | Image = "white shirt.jpg" 62 | }, 63 | new Product 64 | { 65 | Name = "Black shirt", 66 | Slug = "black-shirt", 67 | Description = "Black shirt", 68 | Price = 7.99M, 69 | Category = shirts, 70 | Image = "black shirt.jpg" 71 | }, 72 | new Product 73 | { 74 | Name = "Yellow shirt", 75 | Slug = "yellow-shirt", 76 | Description = "Yellow shirt", 77 | Price = 11.99M, 78 | Category = shirts, 79 | Image = "yellow shirt.jpg" 80 | }, 81 | new Product 82 | { 83 | Name = "Grey shirt", 84 | Slug = "grey-shirt", 85 | Description = "Grey shirt", 86 | Price = 12.99M, 87 | Category = shirts, 88 | Image = "grey shirt.jpg" 89 | } 90 | ); 91 | 92 | context.SaveChanges(); 93 | } 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /ShoppingCart/Infrastructure/SessionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace ShoppingCart.Infrastructure 4 | { 5 | public static class SessionExtensions 6 | { 7 | public static void SetJson(this ISession session, string key, object value) 8 | { 9 | session.SetString(key, JsonConvert.SerializeObject(value)); 10 | } 11 | 12 | public static T GetJson(this ISession session, string key) 13 | { 14 | var sessionData = session.GetString(key); 15 | return sessionData == null ? default(T) : JsonConvert.DeserializeObject(sessionData); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ShoppingCart/Infrastructure/TagHelpers/PaginationTagHelper.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Razor.TagHelpers; 2 | using System.Text; 3 | 4 | namespace CmsShopping.Infrastructure.TagHelpers 5 | { 6 | public class PaginationTagHelper : TagHelper 7 | { 8 | public override void Process(TagHelperContext context, TagHelperOutput output) 9 | { 10 | output.TagName = "nav"; 11 | output.TagMode = TagMode.StartTagAndEndTag; 12 | output.Attributes.Add("aria-label", "Page navigation"); 13 | output.Content.SetHtmlContent(AddPageContent()); 14 | } 15 | 16 | public int PageNumber { get; set; } 17 | public int PageSize { get; set; } 18 | public int PageCount { get; set; } 19 | public int PageRange { get; set; } 20 | public string PageFirst { get; set; } 21 | public string PageLast { get; set; } 22 | public string PageTarget { get; set; } 23 | 24 | private string AddPageContent() 25 | { 26 | if (PageRange == 0) 27 | { 28 | PageRange = 1; 29 | } 30 | 31 | if (PageCount < PageRange) 32 | { 33 | PageRange = PageCount; 34 | } 35 | 36 | if (string.IsNullOrEmpty(PageFirst)) 37 | { 38 | PageFirst = "First"; 39 | } 40 | 41 | if (string.IsNullOrEmpty(PageLast)) 42 | { 43 | PageLast = "Last"; 44 | } 45 | 46 | var content = new StringBuilder(); 47 | content.Append("
    "); 48 | 49 | if (PageNumber != 1) 50 | { 51 | content.Append($"
  • {PageFirst}
  • "); 52 | } 53 | 54 | 55 | if (PageNumber <= PageRange) 56 | { 57 | for (int currentPage = 1; currentPage < 2 * PageRange + 1; currentPage++) 58 | { 59 | if (currentPage < 1 || currentPage > PageCount) 60 | { 61 | continue; 62 | } 63 | var active = currentPage == PageNumber ? "active" : ""; 64 | content.Append($"
  • {currentPage}
  • "); 65 | } 66 | } 67 | else if (PageNumber > PageRange && PageNumber < PageCount - PageRange) 68 | { 69 | for (int currentPage = PageNumber - PageRange; currentPage < PageNumber + PageRange; currentPage++) 70 | { 71 | if (currentPage < 1 || currentPage > PageCount) 72 | { 73 | continue; 74 | } 75 | var active = currentPage == PageNumber ? "active" : ""; 76 | content.Append($"
  • {currentPage}
  • "); 77 | } 78 | } 79 | else 80 | { 81 | for (int currentPage = PageCount - (2 * PageRange); currentPage < PageCount + 1; currentPage++) 82 | { 83 | if (currentPage < 1 || currentPage > PageCount) 84 | { 85 | continue; 86 | } 87 | var active = currentPage == PageNumber ? "active" : ""; 88 | content.Append($"
  • {currentPage}
  • "); 89 | } 90 | } 91 | 92 | if (PageNumber != PageCount) 93 | { 94 | content.Append($"
  • {PageLast}
  • "); 95 | } 96 | 97 | 98 | content.Append(" extension.EndsWith(x)); 15 | 16 | if (!result) 17 | { 18 | return new ValidationResult("Allowed extensions are jpg and png"); 19 | } 20 | } 21 | 22 | return ValidationResult.Success; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /ShoppingCart/Migrations/20220622071239_Initial.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | using ShoppingCart.Infrastructure; 8 | 9 | #nullable disable 10 | 11 | namespace ShoppingCart.Migrations 12 | { 13 | [DbContext(typeof(DataContext))] 14 | [Migration("20220622071239_Initial")] 15 | partial class Initial 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder 21 | .HasAnnotation("ProductVersion", "6.0.6") 22 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 23 | 24 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); 25 | 26 | modelBuilder.Entity("ShoppingCart.Models.Category", b => 27 | { 28 | b.Property("Id") 29 | .ValueGeneratedOnAdd() 30 | .HasColumnType("bigint"); 31 | 32 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 33 | 34 | b.Property("Name") 35 | .HasColumnType("nvarchar(max)"); 36 | 37 | b.Property("Slug") 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.HasKey("Id"); 41 | 42 | b.ToTable("Categories"); 43 | }); 44 | 45 | modelBuilder.Entity("ShoppingCart.Models.Product", b => 46 | { 47 | b.Property("Id") 48 | .ValueGeneratedOnAdd() 49 | .HasColumnType("bigint"); 50 | 51 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 52 | 53 | b.Property("CategoryId") 54 | .HasColumnType("bigint"); 55 | 56 | b.Property("Description") 57 | .IsRequired() 58 | .HasColumnType("nvarchar(max)"); 59 | 60 | b.Property("Image") 61 | .HasColumnType("nvarchar(max)"); 62 | 63 | b.Property("Name") 64 | .IsRequired() 65 | .HasColumnType("nvarchar(max)"); 66 | 67 | b.Property("Price") 68 | .HasColumnType("decimal(8,2)"); 69 | 70 | b.Property("Slug") 71 | .HasColumnType("nvarchar(max)"); 72 | 73 | b.HasKey("Id"); 74 | 75 | b.HasIndex("CategoryId"); 76 | 77 | b.ToTable("Products"); 78 | }); 79 | 80 | modelBuilder.Entity("ShoppingCart.Models.Product", b => 81 | { 82 | b.HasOne("ShoppingCart.Models.Category", "Category") 83 | .WithMany() 84 | .HasForeignKey("CategoryId") 85 | .OnDelete(DeleteBehavior.Cascade) 86 | .IsRequired(); 87 | 88 | b.Navigation("Category"); 89 | }); 90 | #pragma warning restore 612, 618 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /ShoppingCart/Migrations/20220622071239_Initial.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace ShoppingCart.Migrations 6 | { 7 | public partial class Initial : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.CreateTable( 12 | name: "Categories", 13 | columns: table => new 14 | { 15 | Id = table.Column(type: "bigint", nullable: false) 16 | .Annotation("SqlServer:Identity", "1, 1"), 17 | Name = table.Column(type: "nvarchar(max)", nullable: true), 18 | Slug = table.Column(type: "nvarchar(max)", nullable: true) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_Categories", x => x.Id); 23 | }); 24 | 25 | migrationBuilder.CreateTable( 26 | name: "Products", 27 | columns: table => new 28 | { 29 | Id = table.Column(type: "bigint", nullable: false) 30 | .Annotation("SqlServer:Identity", "1, 1"), 31 | Name = table.Column(type: "nvarchar(max)", nullable: false), 32 | Slug = table.Column(type: "nvarchar(max)", nullable: true), 33 | Description = table.Column(type: "nvarchar(max)", nullable: false), 34 | Price = table.Column(type: "decimal(8,2)", nullable: false), 35 | CategoryId = table.Column(type: "bigint", nullable: false), 36 | Image = table.Column(type: "nvarchar(max)", nullable: true) 37 | }, 38 | constraints: table => 39 | { 40 | table.PrimaryKey("PK_Products", x => x.Id); 41 | table.ForeignKey( 42 | name: "FK_Products_Categories_CategoryId", 43 | column: x => x.CategoryId, 44 | principalTable: "Categories", 45 | principalColumn: "Id", 46 | onDelete: ReferentialAction.Cascade); 47 | }); 48 | 49 | migrationBuilder.CreateIndex( 50 | name: "IX_Products_CategoryId", 51 | table: "Products", 52 | column: "CategoryId"); 53 | } 54 | 55 | protected override void Down(MigrationBuilder migrationBuilder) 56 | { 57 | migrationBuilder.DropTable( 58 | name: "Products"); 59 | 60 | migrationBuilder.DropTable( 61 | name: "Categories"); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /ShoppingCart/Migrations/20220623100340_Second.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 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 ShoppingCart.Infrastructure; 9 | 10 | #nullable disable 11 | 12 | namespace ShoppingCart.Migrations 13 | { 14 | [DbContext(typeof(DataContext))] 15 | [Migration("20220623100340_Second")] 16 | partial class Second 17 | { 18 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 19 | { 20 | #pragma warning disable 612, 618 21 | modelBuilder 22 | .HasAnnotation("ProductVersion", "6.0.6") 23 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 24 | 25 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); 26 | 27 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 28 | { 29 | b.Property("Id") 30 | .HasColumnType("nvarchar(450)"); 31 | 32 | b.Property("ConcurrencyStamp") 33 | .IsConcurrencyToken() 34 | .HasColumnType("nvarchar(max)"); 35 | 36 | b.Property("Name") 37 | .HasMaxLength(256) 38 | .HasColumnType("nvarchar(256)"); 39 | 40 | b.Property("NormalizedName") 41 | .HasMaxLength(256) 42 | .HasColumnType("nvarchar(256)"); 43 | 44 | b.HasKey("Id"); 45 | 46 | b.HasIndex("NormalizedName") 47 | .IsUnique() 48 | .HasDatabaseName("RoleNameIndex") 49 | .HasFilter("[NormalizedName] IS NOT NULL"); 50 | 51 | b.ToTable("AspNetRoles", (string)null); 52 | }); 53 | 54 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 55 | { 56 | b.Property("Id") 57 | .ValueGeneratedOnAdd() 58 | .HasColumnType("int"); 59 | 60 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 61 | 62 | b.Property("ClaimType") 63 | .HasColumnType("nvarchar(max)"); 64 | 65 | b.Property("ClaimValue") 66 | .HasColumnType("nvarchar(max)"); 67 | 68 | b.Property("RoleId") 69 | .IsRequired() 70 | .HasColumnType("nvarchar(450)"); 71 | 72 | b.HasKey("Id"); 73 | 74 | b.HasIndex("RoleId"); 75 | 76 | b.ToTable("AspNetRoleClaims", (string)null); 77 | }); 78 | 79 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 80 | { 81 | b.Property("Id") 82 | .ValueGeneratedOnAdd() 83 | .HasColumnType("int"); 84 | 85 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 86 | 87 | b.Property("ClaimType") 88 | .HasColumnType("nvarchar(max)"); 89 | 90 | b.Property("ClaimValue") 91 | .HasColumnType("nvarchar(max)"); 92 | 93 | b.Property("UserId") 94 | .IsRequired() 95 | .HasColumnType("nvarchar(450)"); 96 | 97 | b.HasKey("Id"); 98 | 99 | b.HasIndex("UserId"); 100 | 101 | b.ToTable("AspNetUserClaims", (string)null); 102 | }); 103 | 104 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 105 | { 106 | b.Property("LoginProvider") 107 | .HasColumnType("nvarchar(450)"); 108 | 109 | b.Property("ProviderKey") 110 | .HasColumnType("nvarchar(450)"); 111 | 112 | b.Property("ProviderDisplayName") 113 | .HasColumnType("nvarchar(max)"); 114 | 115 | b.Property("UserId") 116 | .IsRequired() 117 | .HasColumnType("nvarchar(450)"); 118 | 119 | b.HasKey("LoginProvider", "ProviderKey"); 120 | 121 | b.HasIndex("UserId"); 122 | 123 | b.ToTable("AspNetUserLogins", (string)null); 124 | }); 125 | 126 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 127 | { 128 | b.Property("UserId") 129 | .HasColumnType("nvarchar(450)"); 130 | 131 | b.Property("RoleId") 132 | .HasColumnType("nvarchar(450)"); 133 | 134 | b.HasKey("UserId", "RoleId"); 135 | 136 | b.HasIndex("RoleId"); 137 | 138 | b.ToTable("AspNetUserRoles", (string)null); 139 | }); 140 | 141 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 142 | { 143 | b.Property("UserId") 144 | .HasColumnType("nvarchar(450)"); 145 | 146 | b.Property("LoginProvider") 147 | .HasColumnType("nvarchar(450)"); 148 | 149 | b.Property("Name") 150 | .HasColumnType("nvarchar(450)"); 151 | 152 | b.Property("Value") 153 | .HasColumnType("nvarchar(max)"); 154 | 155 | b.HasKey("UserId", "LoginProvider", "Name"); 156 | 157 | b.ToTable("AspNetUserTokens", (string)null); 158 | }); 159 | 160 | modelBuilder.Entity("ShoppingCart.Models.AppUser", b => 161 | { 162 | b.Property("Id") 163 | .HasColumnType("nvarchar(450)"); 164 | 165 | b.Property("AccessFailedCount") 166 | .HasColumnType("int"); 167 | 168 | b.Property("ConcurrencyStamp") 169 | .IsConcurrencyToken() 170 | .HasColumnType("nvarchar(max)"); 171 | 172 | b.Property("Email") 173 | .HasMaxLength(256) 174 | .HasColumnType("nvarchar(256)"); 175 | 176 | b.Property("EmailConfirmed") 177 | .HasColumnType("bit"); 178 | 179 | b.Property("LockoutEnabled") 180 | .HasColumnType("bit"); 181 | 182 | b.Property("LockoutEnd") 183 | .HasColumnType("datetimeoffset"); 184 | 185 | b.Property("NormalizedEmail") 186 | .HasMaxLength(256) 187 | .HasColumnType("nvarchar(256)"); 188 | 189 | b.Property("NormalizedUserName") 190 | .HasMaxLength(256) 191 | .HasColumnType("nvarchar(256)"); 192 | 193 | b.Property("Occupation") 194 | .HasColumnType("nvarchar(max)"); 195 | 196 | b.Property("PasswordHash") 197 | .HasColumnType("nvarchar(max)"); 198 | 199 | b.Property("PhoneNumber") 200 | .HasColumnType("nvarchar(max)"); 201 | 202 | b.Property("PhoneNumberConfirmed") 203 | .HasColumnType("bit"); 204 | 205 | b.Property("SecurityStamp") 206 | .HasColumnType("nvarchar(max)"); 207 | 208 | b.Property("TwoFactorEnabled") 209 | .HasColumnType("bit"); 210 | 211 | b.Property("UserName") 212 | .HasMaxLength(256) 213 | .HasColumnType("nvarchar(256)"); 214 | 215 | b.HasKey("Id"); 216 | 217 | b.HasIndex("NormalizedEmail") 218 | .HasDatabaseName("EmailIndex"); 219 | 220 | b.HasIndex("NormalizedUserName") 221 | .IsUnique() 222 | .HasDatabaseName("UserNameIndex") 223 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 224 | 225 | b.ToTable("AspNetUsers", (string)null); 226 | }); 227 | 228 | modelBuilder.Entity("ShoppingCart.Models.Category", b => 229 | { 230 | b.Property("Id") 231 | .ValueGeneratedOnAdd() 232 | .HasColumnType("bigint"); 233 | 234 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 235 | 236 | b.Property("Name") 237 | .HasColumnType("nvarchar(max)"); 238 | 239 | b.Property("Slug") 240 | .HasColumnType("nvarchar(max)"); 241 | 242 | b.HasKey("Id"); 243 | 244 | b.ToTable("Categories"); 245 | }); 246 | 247 | modelBuilder.Entity("ShoppingCart.Models.Product", b => 248 | { 249 | b.Property("Id") 250 | .ValueGeneratedOnAdd() 251 | .HasColumnType("bigint"); 252 | 253 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 254 | 255 | b.Property("CategoryId") 256 | .HasColumnType("bigint"); 257 | 258 | b.Property("Description") 259 | .IsRequired() 260 | .HasColumnType("nvarchar(max)"); 261 | 262 | b.Property("Image") 263 | .HasColumnType("nvarchar(max)"); 264 | 265 | b.Property("Name") 266 | .IsRequired() 267 | .HasColumnType("nvarchar(max)"); 268 | 269 | b.Property("Price") 270 | .HasColumnType("decimal(8,2)"); 271 | 272 | b.Property("Slug") 273 | .HasColumnType("nvarchar(max)"); 274 | 275 | b.HasKey("Id"); 276 | 277 | b.HasIndex("CategoryId"); 278 | 279 | b.ToTable("Products"); 280 | }); 281 | 282 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 283 | { 284 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 285 | .WithMany() 286 | .HasForeignKey("RoleId") 287 | .OnDelete(DeleteBehavior.Cascade) 288 | .IsRequired(); 289 | }); 290 | 291 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 292 | { 293 | b.HasOne("ShoppingCart.Models.AppUser", null) 294 | .WithMany() 295 | .HasForeignKey("UserId") 296 | .OnDelete(DeleteBehavior.Cascade) 297 | .IsRequired(); 298 | }); 299 | 300 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 301 | { 302 | b.HasOne("ShoppingCart.Models.AppUser", null) 303 | .WithMany() 304 | .HasForeignKey("UserId") 305 | .OnDelete(DeleteBehavior.Cascade) 306 | .IsRequired(); 307 | }); 308 | 309 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 310 | { 311 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 312 | .WithMany() 313 | .HasForeignKey("RoleId") 314 | .OnDelete(DeleteBehavior.Cascade) 315 | .IsRequired(); 316 | 317 | b.HasOne("ShoppingCart.Models.AppUser", null) 318 | .WithMany() 319 | .HasForeignKey("UserId") 320 | .OnDelete(DeleteBehavior.Cascade) 321 | .IsRequired(); 322 | }); 323 | 324 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 325 | { 326 | b.HasOne("ShoppingCart.Models.AppUser", null) 327 | .WithMany() 328 | .HasForeignKey("UserId") 329 | .OnDelete(DeleteBehavior.Cascade) 330 | .IsRequired(); 331 | }); 332 | 333 | modelBuilder.Entity("ShoppingCart.Models.Product", b => 334 | { 335 | b.HasOne("ShoppingCart.Models.Category", "Category") 336 | .WithMany() 337 | .HasForeignKey("CategoryId") 338 | .OnDelete(DeleteBehavior.Cascade) 339 | .IsRequired(); 340 | 341 | b.Navigation("Category"); 342 | }); 343 | #pragma warning restore 612, 618 344 | } 345 | } 346 | } 347 | -------------------------------------------------------------------------------- /ShoppingCart/Migrations/20220623100340_Second.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace ShoppingCart.Migrations 6 | { 7 | public partial class Second : 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(type: "nvarchar(450)", nullable: false), 16 | Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 17 | NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 18 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", 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(type: "nvarchar(450)", nullable: false), 30 | Occupation = table.Column(type: "nvarchar(max)", nullable: true), 31 | UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 32 | NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 33 | Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 34 | NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 35 | EmailConfirmed = table.Column(type: "bit", nullable: false), 36 | PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), 37 | SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), 38 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), 39 | PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), 40 | PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), 41 | TwoFactorEnabled = table.Column(type: "bit", nullable: false), 42 | LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), 43 | LockoutEnabled = table.Column(type: "bit", nullable: false), 44 | AccessFailedCount = table.Column(type: "int", nullable: false) 45 | }, 46 | constraints: table => 47 | { 48 | table.PrimaryKey("PK_AspNetUsers", x => x.Id); 49 | }); 50 | 51 | migrationBuilder.CreateTable( 52 | name: "AspNetRoleClaims", 53 | columns: table => new 54 | { 55 | Id = table.Column(type: "int", nullable: false) 56 | .Annotation("SqlServer:Identity", "1, 1"), 57 | RoleId = table.Column(type: "nvarchar(450)", nullable: false), 58 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 59 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 60 | }, 61 | constraints: table => 62 | { 63 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); 64 | table.ForeignKey( 65 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", 66 | column: x => x.RoleId, 67 | principalTable: "AspNetRoles", 68 | principalColumn: "Id", 69 | onDelete: ReferentialAction.Cascade); 70 | }); 71 | 72 | migrationBuilder.CreateTable( 73 | name: "AspNetUserClaims", 74 | columns: table => new 75 | { 76 | Id = table.Column(type: "int", nullable: false) 77 | .Annotation("SqlServer:Identity", "1, 1"), 78 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 79 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 80 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 81 | }, 82 | constraints: table => 83 | { 84 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); 85 | table.ForeignKey( 86 | name: "FK_AspNetUserClaims_AspNetUsers_UserId", 87 | column: x => x.UserId, 88 | principalTable: "AspNetUsers", 89 | principalColumn: "Id", 90 | onDelete: ReferentialAction.Cascade); 91 | }); 92 | 93 | migrationBuilder.CreateTable( 94 | name: "AspNetUserLogins", 95 | columns: table => new 96 | { 97 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 98 | ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), 99 | ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), 100 | UserId = table.Column(type: "nvarchar(450)", nullable: false) 101 | }, 102 | constraints: table => 103 | { 104 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); 105 | table.ForeignKey( 106 | name: "FK_AspNetUserLogins_AspNetUsers_UserId", 107 | column: x => x.UserId, 108 | principalTable: "AspNetUsers", 109 | principalColumn: "Id", 110 | onDelete: ReferentialAction.Cascade); 111 | }); 112 | 113 | migrationBuilder.CreateTable( 114 | name: "AspNetUserRoles", 115 | columns: table => new 116 | { 117 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 118 | RoleId = table.Column(type: "nvarchar(450)", nullable: false) 119 | }, 120 | constraints: table => 121 | { 122 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); 123 | table.ForeignKey( 124 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId", 125 | column: x => x.RoleId, 126 | principalTable: "AspNetRoles", 127 | principalColumn: "Id", 128 | onDelete: ReferentialAction.Cascade); 129 | table.ForeignKey( 130 | name: "FK_AspNetUserRoles_AspNetUsers_UserId", 131 | column: x => x.UserId, 132 | principalTable: "AspNetUsers", 133 | principalColumn: "Id", 134 | onDelete: ReferentialAction.Cascade); 135 | }); 136 | 137 | migrationBuilder.CreateTable( 138 | name: "AspNetUserTokens", 139 | columns: table => new 140 | { 141 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 142 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 143 | Name = table.Column(type: "nvarchar(450)", nullable: false), 144 | Value = table.Column(type: "nvarchar(max)", nullable: true) 145 | }, 146 | constraints: table => 147 | { 148 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); 149 | table.ForeignKey( 150 | name: "FK_AspNetUserTokens_AspNetUsers_UserId", 151 | column: x => x.UserId, 152 | principalTable: "AspNetUsers", 153 | principalColumn: "Id", 154 | onDelete: ReferentialAction.Cascade); 155 | }); 156 | 157 | migrationBuilder.CreateIndex( 158 | name: "IX_AspNetRoleClaims_RoleId", 159 | table: "AspNetRoleClaims", 160 | column: "RoleId"); 161 | 162 | migrationBuilder.CreateIndex( 163 | name: "RoleNameIndex", 164 | table: "AspNetRoles", 165 | column: "NormalizedName", 166 | unique: true, 167 | filter: "[NormalizedName] IS NOT NULL"); 168 | 169 | migrationBuilder.CreateIndex( 170 | name: "IX_AspNetUserClaims_UserId", 171 | table: "AspNetUserClaims", 172 | column: "UserId"); 173 | 174 | migrationBuilder.CreateIndex( 175 | name: "IX_AspNetUserLogins_UserId", 176 | table: "AspNetUserLogins", 177 | column: "UserId"); 178 | 179 | migrationBuilder.CreateIndex( 180 | name: "IX_AspNetUserRoles_RoleId", 181 | table: "AspNetUserRoles", 182 | column: "RoleId"); 183 | 184 | migrationBuilder.CreateIndex( 185 | name: "EmailIndex", 186 | table: "AspNetUsers", 187 | column: "NormalizedEmail"); 188 | 189 | migrationBuilder.CreateIndex( 190 | name: "UserNameIndex", 191 | table: "AspNetUsers", 192 | column: "NormalizedUserName", 193 | unique: true, 194 | filter: "[NormalizedUserName] IS NOT NULL"); 195 | } 196 | 197 | protected override void Down(MigrationBuilder migrationBuilder) 198 | { 199 | migrationBuilder.DropTable( 200 | name: "AspNetRoleClaims"); 201 | 202 | migrationBuilder.DropTable( 203 | name: "AspNetUserClaims"); 204 | 205 | migrationBuilder.DropTable( 206 | name: "AspNetUserLogins"); 207 | 208 | migrationBuilder.DropTable( 209 | name: "AspNetUserRoles"); 210 | 211 | migrationBuilder.DropTable( 212 | name: "AspNetUserTokens"); 213 | 214 | migrationBuilder.DropTable( 215 | name: "AspNetRoles"); 216 | 217 | migrationBuilder.DropTable( 218 | name: "AspNetUsers"); 219 | } 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /ShoppingCart/Migrations/DataContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.EntityFrameworkCore.Infrastructure; 5 | using Microsoft.EntityFrameworkCore.Metadata; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | using ShoppingCart.Infrastructure; 8 | 9 | #nullable disable 10 | 11 | namespace ShoppingCart.Migrations 12 | { 13 | [DbContext(typeof(DataContext))] 14 | partial class DataContextModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "6.0.6") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 22 | 23 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); 24 | 25 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 26 | { 27 | b.Property("Id") 28 | .HasColumnType("nvarchar(450)"); 29 | 30 | b.Property("ConcurrencyStamp") 31 | .IsConcurrencyToken() 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("Name") 35 | .HasMaxLength(256) 36 | .HasColumnType("nvarchar(256)"); 37 | 38 | b.Property("NormalizedName") 39 | .HasMaxLength(256) 40 | .HasColumnType("nvarchar(256)"); 41 | 42 | b.HasKey("Id"); 43 | 44 | b.HasIndex("NormalizedName") 45 | .IsUnique() 46 | .HasDatabaseName("RoleNameIndex") 47 | .HasFilter("[NormalizedName] IS NOT NULL"); 48 | 49 | b.ToTable("AspNetRoles", (string)null); 50 | }); 51 | 52 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 53 | { 54 | b.Property("Id") 55 | .ValueGeneratedOnAdd() 56 | .HasColumnType("int"); 57 | 58 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 59 | 60 | b.Property("ClaimType") 61 | .HasColumnType("nvarchar(max)"); 62 | 63 | b.Property("ClaimValue") 64 | .HasColumnType("nvarchar(max)"); 65 | 66 | b.Property("RoleId") 67 | .IsRequired() 68 | .HasColumnType("nvarchar(450)"); 69 | 70 | b.HasKey("Id"); 71 | 72 | b.HasIndex("RoleId"); 73 | 74 | b.ToTable("AspNetRoleClaims", (string)null); 75 | }); 76 | 77 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 78 | { 79 | b.Property("Id") 80 | .ValueGeneratedOnAdd() 81 | .HasColumnType("int"); 82 | 83 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 84 | 85 | b.Property("ClaimType") 86 | .HasColumnType("nvarchar(max)"); 87 | 88 | b.Property("ClaimValue") 89 | .HasColumnType("nvarchar(max)"); 90 | 91 | b.Property("UserId") 92 | .IsRequired() 93 | .HasColumnType("nvarchar(450)"); 94 | 95 | b.HasKey("Id"); 96 | 97 | b.HasIndex("UserId"); 98 | 99 | b.ToTable("AspNetUserClaims", (string)null); 100 | }); 101 | 102 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 103 | { 104 | b.Property("LoginProvider") 105 | .HasColumnType("nvarchar(450)"); 106 | 107 | b.Property("ProviderKey") 108 | .HasColumnType("nvarchar(450)"); 109 | 110 | b.Property("ProviderDisplayName") 111 | .HasColumnType("nvarchar(max)"); 112 | 113 | b.Property("UserId") 114 | .IsRequired() 115 | .HasColumnType("nvarchar(450)"); 116 | 117 | b.HasKey("LoginProvider", "ProviderKey"); 118 | 119 | b.HasIndex("UserId"); 120 | 121 | b.ToTable("AspNetUserLogins", (string)null); 122 | }); 123 | 124 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 125 | { 126 | b.Property("UserId") 127 | .HasColumnType("nvarchar(450)"); 128 | 129 | b.Property("RoleId") 130 | .HasColumnType("nvarchar(450)"); 131 | 132 | b.HasKey("UserId", "RoleId"); 133 | 134 | b.HasIndex("RoleId"); 135 | 136 | b.ToTable("AspNetUserRoles", (string)null); 137 | }); 138 | 139 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 140 | { 141 | b.Property("UserId") 142 | .HasColumnType("nvarchar(450)"); 143 | 144 | b.Property("LoginProvider") 145 | .HasColumnType("nvarchar(450)"); 146 | 147 | b.Property("Name") 148 | .HasColumnType("nvarchar(450)"); 149 | 150 | b.Property("Value") 151 | .HasColumnType("nvarchar(max)"); 152 | 153 | b.HasKey("UserId", "LoginProvider", "Name"); 154 | 155 | b.ToTable("AspNetUserTokens", (string)null); 156 | }); 157 | 158 | modelBuilder.Entity("ShoppingCart.Models.AppUser", b => 159 | { 160 | b.Property("Id") 161 | .HasColumnType("nvarchar(450)"); 162 | 163 | b.Property("AccessFailedCount") 164 | .HasColumnType("int"); 165 | 166 | b.Property("ConcurrencyStamp") 167 | .IsConcurrencyToken() 168 | .HasColumnType("nvarchar(max)"); 169 | 170 | b.Property("Email") 171 | .HasMaxLength(256) 172 | .HasColumnType("nvarchar(256)"); 173 | 174 | b.Property("EmailConfirmed") 175 | .HasColumnType("bit"); 176 | 177 | b.Property("LockoutEnabled") 178 | .HasColumnType("bit"); 179 | 180 | b.Property("LockoutEnd") 181 | .HasColumnType("datetimeoffset"); 182 | 183 | b.Property("NormalizedEmail") 184 | .HasMaxLength(256) 185 | .HasColumnType("nvarchar(256)"); 186 | 187 | b.Property("NormalizedUserName") 188 | .HasMaxLength(256) 189 | .HasColumnType("nvarchar(256)"); 190 | 191 | b.Property("Occupation") 192 | .HasColumnType("nvarchar(max)"); 193 | 194 | b.Property("PasswordHash") 195 | .HasColumnType("nvarchar(max)"); 196 | 197 | b.Property("PhoneNumber") 198 | .HasColumnType("nvarchar(max)"); 199 | 200 | b.Property("PhoneNumberConfirmed") 201 | .HasColumnType("bit"); 202 | 203 | b.Property("SecurityStamp") 204 | .HasColumnType("nvarchar(max)"); 205 | 206 | b.Property("TwoFactorEnabled") 207 | .HasColumnType("bit"); 208 | 209 | b.Property("UserName") 210 | .HasMaxLength(256) 211 | .HasColumnType("nvarchar(256)"); 212 | 213 | b.HasKey("Id"); 214 | 215 | b.HasIndex("NormalizedEmail") 216 | .HasDatabaseName("EmailIndex"); 217 | 218 | b.HasIndex("NormalizedUserName") 219 | .IsUnique() 220 | .HasDatabaseName("UserNameIndex") 221 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 222 | 223 | b.ToTable("AspNetUsers", (string)null); 224 | }); 225 | 226 | modelBuilder.Entity("ShoppingCart.Models.Category", b => 227 | { 228 | b.Property("Id") 229 | .ValueGeneratedOnAdd() 230 | .HasColumnType("bigint"); 231 | 232 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 233 | 234 | b.Property("Name") 235 | .HasColumnType("nvarchar(max)"); 236 | 237 | b.Property("Slug") 238 | .HasColumnType("nvarchar(max)"); 239 | 240 | b.HasKey("Id"); 241 | 242 | b.ToTable("Categories"); 243 | }); 244 | 245 | modelBuilder.Entity("ShoppingCart.Models.Product", b => 246 | { 247 | b.Property("Id") 248 | .ValueGeneratedOnAdd() 249 | .HasColumnType("bigint"); 250 | 251 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); 252 | 253 | b.Property("CategoryId") 254 | .HasColumnType("bigint"); 255 | 256 | b.Property("Description") 257 | .IsRequired() 258 | .HasColumnType("nvarchar(max)"); 259 | 260 | b.Property("Image") 261 | .HasColumnType("nvarchar(max)"); 262 | 263 | b.Property("Name") 264 | .IsRequired() 265 | .HasColumnType("nvarchar(max)"); 266 | 267 | b.Property("Price") 268 | .HasColumnType("decimal(8,2)"); 269 | 270 | b.Property("Slug") 271 | .HasColumnType("nvarchar(max)"); 272 | 273 | b.HasKey("Id"); 274 | 275 | b.HasIndex("CategoryId"); 276 | 277 | b.ToTable("Products"); 278 | }); 279 | 280 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 281 | { 282 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 283 | .WithMany() 284 | .HasForeignKey("RoleId") 285 | .OnDelete(DeleteBehavior.Cascade) 286 | .IsRequired(); 287 | }); 288 | 289 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 290 | { 291 | b.HasOne("ShoppingCart.Models.AppUser", null) 292 | .WithMany() 293 | .HasForeignKey("UserId") 294 | .OnDelete(DeleteBehavior.Cascade) 295 | .IsRequired(); 296 | }); 297 | 298 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 299 | { 300 | b.HasOne("ShoppingCart.Models.AppUser", null) 301 | .WithMany() 302 | .HasForeignKey("UserId") 303 | .OnDelete(DeleteBehavior.Cascade) 304 | .IsRequired(); 305 | }); 306 | 307 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 308 | { 309 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 310 | .WithMany() 311 | .HasForeignKey("RoleId") 312 | .OnDelete(DeleteBehavior.Cascade) 313 | .IsRequired(); 314 | 315 | b.HasOne("ShoppingCart.Models.AppUser", null) 316 | .WithMany() 317 | .HasForeignKey("UserId") 318 | .OnDelete(DeleteBehavior.Cascade) 319 | .IsRequired(); 320 | }); 321 | 322 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 323 | { 324 | b.HasOne("ShoppingCart.Models.AppUser", null) 325 | .WithMany() 326 | .HasForeignKey("UserId") 327 | .OnDelete(DeleteBehavior.Cascade) 328 | .IsRequired(); 329 | }); 330 | 331 | modelBuilder.Entity("ShoppingCart.Models.Product", b => 332 | { 333 | b.HasOne("ShoppingCart.Models.Category", "Category") 334 | .WithMany() 335 | .HasForeignKey("CategoryId") 336 | .OnDelete(DeleteBehavior.Cascade) 337 | .IsRequired(); 338 | 339 | b.Navigation("Category"); 340 | }); 341 | #pragma warning restore 612, 618 342 | } 343 | } 344 | } 345 | -------------------------------------------------------------------------------- /ShoppingCart/Models/AppUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace ShoppingCart.Models 4 | { 5 | public class AppUser : IdentityUser 6 | { 7 | public string Occupation { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ShoppingCart/Models/CartItem.cs: -------------------------------------------------------------------------------- 1 | namespace ShoppingCart.Models 2 | { 3 | public class CartItem 4 | { 5 | public long ProductId { get; set; } 6 | public string ProductName { get; set; } 7 | public int Quantity { get; set; } 8 | public decimal Price { get; set; } 9 | public decimal Total 10 | { 11 | get { return Quantity * Price; } 12 | } 13 | public string Image { get; set; } 14 | 15 | public CartItem() 16 | { 17 | } 18 | 19 | public CartItem(Product product) 20 | { 21 | ProductId = product.Id; 22 | ProductName = product.Name; 23 | Price = product.Price; 24 | Quantity = 1; 25 | Image = product.Image; 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ShoppingCart/Models/Category.cs: -------------------------------------------------------------------------------- 1 | namespace ShoppingCart.Models 2 | { 3 | public class Category 4 | { 5 | public long Id { get; set; } 6 | public string Name { get; set; } 7 | public string Slug { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ShoppingCart/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace ShoppingCart.Models 2 | { 3 | public class ErrorViewModel 4 | { 5 | public string? RequestId { get; set; } 6 | 7 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 8 | } 9 | } -------------------------------------------------------------------------------- /ShoppingCart/Models/Product.cs: -------------------------------------------------------------------------------- 1 | using ShoppingCart.Infrastructure.Validation; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | 5 | namespace ShoppingCart.Models 6 | { 7 | public class Product 8 | { 9 | public long Id { get; set; } 10 | 11 | [Required(ErrorMessage = "Please enter a value")] 12 | public string Name { get; set; } 13 | 14 | public string Slug { get; set; } 15 | 16 | [Required, MinLength(4, ErrorMessage = "Minimum length is 2")] 17 | public string Description { get; set; } 18 | 19 | [Required] 20 | [Range(0.01, double.MaxValue, ErrorMessage = "Please enter a value")] 21 | [Column(TypeName = "decimal(8, 2)")] 22 | public decimal Price { get; set; } 23 | 24 | [Required, Range(1, int.MaxValue, ErrorMessage = "You must choose a category")] 25 | public long CategoryId { get; set; } 26 | 27 | public Category Category { get; set; } 28 | 29 | public string Image { get; set; } = "noimage.png"; 30 | 31 | [NotMapped] 32 | [FileExtension] 33 | public IFormFile ImageUpload { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ShoppingCart/Models/User.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace ShoppingCart.Models 4 | { 5 | public class User 6 | { 7 | public string Id { get; set; } 8 | 9 | [Required, MinLength(2, ErrorMessage = "Minimum length is 2")] 10 | [Display(Name = "Username")] 11 | public string UserName { get; set; } 12 | [Required, EmailAddress] 13 | public string Email { get; set; } 14 | [DataType(DataType.Password), Required, MinLength(4, ErrorMessage = "Minimum length is 4")] 15 | public string Password { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /ShoppingCart/Models/ViewModels/CartViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace ShoppingCart.Models.ViewModels 2 | { 3 | public class CartViewModel 4 | { 5 | public List CartItems { get; set; } 6 | public decimal GrandTotal { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ShoppingCart/Models/ViewModels/LoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace ShoppingCart.Models.ViewModels 4 | { 5 | public class LoginViewModel 6 | { 7 | [Required, MinLength(2, ErrorMessage = "Minimum length is 2")] 8 | [Display(Name = "Username")] 9 | public string UserName { get; set; } 10 | 11 | [DataType(DataType.Password), Required, MinLength(4, ErrorMessage = "Minimum length is 4")] 12 | public string Password { get; set; } 13 | 14 | public string ReturnUrl { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /ShoppingCart/Models/ViewModels/SmallCartViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace ShoppingCart.Models.ViewModels 2 | { 3 | public class SmallCartViewModel 4 | { 5 | public int NumberOfItems { get; set; } 6 | public decimal TotalAmount { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ShoppingCart/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using Microsoft.EntityFrameworkCore; 3 | using ShoppingCart.Infrastructure; 4 | using ShoppingCart.Models; 5 | 6 | var builder = WebApplication.CreateBuilder(args); 7 | 8 | builder.Services.AddDbContext(options => 9 | { 10 | options.UseSqlServer(builder.Configuration["ConnectionStrings:DbConnection"]); 11 | }); 12 | 13 | builder.Services.AddDistributedMemoryCache(); 14 | 15 | builder.Services.AddSession(options => 16 | { 17 | options.IdleTimeout = TimeSpan.FromMinutes(30); 18 | options.Cookie.IsEssential = true; 19 | }); 20 | 21 | builder.Services.AddIdentity().AddEntityFrameworkStores().AddDefaultTokenProviders(); 22 | builder.Services.Configure(options => 23 | { 24 | options.Password.RequiredLength = 4; 25 | options.Password.RequireNonAlphanumeric = false; 26 | options.Password.RequireLowercase = false; 27 | options.Password.RequireUppercase = false; 28 | options.Password.RequireDigit = false; 29 | 30 | options.User.RequireUniqueEmail = true; 31 | }); 32 | 33 | // Add services to the container. 34 | builder.Services.AddControllersWithViews(); 35 | 36 | var app = builder.Build(); 37 | 38 | app.UseSession(); 39 | 40 | // Configure the HTTP request pipeline. 41 | if (!app.Environment.IsDevelopment()) 42 | { 43 | app.UseExceptionHandler("/Home/Error"); 44 | } 45 | app.UseStaticFiles(); 46 | 47 | app.UseRouting(); 48 | 49 | app.UseAuthentication(); 50 | app.UseAuthorization(); 51 | 52 | app.MapControllerRoute( 53 | name: "Areas", 54 | pattern: "{area:exists}/{controller=Products}/{action=Index}/{id?}"); 55 | 56 | app.MapControllerRoute( 57 | name: "products", 58 | pattern: "/products/{categorySlug?}", 59 | defaults: new { controller = "Products", action = "Index" }); 60 | 61 | app.MapControllerRoute( 62 | name: "default", 63 | pattern: "{controller=Home}/{action=Index}/{id?}"); 64 | 65 | var context = app.Services.CreateScope().ServiceProvider.GetRequiredService(); 66 | SeedData.SeedDatabase(context); 67 | 68 | app.Run(); 69 | -------------------------------------------------------------------------------- /ShoppingCart/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:53250", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "ShoppingCart": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": false, 15 | "applicationUrl": "http://localhost:3000", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "IIS Express": { 21 | "commandName": "IISExpress", 22 | "launchBrowser": true, 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ShoppingCart/ShoppingCart.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | disable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | all 13 | runtime; build; native; contentfiles; analyzers; buildtransitive 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Account/Create.cshtml: -------------------------------------------------------------------------------- 1 | @model User 2 | 3 | @{ 4 | ViewData["Title"] = "Create"; 5 | } 6 | 7 |

    Create

    8 | 9 |
    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 |
    -------------------------------------------------------------------------------- /ShoppingCart/Views/Account/Login.cshtml: -------------------------------------------------------------------------------- 1 | @model LoginViewModel 2 | 3 | @{ 4 | ViewData["Title"] = "Login"; 5 | } 6 | 7 |

    Login

    8 | 9 |
    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 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Cart/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model CartViewModel 2 | 3 | @{ 4 | ViewData["Title"] = "Cart Overview"; 5 | } 6 | 7 | @if (Model.CartItems.Count > 0) 8 | { 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | @foreach (var item in Model.CartItems) 18 | { 19 | 20 | 21 | 22 | 27 | 28 | 29 | 30 | } 31 | 32 | 33 | 34 | 35 | 39 | 40 |
    ProductQuantityPriceTotal
    @item.ProductName@item.Quantity 23 | + 24 | - 25 | Remove 26 | @item.Price.ToString("C2")@Model.CartItems.Where(x => x.ProductId == item.ProductId).Sum(x => x.Quantity * x.Price).ToString("C2")
    Grand Total: @Model.GrandTotal.ToString("C2")
    36 | Clear Cart 37 | Checkout 38 |
    41 | 42 | 43 | } 44 | else 45 | { 46 |

    Your cart is empty.

    47 | } 48 | 49 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Home Page"; 3 | } 4 | 5 |
    6 |

    Welcome

    7 |

    Learn about building Web apps with ASP.NET Core.

    8 |
    9 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

    @ViewData["Title"]

    5 | 6 |

    Use this page to detail your site's privacy policy.

    7 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Products/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | 3 | @{ 4 | ViewData["Title"] = "Products"; 5 | } 6 | 7 |

    Products

    8 | 9 |
    10 | @foreach (var item in Model) 11 | { 12 |
    13 | 14 |

    @item.Name

    15 |
    16 | @Html.Raw(item.Description) 17 |
    18 |

    19 | @item.Price.ToString("C2") 20 |

    21 |

    22 | Add to cart 23 |

    24 |
    25 | } 26 | 27 | 28 | @if (ViewBag.TotalPages > 1) 29 | { 30 |
    31 | 35 | 36 |
    37 | } 38 | 39 |
    40 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Shared/Components/Categories/Default.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | 3 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Shared/Components/SmallCart/Default.cshtml: -------------------------------------------------------------------------------- 1 | @model SmallCartViewModel 2 | 3 | @if (Model != null) 4 | { 5 |

    Items in cart: @Model.NumberOfItems

    6 |

    Total: @Model.TotalAmount.ToString("C2")

    7 | View Cart 8 | Clear Cart 9 | } 10 | else 11 | { 12 |

    Your cart is empty

    13 | } 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

    Error.

    7 |

    An error occurred while processing your request.

    8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

    12 | Request ID: @Model.RequestId 13 |

    14 | } 15 | 16 |

    Development Mode

    17 |

    18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

    20 |

    21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

    26 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - ShoppingCart 7 | 8 | 9 | 10 | 11 | 12 |
    13 | 53 |
    54 |
    55 |
    56 |
    57 |
    58 | 59 | 60 |
    61 | 62 |
    63 |
    64 |
    65 | 66 | @RenderBody() 67 |
    68 |
    69 |
    70 |
    71 | 72 |
    73 |
    74 | © 2022 - ShoppingCart - Privacy 75 |
    76 |
    77 | 78 | 79 | 80 | @await RenderSectionAsync("Scripts", required: false) 81 | 82 | 83 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Shared/_Layout.cshtml.css: -------------------------------------------------------------------------------- 1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | for details on configuring this project to bundle and minify static web assets. */ 3 | 4 | a.navbar-brand { 5 | white-space: normal; 6 | text-align: center; 7 | word-break: break-all; 8 | } 9 | 10 | a { 11 | color: #0077cc; 12 | } 13 | 14 | .btn-primary { 15 | color: #fff; 16 | background-color: #1b6ec2; 17 | border-color: #1861ac; 18 | } 19 | 20 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link { 21 | color: #fff; 22 | background-color: #1b6ec2; 23 | border-color: #1861ac; 24 | } 25 | 26 | .border-top { 27 | border-top: 1px solid #e5e5e5; 28 | } 29 | .border-bottom { 30 | border-bottom: 1px solid #e5e5e5; 31 | } 32 | 33 | .box-shadow { 34 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); 35 | } 36 | 37 | button.accept-policy { 38 | font-size: 1rem; 39 | line-height: inherit; 40 | } 41 | 42 | .footer { 43 | position: absolute; 44 | bottom: 0; 45 | width: 100%; 46 | white-space: nowrap; 47 | line-height: 60px; 48 | } 49 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Shared/_NotificationPartial.cshtml: -------------------------------------------------------------------------------- 1 | @if (TempData["Success"] != null) 2 | { 3 |
    4 | @TempData["Success"] 5 |
    6 | } 7 | 8 | @if (TempData["Error"] != null) 9 | { 10 |
    11 | @TempData["Error"] 12 |
    13 | } 14 | -------------------------------------------------------------------------------- /ShoppingCart/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /ShoppingCart/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using ShoppingCart 2 | @using ShoppingCart.Models 3 | @using ShoppingCart.Models.ViewModels 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | @addTagHelper *, ShoppingCart 6 | -------------------------------------------------------------------------------- /ShoppingCart/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /ShoppingCart/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ShoppingCart/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "ConnectionStrings": { 10 | "DbConnection": "Server=(localdb)\\MSSQLLocalDB;Database=ShoppingCart;MultipleActiveResultSets=True" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-size: 14px; 3 | } 4 | 5 | @media (min-width: 768px) { 6 | html { 7 | font-size: 16px; 8 | } 9 | } 10 | 11 | html { 12 | position: relative; 13 | min-height: 100%; 14 | } 15 | 16 | body { 17 | margin-bottom: 60px; 18 | } -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fep-coder/asp.net-core-6-.net-6-project-shopping-cart/f2cf7f92f9beadf5ed30502fef1796b830d57474/ShoppingCart/wwwroot/favicon.ico -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | $(function () { 2 | 3 | if ($("a.confirmDeletion").length) { 4 | $("a.confirmDeletion").click(() => { 5 | if (!confirm("Confirm deletion")) return false; 6 | }); 7 | } 8 | 9 | if ($("div.alert.notification").length) { 10 | setTimeout(() => { 11 | $("div.alert.notification").fadeOut(); 12 | }, 2000); 13 | } 14 | 15 | }); 16 | 17 | function readURL(input) { 18 | if (input.files && input.files[0]) { 19 | let reader = new FileReader(); 20 | 21 | reader.onload = function (e) { 22 | $("img#imgpreview").attr("src", e.target.result).width(200).height(200); 23 | }; 24 | 25 | reader.readAsDataURL(input.files[0]); 26 | } 27 | } -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2021 Twitter, Inc. 4 | Copyright (c) 2011-2021 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */ 8 | *, 9 | *::before, 10 | *::after { 11 | box-sizing: border-box; 12 | } 13 | 14 | @media (prefers-reduced-motion: no-preference) { 15 | :root { 16 | scroll-behavior: smooth; 17 | } 18 | } 19 | 20 | body { 21 | margin: 0; 22 | font-family: var(--bs-body-font-family); 23 | font-size: var(--bs-body-font-size); 24 | font-weight: var(--bs-body-font-weight); 25 | line-height: var(--bs-body-line-height); 26 | color: var(--bs-body-color); 27 | text-align: var(--bs-body-text-align); 28 | background-color: var(--bs-body-bg); 29 | -webkit-text-size-adjust: 100%; 30 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 31 | } 32 | 33 | hr { 34 | margin: 1rem 0; 35 | color: inherit; 36 | background-color: currentColor; 37 | border: 0; 38 | opacity: 0.25; 39 | } 40 | 41 | hr:not([size]) { 42 | height: 1px; 43 | } 44 | 45 | h6, h5, h4, h3, h2, h1 { 46 | margin-top: 0; 47 | margin-bottom: 0.5rem; 48 | font-weight: 500; 49 | line-height: 1.2; 50 | } 51 | 52 | h1 { 53 | font-size: calc(1.375rem + 1.5vw); 54 | } 55 | @media (min-width: 1200px) { 56 | h1 { 57 | font-size: 2.5rem; 58 | } 59 | } 60 | 61 | h2 { 62 | font-size: calc(1.325rem + 0.9vw); 63 | } 64 | @media (min-width: 1200px) { 65 | h2 { 66 | font-size: 2rem; 67 | } 68 | } 69 | 70 | h3 { 71 | font-size: calc(1.3rem + 0.6vw); 72 | } 73 | @media (min-width: 1200px) { 74 | h3 { 75 | font-size: 1.75rem; 76 | } 77 | } 78 | 79 | h4 { 80 | font-size: calc(1.275rem + 0.3vw); 81 | } 82 | @media (min-width: 1200px) { 83 | h4 { 84 | font-size: 1.5rem; 85 | } 86 | } 87 | 88 | h5 { 89 | font-size: 1.25rem; 90 | } 91 | 92 | h6 { 93 | font-size: 1rem; 94 | } 95 | 96 | p { 97 | margin-top: 0; 98 | margin-bottom: 1rem; 99 | } 100 | 101 | abbr[title], 102 | abbr[data-bs-original-title] { 103 | -webkit-text-decoration: underline dotted; 104 | text-decoration: underline dotted; 105 | cursor: help; 106 | -webkit-text-decoration-skip-ink: none; 107 | text-decoration-skip-ink: none; 108 | } 109 | 110 | address { 111 | margin-bottom: 1rem; 112 | font-style: normal; 113 | line-height: inherit; 114 | } 115 | 116 | ol, 117 | ul { 118 | padding-left: 2rem; 119 | } 120 | 121 | ol, 122 | ul, 123 | dl { 124 | margin-top: 0; 125 | margin-bottom: 1rem; 126 | } 127 | 128 | ol ol, 129 | ul ul, 130 | ol ul, 131 | ul ol { 132 | margin-bottom: 0; 133 | } 134 | 135 | dt { 136 | font-weight: 700; 137 | } 138 | 139 | dd { 140 | margin-bottom: 0.5rem; 141 | margin-left: 0; 142 | } 143 | 144 | blockquote { 145 | margin: 0 0 1rem; 146 | } 147 | 148 | b, 149 | strong { 150 | font-weight: bolder; 151 | } 152 | 153 | small { 154 | font-size: 0.875em; 155 | } 156 | 157 | mark { 158 | padding: 0.2em; 159 | background-color: #fcf8e3; 160 | } 161 | 162 | sub, 163 | sup { 164 | position: relative; 165 | font-size: 0.75em; 166 | line-height: 0; 167 | vertical-align: baseline; 168 | } 169 | 170 | sub { 171 | bottom: -0.25em; 172 | } 173 | 174 | sup { 175 | top: -0.5em; 176 | } 177 | 178 | a { 179 | color: #0d6efd; 180 | text-decoration: underline; 181 | } 182 | a:hover { 183 | color: #0a58ca; 184 | } 185 | 186 | a:not([href]):not([class]), a:not([href]):not([class]):hover { 187 | color: inherit; 188 | text-decoration: none; 189 | } 190 | 191 | pre, 192 | code, 193 | kbd, 194 | samp { 195 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; 196 | font-size: 1em; 197 | direction: ltr /* rtl:ignore */; 198 | unicode-bidi: bidi-override; 199 | } 200 | 201 | pre { 202 | display: block; 203 | margin-top: 0; 204 | margin-bottom: 1rem; 205 | overflow: auto; 206 | font-size: 0.875em; 207 | } 208 | pre code { 209 | font-size: inherit; 210 | color: inherit; 211 | word-break: normal; 212 | } 213 | 214 | code { 215 | font-size: 0.875em; 216 | color: #d63384; 217 | word-wrap: break-word; 218 | } 219 | a > code { 220 | color: inherit; 221 | } 222 | 223 | kbd { 224 | padding: 0.2rem 0.4rem; 225 | font-size: 0.875em; 226 | color: #fff; 227 | background-color: #212529; 228 | border-radius: 0.2rem; 229 | } 230 | kbd kbd { 231 | padding: 0; 232 | font-size: 1em; 233 | font-weight: 700; 234 | } 235 | 236 | figure { 237 | margin: 0 0 1rem; 238 | } 239 | 240 | img, 241 | svg { 242 | vertical-align: middle; 243 | } 244 | 245 | table { 246 | caption-side: bottom; 247 | border-collapse: collapse; 248 | } 249 | 250 | caption { 251 | padding-top: 0.5rem; 252 | padding-bottom: 0.5rem; 253 | color: #6c757d; 254 | text-align: left; 255 | } 256 | 257 | th { 258 | text-align: inherit; 259 | text-align: -webkit-match-parent; 260 | } 261 | 262 | thead, 263 | tbody, 264 | tfoot, 265 | tr, 266 | td, 267 | th { 268 | border-color: inherit; 269 | border-style: solid; 270 | border-width: 0; 271 | } 272 | 273 | label { 274 | display: inline-block; 275 | } 276 | 277 | button { 278 | border-radius: 0; 279 | } 280 | 281 | button:focus:not(:focus-visible) { 282 | outline: 0; 283 | } 284 | 285 | input, 286 | button, 287 | select, 288 | optgroup, 289 | textarea { 290 | margin: 0; 291 | font-family: inherit; 292 | font-size: inherit; 293 | line-height: inherit; 294 | } 295 | 296 | button, 297 | select { 298 | text-transform: none; 299 | } 300 | 301 | [role=button] { 302 | cursor: pointer; 303 | } 304 | 305 | select { 306 | word-wrap: normal; 307 | } 308 | select:disabled { 309 | opacity: 1; 310 | } 311 | 312 | [list]::-webkit-calendar-picker-indicator { 313 | display: none; 314 | } 315 | 316 | button, 317 | [type=button], 318 | [type=reset], 319 | [type=submit] { 320 | -webkit-appearance: button; 321 | } 322 | button:not(:disabled), 323 | [type=button]:not(:disabled), 324 | [type=reset]:not(:disabled), 325 | [type=submit]:not(:disabled) { 326 | cursor: pointer; 327 | } 328 | 329 | ::-moz-focus-inner { 330 | padding: 0; 331 | border-style: none; 332 | } 333 | 334 | textarea { 335 | resize: vertical; 336 | } 337 | 338 | fieldset { 339 | min-width: 0; 340 | padding: 0; 341 | margin: 0; 342 | border: 0; 343 | } 344 | 345 | legend { 346 | float: left; 347 | width: 100%; 348 | padding: 0; 349 | margin-bottom: 0.5rem; 350 | font-size: calc(1.275rem + 0.3vw); 351 | line-height: inherit; 352 | } 353 | @media (min-width: 1200px) { 354 | legend { 355 | font-size: 1.5rem; 356 | } 357 | } 358 | legend + * { 359 | clear: left; 360 | } 361 | 362 | ::-webkit-datetime-edit-fields-wrapper, 363 | ::-webkit-datetime-edit-text, 364 | ::-webkit-datetime-edit-minute, 365 | ::-webkit-datetime-edit-hour-field, 366 | ::-webkit-datetime-edit-day-field, 367 | ::-webkit-datetime-edit-month-field, 368 | ::-webkit-datetime-edit-year-field { 369 | padding: 0; 370 | } 371 | 372 | ::-webkit-inner-spin-button { 373 | height: auto; 374 | } 375 | 376 | [type=search] { 377 | outline-offset: -2px; 378 | -webkit-appearance: textfield; 379 | } 380 | 381 | /* rtl:raw: 382 | [type="tel"], 383 | [type="url"], 384 | [type="email"], 385 | [type="number"] { 386 | direction: ltr; 387 | } 388 | */ 389 | ::-webkit-search-decoration { 390 | -webkit-appearance: none; 391 | } 392 | 393 | ::-webkit-color-swatch-wrapper { 394 | padding: 0; 395 | } 396 | 397 | ::file-selector-button { 398 | font: inherit; 399 | } 400 | 401 | ::-webkit-file-upload-button { 402 | font: inherit; 403 | -webkit-appearance: button; 404 | } 405 | 406 | output { 407 | display: inline-block; 408 | } 409 | 410 | iframe { 411 | border: 0; 412 | } 413 | 414 | summary { 415 | display: list-item; 416 | cursor: pointer; 417 | } 418 | 419 | progress { 420 | vertical-align: baseline; 421 | } 422 | 423 | [hidden] { 424 | display: none !important; 425 | } 426 | 427 | /*# sourceMappingURL=bootstrap-reboot.css.map */ -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important} 8 | /*# sourceMappingURL=bootstrap-reboot.min.css.map */ -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.rtl.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */ 8 | *, 9 | *::before, 10 | *::after { 11 | box-sizing: border-box; 12 | } 13 | 14 | @media (prefers-reduced-motion: no-preference) { 15 | :root { 16 | scroll-behavior: smooth; 17 | } 18 | } 19 | 20 | body { 21 | margin: 0; 22 | font-family: var(--bs-body-font-family); 23 | font-size: var(--bs-body-font-size); 24 | font-weight: var(--bs-body-font-weight); 25 | line-height: var(--bs-body-line-height); 26 | color: var(--bs-body-color); 27 | text-align: var(--bs-body-text-align); 28 | background-color: var(--bs-body-bg); 29 | -webkit-text-size-adjust: 100%; 30 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 31 | } 32 | 33 | hr { 34 | margin: 1rem 0; 35 | color: inherit; 36 | background-color: currentColor; 37 | border: 0; 38 | opacity: 0.25; 39 | } 40 | 41 | hr:not([size]) { 42 | height: 1px; 43 | } 44 | 45 | h6, h5, h4, h3, h2, h1 { 46 | margin-top: 0; 47 | margin-bottom: 0.5rem; 48 | font-weight: 500; 49 | line-height: 1.2; 50 | } 51 | 52 | h1 { 53 | font-size: calc(1.375rem + 1.5vw); 54 | } 55 | @media (min-width: 1200px) { 56 | h1 { 57 | font-size: 2.5rem; 58 | } 59 | } 60 | 61 | h2 { 62 | font-size: calc(1.325rem + 0.9vw); 63 | } 64 | @media (min-width: 1200px) { 65 | h2 { 66 | font-size: 2rem; 67 | } 68 | } 69 | 70 | h3 { 71 | font-size: calc(1.3rem + 0.6vw); 72 | } 73 | @media (min-width: 1200px) { 74 | h3 { 75 | font-size: 1.75rem; 76 | } 77 | } 78 | 79 | h4 { 80 | font-size: calc(1.275rem + 0.3vw); 81 | } 82 | @media (min-width: 1200px) { 83 | h4 { 84 | font-size: 1.5rem; 85 | } 86 | } 87 | 88 | h5 { 89 | font-size: 1.25rem; 90 | } 91 | 92 | h6 { 93 | font-size: 1rem; 94 | } 95 | 96 | p { 97 | margin-top: 0; 98 | margin-bottom: 1rem; 99 | } 100 | 101 | abbr[title], 102 | abbr[data-bs-original-title] { 103 | -webkit-text-decoration: underline dotted; 104 | text-decoration: underline dotted; 105 | cursor: help; 106 | -webkit-text-decoration-skip-ink: none; 107 | text-decoration-skip-ink: none; 108 | } 109 | 110 | address { 111 | margin-bottom: 1rem; 112 | font-style: normal; 113 | line-height: inherit; 114 | } 115 | 116 | ol, 117 | ul { 118 | padding-right: 2rem; 119 | } 120 | 121 | ol, 122 | ul, 123 | dl { 124 | margin-top: 0; 125 | margin-bottom: 1rem; 126 | } 127 | 128 | ol ol, 129 | ul ul, 130 | ol ul, 131 | ul ol { 132 | margin-bottom: 0; 133 | } 134 | 135 | dt { 136 | font-weight: 700; 137 | } 138 | 139 | dd { 140 | margin-bottom: 0.5rem; 141 | margin-right: 0; 142 | } 143 | 144 | blockquote { 145 | margin: 0 0 1rem; 146 | } 147 | 148 | b, 149 | strong { 150 | font-weight: bolder; 151 | } 152 | 153 | small { 154 | font-size: 0.875em; 155 | } 156 | 157 | mark { 158 | padding: 0.2em; 159 | background-color: #fcf8e3; 160 | } 161 | 162 | sub, 163 | sup { 164 | position: relative; 165 | font-size: 0.75em; 166 | line-height: 0; 167 | vertical-align: baseline; 168 | } 169 | 170 | sub { 171 | bottom: -0.25em; 172 | } 173 | 174 | sup { 175 | top: -0.5em; 176 | } 177 | 178 | a { 179 | color: #0d6efd; 180 | text-decoration: underline; 181 | } 182 | a:hover { 183 | color: #0a58ca; 184 | } 185 | 186 | a:not([href]):not([class]), a:not([href]):not([class]):hover { 187 | color: inherit; 188 | text-decoration: none; 189 | } 190 | 191 | pre, 192 | code, 193 | kbd, 194 | samp { 195 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; 196 | font-size: 1em; 197 | direction: ltr ; 198 | unicode-bidi: bidi-override; 199 | } 200 | 201 | pre { 202 | display: block; 203 | margin-top: 0; 204 | margin-bottom: 1rem; 205 | overflow: auto; 206 | font-size: 0.875em; 207 | } 208 | pre code { 209 | font-size: inherit; 210 | color: inherit; 211 | word-break: normal; 212 | } 213 | 214 | code { 215 | font-size: 0.875em; 216 | color: #d63384; 217 | word-wrap: break-word; 218 | } 219 | a > code { 220 | color: inherit; 221 | } 222 | 223 | kbd { 224 | padding: 0.2rem 0.4rem; 225 | font-size: 0.875em; 226 | color: #fff; 227 | background-color: #212529; 228 | border-radius: 0.2rem; 229 | } 230 | kbd kbd { 231 | padding: 0; 232 | font-size: 1em; 233 | font-weight: 700; 234 | } 235 | 236 | figure { 237 | margin: 0 0 1rem; 238 | } 239 | 240 | img, 241 | svg { 242 | vertical-align: middle; 243 | } 244 | 245 | table { 246 | caption-side: bottom; 247 | border-collapse: collapse; 248 | } 249 | 250 | caption { 251 | padding-top: 0.5rem; 252 | padding-bottom: 0.5rem; 253 | color: #6c757d; 254 | text-align: right; 255 | } 256 | 257 | th { 258 | text-align: inherit; 259 | text-align: -webkit-match-parent; 260 | } 261 | 262 | thead, 263 | tbody, 264 | tfoot, 265 | tr, 266 | td, 267 | th { 268 | border-color: inherit; 269 | border-style: solid; 270 | border-width: 0; 271 | } 272 | 273 | label { 274 | display: inline-block; 275 | } 276 | 277 | button { 278 | border-radius: 0; 279 | } 280 | 281 | button:focus:not(:focus-visible) { 282 | outline: 0; 283 | } 284 | 285 | input, 286 | button, 287 | select, 288 | optgroup, 289 | textarea { 290 | margin: 0; 291 | font-family: inherit; 292 | font-size: inherit; 293 | line-height: inherit; 294 | } 295 | 296 | button, 297 | select { 298 | text-transform: none; 299 | } 300 | 301 | [role=button] { 302 | cursor: pointer; 303 | } 304 | 305 | select { 306 | word-wrap: normal; 307 | } 308 | select:disabled { 309 | opacity: 1; 310 | } 311 | 312 | [list]::-webkit-calendar-picker-indicator { 313 | display: none; 314 | } 315 | 316 | button, 317 | [type=button], 318 | [type=reset], 319 | [type=submit] { 320 | -webkit-appearance: button; 321 | } 322 | button:not(:disabled), 323 | [type=button]:not(:disabled), 324 | [type=reset]:not(:disabled), 325 | [type=submit]:not(:disabled) { 326 | cursor: pointer; 327 | } 328 | 329 | ::-moz-focus-inner { 330 | padding: 0; 331 | border-style: none; 332 | } 333 | 334 | textarea { 335 | resize: vertical; 336 | } 337 | 338 | fieldset { 339 | min-width: 0; 340 | padding: 0; 341 | margin: 0; 342 | border: 0; 343 | } 344 | 345 | legend { 346 | float: right; 347 | width: 100%; 348 | padding: 0; 349 | margin-bottom: 0.5rem; 350 | font-size: calc(1.275rem + 0.3vw); 351 | line-height: inherit; 352 | } 353 | @media (min-width: 1200px) { 354 | legend { 355 | font-size: 1.5rem; 356 | } 357 | } 358 | legend + * { 359 | clear: right; 360 | } 361 | 362 | ::-webkit-datetime-edit-fields-wrapper, 363 | ::-webkit-datetime-edit-text, 364 | ::-webkit-datetime-edit-minute, 365 | ::-webkit-datetime-edit-hour-field, 366 | ::-webkit-datetime-edit-day-field, 367 | ::-webkit-datetime-edit-month-field, 368 | ::-webkit-datetime-edit-year-field { 369 | padding: 0; 370 | } 371 | 372 | ::-webkit-inner-spin-button { 373 | height: auto; 374 | } 375 | 376 | [type=search] { 377 | outline-offset: -2px; 378 | -webkit-appearance: textfield; 379 | } 380 | 381 | [type="tel"], 382 | [type="url"], 383 | [type="email"], 384 | [type="number"] { 385 | direction: ltr; 386 | } 387 | ::-webkit-search-decoration { 388 | -webkit-appearance: none; 389 | } 390 | 391 | ::-webkit-color-swatch-wrapper { 392 | padding: 0; 393 | } 394 | 395 | ::file-selector-button { 396 | font: inherit; 397 | } 398 | 399 | ::-webkit-file-upload-button { 400 | font: inherit; 401 | -webkit-appearance: button; 402 | } 403 | 404 | output { 405 | display: inline-block; 406 | } 407 | 408 | iframe { 409 | border: 0; 410 | } 411 | 412 | summary { 413 | display: list-item; 414 | cursor: pointer; 415 | } 416 | 417 | progress { 418 | vertical-align: baseline; 419 | } 420 | 421 | [hidden] { 422 | display: none !important; 423 | } 424 | /*# sourceMappingURL=bootstrap-reboot.rtl.css.map */ -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.rtl.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-right:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-right:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:right}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:right;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:right}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}[type=email],[type=number],[type=tel],[type=url]{direction:ltr}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important} 8 | /*# sourceMappingURL=bootstrap-reboot.rtl.min.css.map */ -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (c) .NET Foundation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4 | // @version v3.2.11 5 | 6 | /*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: false */ 7 | /*global document: false, jQuery: false */ 8 | 9 | (function (factory) { 10 | if (typeof define === 'function' && define.amd) { 11 | // AMD. Register as an anonymous module. 12 | define("jquery.validate.unobtrusive", ['jquery-validation'], factory); 13 | } else if (typeof module === 'object' && module.exports) { 14 | // CommonJS-like environments that support module.exports 15 | module.exports = factory(require('jquery-validation')); 16 | } else { 17 | // Browser global 18 | jQuery.validator.unobtrusive = factory(jQuery); 19 | } 20 | }(function ($) { 21 | var $jQval = $.validator, 22 | adapters, 23 | data_validation = "unobtrusiveValidation"; 24 | 25 | function setValidationValues(options, ruleName, value) { 26 | options.rules[ruleName] = value; 27 | if (options.message) { 28 | options.messages[ruleName] = options.message; 29 | } 30 | } 31 | 32 | function splitAndTrim(value) { 33 | return value.replace(/^\s+|\s+$/g, "").split(/\s*,\s*/g); 34 | } 35 | 36 | function escapeAttributeValue(value) { 37 | // As mentioned on http://api.jquery.com/category/selectors/ 38 | return value.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g, "\\$1"); 39 | } 40 | 41 | function getModelPrefix(fieldName) { 42 | return fieldName.substr(0, fieldName.lastIndexOf(".") + 1); 43 | } 44 | 45 | function appendModelPrefix(value, prefix) { 46 | if (value.indexOf("*.") === 0) { 47 | value = value.replace("*.", prefix); 48 | } 49 | return value; 50 | } 51 | 52 | function onError(error, inputElement) { // 'this' is the form element 53 | var container = $(this).find("[data-valmsg-for='" + escapeAttributeValue(inputElement[0].name) + "']"), 54 | replaceAttrValue = container.attr("data-valmsg-replace"), 55 | replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) !== false : null; 56 | 57 | container.removeClass("field-validation-valid").addClass("field-validation-error"); 58 | error.data("unobtrusiveContainer", container); 59 | 60 | if (replace) { 61 | container.empty(); 62 | error.removeClass("input-validation-error").appendTo(container); 63 | } 64 | else { 65 | error.hide(); 66 | } 67 | } 68 | 69 | function onErrors(event, validator) { // 'this' is the form element 70 | var container = $(this).find("[data-valmsg-summary=true]"), 71 | list = container.find("ul"); 72 | 73 | if (list && list.length && validator.errorList.length) { 74 | list.empty(); 75 | container.addClass("validation-summary-errors").removeClass("validation-summary-valid"); 76 | 77 | $.each(validator.errorList, function () { 78 | $("
  • ").html(this.message).appendTo(list); 79 | }); 80 | } 81 | } 82 | 83 | function onSuccess(error) { // 'this' is the form element 84 | var container = error.data("unobtrusiveContainer"); 85 | 86 | if (container) { 87 | var replaceAttrValue = container.attr("data-valmsg-replace"), 88 | replace = replaceAttrValue ? $.parseJSON(replaceAttrValue) : null; 89 | 90 | container.addClass("field-validation-valid").removeClass("field-validation-error"); 91 | error.removeData("unobtrusiveContainer"); 92 | 93 | if (replace) { 94 | container.empty(); 95 | } 96 | } 97 | } 98 | 99 | function onReset(event) { // 'this' is the form element 100 | var $form = $(this), 101 | key = '__jquery_unobtrusive_validation_form_reset'; 102 | if ($form.data(key)) { 103 | return; 104 | } 105 | // Set a flag that indicates we're currently resetting the form. 106 | $form.data(key, true); 107 | try { 108 | $form.data("validator").resetForm(); 109 | } finally { 110 | $form.removeData(key); 111 | } 112 | 113 | $form.find(".validation-summary-errors") 114 | .addClass("validation-summary-valid") 115 | .removeClass("validation-summary-errors"); 116 | $form.find(".field-validation-error") 117 | .addClass("field-validation-valid") 118 | .removeClass("field-validation-error") 119 | .removeData("unobtrusiveContainer") 120 | .find(">*") // If we were using valmsg-replace, get the underlying error 121 | .removeData("unobtrusiveContainer"); 122 | } 123 | 124 | function validationInfo(form) { 125 | var $form = $(form), 126 | result = $form.data(data_validation), 127 | onResetProxy = $.proxy(onReset, form), 128 | defaultOptions = $jQval.unobtrusive.options || {}, 129 | execInContext = function (name, args) { 130 | var func = defaultOptions[name]; 131 | func && $.isFunction(func) && func.apply(form, args); 132 | }; 133 | 134 | if (!result) { 135 | result = { 136 | options: { // options structure passed to jQuery Validate's validate() method 137 | errorClass: defaultOptions.errorClass || "input-validation-error", 138 | errorElement: defaultOptions.errorElement || "span", 139 | errorPlacement: function () { 140 | onError.apply(form, arguments); 141 | execInContext("errorPlacement", arguments); 142 | }, 143 | invalidHandler: function () { 144 | onErrors.apply(form, arguments); 145 | execInContext("invalidHandler", arguments); 146 | }, 147 | messages: {}, 148 | rules: {}, 149 | success: function () { 150 | onSuccess.apply(form, arguments); 151 | execInContext("success", arguments); 152 | } 153 | }, 154 | attachValidation: function () { 155 | $form 156 | .off("reset." + data_validation, onResetProxy) 157 | .on("reset." + data_validation, onResetProxy) 158 | .validate(this.options); 159 | }, 160 | validate: function () { // a validation function that is called by unobtrusive Ajax 161 | $form.validate(); 162 | return $form.valid(); 163 | } 164 | }; 165 | $form.data(data_validation, result); 166 | } 167 | 168 | return result; 169 | } 170 | 171 | $jQval.unobtrusive = { 172 | adapters: [], 173 | 174 | parseElement: function (element, skipAttach) { 175 | /// 176 | /// Parses a single HTML element for unobtrusive validation attributes. 177 | /// 178 | /// The HTML element to be parsed. 179 | /// [Optional] true to skip attaching the 180 | /// validation to the form. If parsing just this single element, you should specify true. 181 | /// If parsing several elements, you should specify false, and manually attach the validation 182 | /// to the form when you are finished. The default is false. 183 | var $element = $(element), 184 | form = $element.parents("form")[0], 185 | valInfo, rules, messages; 186 | 187 | if (!form) { // Cannot do client-side validation without a form 188 | return; 189 | } 190 | 191 | valInfo = validationInfo(form); 192 | valInfo.options.rules[element.name] = rules = {}; 193 | valInfo.options.messages[element.name] = messages = {}; 194 | 195 | $.each(this.adapters, function () { 196 | var prefix = "data-val-" + this.name, 197 | message = $element.attr(prefix), 198 | paramValues = {}; 199 | 200 | if (message !== undefined) { // Compare against undefined, because an empty message is legal (and falsy) 201 | prefix += "-"; 202 | 203 | $.each(this.params, function () { 204 | paramValues[this] = $element.attr(prefix + this); 205 | }); 206 | 207 | this.adapt({ 208 | element: element, 209 | form: form, 210 | message: message, 211 | params: paramValues, 212 | rules: rules, 213 | messages: messages 214 | }); 215 | } 216 | }); 217 | 218 | $.extend(rules, { "__dummy__": true }); 219 | 220 | if (!skipAttach) { 221 | valInfo.attachValidation(); 222 | } 223 | }, 224 | 225 | parse: function (selector) { 226 | /// 227 | /// Parses all the HTML elements in the specified selector. It looks for input elements decorated 228 | /// with the [data-val=true] attribute value and enables validation according to the data-val-* 229 | /// attribute values. 230 | /// 231 | /// Any valid jQuery selector. 232 | 233 | // $forms includes all forms in selector's DOM hierarchy (parent, children and self) that have at least one 234 | // element with data-val=true 235 | var $selector = $(selector), 236 | $forms = $selector.parents() 237 | .addBack() 238 | .filter("form") 239 | .add($selector.find("form")) 240 | .has("[data-val=true]"); 241 | 242 | $selector.find("[data-val=true]").each(function () { 243 | $jQval.unobtrusive.parseElement(this, true); 244 | }); 245 | 246 | $forms.each(function () { 247 | var info = validationInfo(this); 248 | if (info) { 249 | info.attachValidation(); 250 | } 251 | }); 252 | } 253 | }; 254 | 255 | adapters = $jQval.unobtrusive.adapters; 256 | 257 | adapters.add = function (adapterName, params, fn) { 258 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation. 259 | /// The name of the adapter to be added. This matches the name used 260 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 261 | /// [Optional] An array of parameter names (strings) that will 262 | /// be extracted from the data-val-nnnn-mmmm HTML attributes (where nnnn is the adapter name, and 263 | /// mmmm is the parameter name). 264 | /// The function to call, which adapts the values from the HTML 265 | /// attributes into jQuery Validate rules and/or messages. 266 | /// 267 | if (!fn) { // Called with no params, just a function 268 | fn = params; 269 | params = []; 270 | } 271 | this.push({ name: adapterName, params: params, adapt: fn }); 272 | return this; 273 | }; 274 | 275 | adapters.addBool = function (adapterName, ruleName) { 276 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 277 | /// the jQuery Validate validation rule has no parameter values. 278 | /// The name of the adapter to be added. This matches the name used 279 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 280 | /// [Optional] The name of the jQuery Validate rule. If not provided, the value 281 | /// of adapterName will be used instead. 282 | /// 283 | return this.add(adapterName, function (options) { 284 | setValidationValues(options, ruleName || adapterName, true); 285 | }); 286 | }; 287 | 288 | adapters.addMinMax = function (adapterName, minRuleName, maxRuleName, minMaxRuleName, minAttribute, maxAttribute) { 289 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 290 | /// the jQuery Validate validation has three potential rules (one for min-only, one for max-only, and 291 | /// one for min-and-max). The HTML parameters are expected to be named -min and -max. 292 | /// The name of the adapter to be added. This matches the name used 293 | /// in the data-val-nnnn HTML attribute (where nnnn is the adapter name). 294 | /// The name of the jQuery Validate rule to be used when you only 295 | /// have a minimum value. 296 | /// The name of the jQuery Validate rule to be used when you only 297 | /// have a maximum value. 298 | /// The name of the jQuery Validate rule to be used when you 299 | /// have both a minimum and maximum value. 300 | /// [Optional] The name of the HTML attribute that 301 | /// contains the minimum value. The default is "min". 302 | /// [Optional] The name of the HTML attribute that 303 | /// contains the maximum value. The default is "max". 304 | /// 305 | return this.add(adapterName, [minAttribute || "min", maxAttribute || "max"], function (options) { 306 | var min = options.params.min, 307 | max = options.params.max; 308 | 309 | if (min && max) { 310 | setValidationValues(options, minMaxRuleName, [min, max]); 311 | } 312 | else if (min) { 313 | setValidationValues(options, minRuleName, min); 314 | } 315 | else if (max) { 316 | setValidationValues(options, maxRuleName, max); 317 | } 318 | }); 319 | }; 320 | 321 | adapters.addSingleVal = function (adapterName, attribute, ruleName) { 322 | /// Adds a new adapter to convert unobtrusive HTML into a jQuery Validate validation, where 323 | /// the jQuery Validate validation rule has a single value. 324 | /// The name of the adapter to be added. This matches the name used 325 | /// in the data-val-nnnn HTML attribute(where nnnn is the adapter name). 326 | /// [Optional] The name of the HTML attribute that contains the value. 327 | /// The default is "val". 328 | /// [Optional] The name of the jQuery Validate rule. If not provided, the value 329 | /// of adapterName will be used instead. 330 | /// 331 | return this.add(adapterName, [attribute || "val"], function (options) { 332 | setValidationValues(options, ruleName || adapterName, options.params[attribute]); 333 | }); 334 | }; 335 | 336 | $jQval.addMethod("__dummy__", function (value, element, params) { 337 | return true; 338 | }); 339 | 340 | $jQval.addMethod("regex", function (value, element, params) { 341 | var match; 342 | if (this.optional(element)) { 343 | return true; 344 | } 345 | 346 | match = new RegExp(params).exec(value); 347 | return (match && (match.index === 0) && (match[0].length === value.length)); 348 | }); 349 | 350 | $jQval.addMethod("nonalphamin", function (value, element, nonalphamin) { 351 | var match; 352 | if (nonalphamin) { 353 | match = value.match(/\W/g); 354 | match = match && match.length >= nonalphamin; 355 | } 356 | return match; 357 | }); 358 | 359 | if ($jQval.methods.extension) { 360 | adapters.addSingleVal("accept", "mimtype"); 361 | adapters.addSingleVal("extension", "extension"); 362 | } else { 363 | // for backward compatibility, when the 'extension' validation method does not exist, such as with versions 364 | // of JQuery Validation plugin prior to 1.10, we should use the 'accept' method for 365 | // validating the extension, and ignore mime-type validations as they are not supported. 366 | adapters.addSingleVal("extension", "extension", "accept"); 367 | } 368 | 369 | adapters.addSingleVal("regex", "pattern"); 370 | adapters.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"); 371 | adapters.addMinMax("length", "minlength", "maxlength", "rangelength").addMinMax("range", "min", "max", "range"); 372 | adapters.addMinMax("minlength", "minlength").addMinMax("maxlength", "minlength", "maxlength"); 373 | adapters.add("equalto", ["other"], function (options) { 374 | var prefix = getModelPrefix(options.element.name), 375 | other = options.params.other, 376 | fullOtherName = appendModelPrefix(other, prefix), 377 | element = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(fullOtherName) + "']")[0]; 378 | 379 | setValidationValues(options, "equalTo", element); 380 | }); 381 | adapters.add("required", function (options) { 382 | // jQuery Validate equates "required" with "mandatory" for checkbox elements 383 | if (options.element.tagName.toUpperCase() !== "INPUT" || options.element.type.toUpperCase() !== "CHECKBOX") { 384 | setValidationValues(options, "required", true); 385 | } 386 | }); 387 | adapters.add("remote", ["url", "type", "additionalfields"], function (options) { 388 | var value = { 389 | url: options.params.url, 390 | type: options.params.type || "GET", 391 | data: {} 392 | }, 393 | prefix = getModelPrefix(options.element.name); 394 | 395 | $.each(splitAndTrim(options.params.additionalfields || options.element.name), function (i, fieldName) { 396 | var paramName = appendModelPrefix(fieldName, prefix); 397 | value.data[paramName] = function () { 398 | var field = $(options.form).find(":input").filter("[name='" + escapeAttributeValue(paramName) + "']"); 399 | // For checkboxes and radio buttons, only pick up values from checked fields. 400 | if (field.is(":checkbox")) { 401 | return field.filter(":checked").val() || field.filter(":hidden").val() || ''; 402 | } 403 | else if (field.is(":radio")) { 404 | return field.filter(":checked").val() || ''; 405 | } 406 | return field.val(); 407 | }; 408 | }); 409 | 410 | setValidationValues(options, "remote", value); 411 | }); 412 | adapters.add("password", ["min", "nonalphamin", "regex"], function (options) { 413 | if (options.params.min) { 414 | setValidationValues(options, "minlength", options.params.min); 415 | } 416 | if (options.params.nonalphamin) { 417 | setValidationValues(options, "nonalphamin", options.params.nonalphamin); 418 | } 419 | if (options.params.regex) { 420 | setValidationValues(options, "regex", options.params.regex); 421 | } 422 | }); 423 | adapters.add("fileextensions", ["extensions"], function (options) { 424 | setValidationValues(options, "extension", options.params.extensions); 425 | }); 426 | 427 | $(function () { 428 | $jQval.unobtrusive.parse(document); 429 | }); 430 | 431 | return $jQval.unobtrusive; 432 | })); 433 | -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (c) .NET Foundation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4 | // @version v3.2.11 5 | !function(a){"function"==typeof define&&define.amd?define("jquery.validate.unobtrusive",["jquery-validation"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery-validation")):jQuery.validator.unobtrusive=a(jQuery)}(function(a){function e(a,e,n){a.rules[e]=n,a.message&&(a.messages[e]=a.message)}function n(a){return a.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function t(a){return a.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g,"\\$1")}function r(a){return a.substr(0,a.lastIndexOf(".")+1)}function i(a,e){return 0===a.indexOf("*.")&&(a=a.replace("*.",e)),a}function o(e,n){var r=a(this).find("[data-valmsg-for='"+t(n[0].name)+"']"),i=r.attr("data-valmsg-replace"),o=i?a.parseJSON(i)!==!1:null;r.removeClass("field-validation-valid").addClass("field-validation-error"),e.data("unobtrusiveContainer",r),o?(r.empty(),e.removeClass("input-validation-error").appendTo(r)):e.hide()}function d(e,n){var t=a(this).find("[data-valmsg-summary=true]"),r=t.find("ul");r&&r.length&&n.errorList.length&&(r.empty(),t.addClass("validation-summary-errors").removeClass("validation-summary-valid"),a.each(n.errorList,function(){a("
  • ").html(this.message).appendTo(r)}))}function s(e){var n=e.data("unobtrusiveContainer");if(n){var t=n.attr("data-valmsg-replace"),r=t?a.parseJSON(t):null;n.addClass("field-validation-valid").removeClass("field-validation-error"),e.removeData("unobtrusiveContainer"),r&&n.empty()}}function l(e){var n=a(this),t="__jquery_unobtrusive_validation_form_reset";if(!n.data(t)){n.data(t,!0);try{n.data("validator").resetForm()}finally{n.removeData(t)}n.find(".validation-summary-errors").addClass("validation-summary-valid").removeClass("validation-summary-errors"),n.find(".field-validation-error").addClass("field-validation-valid").removeClass("field-validation-error").removeData("unobtrusiveContainer").find(">*").removeData("unobtrusiveContainer")}}function u(e){var n=a(e),t=n.data(v),r=a.proxy(l,e),i=f.unobtrusive.options||{},u=function(n,t){var r=i[n];r&&a.isFunction(r)&&r.apply(e,t)};return t||(t={options:{errorClass:i.errorClass||"input-validation-error",errorElement:i.errorElement||"span",errorPlacement:function(){o.apply(e,arguments),u("errorPlacement",arguments)},invalidHandler:function(){d.apply(e,arguments),u("invalidHandler",arguments)},messages:{},rules:{},success:function(){s.apply(e,arguments),u("success",arguments)}},attachValidation:function(){n.off("reset."+v,r).on("reset."+v,r).validate(this.options)},validate:function(){return n.validate(),n.valid()}},n.data(v,t)),t}var m,f=a.validator,v="unobtrusiveValidation";return f.unobtrusive={adapters:[],parseElement:function(e,n){var t,r,i,o=a(e),d=o.parents("form")[0];d&&(t=u(d),t.options.rules[e.name]=r={},t.options.messages[e.name]=i={},a.each(this.adapters,function(){var n="data-val-"+this.name,t=o.attr(n),s={};void 0!==t&&(n+="-",a.each(this.params,function(){s[this]=o.attr(n+this)}),this.adapt({element:e,form:d,message:t,params:s,rules:r,messages:i}))}),a.extend(r,{__dummy__:!0}),n||t.attachValidation())},parse:function(e){var n=a(e),t=n.parents().addBack().filter("form").add(n.find("form")).has("[data-val=true]");n.find("[data-val=true]").each(function(){f.unobtrusive.parseElement(this,!0)}),t.each(function(){var a=u(this);a&&a.attachValidation()})}},m=f.unobtrusive.adapters,m.add=function(a,e,n){return n||(n=e,e=[]),this.push({name:a,params:e,adapt:n}),this},m.addBool=function(a,n){return this.add(a,function(t){e(t,n||a,!0)})},m.addMinMax=function(a,n,t,r,i,o){return this.add(a,[i||"min",o||"max"],function(a){var i=a.params.min,o=a.params.max;i&&o?e(a,r,[i,o]):i?e(a,n,i):o&&e(a,t,o)})},m.addSingleVal=function(a,n,t){return this.add(a,[n||"val"],function(r){e(r,t||a,r.params[n])})},f.addMethod("__dummy__",function(a,e,n){return!0}),f.addMethod("regex",function(a,e,n){var t;return!!this.optional(e)||(t=new RegExp(n).exec(a),t&&0===t.index&&t[0].length===a.length)}),f.addMethod("nonalphamin",function(a,e,n){var t;return n&&(t=a.match(/\W/g),t=t&&t.length>=n),t}),f.methods.extension?(m.addSingleVal("accept","mimtype"),m.addSingleVal("extension","extension")):m.addSingleVal("extension","extension","accept"),m.addSingleVal("regex","pattern"),m.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"),m.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range"),m.addMinMax("minlength","minlength").addMinMax("maxlength","minlength","maxlength"),m.add("equalto",["other"],function(n){var o=r(n.element.name),d=n.params.other,s=i(d,o),l=a(n.form).find(":input").filter("[name='"+t(s)+"']")[0];e(n,"equalTo",l)}),m.add("required",function(a){"INPUT"===a.element.tagName.toUpperCase()&&"CHECKBOX"===a.element.type.toUpperCase()||e(a,"required",!0)}),m.add("remote",["url","type","additionalfields"],function(o){var d={url:o.params.url,type:o.params.type||"GET",data:{}},s=r(o.element.name);a.each(n(o.params.additionalfields||o.element.name),function(e,n){var r=i(n,s);d.data[r]=function(){var e=a(o.form).find(":input").filter("[name='"+t(r)+"']");return e.is(":checkbox")?e.filter(":checked").val()||e.filter(":hidden").val()||"":e.is(":radio")?e.filter(":checked").val()||"":e.val()}}),e(o,"remote",d)}),m.add("password",["min","nonalphamin","regex"],function(a){a.params.min&&e(a,"minlength",a.params.min),a.params.nonalphamin&&e(a,"nonalphamin",a.params.nonalphamin),a.params.regex&&e(a,"regex",a.params.regex)}),m.add("fileextensions",["extensions"],function(a){e(a,"extension",a.params.extensions)}),a(function(){f.unobtrusive.parse(document)}),f.unobtrusive}); 6 | -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /ShoppingCart/wwwroot/lib/jquery-validation/dist/additional-methods.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery Validation Plugin - v1.17.0 - 7/29/2017 2 | * https://jqueryvalidation.org/ 3 | * Copyright (c) 2017 Jörn Zaefferer; Licensed MIT */ 4 | !function(a){"function"==typeof define&&define.amd?define(["jquery","./jquery.validate.min"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){return function(){function b(a){return a.replace(/<.[^<>]*?>/g," ").replace(/ | /gi," ").replace(/[.(),;:!?%#$'\"_+=\/\-“”’]*/g,"")}a.validator.addMethod("maxWords",function(a,c,d){return this.optional(c)||b(a).match(/\b\w+\b/g).length<=d},a.validator.format("Please enter {0} words or less.")),a.validator.addMethod("minWords",function(a,c,d){return this.optional(c)||b(a).match(/\b\w+\b/g).length>=d},a.validator.format("Please enter at least {0} words.")),a.validator.addMethod("rangeWords",function(a,c,d){var e=b(a),f=/\b\w+\b/g;return this.optional(c)||e.match(f).length>=d[0]&&e.match(f).length<=d[1]},a.validator.format("Please enter between {0} and {1} words."))}(),a.validator.addMethod("accept",function(b,c,d){var e,f,g,h="string"==typeof d?d.replace(/\s/g,""):"image/*",i=this.optional(c);if(i)return i;if("file"===a(c).attr("type")&&(h=h.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g,"\\$&").replace(/,/g,"|").replace(/\/\*/g,"/.*"),c.files&&c.files.length))for(g=new RegExp(".?("+h+")$","i"),e=0;e9?"0":f,g="JABCDEFGHI".substr(f,1).toString(),i.match(/[ABEH]/)?k===f:i.match(/[KPQS]/)?k===g:k===f||k===g},"Please specify a valid CIF number."),a.validator.addMethod("cpfBR",function(a){if(a=a.replace(/([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g,""),11!==a.length)return!1;var b,c,d,e,f=0;if(b=parseInt(a.substring(9,10),10),c=parseInt(a.substring(10,11),10),d=function(a,b){var c=10*a%11;return 10!==c&&11!==c||(c=0),c===b},""===a||"00000000000"===a||"11111111111"===a||"22222222222"===a||"33333333333"===a||"44444444444"===a||"55555555555"===a||"66666666666"===a||"77777777777"===a||"88888888888"===a||"99999999999"===a)return!1;for(e=1;e<=9;e++)f+=parseInt(a.substring(e-1,e),10)*(11-e);if(d(f,b)){for(f=0,e=1;e<=10;e++)f+=parseInt(a.substring(e-1,e),10)*(12-e);return d(f,c)}return!1},"Please specify a valid CPF number"),a.validator.addMethod("creditcard",function(a,b){if(this.optional(b))return"dependency-mismatch";if(/[^0-9 \-]+/.test(a))return!1;var c,d,e=0,f=0,g=!1;if(a=a.replace(/\D/g,""),a.length<13||a.length>19)return!1;for(c=a.length-1;c>=0;c--)d=a.charAt(c),f=parseInt(d,10),g&&(f*=2)>9&&(f-=9),e+=f,g=!g;return e%10===0},"Please enter a valid credit card number."),a.validator.addMethod("creditcardtypes",function(a,b,c){if(/[^0-9\-]+/.test(a))return!1;a=a.replace(/\D/g,"");var d=0;return c.mastercard&&(d|=1),c.visa&&(d|=2),c.amex&&(d|=4),c.dinersclub&&(d|=8),c.enroute&&(d|=16),c.discover&&(d|=32),c.jcb&&(d|=64),c.unknown&&(d|=128),c.all&&(d=255),1&d&&/^(5[12345])/.test(a)?16===a.length:2&d&&/^(4)/.test(a)?16===a.length:4&d&&/^(3[47])/.test(a)?15===a.length:8&d&&/^(3(0[012345]|[68]))/.test(a)?14===a.length:16&d&&/^(2(014|149))/.test(a)?15===a.length:32&d&&/^(6011)/.test(a)?16===a.length:64&d&&/^(3)/.test(a)?16===a.length:64&d&&/^(2131|1800)/.test(a)?15===a.length:!!(128&d)},"Please enter a valid credit card number."),a.validator.addMethod("currency",function(a,b,c){var d,e="string"==typeof c,f=e?c:c[0],g=!!e||c[1];return f=f.replace(/,/g,""),f=g?f+"]":f+"]?",d="^["+f+"([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$",d=new RegExp(d),this.optional(b)||d.test(a)},"Please specify a valid currency"),a.validator.addMethod("dateFA",function(a,b){return this.optional(b)||/^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test(a)},a.validator.messages.date),a.validator.addMethod("dateITA",function(a,b){var c,d,e,f,g,h=!1,i=/^\d{1,2}\/\d{1,2}\/\d{4}$/;return i.test(a)?(c=a.split("/"),d=parseInt(c[0],10),e=parseInt(c[1],10),f=parseInt(c[2],10),g=new Date(Date.UTC(f,e-1,d,12,0,0,0)),h=g.getUTCFullYear()===f&&g.getUTCMonth()===e-1&&g.getUTCDate()===d):h=!1,this.optional(b)||h},a.validator.messages.date),a.validator.addMethod("dateNL",function(a,b){return this.optional(b)||/^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(a)},a.validator.messages.date),a.validator.addMethod("extension",function(a,b,c){return c="string"==typeof c?c.replace(/,/g,"|"):"png|jpe?g|gif",this.optional(b)||a.match(new RegExp("\\.("+c+")$","i"))},a.validator.format("Please enter a value with a valid extension.")),a.validator.addMethod("giroaccountNL",function(a,b){return this.optional(b)||/^[0-9]{1,7}$/.test(a)},"Please specify a valid giro account number"),a.validator.addMethod("iban",function(a,b){if(this.optional(b))return!0;var c,d,e,f,g,h,i,j,k,l=a.replace(/ /g,"").toUpperCase(),m="",n=!0,o="",p="",q=5;if(l.length9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/)},"Please specify a valid mobile number"),a.validator.addMethod("netmask",function(a,b){return this.optional(b)||/^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)/i.test(a)},"Please enter a valid netmask."),a.validator.addMethod("nieES",function(a,b){"use strict";if(this.optional(b))return!0;var c,d=new RegExp(/^[MXYZ]{1}[0-9]{7,8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/gi),e="TRWAGMYFPDXBNJZSQVHLCKET",f=a.substr(a.length-1).toUpperCase();return a=a.toString().toUpperCase(),!(a.length>10||a.length<9||!d.test(a))&&(a=a.replace(/^[X]/,"0").replace(/^[Y]/,"1").replace(/^[Z]/,"2"),c=9===a.length?a.substr(0,8):a.substr(0,9),e.charAt(parseInt(c,10)%23)===f)},"Please specify a valid NIE number."),a.validator.addMethod("nifES",function(a,b){"use strict";return!!this.optional(b)||(a=a.toUpperCase(),!!a.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)")&&(/^[0-9]{8}[A-Z]{1}$/.test(a)?"TRWAGMYFPDXBNJZSQVHLCKE".charAt(a.substring(8,0)%23)===a.charAt(8):!!/^[KLM]{1}/.test(a)&&a[8]==="TRWAGMYFPDXBNJZSQVHLCKE".charAt(a.substring(8,1)%23)))},"Please specify a valid NIF number."),a.validator.addMethod("nipPL",function(a){"use strict";if(a=a.replace(/[^0-9]/g,""),10!==a.length)return!1;for(var b=[6,5,7,2,3,4,5,6,7],c=0,d=0;d<9;d++)c+=b[d]*a[d];var e=c%11,f=10===e?0:e;return f===parseInt(a[9],10)},"Please specify a valid NIP number."),a.validator.addMethod("notEqualTo",function(b,c,d){return this.optional(c)||!a.validator.methods.equalTo.call(this,b,c,d)},"Please enter a different value, values must not be the same."),a.validator.addMethod("nowhitespace",function(a,b){return this.optional(b)||/^\S+$/i.test(a)},"No white space please"),a.validator.addMethod("pattern",function(a,b,c){return!!this.optional(b)||("string"==typeof c&&(c=new RegExp("^(?:"+c+")$")),c.test(a))},"Invalid format."),a.validator.addMethod("phoneNL",function(a,b){return this.optional(b)||/^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test(a)},"Please specify a valid phone number."),a.validator.addMethod("phonesUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/)},"Please specify a valid uk phone number"),a.validator.addMethod("phoneUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/)},"Please specify a valid phone number"),a.validator.addMethod("phoneUS",function(a,b){return a=a.replace(/\s+/g,""),this.optional(b)||a.length>9&&a.match(/^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/)},"Please specify a valid phone number"),a.validator.addMethod("postalcodeBR",function(a,b){return this.optional(b)||/^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test(a)},"Informe um CEP válido."),a.validator.addMethod("postalCodeCA",function(a,b){return this.optional(b)||/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postalcodeIT",function(a,b){return this.optional(b)||/^\d{5}$/.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postalcodeNL",function(a,b){return this.optional(b)||/^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postcodeUK",function(a,b){return this.optional(b)||/^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test(a)},"Please specify a valid UK postcode"),a.validator.addMethod("require_from_group",function(b,c,d){var e=a(d[1],c.form),f=e.eq(0),g=f.data("valid_req_grp")?f.data("valid_req_grp"):a.extend({},this),h=e.filter(function(){return g.elementValue(this)}).length>=d[0];return f.data("valid_req_grp",g),a(c).data("being_validated")||(e.data("being_validated",!0),e.each(function(){g.element(this)}),e.data("being_validated",!1)),h},a.validator.format("Please fill at least {0} of these fields.")),a.validator.addMethod("skip_or_fill_minimum",function(b,c,d){var e=a(d[1],c.form),f=e.eq(0),g=f.data("valid_skip")?f.data("valid_skip"):a.extend({},this),h=e.filter(function(){return g.elementValue(this)}).length,i=0===h||h>=d[0];return f.data("valid_skip",g),a(c).data("being_validated")||(e.data("being_validated",!0),e.each(function(){g.element(this)}),e.data("being_validated",!1)),i},a.validator.format("Please either skip these fields or fill at least {0} of them.")),a.validator.addMethod("stateUS",function(a,b,c){var d,e="undefined"==typeof c,f=!e&&"undefined"!=typeof c.caseSensitive&&c.caseSensitive,g=!e&&"undefined"!=typeof c.includeTerritories&&c.includeTerritories,h=!e&&"undefined"!=typeof c.includeMilitary&&c.includeMilitary;return d=g||h?g&&h?"^(A[AEKLPRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$":g?"^(A[KLRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$":"^(A[AEKLPRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$":"^(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$",d=f?new RegExp(d):new RegExp(d,"i"),this.optional(b)||d.test(a)},"Please specify a valid state"),a.validator.addMethod("strippedminlength",function(b,c,d){return a(b).text().length>=d},a.validator.format("Please enter at least {0} characters")),a.validator.addMethod("time",function(a,b){return this.optional(b)||/^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test(a)},"Please enter a valid time, between 00:00 and 23:59"),a.validator.addMethod("time12h",function(a,b){return this.optional(b)||/^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test(a)},"Please enter a valid time in 12-hour am/pm format"),a.validator.addMethod("url2",function(a,b){return this.optional(b)||/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(a)},a.validator.messages.url),a.validator.addMethod("vinUS",function(a){if(17!==a.length)return!1;var b,c,d,e,f,g,h=["A","B","C","D","E","F","G","H","J","K","L","M","N","P","R","S","T","U","V","W","X","Y","Z"],i=[1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9],j=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2],k=0;for(b=0;b<17;b++){if(e=j[b],d=a.slice(b,b+1),8===b&&(g=d),isNaN(d)){for(c=0;c"); 48 | 49 | if (PageNumber != 1) 50 | { 51 | content.Append($"
  • {PageFirst}
  • "); 52 | } 53 | 54 | 55 | if (PageNumber <= PageRange) 56 | { 57 | for (int currentPage = 1; currentPage < 2 * PageRange + 1; currentPage++) 58 | { 59 | if (currentPage < 1 || currentPage > PageCount) 60 | { 61 | continue; 62 | } 63 | var active = currentPage == PageNumber ? "active" : ""; 64 | content.Append($"
  • {currentPage}
  • "); 65 | } 66 | } 67 | else if (PageNumber > PageRange && PageNumber < PageCount - PageRange) 68 | { 69 | for (int currentPage = PageNumber - PageRange; currentPage < PageNumber + PageRange; currentPage++) 70 | { 71 | if (currentPage < 1 || currentPage > PageCount) 72 | { 73 | continue; 74 | } 75 | var active = currentPage == PageNumber ? "active" : ""; 76 | content.Append($"
  • {currentPage}
  • "); 77 | } 78 | } 79 | else 80 | { 81 | for (int currentPage = PageCount - (2 * PageRange); currentPage < PageCount + 1; currentPage++) 82 | { 83 | if (currentPage < 1 || currentPage > PageCount) 84 | { 85 | continue; 86 | } 87 | var active = currentPage == PageNumber ? "active" : ""; 88 | content.Append($"
  • {currentPage}
  • "); 89 | } 90 | } 91 | 92 | if (PageNumber != PageCount) 93 | { 94 | content.Append($"
  • {PageLast}
  • "); 95 | } 96 | 97 | 98 | content.Append(" { 5 | if (!confirm("Confirm deletion")) return false; 6 | }); 7 | } 8 | 9 | if ($("div.alert.notification").length) { 10 | setTimeout(() => { 11 | $("div.alert.notification").fadeOut(); 12 | }, 2000); 13 | } 14 | 15 | }); 16 | 17 | function readURL(input) { 18 | if (input.files && input.files[0]) { 19 | let reader = new FileReader(); 20 | 21 | reader.onload = function (e) { 22 | $("img#imgpreview").attr("src", e.target.result).width(200).height(200); 23 | }; 24 | 25 | reader.readAsDataURL(input.files[0]); 26 | } 27 | } -------------------------------------------------------------------------------- /course files/test.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fep-coder/asp.net-core-6-.net-6-project-shopping-cart/f2cf7f92f9beadf5ed30502fef1796b830d57474/course files/test.txt --------------------------------------------------------------------------------