├── .gitattributes ├── .gitignore ├── Lab1.sln ├── Lab1 ├── Controllers │ ├── AccountController.cs │ ├── CategoryController.cs │ ├── ProductController.cs │ ├── RoleController.cs │ ├── UserController.cs │ └── WeatherForecastController.cs ├── DTO │ ├── CatID_Name_ProductsDTO.cs │ ├── CategoryID_NameDTO.cs │ ├── LoginUserDTO.cs │ ├── ProductName_Description_Price_CatIDDTO.cs │ └── RegisterUserDTO.cs ├── Lab1.csproj ├── Lab1.http ├── Migrations │ ├── 20240330114602_init.Designer.cs │ ├── 20240330114602_init.cs │ ├── 20240331165837_init2.Designer.cs │ ├── 20240331165837_init2.cs │ ├── 20240331170333_init3.Designer.cs │ ├── 20240331170333_init3.cs │ ├── 20240331195353_init4.Designer.cs │ ├── 20240331195353_init4.cs │ ├── 20240402163355_init5.Designer.cs │ ├── 20240402163355_init5.cs │ └── ContextModelSnapshot.cs ├── Models │ ├── ApplicationUser.cs │ ├── Category.cs │ ├── Context.cs │ └── Product.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Repository │ ├── CategoryRepository.cs │ ├── ICategoryRepository.cs │ ├── IProductRepository.cs │ └── ProductRepository.cs ├── WeatherForecast.cs ├── appsettings.Development.json ├── appsettings.json └── wwwroot │ └── Consumer.html └── README.md /.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 -------------------------------------------------------------------------------- /Lab1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34408.163 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1", "Lab1\Lab1.csproj", "{10D3D6BA-0A3E-4102-B1AC-F0F7E77B15B5}" 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 | {10D3D6BA-0A3E-4102-B1AC-F0F7E77B15B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {10D3D6BA-0A3E-4102-B1AC-F0F7E77B15B5}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {10D3D6BA-0A3E-4102-B1AC-F0F7E77B15B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {10D3D6BA-0A3E-4102-B1AC-F0F7E77B15B5}.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 = {B3C2D432-DB76-4774-9655-2A2970A57455} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Lab1/Controllers/AccountController.cs: -------------------------------------------------------------------------------- 1 | using Lab1.DTO; 2 | using Lab1.Models; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.AspNetCore.Identity; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.IdentityModel.Tokens; 7 | using System.IdentityModel.Tokens.Jwt; 8 | using System.Security.Claims; 9 | using System.Text; 10 | 11 | namespace Lab1.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class AccountController : ControllerBase 16 | { 17 | private readonly UserManager userManager; 18 | private readonly IConfiguration config; 19 | public AccountController(UserManager _userManager, IConfiguration config) 20 | { 21 | userManager = _userManager; 22 | this.config = config; 23 | } 24 | [HttpPost("register")] 25 | public async Task< IActionResult> Registe(RegisterUserDTO userDTO) 26 | { 27 | if(ModelState.IsValid) 28 | { 29 | ApplicationUser AppUser = new ApplicationUser() 30 | { 31 | UserName = userDTO.UserName, 32 | Email = userDTO.Email, 33 | PasswordHash = userDTO.Password, 34 | }; 35 | IdentityResult Result= await userManager.CreateAsync(AppUser,userDTO.Password); 36 | if (Result.Succeeded) 37 | { 38 | //this when you make to add registered user as an admin 39 | await userManager.AddToRoleAsync(AppUser, "Admin"); 40 | return Ok("Account Created"); 41 | } 42 | return BadRequest(Result.Errors); 43 | } 44 | return BadRequest(ModelState); 45 | } 46 | 47 | [HttpPost("login")] 48 | public async Task< IActionResult> Login(LoginUserDTO userDTO) 49 | { 50 | if(ModelState.IsValid) 51 | { 52 | ApplicationUser? UserFromDB= await userManager.FindByNameAsync(userDTO.UserName); 53 | if (UserFromDB != null) 54 | { 55 | bool found= await userManager.CheckPasswordAsync(UserFromDB,userDTO.Password); 56 | if (found) 57 | { 58 | //Create Token 59 | List myclaims = new List(); 60 | myclaims.Add(new Claim(ClaimTypes.Name,UserFromDB.UserName)); 61 | myclaims.Add(new Claim(ClaimTypes.NameIdentifier, UserFromDB.Id)); 62 | myclaims.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); 63 | 64 | var roles=await userManager.GetRolesAsync(UserFromDB); 65 | foreach (var role in roles) 66 | { 67 | myclaims.Add(new Claim(ClaimTypes.Role, role)); 68 | } 69 | 70 | var SignKey = new SymmetricSecurityKey( 71 | Encoding.UTF8.GetBytes(config["JWT:SecritKey"])); 72 | 73 | SigningCredentials signingCredentials = 74 | new SigningCredentials(SignKey, SecurityAlgorithms.HmacSha256); 75 | 76 | JwtSecurityToken mytoken = new JwtSecurityToken( 77 | issuer: config["JWT:ValidIss"],//provider create token 78 | audience: config["JWT:ValidAud"],//cousumer url 79 | expires: DateTime.Now.AddHours(1), 80 | claims: myclaims, 81 | signingCredentials: signingCredentials); 82 | return Ok(new 83 | { 84 | token = new JwtSecurityTokenHandler().WriteToken(mytoken), 85 | expired = mytoken.ValidTo 86 | }); 87 | } 88 | } 89 | return BadRequest("Invalid Request"); 90 | } 91 | return BadRequest(ModelState); 92 | } 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Lab1/Controllers/CategoryController.cs: -------------------------------------------------------------------------------- 1 | using Lab1.DTO; 2 | using Lab1.Models; 3 | using Lab1.Repository; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace Lab1.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | [ApiController] 11 | public class CategoryController : ControllerBase 12 | { 13 | private readonly ICategoryRepository categoryRepository; 14 | 15 | public CategoryController(ICategoryRepository _CategoryRepository) 16 | { 17 | categoryRepository = _CategoryRepository; 18 | } 19 | [HttpGet("{id:int}")] 20 | public IActionResult GetByID(int id) 21 | { 22 | Category? CategoryData = categoryRepository.GetById(id); 23 | if (CategoryData == null) 24 | { 25 | return NotFound(); 26 | } 27 | CatID_Name_ProductsDTO CategoryDataModel = new CatID_Name_ProductsDTO { 28 | 29 | Id = id, 30 | Name = CategoryData.Name, 31 | productsName = CategoryData.products.Select(p => p.Name).ToList() 32 | }; 33 | 34 | return Ok(CategoryDataModel); 35 | 36 | } 37 | [HttpGet] 38 | public IActionResult GetAll () 39 | { 40 | List categories = categoryRepository.GetAll(); 41 | if(categories == null || categories.Count == 0) 42 | return NotFound(); 43 | return Ok(categories); 44 | } 45 | 46 | [HttpGet("{name:regex(^[[a-zA-Z0-9-]]+$)}")] 47 | public IActionResult GetByName(string name) 48 | { 49 | Category category = categoryRepository.GetByName(name); 50 | if(category == null) 51 | return NotFound(); 52 | return Ok(category); 53 | } 54 | [HttpPost] 55 | public IActionResult Add(CategoryID_NameDTO category) 56 | { 57 | Category NewCategory1 = (new Category 58 | { 59 | Id = category.Id, 60 | Name = category.Name 61 | }); 62 | categoryRepository.Add(NewCategory1); 63 | return Ok(); 64 | } 65 | [HttpPut] 66 | public IActionResult Update(int id, CategoryID_NameDTO category) 67 | { 68 | bool ISUpdated = true; 69 | Category categoryAfterUpdate = (new Category 70 | { 71 | Id=category.Id, 72 | Name = category.Name 73 | }); 74 | ISUpdated=categoryRepository.Update( id, categoryAfterUpdate); 75 | if(ISUpdated) 76 | { 77 | return Ok(); 78 | } 79 | return BadRequest(); 80 | } 81 | [HttpDelete] 82 | public IActionResult Delete(int id) 83 | { 84 | if (categoryRepository.Delete(id)) 85 | { 86 | return Ok(); 87 | } 88 | return BadRequest(); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Lab1/Controllers/ProductController.cs: -------------------------------------------------------------------------------- 1 | using Lab1.DTO; 2 | using Lab1.Models; 3 | using Lab1.Repository; 4 | using Microsoft.AspNetCore.Authorization; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Mvc; 7 | 8 | namespace Lab1.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | [ApiController] 12 | public class ProductController : ControllerBase 13 | { 14 | private readonly IProductRepository productRepository; 15 | public ProductController(IProductRepository _ProductRepository) 16 | { 17 | productRepository = _ProductRepository; 18 | } 19 | 20 | [HttpGet] 21 | [Authorize] 22 | public IActionResult GetAll() 23 | { 24 | List products = productRepository.GetAll(); 25 | return Ok(products); 26 | } 27 | 28 | [HttpGet("{id:int}")] 29 | public IActionResult GetByID(int id) 30 | { 31 | Product product = productRepository.GetById(id); 32 | if(product == null) 33 | { 34 | return BadRequest("Can't find this product"); 35 | } 36 | return Ok(product); 37 | } 38 | [HttpGet("{name:regex(^[[a-zA-Z0-9-]]+$)}")] 39 | public IActionResult GetByName(string name) 40 | { 41 | List products=productRepository.GetByName(name); 42 | if(products == null) 43 | { 44 | return BadRequest("Can't find this product"); 45 | } 46 | return Ok(products); 47 | } 48 | 49 | [HttpPost] 50 | public IActionResult Add(ProductName_Description_Price_CatIDDTO NewProduct) 51 | { 52 | if (ModelState.IsValid == true) 53 | { 54 | Product product = (new Product 55 | { 56 | Name=NewProduct.Name, 57 | Price=NewProduct.Price, 58 | Description=NewProduct.Description, 59 | CategoryId=NewProduct.CategoryId 60 | }); 61 | 62 | 63 | productRepository.Add(product); 64 | return CreatedAtAction("GetByID", new { id = product.Id }, product); 65 | 66 | } 67 | return BadRequest(ModelState); 68 | } 69 | [HttpPut] 70 | public IActionResult Update(int id,ProductName_Description_Price_CatIDDTO product) 71 | { 72 | Product UpdatedProduct = (new Product 73 | { 74 | Name = product.Name, 75 | Price = product.Price, 76 | Description = product.Description, 77 | CategoryId=product.CategoryId 78 | }); 79 | bool ISUpdated = productRepository.Update(id, UpdatedProduct); 80 | if (ISUpdated) 81 | { 82 | return NoContent(); 83 | } 84 | return BadRequest("Can't Updated"); 85 | 86 | } 87 | [HttpDelete("{id:int}")] 88 | public IActionResult Delete(int id) 89 | { 90 | bool IsDeleted = productRepository.Delete(id); 91 | if(IsDeleted) 92 | { 93 | return NoContent(); 94 | } 95 | else 96 | { 97 | return BadRequest("Can't Deleted"); 98 | } 99 | } 100 | 101 | 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Lab1/Controllers/RoleController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Identity; 4 | using Microsoft.AspNetCore.Mvc; 5 | 6 | namespace Lab1.Controllers 7 | { 8 | [Route("api/[controller]")] 9 | [ApiController] 10 | public class RoleController : ControllerBase 11 | { 12 | private readonly RoleManager roleManager; 13 | public RoleController(RoleManager _roleManager) 14 | { 15 | roleManager = _roleManager; 16 | } 17 | [HttpPost] 18 | public async Task CreateRole(string roleName) 19 | { 20 | bool roleExist = await roleManager.RoleExistsAsync(roleName); 21 | 22 | if (!roleExist) 23 | { 24 | IdentityResult result = await roleManager.CreateAsync(new IdentityRole { Name = roleName }); 25 | if (result.Succeeded) 26 | { 27 | return Ok($"Role {roleName} created successfully"); 28 | } 29 | else 30 | { 31 | return BadRequest(result.Errors); 32 | } 33 | 34 | } 35 | else 36 | { 37 | return BadRequest($"Role {roleName} already exists"); 38 | } 39 | 40 | } 41 | [HttpGet] 42 | public IActionResult GetRoles() 43 | { 44 | IQueryable roles = roleManager.Roles; 45 | return Ok(roles); 46 | } 47 | [HttpDelete] 48 | public async Task< IActionResult> DeleteRole(string roleName) 49 | { 50 | var role= await roleManager.FindByNameAsync(roleName); 51 | if(role != null) 52 | { 53 | IdentityResult result= await roleManager.DeleteAsync(role); 54 | if(result.Succeeded) 55 | { 56 | return Ok($"Role {roleName} deleted successfully"); 57 | } 58 | else 59 | { 60 | return BadRequest(result.Errors); 61 | } 62 | 63 | } 64 | else 65 | { 66 | return BadRequest($"Role {roleName} not found"); 67 | } 68 | } 69 | [HttpPut] 70 | [Authorize(Roles = "Admin")] 71 | public async Task UpdateRole(string roleName,string newRoleName) 72 | { 73 | IdentityRole role = await roleManager.FindByNameAsync(roleName); 74 | if(role != null) 75 | { role.Name = newRoleName; 76 | IdentityResult result=await roleManager.UpdateAsync(role); 77 | if(result.Succeeded) 78 | { 79 | return Ok($"Role {roleName} updated to {newRoleName} successfully"); 80 | } 81 | else 82 | { 83 | return BadRequest(result.Errors); 84 | } 85 | 86 | } 87 | else 88 | { 89 | return NotFound($"Role {roleName} not found"); 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Lab1/Controllers/UserController.cs: -------------------------------------------------------------------------------- 1 | using Lab1.DTO; 2 | using Lab1.Models; 3 | using Microsoft.AspNetCore.Authorization; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Identity; 6 | using Microsoft.AspNetCore.Mvc; 7 | 8 | namespace Lab1.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | [ApiController] 12 | public class UserController : ControllerBase 13 | { 14 | private readonly UserManager userManager; 15 | public UserController(UserManager _userManager) 16 | { 17 | userManager = _userManager; 18 | } 19 | [HttpPost] 20 | [Authorize(Roles = "Admin")] 21 | public async Task CreateUser(RegisterUserDTO userDTO) 22 | { 23 | if(ModelState.IsValid) 24 | { 25 | ApplicationUser user = new ApplicationUser 26 | { 27 | UserName = userDTO.UserName, 28 | Email = userDTO.Email, 29 | PasswordHash=userDTO.Password, 30 | }; 31 | 32 | IdentityResult result= await userManager.CreateAsync(user,userDTO.Password); 33 | if(result.Succeeded) 34 | { 35 | return Ok($"User {user.UserName} created successfully"); 36 | } 37 | else 38 | { 39 | return BadRequest(result.Errors); 40 | } 41 | } 42 | else 43 | { 44 | return BadRequest(ModelState); 45 | } 46 | } 47 | [HttpGet] 48 | [Authorize(Roles = "Admin")] 49 | public IActionResult GetUsers() 50 | { 51 | var users = userManager.Users.ToList(); 52 | return Ok(users); 53 | } 54 | [HttpDelete] 55 | [Authorize(Roles = "Admin")] 56 | public async TaskDeleteUser(string Name) 57 | { 58 | ApplicationUser user= await userManager.FindByNameAsync(Name); 59 | if(user!=null) 60 | { 61 | IdentityResult result = await userManager.DeleteAsync(user); 62 | if(result.Succeeded) 63 | { 64 | return Ok($"User {Name} deleted successfully"); 65 | } 66 | else 67 | { 68 | return BadRequest(result.Errors); 69 | } 70 | } 71 | return NotFound($"User with Name {Name} not found"); 72 | } 73 | [HttpPut] 74 | [Authorize(Roles = "Admin")] 75 | public async TaskUpdateUser(string userName, RegisterUserDTO userDTO) 76 | { 77 | ApplicationUser user=await userManager.FindByNameAsync(userName); 78 | if (user != null) 79 | { 80 | user.UserName = userDTO.UserName; 81 | user.PasswordHash = userDTO.Password; 82 | user.Email = userDTO.Email; 83 | 84 | IdentityResult result = await userManager.UpdateAsync(user); 85 | if (result.Succeeded) 86 | { 87 | return Ok($"User {userName} updated successfully"); 88 | } 89 | else 90 | { 91 | return BadRequest(result.Errors); 92 | } 93 | } 94 | return NotFound($"User with Name {userName} not found"); 95 | } 96 | 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Lab1/Controllers/WeatherForecastController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Lab1.Controllers 4 | { 5 | [ApiController] 6 | [Route("[controller]")] 7 | public class WeatherForecastController : ControllerBase 8 | { 9 | private static readonly string[] Summaries = new[] 10 | { 11 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 12 | }; 13 | 14 | private readonly ILogger _logger; 15 | 16 | public WeatherForecastController(ILogger logger) 17 | { 18 | _logger = logger; 19 | } 20 | 21 | [HttpGet(Name = "GetWeatherForecast")] 22 | public IEnumerable Get() 23 | { 24 | return Enumerable.Range(1, 5).Select(index => new WeatherForecast 25 | { 26 | Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), 27 | TemperatureC = Random.Shared.Next(-20, 55), 28 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 29 | }) 30 | .ToArray(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Lab1/DTO/CatID_Name_ProductsDTO.cs: -------------------------------------------------------------------------------- 1 | using Lab1.Models; 2 | 3 | namespace Lab1.DTO 4 | { 5 | public class CatID_Name_ProductsDTO 6 | { 7 | public int Id { get; set; } 8 | public string Name { get; set;} 9 | 10 | public List productsName { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lab1/DTO/CategoryID_NameDTO.cs: -------------------------------------------------------------------------------- 1 | namespace Lab1.DTO 2 | { 3 | public class CategoryID_NameDTO 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lab1/DTO/LoginUserDTO.cs: -------------------------------------------------------------------------------- 1 | namespace Lab1.DTO 2 | { 3 | public class LoginUserDTO 4 | { 5 | public string UserName { get; set; } 6 | public string Password { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lab1/DTO/ProductName_Description_Price_CatIDDTO.cs: -------------------------------------------------------------------------------- 1 | namespace Lab1.DTO 2 | { 3 | public class ProductName_Description_Price_CatIDDTO 4 | { 5 | public string Name { get; set; } 6 | public string? Description { get; set; } 7 | public decimal Price { get; set; } 8 | public int CategoryId { get; set; } 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lab1/DTO/RegisterUserDTO.cs: -------------------------------------------------------------------------------- 1 | namespace Lab1.DTO 2 | { 3 | public class RegisterUserDTO 4 | { 5 | public string UserName { get; set; } 6 | public string Password { get; set; } 7 | public string Email { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Lab1/Lab1.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | false 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | all 17 | runtime; build; native; contentfiles; analyzers; buildtransitive 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Lab1/Lab1.http: -------------------------------------------------------------------------------- 1 | @Lab1_HostAddress = http://localhost:5117 2 | 3 | GET {{Lab1_HostAddress}}/weatherforecast/ 4 | Accept: application/json 5 | 6 | ### 7 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240330114602_init.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Lab1.Models; 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 | 9 | #nullable disable 10 | 11 | namespace Lab1.Migrations 12 | { 13 | [DbContext(typeof(Context))] 14 | [Migration("20240330114602_init")] 15 | partial class init 16 | { 17 | /// 18 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 19 | { 20 | #pragma warning disable 612, 618 21 | modelBuilder 22 | .HasAnnotation("ProductVersion", "8.0.3") 23 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 24 | 25 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 26 | 27 | modelBuilder.Entity("Lab1.Models.Product", b => 28 | { 29 | b.Property("Id") 30 | .ValueGeneratedOnAdd() 31 | .HasColumnType("int"); 32 | 33 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 34 | 35 | b.Property("Description") 36 | .IsRequired() 37 | .HasColumnType("nvarchar(max)"); 38 | 39 | b.Property("Name") 40 | .IsRequired() 41 | .HasColumnType("nvarchar(max)"); 42 | 43 | b.Property("Price") 44 | .HasColumnType("decimal(18,2)"); 45 | 46 | b.HasKey("Id"); 47 | 48 | b.ToTable("Products"); 49 | }); 50 | #pragma warning restore 612, 618 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240330114602_init.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace Lab1.Migrations 6 | { 7 | /// 8 | public partial class init : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.CreateTable( 14 | name: "Products", 15 | columns: table => new 16 | { 17 | Id = table.Column(type: "int", nullable: false) 18 | .Annotation("SqlServer:Identity", "1, 1"), 19 | Name = table.Column(type: "nvarchar(max)", nullable: false), 20 | Description = table.Column(type: "nvarchar(max)", nullable: false), 21 | Price = table.Column(type: "decimal(18,2)", nullable: false) 22 | }, 23 | constraints: table => 24 | { 25 | table.PrimaryKey("PK_Products", x => x.Id); 26 | }); 27 | } 28 | 29 | /// 30 | protected override void Down(MigrationBuilder migrationBuilder) 31 | { 32 | migrationBuilder.DropTable( 33 | name: "Products"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240331165837_init2.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Lab1.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace Lab1.Migrations 13 | { 14 | [DbContext(typeof(Context))] 15 | [Migration("20240331165837_init2")] 16 | partial class init2 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "8.0.3") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 25 | 26 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("Lab1.Models.Category", b => 29 | { 30 | b.Property("Id") 31 | .ValueGeneratedOnAdd() 32 | .HasColumnType("int"); 33 | 34 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 35 | 36 | b.Property("Name") 37 | .IsRequired() 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.HasKey("Id"); 41 | 42 | b.ToTable("Category"); 43 | }); 44 | 45 | modelBuilder.Entity("Lab1.Models.Product", b => 46 | { 47 | b.Property("Id") 48 | .ValueGeneratedOnAdd() 49 | .HasColumnType("int"); 50 | 51 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 52 | 53 | b.Property("CategoryId") 54 | .HasColumnType("int"); 55 | 56 | b.Property("Description") 57 | .IsRequired() 58 | .HasColumnType("nvarchar(max)"); 59 | 60 | b.Property("Name") 61 | .IsRequired() 62 | .HasColumnType("nvarchar(max)"); 63 | 64 | b.Property("Price") 65 | .HasColumnType("decimal(18,2)"); 66 | 67 | b.HasKey("Id"); 68 | 69 | b.HasIndex("CategoryId"); 70 | 71 | b.ToTable("Products"); 72 | }); 73 | 74 | modelBuilder.Entity("Lab1.Models.Product", b => 75 | { 76 | b.HasOne("Lab1.Models.Category", "Category") 77 | .WithMany("products") 78 | .HasForeignKey("CategoryId"); 79 | 80 | b.Navigation("Category"); 81 | }); 82 | 83 | modelBuilder.Entity("Lab1.Models.Category", b => 84 | { 85 | b.Navigation("products"); 86 | }); 87 | #pragma warning restore 612, 618 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240331165837_init2.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace Lab1.Migrations 6 | { 7 | /// 8 | public partial class init2 : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.AddColumn( 14 | name: "CategoryId", 15 | table: "Products", 16 | type: "int", 17 | nullable: true); 18 | 19 | migrationBuilder.CreateTable( 20 | name: "Category", 21 | columns: table => new 22 | { 23 | Id = table.Column(type: "int", nullable: false) 24 | .Annotation("SqlServer:Identity", "1, 1"), 25 | Name = table.Column(type: "nvarchar(max)", nullable: false) 26 | }, 27 | constraints: table => 28 | { 29 | table.PrimaryKey("PK_Category", x => x.Id); 30 | }); 31 | 32 | migrationBuilder.CreateIndex( 33 | name: "IX_Products_CategoryId", 34 | table: "Products", 35 | column: "CategoryId"); 36 | 37 | migrationBuilder.AddForeignKey( 38 | name: "FK_Products_Category_CategoryId", 39 | table: "Products", 40 | column: "CategoryId", 41 | principalTable: "Category", 42 | principalColumn: "Id"); 43 | } 44 | 45 | /// 46 | protected override void Down(MigrationBuilder migrationBuilder) 47 | { 48 | migrationBuilder.DropForeignKey( 49 | name: "FK_Products_Category_CategoryId", 50 | table: "Products"); 51 | 52 | migrationBuilder.DropTable( 53 | name: "Category"); 54 | 55 | migrationBuilder.DropIndex( 56 | name: "IX_Products_CategoryId", 57 | table: "Products"); 58 | 59 | migrationBuilder.DropColumn( 60 | name: "CategoryId", 61 | table: "Products"); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240331170333_init3.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Lab1.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace Lab1.Migrations 13 | { 14 | [DbContext(typeof(Context))] 15 | [Migration("20240331170333_init3")] 16 | partial class init3 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "8.0.3") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 25 | 26 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("Lab1.Models.Category", b => 29 | { 30 | b.Property("Id") 31 | .ValueGeneratedOnAdd() 32 | .HasColumnType("int"); 33 | 34 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 35 | 36 | b.Property("Name") 37 | .IsRequired() 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.HasKey("Id"); 41 | 42 | b.ToTable("Categories"); 43 | }); 44 | 45 | modelBuilder.Entity("Lab1.Models.Product", b => 46 | { 47 | b.Property("Id") 48 | .ValueGeneratedOnAdd() 49 | .HasColumnType("int"); 50 | 51 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 52 | 53 | b.Property("CategoryId") 54 | .HasColumnType("int"); 55 | 56 | b.Property("Description") 57 | .IsRequired() 58 | .HasColumnType("nvarchar(max)"); 59 | 60 | b.Property("Name") 61 | .IsRequired() 62 | .HasColumnType("nvarchar(max)"); 63 | 64 | b.Property("Price") 65 | .HasColumnType("decimal(18,2)"); 66 | 67 | b.HasKey("Id"); 68 | 69 | b.HasIndex("CategoryId"); 70 | 71 | b.ToTable("Products"); 72 | }); 73 | 74 | modelBuilder.Entity("Lab1.Models.Product", b => 75 | { 76 | b.HasOne("Lab1.Models.Category", "Category") 77 | .WithMany("products") 78 | .HasForeignKey("CategoryId"); 79 | 80 | b.Navigation("Category"); 81 | }); 82 | 83 | modelBuilder.Entity("Lab1.Models.Category", b => 84 | { 85 | b.Navigation("products"); 86 | }); 87 | #pragma warning restore 612, 618 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240331170333_init3.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace Lab1.Migrations 6 | { 7 | /// 8 | public partial class init3 : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.DropForeignKey( 14 | name: "FK_Products_Category_CategoryId", 15 | table: "Products"); 16 | 17 | migrationBuilder.DropPrimaryKey( 18 | name: "PK_Category", 19 | table: "Category"); 20 | 21 | migrationBuilder.RenameTable( 22 | name: "Category", 23 | newName: "Categories"); 24 | 25 | migrationBuilder.AddPrimaryKey( 26 | name: "PK_Categories", 27 | table: "Categories", 28 | column: "Id"); 29 | 30 | migrationBuilder.AddForeignKey( 31 | name: "FK_Products_Categories_CategoryId", 32 | table: "Products", 33 | column: "CategoryId", 34 | principalTable: "Categories", 35 | principalColumn: "Id"); 36 | } 37 | 38 | /// 39 | protected override void Down(MigrationBuilder migrationBuilder) 40 | { 41 | migrationBuilder.DropForeignKey( 42 | name: "FK_Products_Categories_CategoryId", 43 | table: "Products"); 44 | 45 | migrationBuilder.DropPrimaryKey( 46 | name: "PK_Categories", 47 | table: "Categories"); 48 | 49 | migrationBuilder.RenameTable( 50 | name: "Categories", 51 | newName: "Category"); 52 | 53 | migrationBuilder.AddPrimaryKey( 54 | name: "PK_Category", 55 | table: "Category", 56 | column: "Id"); 57 | 58 | migrationBuilder.AddForeignKey( 59 | name: "FK_Products_Category_CategoryId", 60 | table: "Products", 61 | column: "CategoryId", 62 | principalTable: "Category", 63 | principalColumn: "Id"); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240331195353_init4.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Lab1.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace Lab1.Migrations 13 | { 14 | [DbContext(typeof(Context))] 15 | [Migration("20240331195353_init4")] 16 | partial class init4 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "8.0.3") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 25 | 26 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("Lab1.Models.Category", b => 29 | { 30 | b.Property("Id") 31 | .ValueGeneratedOnAdd() 32 | .HasColumnType("int"); 33 | 34 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 35 | 36 | b.Property("Name") 37 | .IsRequired() 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.HasKey("Id"); 41 | 42 | b.ToTable("Categories"); 43 | }); 44 | 45 | modelBuilder.Entity("Lab1.Models.Product", b => 46 | { 47 | b.Property("Id") 48 | .ValueGeneratedOnAdd() 49 | .HasColumnType("int"); 50 | 51 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 52 | 53 | b.Property("CategoryId") 54 | .HasColumnType("int"); 55 | 56 | b.Property("Description") 57 | .IsRequired() 58 | .HasColumnType("nvarchar(max)"); 59 | 60 | b.Property("Name") 61 | .IsRequired() 62 | .HasColumnType("nvarchar(max)"); 63 | 64 | b.Property("Price") 65 | .HasColumnType("decimal(18,2)"); 66 | 67 | b.HasKey("Id"); 68 | 69 | b.HasIndex("CategoryId"); 70 | 71 | b.ToTable("Products"); 72 | }); 73 | 74 | modelBuilder.Entity("Lab1.Models.Product", b => 75 | { 76 | b.HasOne("Lab1.Models.Category", "Category") 77 | .WithMany("products") 78 | .HasForeignKey("CategoryId"); 79 | 80 | b.Navigation("Category"); 81 | }); 82 | 83 | modelBuilder.Entity("Lab1.Models.Category", b => 84 | { 85 | b.Navigation("products"); 86 | }); 87 | #pragma warning restore 612, 618 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240331195353_init4.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace Lab1.Migrations 6 | { 7 | /// 8 | public partial class init4 : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | 14 | } 15 | 16 | /// 17 | protected override void Down(MigrationBuilder migrationBuilder) 18 | { 19 | 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240402163355_init5.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Lab1.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace Lab1.Migrations 13 | { 14 | [DbContext(typeof(Context))] 15 | [Migration("20240402163355_init5")] 16 | partial class init5 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "8.0.3") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 25 | 26 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("Lab1.Models.ApplicationUser", b => 29 | { 30 | b.Property("Id") 31 | .HasColumnType("nvarchar(450)"); 32 | 33 | b.Property("AccessFailedCount") 34 | .HasColumnType("int"); 35 | 36 | b.Property("ConcurrencyStamp") 37 | .IsConcurrencyToken() 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.Property("Email") 41 | .HasMaxLength(256) 42 | .HasColumnType("nvarchar(256)"); 43 | 44 | b.Property("EmailConfirmed") 45 | .HasColumnType("bit"); 46 | 47 | b.Property("LockoutEnabled") 48 | .HasColumnType("bit"); 49 | 50 | b.Property("LockoutEnd") 51 | .HasColumnType("datetimeoffset"); 52 | 53 | b.Property("NormalizedEmail") 54 | .HasMaxLength(256) 55 | .HasColumnType("nvarchar(256)"); 56 | 57 | b.Property("NormalizedUserName") 58 | .HasMaxLength(256) 59 | .HasColumnType("nvarchar(256)"); 60 | 61 | b.Property("PasswordHash") 62 | .HasColumnType("nvarchar(max)"); 63 | 64 | b.Property("PhoneNumber") 65 | .HasColumnType("nvarchar(max)"); 66 | 67 | b.Property("PhoneNumberConfirmed") 68 | .HasColumnType("bit"); 69 | 70 | b.Property("SecurityStamp") 71 | .HasColumnType("nvarchar(max)"); 72 | 73 | b.Property("TwoFactorEnabled") 74 | .HasColumnType("bit"); 75 | 76 | b.Property("UserName") 77 | .HasMaxLength(256) 78 | .HasColumnType("nvarchar(256)"); 79 | 80 | b.HasKey("Id"); 81 | 82 | b.HasIndex("NormalizedEmail") 83 | .HasDatabaseName("EmailIndex"); 84 | 85 | b.HasIndex("NormalizedUserName") 86 | .IsUnique() 87 | .HasDatabaseName("UserNameIndex") 88 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 89 | 90 | b.ToTable("AspNetUsers", (string)null); 91 | }); 92 | 93 | modelBuilder.Entity("Lab1.Models.Category", b => 94 | { 95 | b.Property("Id") 96 | .ValueGeneratedOnAdd() 97 | .HasColumnType("int"); 98 | 99 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 100 | 101 | b.Property("Name") 102 | .IsRequired() 103 | .HasColumnType("nvarchar(max)"); 104 | 105 | b.HasKey("Id"); 106 | 107 | b.ToTable("Categories"); 108 | }); 109 | 110 | modelBuilder.Entity("Lab1.Models.Product", b => 111 | { 112 | b.Property("Id") 113 | .ValueGeneratedOnAdd() 114 | .HasColumnType("int"); 115 | 116 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 117 | 118 | b.Property("CategoryId") 119 | .HasColumnType("int"); 120 | 121 | b.Property("Description") 122 | .IsRequired() 123 | .HasColumnType("nvarchar(max)"); 124 | 125 | b.Property("Name") 126 | .IsRequired() 127 | .HasColumnType("nvarchar(max)"); 128 | 129 | b.Property("Price") 130 | .HasColumnType("decimal(18,2)"); 131 | 132 | b.HasKey("Id"); 133 | 134 | b.HasIndex("CategoryId"); 135 | 136 | b.ToTable("Products"); 137 | }); 138 | 139 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 140 | { 141 | b.Property("Id") 142 | .HasColumnType("nvarchar(450)"); 143 | 144 | b.Property("ConcurrencyStamp") 145 | .IsConcurrencyToken() 146 | .HasColumnType("nvarchar(max)"); 147 | 148 | b.Property("Name") 149 | .HasMaxLength(256) 150 | .HasColumnType("nvarchar(256)"); 151 | 152 | b.Property("NormalizedName") 153 | .HasMaxLength(256) 154 | .HasColumnType("nvarchar(256)"); 155 | 156 | b.HasKey("Id"); 157 | 158 | b.HasIndex("NormalizedName") 159 | .IsUnique() 160 | .HasDatabaseName("RoleNameIndex") 161 | .HasFilter("[NormalizedName] IS NOT NULL"); 162 | 163 | b.ToTable("AspNetRoles", (string)null); 164 | }); 165 | 166 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 167 | { 168 | b.Property("Id") 169 | .ValueGeneratedOnAdd() 170 | .HasColumnType("int"); 171 | 172 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 173 | 174 | b.Property("ClaimType") 175 | .HasColumnType("nvarchar(max)"); 176 | 177 | b.Property("ClaimValue") 178 | .HasColumnType("nvarchar(max)"); 179 | 180 | b.Property("RoleId") 181 | .IsRequired() 182 | .HasColumnType("nvarchar(450)"); 183 | 184 | b.HasKey("Id"); 185 | 186 | b.HasIndex("RoleId"); 187 | 188 | b.ToTable("AspNetRoleClaims", (string)null); 189 | }); 190 | 191 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 192 | { 193 | b.Property("Id") 194 | .ValueGeneratedOnAdd() 195 | .HasColumnType("int"); 196 | 197 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 198 | 199 | b.Property("ClaimType") 200 | .HasColumnType("nvarchar(max)"); 201 | 202 | b.Property("ClaimValue") 203 | .HasColumnType("nvarchar(max)"); 204 | 205 | b.Property("UserId") 206 | .IsRequired() 207 | .HasColumnType("nvarchar(450)"); 208 | 209 | b.HasKey("Id"); 210 | 211 | b.HasIndex("UserId"); 212 | 213 | b.ToTable("AspNetUserClaims", (string)null); 214 | }); 215 | 216 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 217 | { 218 | b.Property("LoginProvider") 219 | .HasColumnType("nvarchar(450)"); 220 | 221 | b.Property("ProviderKey") 222 | .HasColumnType("nvarchar(450)"); 223 | 224 | b.Property("ProviderDisplayName") 225 | .HasColumnType("nvarchar(max)"); 226 | 227 | b.Property("UserId") 228 | .IsRequired() 229 | .HasColumnType("nvarchar(450)"); 230 | 231 | b.HasKey("LoginProvider", "ProviderKey"); 232 | 233 | b.HasIndex("UserId"); 234 | 235 | b.ToTable("AspNetUserLogins", (string)null); 236 | }); 237 | 238 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 239 | { 240 | b.Property("UserId") 241 | .HasColumnType("nvarchar(450)"); 242 | 243 | b.Property("RoleId") 244 | .HasColumnType("nvarchar(450)"); 245 | 246 | b.HasKey("UserId", "RoleId"); 247 | 248 | b.HasIndex("RoleId"); 249 | 250 | b.ToTable("AspNetUserRoles", (string)null); 251 | }); 252 | 253 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 254 | { 255 | b.Property("UserId") 256 | .HasColumnType("nvarchar(450)"); 257 | 258 | b.Property("LoginProvider") 259 | .HasColumnType("nvarchar(450)"); 260 | 261 | b.Property("Name") 262 | .HasColumnType("nvarchar(450)"); 263 | 264 | b.Property("Value") 265 | .HasColumnType("nvarchar(max)"); 266 | 267 | b.HasKey("UserId", "LoginProvider", "Name"); 268 | 269 | b.ToTable("AspNetUserTokens", (string)null); 270 | }); 271 | 272 | modelBuilder.Entity("Lab1.Models.Product", b => 273 | { 274 | b.HasOne("Lab1.Models.Category", "Category") 275 | .WithMany("products") 276 | .HasForeignKey("CategoryId"); 277 | 278 | b.Navigation("Category"); 279 | }); 280 | 281 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 282 | { 283 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 284 | .WithMany() 285 | .HasForeignKey("RoleId") 286 | .OnDelete(DeleteBehavior.Cascade) 287 | .IsRequired(); 288 | }); 289 | 290 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 291 | { 292 | b.HasOne("Lab1.Models.ApplicationUser", null) 293 | .WithMany() 294 | .HasForeignKey("UserId") 295 | .OnDelete(DeleteBehavior.Cascade) 296 | .IsRequired(); 297 | }); 298 | 299 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 300 | { 301 | b.HasOne("Lab1.Models.ApplicationUser", null) 302 | .WithMany() 303 | .HasForeignKey("UserId") 304 | .OnDelete(DeleteBehavior.Cascade) 305 | .IsRequired(); 306 | }); 307 | 308 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 309 | { 310 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 311 | .WithMany() 312 | .HasForeignKey("RoleId") 313 | .OnDelete(DeleteBehavior.Cascade) 314 | .IsRequired(); 315 | 316 | b.HasOne("Lab1.Models.ApplicationUser", null) 317 | .WithMany() 318 | .HasForeignKey("UserId") 319 | .OnDelete(DeleteBehavior.Cascade) 320 | .IsRequired(); 321 | }); 322 | 323 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 324 | { 325 | b.HasOne("Lab1.Models.ApplicationUser", null) 326 | .WithMany() 327 | .HasForeignKey("UserId") 328 | .OnDelete(DeleteBehavior.Cascade) 329 | .IsRequired(); 330 | }); 331 | 332 | modelBuilder.Entity("Lab1.Models.Category", b => 333 | { 334 | b.Navigation("products"); 335 | }); 336 | #pragma warning restore 612, 618 337 | } 338 | } 339 | } 340 | -------------------------------------------------------------------------------- /Lab1/Migrations/20240402163355_init5.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace Lab1.Migrations 7 | { 8 | /// 9 | public partial class init5 : Migration 10 | { 11 | /// 12 | protected override void Up(MigrationBuilder migrationBuilder) 13 | { 14 | migrationBuilder.CreateTable( 15 | name: "AspNetRoles", 16 | columns: table => new 17 | { 18 | Id = table.Column(type: "nvarchar(450)", nullable: false), 19 | Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 20 | NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 21 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) 22 | }, 23 | constraints: table => 24 | { 25 | table.PrimaryKey("PK_AspNetRoles", x => x.Id); 26 | }); 27 | 28 | migrationBuilder.CreateTable( 29 | name: "AspNetUsers", 30 | columns: table => new 31 | { 32 | Id = table.Column(type: "nvarchar(450)", nullable: false), 33 | UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 34 | NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 35 | Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 36 | NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 37 | EmailConfirmed = table.Column(type: "bit", nullable: false), 38 | PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), 39 | SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), 40 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), 41 | PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), 42 | PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), 43 | TwoFactorEnabled = table.Column(type: "bit", nullable: false), 44 | LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), 45 | LockoutEnabled = table.Column(type: "bit", nullable: false), 46 | AccessFailedCount = table.Column(type: "int", nullable: false) 47 | }, 48 | constraints: table => 49 | { 50 | table.PrimaryKey("PK_AspNetUsers", x => x.Id); 51 | }); 52 | 53 | migrationBuilder.CreateTable( 54 | name: "AspNetRoleClaims", 55 | columns: table => new 56 | { 57 | Id = table.Column(type: "int", nullable: false) 58 | .Annotation("SqlServer:Identity", "1, 1"), 59 | RoleId = table.Column(type: "nvarchar(450)", nullable: false), 60 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 61 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 62 | }, 63 | constraints: table => 64 | { 65 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); 66 | table.ForeignKey( 67 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", 68 | column: x => x.RoleId, 69 | principalTable: "AspNetRoles", 70 | principalColumn: "Id", 71 | onDelete: ReferentialAction.Cascade); 72 | }); 73 | 74 | migrationBuilder.CreateTable( 75 | name: "AspNetUserClaims", 76 | columns: table => new 77 | { 78 | Id = table.Column(type: "int", nullable: false) 79 | .Annotation("SqlServer:Identity", "1, 1"), 80 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 81 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 82 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 83 | }, 84 | constraints: table => 85 | { 86 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); 87 | table.ForeignKey( 88 | name: "FK_AspNetUserClaims_AspNetUsers_UserId", 89 | column: x => x.UserId, 90 | principalTable: "AspNetUsers", 91 | principalColumn: "Id", 92 | onDelete: ReferentialAction.Cascade); 93 | }); 94 | 95 | migrationBuilder.CreateTable( 96 | name: "AspNetUserLogins", 97 | columns: table => new 98 | { 99 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 100 | ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), 101 | ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), 102 | UserId = table.Column(type: "nvarchar(450)", nullable: false) 103 | }, 104 | constraints: table => 105 | { 106 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); 107 | table.ForeignKey( 108 | name: "FK_AspNetUserLogins_AspNetUsers_UserId", 109 | column: x => x.UserId, 110 | principalTable: "AspNetUsers", 111 | principalColumn: "Id", 112 | onDelete: ReferentialAction.Cascade); 113 | }); 114 | 115 | migrationBuilder.CreateTable( 116 | name: "AspNetUserRoles", 117 | columns: table => new 118 | { 119 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 120 | RoleId = table.Column(type: "nvarchar(450)", nullable: false) 121 | }, 122 | constraints: table => 123 | { 124 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); 125 | table.ForeignKey( 126 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId", 127 | column: x => x.RoleId, 128 | principalTable: "AspNetRoles", 129 | principalColumn: "Id", 130 | onDelete: ReferentialAction.Cascade); 131 | table.ForeignKey( 132 | name: "FK_AspNetUserRoles_AspNetUsers_UserId", 133 | column: x => x.UserId, 134 | principalTable: "AspNetUsers", 135 | principalColumn: "Id", 136 | onDelete: ReferentialAction.Cascade); 137 | }); 138 | 139 | migrationBuilder.CreateTable( 140 | name: "AspNetUserTokens", 141 | columns: table => new 142 | { 143 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 144 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 145 | Name = table.Column(type: "nvarchar(450)", nullable: false), 146 | Value = table.Column(type: "nvarchar(max)", nullable: true) 147 | }, 148 | constraints: table => 149 | { 150 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); 151 | table.ForeignKey( 152 | name: "FK_AspNetUserTokens_AspNetUsers_UserId", 153 | column: x => x.UserId, 154 | principalTable: "AspNetUsers", 155 | principalColumn: "Id", 156 | onDelete: ReferentialAction.Cascade); 157 | }); 158 | 159 | migrationBuilder.CreateIndex( 160 | name: "IX_AspNetRoleClaims_RoleId", 161 | table: "AspNetRoleClaims", 162 | column: "RoleId"); 163 | 164 | migrationBuilder.CreateIndex( 165 | name: "RoleNameIndex", 166 | table: "AspNetRoles", 167 | column: "NormalizedName", 168 | unique: true, 169 | filter: "[NormalizedName] IS NOT NULL"); 170 | 171 | migrationBuilder.CreateIndex( 172 | name: "IX_AspNetUserClaims_UserId", 173 | table: "AspNetUserClaims", 174 | column: "UserId"); 175 | 176 | migrationBuilder.CreateIndex( 177 | name: "IX_AspNetUserLogins_UserId", 178 | table: "AspNetUserLogins", 179 | column: "UserId"); 180 | 181 | migrationBuilder.CreateIndex( 182 | name: "IX_AspNetUserRoles_RoleId", 183 | table: "AspNetUserRoles", 184 | column: "RoleId"); 185 | 186 | migrationBuilder.CreateIndex( 187 | name: "EmailIndex", 188 | table: "AspNetUsers", 189 | column: "NormalizedEmail"); 190 | 191 | migrationBuilder.CreateIndex( 192 | name: "UserNameIndex", 193 | table: "AspNetUsers", 194 | column: "NormalizedUserName", 195 | unique: true, 196 | filter: "[NormalizedUserName] IS NOT NULL"); 197 | } 198 | 199 | /// 200 | protected override void Down(MigrationBuilder migrationBuilder) 201 | { 202 | migrationBuilder.DropTable( 203 | name: "AspNetRoleClaims"); 204 | 205 | migrationBuilder.DropTable( 206 | name: "AspNetUserClaims"); 207 | 208 | migrationBuilder.DropTable( 209 | name: "AspNetUserLogins"); 210 | 211 | migrationBuilder.DropTable( 212 | name: "AspNetUserRoles"); 213 | 214 | migrationBuilder.DropTable( 215 | name: "AspNetUserTokens"); 216 | 217 | migrationBuilder.DropTable( 218 | name: "AspNetRoles"); 219 | 220 | migrationBuilder.DropTable( 221 | name: "AspNetUsers"); 222 | } 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /Lab1/Migrations/ContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Lab1.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | #nullable disable 10 | 11 | namespace Lab1.Migrations 12 | { 13 | [DbContext(typeof(Context))] 14 | partial class ContextModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "8.0.3") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 22 | 23 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 24 | 25 | modelBuilder.Entity("Lab1.Models.ApplicationUser", b => 26 | { 27 | b.Property("Id") 28 | .HasColumnType("nvarchar(450)"); 29 | 30 | b.Property("AccessFailedCount") 31 | .HasColumnType("int"); 32 | 33 | b.Property("ConcurrencyStamp") 34 | .IsConcurrencyToken() 35 | .HasColumnType("nvarchar(max)"); 36 | 37 | b.Property("Email") 38 | .HasMaxLength(256) 39 | .HasColumnType("nvarchar(256)"); 40 | 41 | b.Property("EmailConfirmed") 42 | .HasColumnType("bit"); 43 | 44 | b.Property("LockoutEnabled") 45 | .HasColumnType("bit"); 46 | 47 | b.Property("LockoutEnd") 48 | .HasColumnType("datetimeoffset"); 49 | 50 | b.Property("NormalizedEmail") 51 | .HasMaxLength(256) 52 | .HasColumnType("nvarchar(256)"); 53 | 54 | b.Property("NormalizedUserName") 55 | .HasMaxLength(256) 56 | .HasColumnType("nvarchar(256)"); 57 | 58 | b.Property("PasswordHash") 59 | .HasColumnType("nvarchar(max)"); 60 | 61 | b.Property("PhoneNumber") 62 | .HasColumnType("nvarchar(max)"); 63 | 64 | b.Property("PhoneNumberConfirmed") 65 | .HasColumnType("bit"); 66 | 67 | b.Property("SecurityStamp") 68 | .HasColumnType("nvarchar(max)"); 69 | 70 | b.Property("TwoFactorEnabled") 71 | .HasColumnType("bit"); 72 | 73 | b.Property("UserName") 74 | .HasMaxLength(256) 75 | .HasColumnType("nvarchar(256)"); 76 | 77 | b.HasKey("Id"); 78 | 79 | b.HasIndex("NormalizedEmail") 80 | .HasDatabaseName("EmailIndex"); 81 | 82 | b.HasIndex("NormalizedUserName") 83 | .IsUnique() 84 | .HasDatabaseName("UserNameIndex") 85 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 86 | 87 | b.ToTable("AspNetUsers", (string)null); 88 | }); 89 | 90 | modelBuilder.Entity("Lab1.Models.Category", b => 91 | { 92 | b.Property("Id") 93 | .ValueGeneratedOnAdd() 94 | .HasColumnType("int"); 95 | 96 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 97 | 98 | b.Property("Name") 99 | .IsRequired() 100 | .HasColumnType("nvarchar(max)"); 101 | 102 | b.HasKey("Id"); 103 | 104 | b.ToTable("Categories"); 105 | }); 106 | 107 | modelBuilder.Entity("Lab1.Models.Product", b => 108 | { 109 | b.Property("Id") 110 | .ValueGeneratedOnAdd() 111 | .HasColumnType("int"); 112 | 113 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 114 | 115 | b.Property("CategoryId") 116 | .HasColumnType("int"); 117 | 118 | b.Property("Description") 119 | .IsRequired() 120 | .HasColumnType("nvarchar(max)"); 121 | 122 | b.Property("Name") 123 | .IsRequired() 124 | .HasColumnType("nvarchar(max)"); 125 | 126 | b.Property("Price") 127 | .HasColumnType("decimal(18,2)"); 128 | 129 | b.HasKey("Id"); 130 | 131 | b.HasIndex("CategoryId"); 132 | 133 | b.ToTable("Products"); 134 | }); 135 | 136 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 137 | { 138 | b.Property("Id") 139 | .HasColumnType("nvarchar(450)"); 140 | 141 | b.Property("ConcurrencyStamp") 142 | .IsConcurrencyToken() 143 | .HasColumnType("nvarchar(max)"); 144 | 145 | b.Property("Name") 146 | .HasMaxLength(256) 147 | .HasColumnType("nvarchar(256)"); 148 | 149 | b.Property("NormalizedName") 150 | .HasMaxLength(256) 151 | .HasColumnType("nvarchar(256)"); 152 | 153 | b.HasKey("Id"); 154 | 155 | b.HasIndex("NormalizedName") 156 | .IsUnique() 157 | .HasDatabaseName("RoleNameIndex") 158 | .HasFilter("[NormalizedName] IS NOT NULL"); 159 | 160 | b.ToTable("AspNetRoles", (string)null); 161 | }); 162 | 163 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 164 | { 165 | b.Property("Id") 166 | .ValueGeneratedOnAdd() 167 | .HasColumnType("int"); 168 | 169 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 170 | 171 | b.Property("ClaimType") 172 | .HasColumnType("nvarchar(max)"); 173 | 174 | b.Property("ClaimValue") 175 | .HasColumnType("nvarchar(max)"); 176 | 177 | b.Property("RoleId") 178 | .IsRequired() 179 | .HasColumnType("nvarchar(450)"); 180 | 181 | b.HasKey("Id"); 182 | 183 | b.HasIndex("RoleId"); 184 | 185 | b.ToTable("AspNetRoleClaims", (string)null); 186 | }); 187 | 188 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 189 | { 190 | b.Property("Id") 191 | .ValueGeneratedOnAdd() 192 | .HasColumnType("int"); 193 | 194 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 195 | 196 | b.Property("ClaimType") 197 | .HasColumnType("nvarchar(max)"); 198 | 199 | b.Property("ClaimValue") 200 | .HasColumnType("nvarchar(max)"); 201 | 202 | b.Property("UserId") 203 | .IsRequired() 204 | .HasColumnType("nvarchar(450)"); 205 | 206 | b.HasKey("Id"); 207 | 208 | b.HasIndex("UserId"); 209 | 210 | b.ToTable("AspNetUserClaims", (string)null); 211 | }); 212 | 213 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 214 | { 215 | b.Property("LoginProvider") 216 | .HasColumnType("nvarchar(450)"); 217 | 218 | b.Property("ProviderKey") 219 | .HasColumnType("nvarchar(450)"); 220 | 221 | b.Property("ProviderDisplayName") 222 | .HasColumnType("nvarchar(max)"); 223 | 224 | b.Property("UserId") 225 | .IsRequired() 226 | .HasColumnType("nvarchar(450)"); 227 | 228 | b.HasKey("LoginProvider", "ProviderKey"); 229 | 230 | b.HasIndex("UserId"); 231 | 232 | b.ToTable("AspNetUserLogins", (string)null); 233 | }); 234 | 235 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 236 | { 237 | b.Property("UserId") 238 | .HasColumnType("nvarchar(450)"); 239 | 240 | b.Property("RoleId") 241 | .HasColumnType("nvarchar(450)"); 242 | 243 | b.HasKey("UserId", "RoleId"); 244 | 245 | b.HasIndex("RoleId"); 246 | 247 | b.ToTable("AspNetUserRoles", (string)null); 248 | }); 249 | 250 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 251 | { 252 | b.Property("UserId") 253 | .HasColumnType("nvarchar(450)"); 254 | 255 | b.Property("LoginProvider") 256 | .HasColumnType("nvarchar(450)"); 257 | 258 | b.Property("Name") 259 | .HasColumnType("nvarchar(450)"); 260 | 261 | b.Property("Value") 262 | .HasColumnType("nvarchar(max)"); 263 | 264 | b.HasKey("UserId", "LoginProvider", "Name"); 265 | 266 | b.ToTable("AspNetUserTokens", (string)null); 267 | }); 268 | 269 | modelBuilder.Entity("Lab1.Models.Product", b => 270 | { 271 | b.HasOne("Lab1.Models.Category", "Category") 272 | .WithMany("products") 273 | .HasForeignKey("CategoryId"); 274 | 275 | b.Navigation("Category"); 276 | }); 277 | 278 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 279 | { 280 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 281 | .WithMany() 282 | .HasForeignKey("RoleId") 283 | .OnDelete(DeleteBehavior.Cascade) 284 | .IsRequired(); 285 | }); 286 | 287 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 288 | { 289 | b.HasOne("Lab1.Models.ApplicationUser", null) 290 | .WithMany() 291 | .HasForeignKey("UserId") 292 | .OnDelete(DeleteBehavior.Cascade) 293 | .IsRequired(); 294 | }); 295 | 296 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 297 | { 298 | b.HasOne("Lab1.Models.ApplicationUser", null) 299 | .WithMany() 300 | .HasForeignKey("UserId") 301 | .OnDelete(DeleteBehavior.Cascade) 302 | .IsRequired(); 303 | }); 304 | 305 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 306 | { 307 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 308 | .WithMany() 309 | .HasForeignKey("RoleId") 310 | .OnDelete(DeleteBehavior.Cascade) 311 | .IsRequired(); 312 | 313 | b.HasOne("Lab1.Models.ApplicationUser", null) 314 | .WithMany() 315 | .HasForeignKey("UserId") 316 | .OnDelete(DeleteBehavior.Cascade) 317 | .IsRequired(); 318 | }); 319 | 320 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 321 | { 322 | b.HasOne("Lab1.Models.ApplicationUser", null) 323 | .WithMany() 324 | .HasForeignKey("UserId") 325 | .OnDelete(DeleteBehavior.Cascade) 326 | .IsRequired(); 327 | }); 328 | 329 | modelBuilder.Entity("Lab1.Models.Category", b => 330 | { 331 | b.Navigation("products"); 332 | }); 333 | #pragma warning restore 612, 618 334 | } 335 | } 336 | } 337 | -------------------------------------------------------------------------------- /Lab1/Models/ApplicationUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace Lab1.Models 4 | { 5 | public class ApplicationUser:IdentityUser 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lab1/Models/Category.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Lab1.Models 3 | { 4 | public class Category 5 | { 6 | public int Id { get; set; } 7 | public string Name { get; set; } 8 | public List?products { get; set; } 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lab1/Models/Context.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace Lab1.Models 5 | { 6 | public class Context:IdentityDbContext 7 | { 8 | public DbSet Products { get; set; } 9 | public DbSet Categories { get; set; } 10 | 11 | 12 | public Context(DbContextOptions options) : base(options) 13 | { 14 | 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lab1/Models/Product.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations.Schema; 2 | 3 | namespace Lab1.Models 4 | { 5 | public class Product 6 | { 7 | public int Id { get; set; } 8 | public string Name { get; set; } 9 | public string Description { get; set; } 10 | public decimal Price { get; set; } 11 | 12 | [ForeignKey("Category")] 13 | public int? CategoryId { get; set; } 14 | public Category? Category { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Lab1/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carolemad965/ASP.NET-Core-Web-API-with-JWT-Authentication/bd3af3c216f3aa8faf6bbce871e2db947aaba10e/Lab1/Program.cs -------------------------------------------------------------------------------- /Lab1/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:58868", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5117", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Lab1/Repository/CategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using Lab1.Models; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Internal; 4 | 5 | namespace Lab1.Repository 6 | { 7 | public class CategoryRepository: ICategoryRepository 8 | { 9 | private readonly Context context; 10 | private readonly IProductRepository productRepository; 11 | public CategoryRepository(Context _context,IProductRepository _ProductRepository) 12 | { 13 | context = _context; 14 | productRepository = _ProductRepository; 15 | } 16 | public List GetAll() 17 | { 18 | return context.Categories.ToList(); 19 | } 20 | public Category GetById(int id) 21 | { 22 | Category? category = context.Categories.Include(c=>c.products).FirstOrDefault(c => c.Id == id); 23 | 24 | return category; 25 | } 26 | public Category GetByName(string name) 27 | { 28 | Category? category=context.Categories.FirstOrDefault(c => c.Name == name); 29 | return category; 30 | } 31 | public void Add(Category category) 32 | { 33 | context.Categories.Add(category); 34 | context.SaveChanges(); 35 | } 36 | public bool Update(int id ,Category category) 37 | { 38 | Category categoryFromDB=GetById(id); 39 | if(categoryFromDB == null) 40 | { 41 | return false; 42 | 43 | } 44 | categoryFromDB.Name = category.Name; 45 | categoryFromDB.Id = id; 46 | context.SaveChanges(); 47 | return true; 48 | } 49 | public bool Delete(int id) 50 | { 51 | Category category = context.Categories.FirstOrDefault(c=>c.Id == id); 52 | if(category == null ) 53 | { 54 | return false; 55 | } 56 | context.Categories.Remove(category); 57 | context.SaveChanges(); 58 | return true; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Lab1/Repository/ICategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using Lab1.Models; 2 | 3 | namespace Lab1.Repository 4 | { 5 | public interface ICategoryRepository 6 | { 7 | List GetAll(); 8 | 9 | Category GetById(int id); 10 | 11 | Category GetByName(string name); 12 | 13 | void Add(Category category); 14 | 15 | bool Update(int id,Category category); 16 | 17 | bool Delete(int id); 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /Lab1/Repository/IProductRepository.cs: -------------------------------------------------------------------------------- 1 | using Lab1.Models; 2 | 3 | namespace Lab1.Repository 4 | { 5 | public interface IProductRepository 6 | { 7 | List GetAll(); 8 | Product GetById(int id); 9 | void Add(Product product); 10 | bool Update(int id,Product product); 11 | bool Delete(int id); 12 | List GetByName(string name); 13 | 14 | 15 | } 16 | } -------------------------------------------------------------------------------- /Lab1/Repository/ProductRepository.cs: -------------------------------------------------------------------------------- 1 | using Lab1.Models; 2 | 3 | namespace Lab1.Repository 4 | { 5 | public class ProductRepository: IProductRepository 6 | { 7 | private readonly Context context; 8 | public ProductRepository(Context _context) { 9 | context = _context; 10 | } 11 | public List GetAll() 12 | { 13 | List products = context.Products.ToList(); 14 | return products; 15 | } 16 | public Product GetById(int id) { 17 | Product? product = context.Products.FirstOrDefault(p => p.Id == id); 18 | 19 | return product; 20 | } 21 | public List GetByName(string name) 22 | { 23 | List products = context.Products.Where(products => products.Name == name).ToList(); 24 | return products; 25 | 26 | } 27 | public void Add(Product product) 28 | { 29 | context.Products.Add(product); 30 | context.SaveChanges(); 31 | } 32 | public bool Update(int id,Product product) 33 | { 34 | Product ProductFromDb=GetById(id); 35 | bool IsValid = true; 36 | if(ProductFromDb == null) 37 | { 38 | IsValid = false; 39 | } 40 | else if(ProductFromDb.Id != id) { 41 | 42 | IsValid = false; 43 | } 44 | 45 | if(IsValid) 46 | { 47 | ProductFromDb.Name= product.Name; 48 | ProductFromDb.Description= product.Description; 49 | ProductFromDb.Price= product.Price; 50 | context.SaveChanges(); 51 | } 52 | return IsValid; 53 | } 54 | public bool Delete(int id) 55 | { 56 | Product ProductFromDB=GetById(id); 57 | if(ProductFromDB!=null) 58 | { 59 | context.Remove(ProductFromDB); 60 | context.SaveChanges(); 61 | return true; 62 | } 63 | return false; 64 | } 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Lab1/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace Lab1 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateOnly Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Lab1/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Lab1/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "JWT": { 10 | "ValidIss": "http://localhost:58868", 11 | "ValidAud": "http://localhost:4200", 12 | "SecritKey": "gfggggggggggggggggggggggggggggggggggg" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Lab1/wwwroot/Consumer.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 |

HTML Page Sevice Consumer

9 |
    10 | 11 | 12 | 13 | 16 | 17 | 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ASP.NET Core Web API with JWT Authentication E-Commerce 2 | This project demonstrates building a secure ASP.NET Core Web API with JWT (JSON Web Token) authentication. It includes features such as user registration, login, and role-based authorization. The API utilizes a code-first approach, integrates with a MSSQL database using Entity Framework Core, and follows modern development practices for maintainability and scalability. 3 | 4 | # Features 5 | 1- JWT Authentication: Implements token-based authentication using JWT to secure user access to the API endpoints. 6 | 7 | 2- User Registration and Login: Provides endpoints for user registration and login, with password hashing for security. 8 | 9 | 3- Role-Based Authorization: Restricts access to certain actions based on user roles. Only admin users have authorization to perform administrative actions. 10 | 11 | 4- Repository Pattern: Utilizes the repository pattern to separate data access logic, improving code organization and testability. 12 | 13 | 5- Dependency Injection: Leverages ASP.NET Core's built-in dependency injection for loosely coupled components and better code maintainability. 14 | 15 | 6- Identity Framework Integration: Integrates with Identity Framework for user authentication and authorization, enabling role-based access control. 16 | 17 | # Technologies Used: 18 | 1-ASP.NET Core. 19 | 20 | 2-Entity Framework Core. 21 | 22 | 3-MSSQL. 23 | 24 | 4-JWT Token Authentication. 25 | 26 | 5-Dependency Injection. 27 | 28 | 6-Repository Pattern. 29 | 30 | 7-LINQ. 31 | 32 | 8-Identity Framework. 33 | 34 | # How It Works 35 | 1- User Registration: Users can register with the API by providing their username, email, and password. Upon successful registration, the user is added to the database, and a JWT token is generated for authentication. 36 | 37 | 2- User Login: Registered users can log in using their credentials. The API verifies the user's credentials, and if valid, issues a JWT token for subsequent requests. 38 | 39 | 3- Role-Based Authorization: Certain actions in the API are restricted to admin users. To grant admin privileges to a user, you can uncomment the line await userManager.AddToRoleAsync(user, "Admin"); in the Register action of the AccountController. This will assign the "Admin" role to the user upon registration. 40 | 41 | 4- Accessing Protected Endpoints: Users can access protected endpoints by including the JWT token in the Authorization header of the HTTP request. The token is validated by the API to ensure the user has the necessary permissions. 42 | 43 | # Getting Started 44 | 1-Clone the Repository: Clone this repository to your local machine using git clone. 45 | 46 | 2-Set Up the Database: Configure a MSSQL database and update the connection string in the appsettings.json file. 47 | 48 | 3-Run Migrations: Run the Entity Framework Core migrations to create the database schema. 49 | 50 | 4-Build and Run the Project: Build and run the ASP.NET Core Web API project using Visual Studio or the .NET CLI. 51 | 52 | 5-Test the Endpoints: Use tools like Postman or curl to test the API endpoints for user registration, login, and other actions. 53 | 54 | # Important Note 55 | To grant admin privileges to a user for the first time, uncomment the line await userManager.AddToRoleAsync(user, "Admin"); in the Register action of the AccountController. This will make the user an admin upon registration. 56 | # Contributing 57 | Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request. 58 | 59 | --------------------------------------------------------------------------------