├── .gitattributes ├── .gitignore ├── WebApplication1.sln └── WebApplication1 ├── Controllers ├── AccountController.cs ├── CartController.cs ├── CategoryController.cs ├── PaymentController.cs ├── ProductController.cs ├── ShipmentController.cs └── WishListController.cs ├── DTO ├── CartDTO.cs ├── CatDTO.cs ├── CategoryWithProduct.cs ├── GeneralResponse.cs ├── LoginUserDTO.cs ├── PaymentDTO.cs ├── ProductDTO.cs ├── RegisterUserDTO.cs ├── ShipmentDTO.cs ├── WishListDTO.cs └── WishListDTOs.cs ├── Migrations ├── 20240409180102_db.Designer.cs ├── 20240409180102_db.cs ├── 20240409200736_PaymentClass.Designer.cs ├── 20240409200736_PaymentClass.cs ├── 20240410101856_CartClass.Designer.cs ├── 20240410101856_CartClass.cs ├── 20240410155050_WishListClass.Designer.cs ├── 20240410155050_WishListClass.cs └── ContextModelSnapshot.cs ├── Models ├── ApplicationUser.cs ├── Cart.cs ├── Category.cs ├── Context.cs ├── Payment.cs ├── Product.cs ├── Shipment.cs └── WishList.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Repository ├── CartRepository.cs ├── CategoryRepository.cs ├── ICartRepository.cs ├── ICategoryRepository.cs ├── IPaymentRepository.cs ├── IProductRepository.cs ├── IShipmentRepository.cs ├── IWishListRepository.cs ├── PaymentRepository.cs ├── ProductRepository.cs ├── ShipmentRepository.cs └── WishListRepository.cs ├── WeatherForecast.cs ├── WebApplication1.csproj ├── WebApplication1.http ├── appsettings.Development.json └── appsettings.json /.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 -------------------------------------------------------------------------------- /WebApplication1.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}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{65A53F84-455B-4B2B-BD10-9B19CE410CA3}" 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 | {65A53F84-455B-4B2B-BD10-9B19CE410CA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {65A53F84-455B-4B2B-BD10-9B19CE410CA3}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {65A53F84-455B-4B2B-BD10-9B19CE410CA3}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {65A53F84-455B-4B2B-BD10-9B19CE410CA3}.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 = {2BA77732-30CF-4EDA-B08F-172112093783} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WebApplication1/Controllers/AccountController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.IdentityModel.Tokens; 4 | using System.IdentityModel.Tokens.Jwt; 5 | using System.Security.Claims; 6 | using System.Text; 7 | using WebApplication1.DTO; 8 | using WebApplication1.Models; 9 | 10 | namespace WebApplication1.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [ApiController] 14 | public class AccountController : ControllerBase 15 | { 16 | private readonly UserManager userManager; 17 | private readonly IConfiguration config; 18 | 19 | public AccountController(UserManager userManager, IConfiguration config) 20 | { 21 | this.userManager = userManager; 22 | this.config = config; 23 | } 24 | 25 | [HttpPost("register")] //api/account/register 26 | public async Task Register(RegisterUserDTO userDto) 27 | { 28 | if (ModelState.IsValid) 29 | { 30 | 31 | ApplicationUser appuser = new ApplicationUser() 32 | { 33 | UserName = userDto.UserName, 34 | Email = userDto.Email, 35 | PasswordHash = userDto.Password 36 | }; 37 | //create account in db 38 | IdentityResult result = await userManager.CreateAsync(appuser, userDto.Password); 39 | if (result.Succeeded) 40 | { 41 | return Ok("Account Created"); 42 | } 43 | return BadRequest(result.Errors); 44 | 45 | } 46 | return BadRequest(ModelState); 47 | } 48 | 49 | 50 | [HttpPost("login")] //api/account/login 51 | public async Task Login(LoginUserDTO userDTO) 52 | { 53 | if (ModelState.IsValid) 54 | { 55 | //return null not Found or AppUser if Found 56 | ApplicationUser? userFromDB = await userManager.FindByNameAsync(userDTO.UserName); 57 | 58 | if (userFromDB != null) 59 | { 60 | //found in db 61 | //check pass 62 | 63 | bool found = await userManager.CheckPasswordAsync(userFromDB, userDTO.Password); 64 | 65 | if (found) 66 | { 67 | //create token 68 | 69 | List myclaim = new List(); 70 | myclaim.Add(new Claim(ClaimTypes.Name, userFromDB.UserName)); 71 | myclaim.Add(new Claim(ClaimTypes.NameIdentifier, userFromDB.Id)); 72 | myclaim.Add(new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())); //jti ==> Token id 73 | 74 | 75 | var roles = await userManager.GetRolesAsync(userFromDB); 76 | foreach (var role in roles) 77 | { 78 | myclaim.Add(new Claim(ClaimTypes.Role, role)); 79 | } 80 | 81 | 82 | var signKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config["JWT:SecritKey"])); //"ssssssssssssssssssssssssssssssssssssssssssssssssssssss" 83 | 84 | SigningCredentials signingCredentials = 85 | new SigningCredentials(signKey, SecurityAlgorithms.HmacSha256); 86 | 87 | 88 | JwtSecurityToken myToken = new JwtSecurityToken( 89 | issuer: config["JWT:ValidIss"], 90 | audience: config["JWT:ValidAud"], 91 | expires: DateTime.Now.AddHours(1), 92 | claims: myclaim, 93 | signingCredentials: signingCredentials 94 | 95 | ); 96 | return Ok(new 97 | { 98 | token = new JwtSecurityTokenHandler().WriteToken(myToken), 99 | expired = myToken.ValidTo 100 | }); 101 | 102 | 103 | } 104 | 105 | 106 | 107 | } 108 | //null no user in db 109 | return Unauthorized("Invalid Account"); 110 | 111 | 112 | 113 | } 114 | return BadRequest(ModelState); 115 | 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /WebApplication1/Controllers/CartController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Identity; 3 | using Microsoft.AspNetCore.Mvc; 4 | using WebApplication1.DTO; 5 | using WebApplication1.Models; 6 | using WebApplication1.Repository; 7 | 8 | namespace WebApplication1.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | [ApiController] 12 | public class CartController : ControllerBase 13 | { 14 | private readonly UserManager userManager; 15 | private readonly ICartRepository cartRepository; 16 | 17 | public CartController(UserManager userManager, ICartRepository cartRepository) 18 | { 19 | this.userManager = userManager; 20 | this.cartRepository = cartRepository; 21 | } 22 | 23 | [HttpGet] 24 | [Authorize] 25 | public ActionResult GetAll() 26 | { 27 | var cartsWithProductNames = cartRepository.GetAll() 28 | .Select(cart => new 29 | { 30 | cart.Id, 31 | cart.Quantity, 32 | cart.Product_Id, 33 | CustomerName = cart.customer.UserName, 34 | CustomerEmail = cart.customer.Email, 35 | ProductNames = cart.product.Name 36 | }) 37 | .ToList(); 38 | 39 | 40 | GeneralResponse response = new GeneralResponse() 41 | { 42 | IsPass = true, 43 | Message = cartsWithProductNames 44 | }; 45 | return response; 46 | 47 | } 48 | 49 | [HttpPost] 50 | [Authorize] 51 | public async Task> AddToCart(CartDTO cartDTO) 52 | { 53 | var currentUser = await userManager.GetUserAsync(User); 54 | if (currentUser == null) 55 | { 56 | return Unauthorized("User not authenticated."); 57 | } 58 | if (ModelState.IsValid) 59 | { 60 | //var currentUser = await userManager.GetUserAsync(User); 61 | var cart = new Cart 62 | { 63 | Quantity = cartDTO.Quantity, 64 | Product_Id = cartDTO.Product_Id, 65 | Customer_Id = currentUser.Id, 66 | 67 | }; 68 | cartRepository.Insert(cart); 69 | cartRepository.Save(); 70 | GeneralResponse response = new GeneralResponse() 71 | { 72 | IsPass = true, 73 | Message = "Done" 74 | }; 75 | return response; 76 | } 77 | else 78 | { 79 | GeneralResponse response = new GeneralResponse() 80 | { 81 | IsPass = false, 82 | Message = "Cant Add To Cart" 83 | }; 84 | return response; 85 | } 86 | } 87 | [HttpPut] 88 | [Authorize] 89 | public ActionResult Edit(int id, CartDTO updatedCart) 90 | { 91 | Cart OldCart = cartRepository.GetById(id); 92 | if (OldCart == null) 93 | { 94 | return NotFound(); 95 | } 96 | OldCart.Quantity = updatedCart.Quantity; 97 | OldCart.Product_Id = updatedCart.Product_Id; 98 | 99 | 100 | 101 | 102 | cartRepository.Update(OldCart); 103 | cartRepository.Save(); 104 | GeneralResponse response = new GeneralResponse() 105 | { 106 | IsPass = true, 107 | Message = "Done" 108 | }; 109 | return response; 110 | } 111 | 112 | 113 | 114 | [HttpDelete("{id}")] 115 | [Authorize] 116 | public ActionResult RemoveFromCart(int id) 117 | { 118 | try 119 | { 120 | cartRepository.Delete(id); 121 | cartRepository.Save(); 122 | GeneralResponse localresponse = new GeneralResponse() 123 | { 124 | IsPass = true, 125 | Message = "Done" 126 | }; 127 | return Ok(localresponse); 128 | } 129 | catch (Exception ex) 130 | { 131 | GeneralResponse response = new GeneralResponse() 132 | { 133 | IsPass = false, 134 | Message = ex.Message 135 | 136 | }; 137 | return StatusCode(500, response); 138 | } 139 | } 140 | 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /WebApplication1/Controllers/CategoryController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Mvc; 3 | using WebApplication1.DTO; 4 | using WebApplication1.Models; 5 | using WebApplication1.Repository; 6 | 7 | namespace WebApplication1.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 | this.categoryRepository = categoryRepository; 18 | } 19 | 20 | [HttpGet] 21 | [Authorize] 22 | public ActionResult GetAllCategory() 23 | { 24 | List categories = categoryRepository.GetAll(); 25 | List categoriesWithProduct = categories.Select(category => 26 | new CategoryWithProduct 27 | { 28 | Id = category.Id, 29 | Category_Name = category.Name, 30 | ProductNames = category.products?.Select(p => p.Name).ToList() 31 | }).ToList(); 32 | //return Ok(categoriesWithProduct); 33 | GeneralResponse response = new GeneralResponse() 34 | { 35 | IsPass = true, 36 | Message = categoriesWithProduct 37 | }; 38 | return response; 39 | } 40 | 41 | [HttpGet("{id:int}")] 42 | [Authorize] 43 | public ActionResult GetById(int id) 44 | { 45 | var category = categoryRepository.GetById(id); 46 | 47 | if (category == null) 48 | { 49 | // return NotFound(); 50 | GeneralResponse LocalResponse = new GeneralResponse() 51 | { 52 | IsPass = false, 53 | Message = "Not Found" 54 | }; 55 | return LocalResponse; 56 | } 57 | 58 | var categoryWithProducts = new CategoryWithProduct 59 | { 60 | Id = category.Id, 61 | Category_Name = category.Name, 62 | ProductNames = category.products.Select(p => p.Name).ToList() 63 | }; 64 | 65 | 66 | // return Ok(categoryWithProducts); 67 | GeneralResponse response = new GeneralResponse() 68 | { 69 | IsPass = true, 70 | Message = categoryWithProducts 71 | }; 72 | return response; 73 | } 74 | 75 | [HttpPost] 76 | [Authorize] 77 | public ActionResult AppCategory(CatDTO catDTO) 78 | { 79 | if (ModelState.IsValid == true) 80 | { 81 | var category = new Category 82 | { 83 | Name = catDTO.Name 84 | // products = catDTO.ProductNames.Select(name => new Product { Name = name }).ToList() 85 | }; 86 | categoryRepository.Insert(category); 87 | categoryRepository.Save(); 88 | // return CreatedAtAction(nameof(GetById), new { id = category.Id }, category); 89 | return new GeneralResponse 90 | { 91 | IsPass = true, 92 | Message = new 93 | { 94 | category.Id, 95 | category.Name, 96 | 97 | } 98 | }; 99 | } 100 | else 101 | { 102 | GeneralResponse localresponse = new GeneralResponse() 103 | { 104 | IsPass = false, 105 | Message = "Cant Add Category" 106 | }; 107 | return localresponse; 108 | } 109 | 110 | 111 | } 112 | 113 | [HttpPut] 114 | [Authorize] 115 | public ActionResult Edit(int id, CatDTO UpdatedCategory) 116 | { 117 | Category OldCategory = categoryRepository.GetById(id); 118 | if (OldCategory == null) 119 | { 120 | // return NotFound(); 121 | GeneralResponse LocalResponse = new GeneralResponse() 122 | { 123 | IsPass = false, 124 | Message = "Not Found" 125 | }; 126 | return LocalResponse; 127 | } 128 | OldCategory.Name = UpdatedCategory.Name; 129 | categoryRepository.Update(OldCategory); 130 | categoryRepository.Save(); 131 | 132 | GeneralResponse response = new GeneralResponse() 133 | { 134 | IsPass = true, 135 | Message = new 136 | { 137 | OldCategory.Id, 138 | OldCategory.Name, 139 | 140 | } 141 | }; 142 | return response; 143 | 144 | } 145 | 146 | 147 | [HttpDelete("{id:int}")] 148 | [Authorize] 149 | public IActionResult Remove(int id) 150 | { 151 | try 152 | { 153 | categoryRepository.Delete(id); 154 | categoryRepository.Save(); 155 | GeneralResponse localresponse = new GeneralResponse() 156 | { 157 | IsPass = true, 158 | Message = "Done" 159 | }; 160 | return Ok(localresponse); 161 | } 162 | catch (Exception ex) 163 | { 164 | GeneralResponse response = new GeneralResponse() 165 | { 166 | IsPass = false, 167 | Message = ex.Message 168 | 169 | }; 170 | return StatusCode(500, response); 171 | } 172 | } 173 | 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /WebApplication1/Controllers/PaymentController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Identity; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System.Security.Claims; 5 | using WebApplication1.DTO; 6 | using WebApplication1.Models; 7 | using WebApplication1.Repository; 8 | 9 | namespace WebApplication1.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class PaymentController : ControllerBase 14 | { 15 | private readonly UserManager userManager; 16 | private readonly IPaymentRepository paymentRepository; 17 | private readonly ICartRepository cartRepository; 18 | 19 | public PaymentController(UserManager userManager, IPaymentRepository paymentRepository, ICartRepository cartRepository) 20 | { 21 | this.userManager = userManager; 22 | this.paymentRepository = paymentRepository; 23 | this.cartRepository = cartRepository; 24 | } 25 | 26 | [HttpGet] 27 | [Authorize] 28 | public ActionResult GetAllPayment() 29 | { 30 | var paymentsWithUserNames = paymentRepository.GetAll() 31 | .Select(payment => new 32 | { 33 | payment.Id, 34 | payment.Date, 35 | payment.Method, 36 | payment.Amount, 37 | CustomerName = payment.customer.UserName, 38 | CustomerEmail = payment.customer.Email 39 | }) 40 | .ToList(); 41 | 42 | //return Ok(paymentsWithUserNames); 43 | GeneralResponse response = new GeneralResponse() 44 | { 45 | IsPass = true, 46 | Message = paymentsWithUserNames 47 | }; 48 | return response; 49 | } 50 | 51 | [HttpGet("{username}")] 52 | [Authorize] 53 | public ActionResult GetAllByUserName(string username) 54 | { 55 | var user = userManager.FindByNameAsync(username).Result; 56 | if (user == null) 57 | { 58 | return NotFound($"User '{username}' not found."); 59 | } 60 | var paymentsWithUserNames = paymentRepository.GetAll() 61 | .Where(payment => payment.customer.UserName == username) 62 | .Select(payment => new 63 | { 64 | payment.Id, 65 | payment.Date, 66 | payment.Method, 67 | payment.Amount, 68 | 69 | CustomerName = payment.customer.UserName, 70 | CustomerEmail = payment.customer.Email 71 | }) 72 | .ToList(); 73 | 74 | // return Ok(paymentsWithUserNames); 75 | GeneralResponse response = new GeneralResponse() 76 | { 77 | IsPass = true, 78 | Message = paymentsWithUserNames 79 | }; 80 | return response; 81 | } 82 | 83 | 84 | 85 | [HttpPost] 86 | [Authorize] 87 | public async Task> AddPayment(PaymentDTO paymentDTO) 88 | { 89 | var currentUser = await userManager.GetUserAsync(User); 90 | if (currentUser == null) 91 | { 92 | return Unauthorized("User not authenticated."); 93 | } 94 | if (ModelState.IsValid) 95 | { 96 | // var currentUser = await userManager.GetUserAsync(User); 97 | var Id = User.FindFirstValue(ClaimTypes.NameIdentifier); 98 | 99 | var payment = new Payment 100 | { 101 | Date = paymentDTO.Date, 102 | Method = paymentDTO.Method, 103 | Amount = cartRepository.GetTotalPrice(Id), 104 | customer = currentUser, 105 | Customer_Id = currentUser.Id 106 | }; 107 | 108 | paymentRepository.Insert(payment); 109 | paymentRepository.Save(); 110 | // return Ok(); 111 | return new GeneralResponse 112 | { 113 | IsPass = true, 114 | Message = new 115 | { 116 | payment.Id, 117 | payment.Method, 118 | payment.Amount 119 | 120 | } 121 | }; 122 | } 123 | else 124 | { 125 | GeneralResponse localresponse = new GeneralResponse() 126 | { 127 | IsPass = false, 128 | Message = "Cant Add Payment" 129 | }; 130 | return localresponse; 131 | } 132 | } 133 | 134 | [HttpPut] 135 | [Authorize] 136 | public ActionResult Edit(int id, PaymentDTO updatedPayment) 137 | { 138 | Payment OldPayment = paymentRepository.GetById(id); 139 | if (OldPayment == null) 140 | { 141 | GeneralResponse LocalResponse = new GeneralResponse() 142 | { 143 | IsPass = false, 144 | Message = "Not Found" 145 | }; 146 | return LocalResponse; 147 | } 148 | OldPayment.Date = updatedPayment.Date; 149 | OldPayment.Method = updatedPayment.Method; 150 | OldPayment.Amount = updatedPayment.Amount; 151 | 152 | 153 | paymentRepository.Update(OldPayment); 154 | paymentRepository.Save(); 155 | // return NoContent(); 156 | GeneralResponse response = new GeneralResponse() 157 | { 158 | IsPass = true, 159 | Message = new 160 | { 161 | OldPayment.Id, 162 | OldPayment.Date, 163 | OldPayment.Method, 164 | OldPayment.Amount 165 | 166 | } 167 | }; 168 | return response; 169 | 170 | } 171 | 172 | [HttpDelete("{id:int}")] 173 | [Authorize] 174 | public ActionResult Remove(int id) 175 | { 176 | try 177 | { 178 | paymentRepository.Delete(id); 179 | paymentRepository.Save(); 180 | GeneralResponse localresponse = new GeneralResponse() 181 | { 182 | IsPass = true, 183 | Message = "Done" 184 | }; 185 | return Ok(localresponse); 186 | } 187 | catch (Exception ex) 188 | { 189 | GeneralResponse response = new GeneralResponse() 190 | { 191 | IsPass = false, 192 | Message = ex.Message 193 | 194 | }; 195 | return StatusCode(500, response); 196 | } 197 | } 198 | 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /WebApplication1/Controllers/ProductController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Mvc; 3 | using WebApplication1.DTO; 4 | using WebApplication1.Models; 5 | using WebApplication1.Repository; 6 | 7 | namespace WebApplication1.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | [ApiController] 11 | public class ProductController : ControllerBase 12 | { 13 | private readonly IProductRepository productRepository; 14 | 15 | 16 | public ProductController(IProductRepository productRepository) 17 | { 18 | this.productRepository = productRepository; 19 | } 20 | 21 | [HttpGet] 22 | [Authorize] 23 | public ActionResult GetAll() 24 | { 25 | List products = productRepository.GetAll(); 26 | List productDTOs = products.Select(product => new ProductDTO 27 | { 28 | Id = product.Id, 29 | Name = product.Name, 30 | Price = product.Price, 31 | Description = product.Description, 32 | Category_Id = product.Category_Id, 33 | 34 | }).ToList(); 35 | GeneralResponse response = new GeneralResponse() 36 | { 37 | IsPass = true, 38 | Message = productDTOs 39 | }; 40 | return response; 41 | 42 | 43 | } 44 | 45 | [HttpGet("{id:int}")] 46 | [Authorize] 47 | public ActionResult GetById(int id) 48 | { 49 | Product product = productRepository.GetById(id); 50 | 51 | if (product == null) 52 | { 53 | GeneralResponse localresponse = new GeneralResponse() 54 | { 55 | IsPass = false, 56 | Message = "Id Not Found" 57 | }; 58 | return localresponse; 59 | } 60 | var productDTo = new ProductDTO 61 | { 62 | Id = product.Id, 63 | Name = product.Name, 64 | Price = product.Price, 65 | Description = product.Description, 66 | Category_Id = product.Category_Id 67 | 68 | }; 69 | 70 | GeneralResponse response = new GeneralResponse() 71 | { 72 | IsPass = true, 73 | Message = productDTo 74 | }; 75 | return response; 76 | 77 | 78 | } 79 | 80 | 81 | 82 | [HttpPost] 83 | [Authorize] 84 | public ActionResult AddProduct(ProductDTO newProductDTO) 85 | { 86 | if (ModelState.IsValid == true) 87 | { 88 | var newProduct = new Product 89 | { 90 | Name = newProductDTO.Name, 91 | Price = newProductDTO.Price, 92 | Description = newProductDTO.Description, 93 | Category_Id = newProductDTO.Category_Id, 94 | }; 95 | productRepository.Insert(newProduct); 96 | productRepository.Save(); 97 | 98 | 99 | return new GeneralResponse 100 | { 101 | IsPass = true, 102 | Message = new 103 | { 104 | newProduct.Id, 105 | newProduct.Name, 106 | newProduct.Price, 107 | newProduct.Description 108 | } 109 | }; 110 | 111 | } 112 | GeneralResponse localresponse = new GeneralResponse() 113 | { 114 | IsPass = false, 115 | Message = "Cant Add" 116 | }; 117 | return localresponse; 118 | } 119 | 120 | 121 | 122 | 123 | [HttpPut] 124 | [Authorize] 125 | public ActionResult Edit(int id, ProductDTO updatedProduct) 126 | { 127 | Product Oldproduct = productRepository.GetById(id); 128 | 129 | if (Oldproduct == null) 130 | { 131 | 132 | GeneralResponse localresponse = new GeneralResponse() 133 | { 134 | IsPass = false, 135 | Message = "Id Not Found" 136 | }; 137 | return localresponse; 138 | } 139 | 140 | Oldproduct.Name = updatedProduct.Name; 141 | Oldproduct.Price = updatedProduct.Price; 142 | Oldproduct.Description = updatedProduct.Description; 143 | Oldproduct.Category_Id = updatedProduct.Category_Id; 144 | productRepository.Update(Oldproduct); 145 | productRepository.Save(); 146 | GeneralResponse response = new GeneralResponse() 147 | { 148 | IsPass = true, 149 | Message = new 150 | { 151 | Oldproduct.Id, 152 | Oldproduct.Name, 153 | Oldproduct.Price, 154 | Oldproduct.Description 155 | } 156 | }; 157 | return response; 158 | 159 | } 160 | 161 | 162 | 163 | [HttpDelete("{id:int}")] 164 | [Authorize] 165 | public IActionResult Remove(int id) 166 | { 167 | try 168 | { 169 | productRepository.Delete(id); 170 | productRepository.Save(); 171 | GeneralResponse localresponse = new GeneralResponse() 172 | { 173 | IsPass = true, 174 | Message = "done" 175 | }; 176 | return Ok(localresponse); 177 | } 178 | catch (Exception ex) 179 | { 180 | //return BadRequest(ex.Message); 181 | 182 | GeneralResponse localresponse = new GeneralResponse() 183 | { 184 | IsPass = false, 185 | Message = ex.Message 186 | 187 | }; 188 | return StatusCode(500, localresponse); 189 | } 190 | } 191 | 192 | 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /WebApplication1/Controllers/ShipmentController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Identity; 3 | using Microsoft.AspNetCore.Mvc; 4 | using WebApplication1.DTO; 5 | using WebApplication1.Models; 6 | using WebApplication1.Repository; 7 | 8 | namespace WebApplication1.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | [ApiController] 12 | public class ShipmentController : ControllerBase 13 | { 14 | private readonly UserManager userManager; 15 | private readonly IShipmentRepository shipmentRepository; 16 | 17 | public ShipmentController(UserManager userManager, IShipmentRepository shipmentRepository) 18 | { 19 | this.userManager = userManager; 20 | this.shipmentRepository = shipmentRepository; 21 | } 22 | [HttpGet] 23 | [Authorize] 24 | public ActionResult GetAll() 25 | { 26 | var shipmentsWithUserNames = shipmentRepository.GetAll() 27 | .Select(shipment => new 28 | { 29 | shipment.Id, 30 | shipment.Date, 31 | shipment.Address, 32 | shipment.State, 33 | shipment.City, 34 | shipment.Zip_Code, 35 | shipment.Country, 36 | CustomerName = shipment.customer.UserName, 37 | CustomerEmail = shipment.customer.Email 38 | }) 39 | .ToList(); 40 | 41 | // return Ok(shipmentsWithUserNames); 42 | GeneralResponse response = new GeneralResponse() 43 | { 44 | IsPass = true, 45 | Message = shipmentsWithUserNames 46 | }; 47 | return response; 48 | } 49 | 50 | 51 | [HttpGet("{username}")] 52 | [Authorize] 53 | public ActionResult GetAllByUserName(string username) 54 | { 55 | var user = userManager.FindByNameAsync(username).Result; 56 | if (user == null) 57 | { 58 | return NotFound($"User '{username}' not found."); 59 | } 60 | var shipmentsWithUserNames = shipmentRepository.GetAll() 61 | .Where(shipment => shipment.customer.UserName == username) 62 | .Select(shipment => new 63 | { 64 | shipment.Id, 65 | shipment.Date, 66 | shipment.Address, 67 | shipment.State, 68 | shipment.City, 69 | shipment.Zip_Code, 70 | shipment.Country, 71 | CustomerName = shipment.customer.UserName, 72 | CustomerEmail = shipment.customer.Email 73 | }) 74 | .ToList(); 75 | 76 | //return Ok(shipmentsWithUserNames); 77 | GeneralResponse response = new GeneralResponse() 78 | { 79 | IsPass = true, 80 | Message = shipmentsWithUserNames 81 | }; 82 | return response; 83 | } 84 | 85 | 86 | [HttpPost] 87 | [Authorize] 88 | public async Task> AddShipment(ShipmentDTO shipmentDTO) 89 | { 90 | var currentUser = await userManager.GetUserAsync(User); 91 | if (currentUser == null) 92 | { 93 | return Unauthorized("User not authenticated."); 94 | } 95 | if (ModelState.IsValid) 96 | { 97 | //var currentUser = await userManager.GetUserAsync(User); 98 | 99 | var shipment = new Shipment 100 | { 101 | Date = shipmentDTO.Date, 102 | Address = shipmentDTO.Address, 103 | State = shipmentDTO.State, 104 | City = shipmentDTO.City, 105 | Zip_Code = shipmentDTO.Zip_Code, 106 | Country = shipmentDTO.Country, 107 | customer = currentUser, 108 | Customer_Id = currentUser.Id 109 | 110 | 111 | }; 112 | 113 | shipmentRepository.Insert(shipment); 114 | shipmentRepository.Save(); 115 | // return Ok(); 116 | return new GeneralResponse 117 | { 118 | IsPass = true, 119 | Message = new 120 | { 121 | shipment.Id, 122 | shipment.Date, 123 | shipment.Address, 124 | shipment.City, 125 | shipment.Country, 126 | shipment.State, 127 | shipment.Zip_Code 128 | 129 | } 130 | }; 131 | } 132 | else 133 | { 134 | GeneralResponse localresponse = new GeneralResponse() 135 | { 136 | IsPass = false, 137 | Message = "Cant Add Shipment" 138 | }; 139 | return localresponse; 140 | } 141 | } 142 | 143 | [HttpPut] 144 | [Authorize] 145 | public ActionResult Edit(int id, ShipmentDTO updatedShipment) 146 | { 147 | Shipment OldShipment = shipmentRepository.GetById(id); 148 | if (OldShipment == null) 149 | { 150 | // return NotFound(); 151 | GeneralResponse LocalResponse = new GeneralResponse() 152 | { 153 | IsPass = false, 154 | Message = "Not Found" 155 | }; 156 | return LocalResponse; 157 | } 158 | OldShipment.Address = updatedShipment.Address; 159 | OldShipment.Date = updatedShipment.Date; 160 | OldShipment.Country = updatedShipment.Country; 161 | OldShipment.City = updatedShipment.City; 162 | OldShipment.State = updatedShipment.State; 163 | OldShipment.Zip_Code = updatedShipment.Zip_Code; 164 | 165 | 166 | 167 | shipmentRepository.Update(OldShipment); 168 | shipmentRepository.Save(); 169 | // return NoContent(); 170 | GeneralResponse response = new GeneralResponse() 171 | { 172 | IsPass = true, 173 | Message = new 174 | { 175 | OldShipment.Id, 176 | OldShipment.Date, 177 | OldShipment.Address, 178 | OldShipment.City, 179 | OldShipment.Country, 180 | OldShipment.State, 181 | OldShipment.Zip_Code 182 | 183 | } 184 | }; 185 | return response; 186 | } 187 | 188 | 189 | 190 | [HttpDelete("{id:int}")] 191 | [Authorize] 192 | public ActionResult Remove(int id) 193 | { 194 | try 195 | { 196 | shipmentRepository.Delete(id); 197 | shipmentRepository.Save(); 198 | // return NoContent(); 199 | GeneralResponse localresponse = new GeneralResponse() 200 | { 201 | IsPass = true, 202 | Message = "Done" 203 | }; 204 | return Ok(localresponse); 205 | } 206 | catch (Exception ex) 207 | { 208 | //return BadRequest(ex.Message); 209 | GeneralResponse response = new GeneralResponse() 210 | { 211 | IsPass = false, 212 | Message = ex.Message 213 | 214 | }; 215 | return StatusCode(500, response); 216 | } 217 | } 218 | 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /WebApplication1/Controllers/WishListController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Identity; 3 | using Microsoft.AspNetCore.Mvc; 4 | using WebApplication1.DTO; 5 | using WebApplication1.Models; 6 | using WebApplication1.Repository; 7 | 8 | namespace WebApplication1.Controllers 9 | { 10 | [Route("api/[controller]")] 11 | [ApiController] 12 | public class WishListController : ControllerBase 13 | { 14 | private readonly UserManager userManager; 15 | private readonly IWishListRepository wishListRepository; 16 | 17 | public WishListController(UserManager userManager, IWishListRepository wishListRepository) 18 | { 19 | this.userManager = userManager; 20 | this.wishListRepository = wishListRepository; 21 | } 22 | 23 | 24 | [HttpGet] 25 | [Authorize] 26 | public ActionResult GetAll() 27 | { 28 | 29 | var wishListWithUserNames = wishListRepository.GetAll() 30 | 31 | .Select(wishList => new 32 | { 33 | wishList.Id, 34 | wishList.Product_Id, 35 | wishList.product.Name, 36 | wishList.product.Price, 37 | wishList.product.Description, 38 | 39 | CustomerName = wishList.customer.UserName, 40 | CustomerEmail = wishList.customer.Email 41 | }) 42 | .ToList(); 43 | 44 | //return Ok(wishListWithUserNames); 45 | GeneralResponse response = new GeneralResponse() 46 | { 47 | IsPass = true, 48 | Message = wishListWithUserNames 49 | }; 50 | return response; 51 | } 52 | 53 | [HttpGet("{id:int}")] 54 | [Authorize] 55 | public ActionResult GetById(int id) 56 | { 57 | var wishList = wishListRepository.GetById(id); 58 | 59 | if (wishList == null) 60 | { 61 | return NotFound(); 62 | } 63 | 64 | 65 | var WishListWithProducts = new 66 | { 67 | wishList.Id, 68 | wishList.Product_Id, 69 | wishList.product.Name, 70 | wishList.product.Price, 71 | wishList.product.Description, 72 | CustomerName = wishList.customer.UserName, 73 | CustomerEmail = wishList.customer.Email 74 | }; 75 | 76 | 77 | // return Ok(WishListWithProducts); 78 | GeneralResponse response = new GeneralResponse() 79 | { 80 | IsPass = true, 81 | Message = WishListWithProducts 82 | }; 83 | return response; 84 | } 85 | 86 | 87 | [HttpGet("{username}")] 88 | [Authorize] 89 | public ActionResult GetAllByUserName(string username) 90 | { 91 | var user = userManager.FindByNameAsync(username).Result; 92 | if (user == null) 93 | { 94 | return NotFound($"User '{username}' not found."); 95 | } 96 | var wishLists = wishListRepository.GetAll() 97 | .Where(wishList => wishList.customer.UserName == username) 98 | .Select(wishList => new WishListDTOs 99 | { 100 | CustomerId = wishList.Customer_Id, 101 | ProductName = wishList.product.Name, 102 | ProductId = wishList.product.Id, 103 | Price = wishList.product.Price 104 | }) 105 | .ToList(); 106 | 107 | // return Ok(wishListWithUserNames); 108 | GeneralResponse response = new GeneralResponse() 109 | { 110 | IsPass = true, 111 | Message = wishLists 112 | }; 113 | return response; 114 | } 115 | 116 | 117 | [HttpPost] 118 | [Authorize] 119 | public async Task> AddToWishList(WishListDTO wishListDTO) 120 | { 121 | var currentUser = await userManager.GetUserAsync(User); 122 | if (currentUser == null) 123 | { 124 | return Unauthorized("User not authenticated."); 125 | } 126 | if (ModelState.IsValid) 127 | { 128 | //var currentUser = await userManager.GetUserAsync(User); 129 | var wishList = new WishList 130 | { 131 | Id = wishListDTO.Id, 132 | Customer_Id = currentUser.Id, 133 | 134 | Product_Id = wishListDTO.Product_Id, 135 | 136 | 137 | }; 138 | wishListRepository.Insert(wishList); 139 | wishListRepository.Save(); 140 | // return Ok(); 141 | return new GeneralResponse 142 | { 143 | IsPass = true, 144 | Message = "Done" 145 | 146 | }; 147 | } 148 | else 149 | { 150 | // return BadRequest(); 151 | GeneralResponse localresponse = new GeneralResponse() 152 | { 153 | IsPass = false, 154 | Message = "Cant Add WishList" 155 | }; 156 | return localresponse; 157 | } 158 | } 159 | 160 | [HttpPut] 161 | [Authorize] 162 | public ActionResult Edit(int id, WishListDTO updatedWishList) 163 | { 164 | WishList OldWishList = wishListRepository.GetById(id); 165 | if (OldWishList == null) 166 | { 167 | // return NotFound(); 168 | GeneralResponse LocalResponse = new GeneralResponse() 169 | { 170 | IsPass = false, 171 | Message = "Not Found" 172 | }; 173 | return LocalResponse; 174 | } 175 | OldWishList.Product_Id = updatedWishList.Product_Id; 176 | 177 | 178 | 179 | 180 | 181 | wishListRepository.Update(OldWishList); 182 | wishListRepository.Save(); 183 | //return NoContent(); 184 | GeneralResponse response = new GeneralResponse() 185 | { 186 | IsPass = true, 187 | Message = "Done" 188 | }; 189 | return response; 190 | } 191 | 192 | 193 | 194 | [HttpDelete("{id}")] 195 | [Authorize] 196 | public ActionResult RemoveFromCart(int id) 197 | { 198 | try 199 | { 200 | wishListRepository.Delete(id); 201 | wishListRepository.Save(); 202 | //return NoContent(); 203 | GeneralResponse localresponse = new GeneralResponse() 204 | { 205 | IsPass = true, 206 | Message = "Done" 207 | }; 208 | return Ok(localresponse); 209 | } 210 | catch (Exception ex) 211 | { 212 | //return BadRequest(ex.Message); 213 | GeneralResponse response = new GeneralResponse() 214 | { 215 | IsPass = false, 216 | Message = ex.Message 217 | 218 | }; 219 | return StatusCode(500, response); 220 | } 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /WebApplication1/DTO/CartDTO.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class CartDTO 4 | { 5 | public int Id { get; set; } 6 | public int Quantity { get; set; } 7 | public int Product_Id { get; set; } 8 | // public List ProductNames { get; set; } 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /WebApplication1/DTO/CatDTO.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class CatDTO 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /WebApplication1/DTO/CategoryWithProduct.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class CategoryWithProduct 4 | { 5 | 6 | public int Id { get; set; } 7 | 8 | public string Category_Name { get; set; } 9 | 10 | public List ProductNames { get; set; } 11 | 12 | 13 | // public List? products { set; get; } 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WebApplication1/DTO/GeneralResponse.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class GeneralResponse 4 | { 5 | public bool IsPass { set; get; } 6 | public dynamic Message { set; get; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /WebApplication1/DTO/LoginUserDTO.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class LoginUserDTO 4 | { 5 | public string UserName { get; set; } 6 | public string Password { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /WebApplication1/DTO/PaymentDTO.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class PaymentDTO 4 | { 5 | public int Id { get; set; } 6 | public DateTime Date { get; set; } 7 | public string Method { get; set; } 8 | public Double Amount { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /WebApplication1/DTO/ProductDTO.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class ProductDTO 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | public int Price { get; set; } 8 | public string Description { get; set; } 9 | public int? Category_Id { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /WebApplication1/DTO/RegisterUserDTO.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class RegisterUserDTO 4 | { 5 | public string UserName { get; set; } 6 | 7 | public string Password { get; set; } 8 | 9 | public string Email { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /WebApplication1/DTO/ShipmentDTO.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class ShipmentDTO 4 | { 5 | 6 | public DateTime Date { get; set; } 7 | public string Address { get; set; } 8 | public string City { get; set; } 9 | public string State { get; set; } 10 | public string Country { get; set; } 11 | public string Zip_Code { get; set; } 12 | 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /WebApplication1/DTO/WishListDTO.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class WishListDTO 4 | { 5 | public int Id { get; set; } 6 | public int Product_Id { get; set; } 7 | 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /WebApplication1/DTO/WishListDTOs.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.DTO 2 | { 3 | public class WishListDTOs 4 | { 5 | public string CustomerId { get; set; } 6 | public string ProductName { get; set; } 7 | public int ProductId { get; set; } 8 | public double Price { get; set; } 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/20240409180102_db.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 WebApplication1.Models; 9 | 10 | #nullable disable 11 | 12 | namespace WebApplication1.Migrations 13 | { 14 | [DbContext(typeof(Context))] 15 | [Migration("20240409180102_db")] 16 | partial class db 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("Microsoft.AspNetCore.Identity.IdentityRole", b => 29 | { 30 | b.Property("Id") 31 | .HasColumnType("nvarchar(450)"); 32 | 33 | b.Property("ConcurrencyStamp") 34 | .IsConcurrencyToken() 35 | .HasColumnType("nvarchar(max)"); 36 | 37 | b.Property("Name") 38 | .HasMaxLength(256) 39 | .HasColumnType("nvarchar(256)"); 40 | 41 | b.Property("NormalizedName") 42 | .HasMaxLength(256) 43 | .HasColumnType("nvarchar(256)"); 44 | 45 | b.HasKey("Id"); 46 | 47 | b.HasIndex("NormalizedName") 48 | .IsUnique() 49 | .HasDatabaseName("RoleNameIndex") 50 | .HasFilter("[NormalizedName] IS NOT NULL"); 51 | 52 | b.ToTable("AspNetRoles", (string)null); 53 | }); 54 | 55 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 56 | { 57 | b.Property("Id") 58 | .ValueGeneratedOnAdd() 59 | .HasColumnType("int"); 60 | 61 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 62 | 63 | b.Property("ClaimType") 64 | .HasColumnType("nvarchar(max)"); 65 | 66 | b.Property("ClaimValue") 67 | .HasColumnType("nvarchar(max)"); 68 | 69 | b.Property("RoleId") 70 | .IsRequired() 71 | .HasColumnType("nvarchar(450)"); 72 | 73 | b.HasKey("Id"); 74 | 75 | b.HasIndex("RoleId"); 76 | 77 | b.ToTable("AspNetRoleClaims", (string)null); 78 | }); 79 | 80 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 81 | { 82 | b.Property("Id") 83 | .ValueGeneratedOnAdd() 84 | .HasColumnType("int"); 85 | 86 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 87 | 88 | b.Property("ClaimType") 89 | .HasColumnType("nvarchar(max)"); 90 | 91 | b.Property("ClaimValue") 92 | .HasColumnType("nvarchar(max)"); 93 | 94 | b.Property("UserId") 95 | .IsRequired() 96 | .HasColumnType("nvarchar(450)"); 97 | 98 | b.HasKey("Id"); 99 | 100 | b.HasIndex("UserId"); 101 | 102 | b.ToTable("AspNetUserClaims", (string)null); 103 | }); 104 | 105 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 106 | { 107 | b.Property("LoginProvider") 108 | .HasColumnType("nvarchar(450)"); 109 | 110 | b.Property("ProviderKey") 111 | .HasColumnType("nvarchar(450)"); 112 | 113 | b.Property("ProviderDisplayName") 114 | .HasColumnType("nvarchar(max)"); 115 | 116 | b.Property("UserId") 117 | .IsRequired() 118 | .HasColumnType("nvarchar(450)"); 119 | 120 | b.HasKey("LoginProvider", "ProviderKey"); 121 | 122 | b.HasIndex("UserId"); 123 | 124 | b.ToTable("AspNetUserLogins", (string)null); 125 | }); 126 | 127 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 128 | { 129 | b.Property("UserId") 130 | .HasColumnType("nvarchar(450)"); 131 | 132 | b.Property("RoleId") 133 | .HasColumnType("nvarchar(450)"); 134 | 135 | b.HasKey("UserId", "RoleId"); 136 | 137 | b.HasIndex("RoleId"); 138 | 139 | b.ToTable("AspNetUserRoles", (string)null); 140 | }); 141 | 142 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 143 | { 144 | b.Property("UserId") 145 | .HasColumnType("nvarchar(450)"); 146 | 147 | b.Property("LoginProvider") 148 | .HasColumnType("nvarchar(450)"); 149 | 150 | b.Property("Name") 151 | .HasColumnType("nvarchar(450)"); 152 | 153 | b.Property("Value") 154 | .HasColumnType("nvarchar(max)"); 155 | 156 | b.HasKey("UserId", "LoginProvider", "Name"); 157 | 158 | b.ToTable("AspNetUserTokens", (string)null); 159 | }); 160 | 161 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 162 | { 163 | b.Property("Id") 164 | .HasColumnType("nvarchar(450)"); 165 | 166 | b.Property("AccessFailedCount") 167 | .HasColumnType("int"); 168 | 169 | b.Property("ConcurrencyStamp") 170 | .IsConcurrencyToken() 171 | .HasColumnType("nvarchar(max)"); 172 | 173 | b.Property("Email") 174 | .HasMaxLength(256) 175 | .HasColumnType("nvarchar(256)"); 176 | 177 | b.Property("EmailConfirmed") 178 | .HasColumnType("bit"); 179 | 180 | b.Property("LockoutEnabled") 181 | .HasColumnType("bit"); 182 | 183 | b.Property("LockoutEnd") 184 | .HasColumnType("datetimeoffset"); 185 | 186 | b.Property("NormalizedEmail") 187 | .HasMaxLength(256) 188 | .HasColumnType("nvarchar(256)"); 189 | 190 | b.Property("NormalizedUserName") 191 | .HasMaxLength(256) 192 | .HasColumnType("nvarchar(256)"); 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("WebApplication1.Models.Category", b => 227 | { 228 | b.Property("Id") 229 | .ValueGeneratedOnAdd() 230 | .HasColumnType("int"); 231 | 232 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 233 | 234 | b.Property("Name") 235 | .IsRequired() 236 | .HasColumnType("nvarchar(max)"); 237 | 238 | b.HasKey("Id"); 239 | 240 | b.ToTable("categories"); 241 | }); 242 | 243 | modelBuilder.Entity("WebApplication1.Models.Product", b => 244 | { 245 | b.Property("Id") 246 | .ValueGeneratedOnAdd() 247 | .HasColumnType("int"); 248 | 249 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 250 | 251 | b.Property("Category_Id") 252 | .HasColumnType("int"); 253 | 254 | b.Property("Description") 255 | .IsRequired() 256 | .HasColumnType("nvarchar(max)"); 257 | 258 | b.Property("Name") 259 | .IsRequired() 260 | .HasColumnType("nvarchar(max)"); 261 | 262 | b.Property("Price") 263 | .HasColumnType("int"); 264 | 265 | b.HasKey("Id"); 266 | 267 | b.HasIndex("Category_Id"); 268 | 269 | b.ToTable("products"); 270 | 271 | b.HasData( 272 | new 273 | { 274 | Id = 1, 275 | Description = "Description1", 276 | Name = "Product1", 277 | Price = 10 278 | }, 279 | new 280 | { 281 | Id = 2, 282 | Description = "Description2", 283 | Name = "Product2", 284 | Price = 20 285 | }); 286 | }); 287 | 288 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 289 | { 290 | b.Property("Id") 291 | .ValueGeneratedOnAdd() 292 | .HasColumnType("int"); 293 | 294 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 295 | 296 | b.Property("Address") 297 | .IsRequired() 298 | .HasColumnType("nvarchar(max)"); 299 | 300 | b.Property("City") 301 | .IsRequired() 302 | .HasColumnType("nvarchar(max)"); 303 | 304 | b.Property("Country") 305 | .IsRequired() 306 | .HasColumnType("nvarchar(max)"); 307 | 308 | b.Property("Customer_Id") 309 | .IsRequired() 310 | .HasColumnType("nvarchar(450)"); 311 | 312 | b.Property("Date") 313 | .HasColumnType("datetime2"); 314 | 315 | b.Property("IsDeleted") 316 | .HasColumnType("bit"); 317 | 318 | b.Property("State") 319 | .IsRequired() 320 | .HasColumnType("nvarchar(max)"); 321 | 322 | b.Property("Zip_Code") 323 | .IsRequired() 324 | .HasColumnType("nvarchar(max)"); 325 | 326 | b.HasKey("Id"); 327 | 328 | b.HasIndex("Customer_Id"); 329 | 330 | b.ToTable("shipments"); 331 | }); 332 | 333 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 334 | { 335 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 336 | .WithMany() 337 | .HasForeignKey("RoleId") 338 | .OnDelete(DeleteBehavior.Cascade) 339 | .IsRequired(); 340 | }); 341 | 342 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 343 | { 344 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 345 | .WithMany() 346 | .HasForeignKey("UserId") 347 | .OnDelete(DeleteBehavior.Cascade) 348 | .IsRequired(); 349 | }); 350 | 351 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 352 | { 353 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 354 | .WithMany() 355 | .HasForeignKey("UserId") 356 | .OnDelete(DeleteBehavior.Cascade) 357 | .IsRequired(); 358 | }); 359 | 360 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 361 | { 362 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 363 | .WithMany() 364 | .HasForeignKey("RoleId") 365 | .OnDelete(DeleteBehavior.Cascade) 366 | .IsRequired(); 367 | 368 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 369 | .WithMany() 370 | .HasForeignKey("UserId") 371 | .OnDelete(DeleteBehavior.Cascade) 372 | .IsRequired(); 373 | }); 374 | 375 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 376 | { 377 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 378 | .WithMany() 379 | .HasForeignKey("UserId") 380 | .OnDelete(DeleteBehavior.Cascade) 381 | .IsRequired(); 382 | }); 383 | 384 | modelBuilder.Entity("WebApplication1.Models.Product", b => 385 | { 386 | b.HasOne("WebApplication1.Models.Category", "category") 387 | .WithMany("products") 388 | .HasForeignKey("Category_Id"); 389 | 390 | b.Navigation("category"); 391 | }); 392 | 393 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 394 | { 395 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 396 | .WithMany("shipments") 397 | .HasForeignKey("Customer_Id") 398 | .OnDelete(DeleteBehavior.Cascade) 399 | .IsRequired(); 400 | 401 | b.Navigation("customer"); 402 | }); 403 | 404 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 405 | { 406 | b.Navigation("shipments"); 407 | }); 408 | 409 | modelBuilder.Entity("WebApplication1.Models.Category", b => 410 | { 411 | b.Navigation("products"); 412 | }); 413 | #pragma warning restore 612, 618 414 | } 415 | } 416 | } 417 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/20240409180102_db.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional 7 | 8 | namespace WebApplication1.Migrations 9 | { 10 | /// 11 | public partial class db : Migration 12 | { 13 | /// 14 | protected override void Up(MigrationBuilder migrationBuilder) 15 | { 16 | migrationBuilder.CreateTable( 17 | name: "AspNetRoles", 18 | columns: table => new 19 | { 20 | Id = table.Column(type: "nvarchar(450)", nullable: false), 21 | Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 22 | NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 23 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) 24 | }, 25 | constraints: table => 26 | { 27 | table.PrimaryKey("PK_AspNetRoles", x => x.Id); 28 | }); 29 | 30 | migrationBuilder.CreateTable( 31 | name: "AspNetUsers", 32 | columns: table => new 33 | { 34 | Id = table.Column(type: "nvarchar(450)", nullable: false), 35 | UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 36 | NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 37 | Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 38 | NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 39 | EmailConfirmed = table.Column(type: "bit", nullable: false), 40 | PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), 41 | SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), 42 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), 43 | PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), 44 | PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), 45 | TwoFactorEnabled = table.Column(type: "bit", nullable: false), 46 | LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), 47 | LockoutEnabled = table.Column(type: "bit", nullable: false), 48 | AccessFailedCount = table.Column(type: "int", nullable: false) 49 | }, 50 | constraints: table => 51 | { 52 | table.PrimaryKey("PK_AspNetUsers", x => x.Id); 53 | }); 54 | 55 | migrationBuilder.CreateTable( 56 | name: "categories", 57 | columns: table => new 58 | { 59 | Id = table.Column(type: "int", nullable: false) 60 | .Annotation("SqlServer:Identity", "1, 1"), 61 | Name = table.Column(type: "nvarchar(max)", nullable: false) 62 | }, 63 | constraints: table => 64 | { 65 | table.PrimaryKey("PK_categories", x => x.Id); 66 | }); 67 | 68 | migrationBuilder.CreateTable( 69 | name: "AspNetRoleClaims", 70 | columns: table => new 71 | { 72 | Id = table.Column(type: "int", nullable: false) 73 | .Annotation("SqlServer:Identity", "1, 1"), 74 | RoleId = table.Column(type: "nvarchar(450)", nullable: false), 75 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 76 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 77 | }, 78 | constraints: table => 79 | { 80 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); 81 | table.ForeignKey( 82 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", 83 | column: x => x.RoleId, 84 | principalTable: "AspNetRoles", 85 | principalColumn: "Id", 86 | onDelete: ReferentialAction.Cascade); 87 | }); 88 | 89 | migrationBuilder.CreateTable( 90 | name: "AspNetUserClaims", 91 | columns: table => new 92 | { 93 | Id = table.Column(type: "int", nullable: false) 94 | .Annotation("SqlServer:Identity", "1, 1"), 95 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 96 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 97 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 98 | }, 99 | constraints: table => 100 | { 101 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); 102 | table.ForeignKey( 103 | name: "FK_AspNetUserClaims_AspNetUsers_UserId", 104 | column: x => x.UserId, 105 | principalTable: "AspNetUsers", 106 | principalColumn: "Id", 107 | onDelete: ReferentialAction.Cascade); 108 | }); 109 | 110 | migrationBuilder.CreateTable( 111 | name: "AspNetUserLogins", 112 | columns: table => new 113 | { 114 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 115 | ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), 116 | ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), 117 | UserId = table.Column(type: "nvarchar(450)", nullable: false) 118 | }, 119 | constraints: table => 120 | { 121 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); 122 | table.ForeignKey( 123 | name: "FK_AspNetUserLogins_AspNetUsers_UserId", 124 | column: x => x.UserId, 125 | principalTable: "AspNetUsers", 126 | principalColumn: "Id", 127 | onDelete: ReferentialAction.Cascade); 128 | }); 129 | 130 | migrationBuilder.CreateTable( 131 | name: "AspNetUserRoles", 132 | columns: table => new 133 | { 134 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 135 | RoleId = table.Column(type: "nvarchar(450)", nullable: false) 136 | }, 137 | constraints: table => 138 | { 139 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); 140 | table.ForeignKey( 141 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId", 142 | column: x => x.RoleId, 143 | principalTable: "AspNetRoles", 144 | principalColumn: "Id", 145 | onDelete: ReferentialAction.Cascade); 146 | table.ForeignKey( 147 | name: "FK_AspNetUserRoles_AspNetUsers_UserId", 148 | column: x => x.UserId, 149 | principalTable: "AspNetUsers", 150 | principalColumn: "Id", 151 | onDelete: ReferentialAction.Cascade); 152 | }); 153 | 154 | migrationBuilder.CreateTable( 155 | name: "AspNetUserTokens", 156 | columns: table => new 157 | { 158 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 159 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 160 | Name = table.Column(type: "nvarchar(450)", nullable: false), 161 | Value = table.Column(type: "nvarchar(max)", nullable: true) 162 | }, 163 | constraints: table => 164 | { 165 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); 166 | table.ForeignKey( 167 | name: "FK_AspNetUserTokens_AspNetUsers_UserId", 168 | column: x => x.UserId, 169 | principalTable: "AspNetUsers", 170 | principalColumn: "Id", 171 | onDelete: ReferentialAction.Cascade); 172 | }); 173 | 174 | migrationBuilder.CreateTable( 175 | name: "shipments", 176 | columns: table => new 177 | { 178 | Id = table.Column(type: "int", nullable: false) 179 | .Annotation("SqlServer:Identity", "1, 1"), 180 | Date = table.Column(type: "datetime2", nullable: false), 181 | Address = table.Column(type: "nvarchar(max)", nullable: false), 182 | City = table.Column(type: "nvarchar(max)", nullable: false), 183 | State = table.Column(type: "nvarchar(max)", nullable: false), 184 | Country = table.Column(type: "nvarchar(max)", nullable: false), 185 | Zip_Code = table.Column(type: "nvarchar(max)", nullable: false), 186 | IsDeleted = table.Column(type: "bit", nullable: false), 187 | Customer_Id = table.Column(type: "nvarchar(450)", nullable: false) 188 | }, 189 | constraints: table => 190 | { 191 | table.PrimaryKey("PK_shipments", x => x.Id); 192 | table.ForeignKey( 193 | name: "FK_shipments_AspNetUsers_Customer_Id", 194 | column: x => x.Customer_Id, 195 | principalTable: "AspNetUsers", 196 | principalColumn: "Id", 197 | onDelete: ReferentialAction.Cascade); 198 | }); 199 | 200 | migrationBuilder.CreateTable( 201 | name: "products", 202 | columns: table => new 203 | { 204 | Id = table.Column(type: "int", nullable: false) 205 | .Annotation("SqlServer:Identity", "1, 1"), 206 | Name = table.Column(type: "nvarchar(max)", nullable: false), 207 | Price = table.Column(type: "int", nullable: false), 208 | Description = table.Column(type: "nvarchar(max)", nullable: false), 209 | Category_Id = table.Column(type: "int", nullable: true) 210 | }, 211 | constraints: table => 212 | { 213 | table.PrimaryKey("PK_products", x => x.Id); 214 | table.ForeignKey( 215 | name: "FK_products_categories_Category_Id", 216 | column: x => x.Category_Id, 217 | principalTable: "categories", 218 | principalColumn: "Id"); 219 | }); 220 | 221 | migrationBuilder.InsertData( 222 | table: "products", 223 | columns: new[] { "Id", "Category_Id", "Description", "Name", "Price" }, 224 | values: new object[,] 225 | { 226 | { 1, null, "Description1", "Product1", 10 }, 227 | { 2, null, "Description2", "Product2", 20 } 228 | }); 229 | 230 | migrationBuilder.CreateIndex( 231 | name: "IX_AspNetRoleClaims_RoleId", 232 | table: "AspNetRoleClaims", 233 | column: "RoleId"); 234 | 235 | migrationBuilder.CreateIndex( 236 | name: "RoleNameIndex", 237 | table: "AspNetRoles", 238 | column: "NormalizedName", 239 | unique: true, 240 | filter: "[NormalizedName] IS NOT NULL"); 241 | 242 | migrationBuilder.CreateIndex( 243 | name: "IX_AspNetUserClaims_UserId", 244 | table: "AspNetUserClaims", 245 | column: "UserId"); 246 | 247 | migrationBuilder.CreateIndex( 248 | name: "IX_AspNetUserLogins_UserId", 249 | table: "AspNetUserLogins", 250 | column: "UserId"); 251 | 252 | migrationBuilder.CreateIndex( 253 | name: "IX_AspNetUserRoles_RoleId", 254 | table: "AspNetUserRoles", 255 | column: "RoleId"); 256 | 257 | migrationBuilder.CreateIndex( 258 | name: "EmailIndex", 259 | table: "AspNetUsers", 260 | column: "NormalizedEmail"); 261 | 262 | migrationBuilder.CreateIndex( 263 | name: "UserNameIndex", 264 | table: "AspNetUsers", 265 | column: "NormalizedUserName", 266 | unique: true, 267 | filter: "[NormalizedUserName] IS NOT NULL"); 268 | 269 | migrationBuilder.CreateIndex( 270 | name: "IX_products_Category_Id", 271 | table: "products", 272 | column: "Category_Id"); 273 | 274 | migrationBuilder.CreateIndex( 275 | name: "IX_shipments_Customer_Id", 276 | table: "shipments", 277 | column: "Customer_Id"); 278 | } 279 | 280 | /// 281 | protected override void Down(MigrationBuilder migrationBuilder) 282 | { 283 | migrationBuilder.DropTable( 284 | name: "AspNetRoleClaims"); 285 | 286 | migrationBuilder.DropTable( 287 | name: "AspNetUserClaims"); 288 | 289 | migrationBuilder.DropTable( 290 | name: "AspNetUserLogins"); 291 | 292 | migrationBuilder.DropTable( 293 | name: "AspNetUserRoles"); 294 | 295 | migrationBuilder.DropTable( 296 | name: "AspNetUserTokens"); 297 | 298 | migrationBuilder.DropTable( 299 | name: "products"); 300 | 301 | migrationBuilder.DropTable( 302 | name: "shipments"); 303 | 304 | migrationBuilder.DropTable( 305 | name: "AspNetRoles"); 306 | 307 | migrationBuilder.DropTable( 308 | name: "categories"); 309 | 310 | migrationBuilder.DropTable( 311 | name: "AspNetUsers"); 312 | } 313 | } 314 | } 315 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/20240409200736_PaymentClass.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 WebApplication1.Models; 9 | 10 | #nullable disable 11 | 12 | namespace WebApplication1.Migrations 13 | { 14 | [DbContext(typeof(Context))] 15 | [Migration("20240409200736_PaymentClass")] 16 | partial class PaymentClass 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("Microsoft.AspNetCore.Identity.IdentityRole", b => 29 | { 30 | b.Property("Id") 31 | .HasColumnType("nvarchar(450)"); 32 | 33 | b.Property("ConcurrencyStamp") 34 | .IsConcurrencyToken() 35 | .HasColumnType("nvarchar(max)"); 36 | 37 | b.Property("Name") 38 | .HasMaxLength(256) 39 | .HasColumnType("nvarchar(256)"); 40 | 41 | b.Property("NormalizedName") 42 | .HasMaxLength(256) 43 | .HasColumnType("nvarchar(256)"); 44 | 45 | b.HasKey("Id"); 46 | 47 | b.HasIndex("NormalizedName") 48 | .IsUnique() 49 | .HasDatabaseName("RoleNameIndex") 50 | .HasFilter("[NormalizedName] IS NOT NULL"); 51 | 52 | b.ToTable("AspNetRoles", (string)null); 53 | }); 54 | 55 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 56 | { 57 | b.Property("Id") 58 | .ValueGeneratedOnAdd() 59 | .HasColumnType("int"); 60 | 61 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 62 | 63 | b.Property("ClaimType") 64 | .HasColumnType("nvarchar(max)"); 65 | 66 | b.Property("ClaimValue") 67 | .HasColumnType("nvarchar(max)"); 68 | 69 | b.Property("RoleId") 70 | .IsRequired() 71 | .HasColumnType("nvarchar(450)"); 72 | 73 | b.HasKey("Id"); 74 | 75 | b.HasIndex("RoleId"); 76 | 77 | b.ToTable("AspNetRoleClaims", (string)null); 78 | }); 79 | 80 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 81 | { 82 | b.Property("Id") 83 | .ValueGeneratedOnAdd() 84 | .HasColumnType("int"); 85 | 86 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 87 | 88 | b.Property("ClaimType") 89 | .HasColumnType("nvarchar(max)"); 90 | 91 | b.Property("ClaimValue") 92 | .HasColumnType("nvarchar(max)"); 93 | 94 | b.Property("UserId") 95 | .IsRequired() 96 | .HasColumnType("nvarchar(450)"); 97 | 98 | b.HasKey("Id"); 99 | 100 | b.HasIndex("UserId"); 101 | 102 | b.ToTable("AspNetUserClaims", (string)null); 103 | }); 104 | 105 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 106 | { 107 | b.Property("LoginProvider") 108 | .HasColumnType("nvarchar(450)"); 109 | 110 | b.Property("ProviderKey") 111 | .HasColumnType("nvarchar(450)"); 112 | 113 | b.Property("ProviderDisplayName") 114 | .HasColumnType("nvarchar(max)"); 115 | 116 | b.Property("UserId") 117 | .IsRequired() 118 | .HasColumnType("nvarchar(450)"); 119 | 120 | b.HasKey("LoginProvider", "ProviderKey"); 121 | 122 | b.HasIndex("UserId"); 123 | 124 | b.ToTable("AspNetUserLogins", (string)null); 125 | }); 126 | 127 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 128 | { 129 | b.Property("UserId") 130 | .HasColumnType("nvarchar(450)"); 131 | 132 | b.Property("RoleId") 133 | .HasColumnType("nvarchar(450)"); 134 | 135 | b.HasKey("UserId", "RoleId"); 136 | 137 | b.HasIndex("RoleId"); 138 | 139 | b.ToTable("AspNetUserRoles", (string)null); 140 | }); 141 | 142 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 143 | { 144 | b.Property("UserId") 145 | .HasColumnType("nvarchar(450)"); 146 | 147 | b.Property("LoginProvider") 148 | .HasColumnType("nvarchar(450)"); 149 | 150 | b.Property("Name") 151 | .HasColumnType("nvarchar(450)"); 152 | 153 | b.Property("Value") 154 | .HasColumnType("nvarchar(max)"); 155 | 156 | b.HasKey("UserId", "LoginProvider", "Name"); 157 | 158 | b.ToTable("AspNetUserTokens", (string)null); 159 | }); 160 | 161 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 162 | { 163 | b.Property("Id") 164 | .HasColumnType("nvarchar(450)"); 165 | 166 | b.Property("AccessFailedCount") 167 | .HasColumnType("int"); 168 | 169 | b.Property("ConcurrencyStamp") 170 | .IsConcurrencyToken() 171 | .HasColumnType("nvarchar(max)"); 172 | 173 | b.Property("Email") 174 | .HasMaxLength(256) 175 | .HasColumnType("nvarchar(256)"); 176 | 177 | b.Property("EmailConfirmed") 178 | .HasColumnType("bit"); 179 | 180 | b.Property("LockoutEnabled") 181 | .HasColumnType("bit"); 182 | 183 | b.Property("LockoutEnd") 184 | .HasColumnType("datetimeoffset"); 185 | 186 | b.Property("NormalizedEmail") 187 | .HasMaxLength(256) 188 | .HasColumnType("nvarchar(256)"); 189 | 190 | b.Property("NormalizedUserName") 191 | .HasMaxLength(256) 192 | .HasColumnType("nvarchar(256)"); 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("WebApplication1.Models.Category", b => 227 | { 228 | b.Property("Id") 229 | .ValueGeneratedOnAdd() 230 | .HasColumnType("int"); 231 | 232 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 233 | 234 | b.Property("Name") 235 | .IsRequired() 236 | .HasColumnType("nvarchar(max)"); 237 | 238 | b.HasKey("Id"); 239 | 240 | b.ToTable("categories"); 241 | }); 242 | 243 | modelBuilder.Entity("WebApplication1.Models.Payment", b => 244 | { 245 | b.Property("Id") 246 | .ValueGeneratedOnAdd() 247 | .HasColumnType("int"); 248 | 249 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 250 | 251 | b.Property("Amount") 252 | .HasColumnType("float"); 253 | 254 | b.Property("Customer_Id") 255 | .IsRequired() 256 | .HasColumnType("nvarchar(450)"); 257 | 258 | b.Property("Date") 259 | .HasColumnType("datetime2"); 260 | 261 | b.Property("IsDeleted") 262 | .HasColumnType("bit"); 263 | 264 | b.Property("Method") 265 | .IsRequired() 266 | .HasColumnType("nvarchar(max)"); 267 | 268 | b.HasKey("Id"); 269 | 270 | b.HasIndex("Customer_Id"); 271 | 272 | b.ToTable("payments"); 273 | }); 274 | 275 | modelBuilder.Entity("WebApplication1.Models.Product", b => 276 | { 277 | b.Property("Id") 278 | .ValueGeneratedOnAdd() 279 | .HasColumnType("int"); 280 | 281 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 282 | 283 | b.Property("Category_Id") 284 | .HasColumnType("int"); 285 | 286 | b.Property("Description") 287 | .IsRequired() 288 | .HasColumnType("nvarchar(max)"); 289 | 290 | b.Property("Name") 291 | .IsRequired() 292 | .HasColumnType("nvarchar(max)"); 293 | 294 | b.Property("Price") 295 | .HasColumnType("int"); 296 | 297 | b.HasKey("Id"); 298 | 299 | b.HasIndex("Category_Id"); 300 | 301 | b.ToTable("products"); 302 | 303 | b.HasData( 304 | new 305 | { 306 | Id = 1, 307 | Description = "Description1", 308 | Name = "Product1", 309 | Price = 10 310 | }, 311 | new 312 | { 313 | Id = 2, 314 | Description = "Description2", 315 | Name = "Product2", 316 | Price = 20 317 | }); 318 | }); 319 | 320 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 321 | { 322 | b.Property("Id") 323 | .ValueGeneratedOnAdd() 324 | .HasColumnType("int"); 325 | 326 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 327 | 328 | b.Property("Address") 329 | .IsRequired() 330 | .HasColumnType("nvarchar(max)"); 331 | 332 | b.Property("City") 333 | .IsRequired() 334 | .HasColumnType("nvarchar(max)"); 335 | 336 | b.Property("Country") 337 | .IsRequired() 338 | .HasColumnType("nvarchar(max)"); 339 | 340 | b.Property("Customer_Id") 341 | .IsRequired() 342 | .HasColumnType("nvarchar(450)"); 343 | 344 | b.Property("Date") 345 | .HasColumnType("datetime2"); 346 | 347 | b.Property("IsDeleted") 348 | .HasColumnType("bit"); 349 | 350 | b.Property("State") 351 | .IsRequired() 352 | .HasColumnType("nvarchar(max)"); 353 | 354 | b.Property("Zip_Code") 355 | .IsRequired() 356 | .HasColumnType("nvarchar(max)"); 357 | 358 | b.HasKey("Id"); 359 | 360 | b.HasIndex("Customer_Id"); 361 | 362 | b.ToTable("shipments"); 363 | }); 364 | 365 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 366 | { 367 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 368 | .WithMany() 369 | .HasForeignKey("RoleId") 370 | .OnDelete(DeleteBehavior.Cascade) 371 | .IsRequired(); 372 | }); 373 | 374 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 375 | { 376 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 377 | .WithMany() 378 | .HasForeignKey("UserId") 379 | .OnDelete(DeleteBehavior.Cascade) 380 | .IsRequired(); 381 | }); 382 | 383 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 384 | { 385 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 386 | .WithMany() 387 | .HasForeignKey("UserId") 388 | .OnDelete(DeleteBehavior.Cascade) 389 | .IsRequired(); 390 | }); 391 | 392 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 393 | { 394 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 395 | .WithMany() 396 | .HasForeignKey("RoleId") 397 | .OnDelete(DeleteBehavior.Cascade) 398 | .IsRequired(); 399 | 400 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 401 | .WithMany() 402 | .HasForeignKey("UserId") 403 | .OnDelete(DeleteBehavior.Cascade) 404 | .IsRequired(); 405 | }); 406 | 407 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 408 | { 409 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 410 | .WithMany() 411 | .HasForeignKey("UserId") 412 | .OnDelete(DeleteBehavior.Cascade) 413 | .IsRequired(); 414 | }); 415 | 416 | modelBuilder.Entity("WebApplication1.Models.Payment", b => 417 | { 418 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 419 | .WithMany("payments") 420 | .HasForeignKey("Customer_Id") 421 | .OnDelete(DeleteBehavior.Cascade) 422 | .IsRequired(); 423 | 424 | b.Navigation("customer"); 425 | }); 426 | 427 | modelBuilder.Entity("WebApplication1.Models.Product", b => 428 | { 429 | b.HasOne("WebApplication1.Models.Category", "category") 430 | .WithMany("products") 431 | .HasForeignKey("Category_Id"); 432 | 433 | b.Navigation("category"); 434 | }); 435 | 436 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 437 | { 438 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 439 | .WithMany("shipments") 440 | .HasForeignKey("Customer_Id") 441 | .OnDelete(DeleteBehavior.Cascade) 442 | .IsRequired(); 443 | 444 | b.Navigation("customer"); 445 | }); 446 | 447 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 448 | { 449 | b.Navigation("payments"); 450 | 451 | b.Navigation("shipments"); 452 | }); 453 | 454 | modelBuilder.Entity("WebApplication1.Models.Category", b => 455 | { 456 | b.Navigation("products"); 457 | }); 458 | #pragma warning restore 612, 618 459 | } 460 | } 461 | } 462 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/20240409200736_PaymentClass.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace WebApplication1.Migrations 7 | { 8 | /// 9 | public partial class PaymentClass : Migration 10 | { 11 | /// 12 | protected override void Up(MigrationBuilder migrationBuilder) 13 | { 14 | migrationBuilder.CreateTable( 15 | name: "payments", 16 | columns: table => new 17 | { 18 | Id = table.Column(type: "int", nullable: false) 19 | .Annotation("SqlServer:Identity", "1, 1"), 20 | Date = table.Column(type: "datetime2", nullable: false), 21 | Method = table.Column(type: "nvarchar(max)", nullable: false), 22 | Amount = table.Column(type: "float", nullable: false), 23 | IsDeleted = table.Column(type: "bit", nullable: false), 24 | Customer_Id = table.Column(type: "nvarchar(450)", nullable: false) 25 | }, 26 | constraints: table => 27 | { 28 | table.PrimaryKey("PK_payments", x => x.Id); 29 | table.ForeignKey( 30 | name: "FK_payments_AspNetUsers_Customer_Id", 31 | column: x => x.Customer_Id, 32 | principalTable: "AspNetUsers", 33 | principalColumn: "Id", 34 | onDelete: ReferentialAction.Cascade); 35 | }); 36 | 37 | migrationBuilder.CreateIndex( 38 | name: "IX_payments_Customer_Id", 39 | table: "payments", 40 | column: "Customer_Id"); 41 | } 42 | 43 | /// 44 | protected override void Down(MigrationBuilder migrationBuilder) 45 | { 46 | migrationBuilder.DropTable( 47 | name: "payments"); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/20240410101856_CartClass.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 WebApplication1.Models; 9 | 10 | #nullable disable 11 | 12 | namespace WebApplication1.Migrations 13 | { 14 | [DbContext(typeof(Context))] 15 | [Migration("20240410101856_CartClass")] 16 | partial class CartClass 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("Microsoft.AspNetCore.Identity.IdentityRole", b => 29 | { 30 | b.Property("Id") 31 | .HasColumnType("nvarchar(450)"); 32 | 33 | b.Property("ConcurrencyStamp") 34 | .IsConcurrencyToken() 35 | .HasColumnType("nvarchar(max)"); 36 | 37 | b.Property("Name") 38 | .HasMaxLength(256) 39 | .HasColumnType("nvarchar(256)"); 40 | 41 | b.Property("NormalizedName") 42 | .HasMaxLength(256) 43 | .HasColumnType("nvarchar(256)"); 44 | 45 | b.HasKey("Id"); 46 | 47 | b.HasIndex("NormalizedName") 48 | .IsUnique() 49 | .HasDatabaseName("RoleNameIndex") 50 | .HasFilter("[NormalizedName] IS NOT NULL"); 51 | 52 | b.ToTable("AspNetRoles", (string)null); 53 | }); 54 | 55 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 56 | { 57 | b.Property("Id") 58 | .ValueGeneratedOnAdd() 59 | .HasColumnType("int"); 60 | 61 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 62 | 63 | b.Property("ClaimType") 64 | .HasColumnType("nvarchar(max)"); 65 | 66 | b.Property("ClaimValue") 67 | .HasColumnType("nvarchar(max)"); 68 | 69 | b.Property("RoleId") 70 | .IsRequired() 71 | .HasColumnType("nvarchar(450)"); 72 | 73 | b.HasKey("Id"); 74 | 75 | b.HasIndex("RoleId"); 76 | 77 | b.ToTable("AspNetRoleClaims", (string)null); 78 | }); 79 | 80 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 81 | { 82 | b.Property("Id") 83 | .ValueGeneratedOnAdd() 84 | .HasColumnType("int"); 85 | 86 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 87 | 88 | b.Property("ClaimType") 89 | .HasColumnType("nvarchar(max)"); 90 | 91 | b.Property("ClaimValue") 92 | .HasColumnType("nvarchar(max)"); 93 | 94 | b.Property("UserId") 95 | .IsRequired() 96 | .HasColumnType("nvarchar(450)"); 97 | 98 | b.HasKey("Id"); 99 | 100 | b.HasIndex("UserId"); 101 | 102 | b.ToTable("AspNetUserClaims", (string)null); 103 | }); 104 | 105 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 106 | { 107 | b.Property("LoginProvider") 108 | .HasColumnType("nvarchar(450)"); 109 | 110 | b.Property("ProviderKey") 111 | .HasColumnType("nvarchar(450)"); 112 | 113 | b.Property("ProviderDisplayName") 114 | .HasColumnType("nvarchar(max)"); 115 | 116 | b.Property("UserId") 117 | .IsRequired() 118 | .HasColumnType("nvarchar(450)"); 119 | 120 | b.HasKey("LoginProvider", "ProviderKey"); 121 | 122 | b.HasIndex("UserId"); 123 | 124 | b.ToTable("AspNetUserLogins", (string)null); 125 | }); 126 | 127 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 128 | { 129 | b.Property("UserId") 130 | .HasColumnType("nvarchar(450)"); 131 | 132 | b.Property("RoleId") 133 | .HasColumnType("nvarchar(450)"); 134 | 135 | b.HasKey("UserId", "RoleId"); 136 | 137 | b.HasIndex("RoleId"); 138 | 139 | b.ToTable("AspNetUserRoles", (string)null); 140 | }); 141 | 142 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 143 | { 144 | b.Property("UserId") 145 | .HasColumnType("nvarchar(450)"); 146 | 147 | b.Property("LoginProvider") 148 | .HasColumnType("nvarchar(450)"); 149 | 150 | b.Property("Name") 151 | .HasColumnType("nvarchar(450)"); 152 | 153 | b.Property("Value") 154 | .HasColumnType("nvarchar(max)"); 155 | 156 | b.HasKey("UserId", "LoginProvider", "Name"); 157 | 158 | b.ToTable("AspNetUserTokens", (string)null); 159 | }); 160 | 161 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 162 | { 163 | b.Property("Id") 164 | .HasColumnType("nvarchar(450)"); 165 | 166 | b.Property("AccessFailedCount") 167 | .HasColumnType("int"); 168 | 169 | b.Property("ConcurrencyStamp") 170 | .IsConcurrencyToken() 171 | .HasColumnType("nvarchar(max)"); 172 | 173 | b.Property("Email") 174 | .HasMaxLength(256) 175 | .HasColumnType("nvarchar(256)"); 176 | 177 | b.Property("EmailConfirmed") 178 | .HasColumnType("bit"); 179 | 180 | b.Property("LockoutEnabled") 181 | .HasColumnType("bit"); 182 | 183 | b.Property("LockoutEnd") 184 | .HasColumnType("datetimeoffset"); 185 | 186 | b.Property("NormalizedEmail") 187 | .HasMaxLength(256) 188 | .HasColumnType("nvarchar(256)"); 189 | 190 | b.Property("NormalizedUserName") 191 | .HasMaxLength(256) 192 | .HasColumnType("nvarchar(256)"); 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("WebApplication1.Models.Cart", b => 227 | { 228 | b.Property("Id") 229 | .ValueGeneratedOnAdd() 230 | .HasColumnType("int"); 231 | 232 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 233 | 234 | b.Property("Customer_Id") 235 | .IsRequired() 236 | .HasColumnType("nvarchar(450)"); 237 | 238 | b.Property("IsDeleted") 239 | .HasColumnType("bit"); 240 | 241 | b.Property("Product_Id") 242 | .HasColumnType("int"); 243 | 244 | b.Property("Quantity") 245 | .HasColumnType("int"); 246 | 247 | b.HasKey("Id"); 248 | 249 | b.HasIndex("Customer_Id"); 250 | 251 | b.HasIndex("Product_Id"); 252 | 253 | b.ToTable("carts"); 254 | }); 255 | 256 | modelBuilder.Entity("WebApplication1.Models.Category", b => 257 | { 258 | b.Property("Id") 259 | .ValueGeneratedOnAdd() 260 | .HasColumnType("int"); 261 | 262 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 263 | 264 | b.Property("Name") 265 | .IsRequired() 266 | .HasColumnType("nvarchar(max)"); 267 | 268 | b.HasKey("Id"); 269 | 270 | b.ToTable("categories"); 271 | }); 272 | 273 | modelBuilder.Entity("WebApplication1.Models.Payment", b => 274 | { 275 | b.Property("Id") 276 | .ValueGeneratedOnAdd() 277 | .HasColumnType("int"); 278 | 279 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 280 | 281 | b.Property("Amount") 282 | .HasColumnType("float"); 283 | 284 | b.Property("Customer_Id") 285 | .IsRequired() 286 | .HasColumnType("nvarchar(450)"); 287 | 288 | b.Property("Date") 289 | .HasColumnType("datetime2"); 290 | 291 | b.Property("IsDeleted") 292 | .HasColumnType("bit"); 293 | 294 | b.Property("Method") 295 | .IsRequired() 296 | .HasColumnType("nvarchar(max)"); 297 | 298 | b.HasKey("Id"); 299 | 300 | b.HasIndex("Customer_Id"); 301 | 302 | b.ToTable("payments"); 303 | }); 304 | 305 | modelBuilder.Entity("WebApplication1.Models.Product", b => 306 | { 307 | b.Property("Id") 308 | .ValueGeneratedOnAdd() 309 | .HasColumnType("int"); 310 | 311 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 312 | 313 | b.Property("Category_Id") 314 | .HasColumnType("int"); 315 | 316 | b.Property("Description") 317 | .IsRequired() 318 | .HasColumnType("nvarchar(max)"); 319 | 320 | b.Property("Name") 321 | .IsRequired() 322 | .HasColumnType("nvarchar(max)"); 323 | 324 | b.Property("Price") 325 | .HasColumnType("int"); 326 | 327 | b.HasKey("Id"); 328 | 329 | b.HasIndex("Category_Id"); 330 | 331 | b.ToTable("products"); 332 | 333 | b.HasData( 334 | new 335 | { 336 | Id = 1, 337 | Description = "Description1", 338 | Name = "Product1", 339 | Price = 10 340 | }, 341 | new 342 | { 343 | Id = 2, 344 | Description = "Description2", 345 | Name = "Product2", 346 | Price = 20 347 | }); 348 | }); 349 | 350 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 351 | { 352 | b.Property("Id") 353 | .ValueGeneratedOnAdd() 354 | .HasColumnType("int"); 355 | 356 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 357 | 358 | b.Property("Address") 359 | .IsRequired() 360 | .HasColumnType("nvarchar(max)"); 361 | 362 | b.Property("City") 363 | .IsRequired() 364 | .HasColumnType("nvarchar(max)"); 365 | 366 | b.Property("Country") 367 | .IsRequired() 368 | .HasColumnType("nvarchar(max)"); 369 | 370 | b.Property("Customer_Id") 371 | .IsRequired() 372 | .HasColumnType("nvarchar(450)"); 373 | 374 | b.Property("Date") 375 | .HasColumnType("datetime2"); 376 | 377 | b.Property("IsDeleted") 378 | .HasColumnType("bit"); 379 | 380 | b.Property("State") 381 | .IsRequired() 382 | .HasColumnType("nvarchar(max)"); 383 | 384 | b.Property("Zip_Code") 385 | .IsRequired() 386 | .HasColumnType("nvarchar(max)"); 387 | 388 | b.HasKey("Id"); 389 | 390 | b.HasIndex("Customer_Id"); 391 | 392 | b.ToTable("shipments"); 393 | }); 394 | 395 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 396 | { 397 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 398 | .WithMany() 399 | .HasForeignKey("RoleId") 400 | .OnDelete(DeleteBehavior.Cascade) 401 | .IsRequired(); 402 | }); 403 | 404 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 405 | { 406 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 407 | .WithMany() 408 | .HasForeignKey("UserId") 409 | .OnDelete(DeleteBehavior.Cascade) 410 | .IsRequired(); 411 | }); 412 | 413 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 414 | { 415 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 416 | .WithMany() 417 | .HasForeignKey("UserId") 418 | .OnDelete(DeleteBehavior.Cascade) 419 | .IsRequired(); 420 | }); 421 | 422 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 423 | { 424 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 425 | .WithMany() 426 | .HasForeignKey("RoleId") 427 | .OnDelete(DeleteBehavior.Cascade) 428 | .IsRequired(); 429 | 430 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 431 | .WithMany() 432 | .HasForeignKey("UserId") 433 | .OnDelete(DeleteBehavior.Cascade) 434 | .IsRequired(); 435 | }); 436 | 437 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 438 | { 439 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 440 | .WithMany() 441 | .HasForeignKey("UserId") 442 | .OnDelete(DeleteBehavior.Cascade) 443 | .IsRequired(); 444 | }); 445 | 446 | modelBuilder.Entity("WebApplication1.Models.Cart", b => 447 | { 448 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 449 | .WithMany("carts") 450 | .HasForeignKey("Customer_Id") 451 | .OnDelete(DeleteBehavior.Cascade) 452 | .IsRequired(); 453 | 454 | b.HasOne("WebApplication1.Models.Product", "product") 455 | .WithMany("carts") 456 | .HasForeignKey("Product_Id") 457 | .OnDelete(DeleteBehavior.Cascade) 458 | .IsRequired(); 459 | 460 | b.Navigation("customer"); 461 | 462 | b.Navigation("product"); 463 | }); 464 | 465 | modelBuilder.Entity("WebApplication1.Models.Payment", b => 466 | { 467 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 468 | .WithMany("payments") 469 | .HasForeignKey("Customer_Id") 470 | .OnDelete(DeleteBehavior.Cascade) 471 | .IsRequired(); 472 | 473 | b.Navigation("customer"); 474 | }); 475 | 476 | modelBuilder.Entity("WebApplication1.Models.Product", b => 477 | { 478 | b.HasOne("WebApplication1.Models.Category", "category") 479 | .WithMany("products") 480 | .HasForeignKey("Category_Id"); 481 | 482 | b.Navigation("category"); 483 | }); 484 | 485 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 486 | { 487 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 488 | .WithMany("shipments") 489 | .HasForeignKey("Customer_Id") 490 | .OnDelete(DeleteBehavior.Cascade) 491 | .IsRequired(); 492 | 493 | b.Navigation("customer"); 494 | }); 495 | 496 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 497 | { 498 | b.Navigation("carts"); 499 | 500 | b.Navigation("payments"); 501 | 502 | b.Navigation("shipments"); 503 | }); 504 | 505 | modelBuilder.Entity("WebApplication1.Models.Category", b => 506 | { 507 | b.Navigation("products"); 508 | }); 509 | 510 | modelBuilder.Entity("WebApplication1.Models.Product", b => 511 | { 512 | b.Navigation("carts"); 513 | }); 514 | #pragma warning restore 612, 618 515 | } 516 | } 517 | } 518 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/20240410101856_CartClass.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace WebApplication1.Migrations 6 | { 7 | /// 8 | public partial class CartClass : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.CreateTable( 14 | name: "carts", 15 | columns: table => new 16 | { 17 | Id = table.Column(type: "int", nullable: false) 18 | .Annotation("SqlServer:Identity", "1, 1"), 19 | Quantity = table.Column(type: "int", nullable: false), 20 | IsDeleted = table.Column(type: "bit", nullable: false), 21 | Customer_Id = table.Column(type: "nvarchar(450)", nullable: false), 22 | Product_Id = table.Column(type: "int", nullable: false) 23 | }, 24 | constraints: table => 25 | { 26 | table.PrimaryKey("PK_carts", x => x.Id); 27 | table.ForeignKey( 28 | name: "FK_carts_AspNetUsers_Customer_Id", 29 | column: x => x.Customer_Id, 30 | principalTable: "AspNetUsers", 31 | principalColumn: "Id", 32 | onDelete: ReferentialAction.Cascade); 33 | table.ForeignKey( 34 | name: "FK_carts_products_Product_Id", 35 | column: x => x.Product_Id, 36 | principalTable: "products", 37 | principalColumn: "Id", 38 | onDelete: ReferentialAction.Cascade); 39 | }); 40 | 41 | migrationBuilder.CreateIndex( 42 | name: "IX_carts_Customer_Id", 43 | table: "carts", 44 | column: "Customer_Id"); 45 | 46 | migrationBuilder.CreateIndex( 47 | name: "IX_carts_Product_Id", 48 | table: "carts", 49 | column: "Product_Id"); 50 | } 51 | 52 | /// 53 | protected override void Down(MigrationBuilder migrationBuilder) 54 | { 55 | migrationBuilder.DropTable( 56 | name: "carts"); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/20240410155050_WishListClass.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 WebApplication1.Models; 9 | 10 | #nullable disable 11 | 12 | namespace WebApplication1.Migrations 13 | { 14 | [DbContext(typeof(Context))] 15 | [Migration("20240410155050_WishListClass")] 16 | partial class WishListClass 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("Microsoft.AspNetCore.Identity.IdentityRole", b => 29 | { 30 | b.Property("Id") 31 | .HasColumnType("nvarchar(450)"); 32 | 33 | b.Property("ConcurrencyStamp") 34 | .IsConcurrencyToken() 35 | .HasColumnType("nvarchar(max)"); 36 | 37 | b.Property("Name") 38 | .HasMaxLength(256) 39 | .HasColumnType("nvarchar(256)"); 40 | 41 | b.Property("NormalizedName") 42 | .HasMaxLength(256) 43 | .HasColumnType("nvarchar(256)"); 44 | 45 | b.HasKey("Id"); 46 | 47 | b.HasIndex("NormalizedName") 48 | .IsUnique() 49 | .HasDatabaseName("RoleNameIndex") 50 | .HasFilter("[NormalizedName] IS NOT NULL"); 51 | 52 | b.ToTable("AspNetRoles", (string)null); 53 | }); 54 | 55 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 56 | { 57 | b.Property("Id") 58 | .ValueGeneratedOnAdd() 59 | .HasColumnType("int"); 60 | 61 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 62 | 63 | b.Property("ClaimType") 64 | .HasColumnType("nvarchar(max)"); 65 | 66 | b.Property("ClaimValue") 67 | .HasColumnType("nvarchar(max)"); 68 | 69 | b.Property("RoleId") 70 | .IsRequired() 71 | .HasColumnType("nvarchar(450)"); 72 | 73 | b.HasKey("Id"); 74 | 75 | b.HasIndex("RoleId"); 76 | 77 | b.ToTable("AspNetRoleClaims", (string)null); 78 | }); 79 | 80 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 81 | { 82 | b.Property("Id") 83 | .ValueGeneratedOnAdd() 84 | .HasColumnType("int"); 85 | 86 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 87 | 88 | b.Property("ClaimType") 89 | .HasColumnType("nvarchar(max)"); 90 | 91 | b.Property("ClaimValue") 92 | .HasColumnType("nvarchar(max)"); 93 | 94 | b.Property("UserId") 95 | .IsRequired() 96 | .HasColumnType("nvarchar(450)"); 97 | 98 | b.HasKey("Id"); 99 | 100 | b.HasIndex("UserId"); 101 | 102 | b.ToTable("AspNetUserClaims", (string)null); 103 | }); 104 | 105 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 106 | { 107 | b.Property("LoginProvider") 108 | .HasColumnType("nvarchar(450)"); 109 | 110 | b.Property("ProviderKey") 111 | .HasColumnType("nvarchar(450)"); 112 | 113 | b.Property("ProviderDisplayName") 114 | .HasColumnType("nvarchar(max)"); 115 | 116 | b.Property("UserId") 117 | .IsRequired() 118 | .HasColumnType("nvarchar(450)"); 119 | 120 | b.HasKey("LoginProvider", "ProviderKey"); 121 | 122 | b.HasIndex("UserId"); 123 | 124 | b.ToTable("AspNetUserLogins", (string)null); 125 | }); 126 | 127 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 128 | { 129 | b.Property("UserId") 130 | .HasColumnType("nvarchar(450)"); 131 | 132 | b.Property("RoleId") 133 | .HasColumnType("nvarchar(450)"); 134 | 135 | b.HasKey("UserId", "RoleId"); 136 | 137 | b.HasIndex("RoleId"); 138 | 139 | b.ToTable("AspNetUserRoles", (string)null); 140 | }); 141 | 142 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 143 | { 144 | b.Property("UserId") 145 | .HasColumnType("nvarchar(450)"); 146 | 147 | b.Property("LoginProvider") 148 | .HasColumnType("nvarchar(450)"); 149 | 150 | b.Property("Name") 151 | .HasColumnType("nvarchar(450)"); 152 | 153 | b.Property("Value") 154 | .HasColumnType("nvarchar(max)"); 155 | 156 | b.HasKey("UserId", "LoginProvider", "Name"); 157 | 158 | b.ToTable("AspNetUserTokens", (string)null); 159 | }); 160 | 161 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 162 | { 163 | b.Property("Id") 164 | .HasColumnType("nvarchar(450)"); 165 | 166 | b.Property("AccessFailedCount") 167 | .HasColumnType("int"); 168 | 169 | b.Property("ConcurrencyStamp") 170 | .IsConcurrencyToken() 171 | .HasColumnType("nvarchar(max)"); 172 | 173 | b.Property("Email") 174 | .HasMaxLength(256) 175 | .HasColumnType("nvarchar(256)"); 176 | 177 | b.Property("EmailConfirmed") 178 | .HasColumnType("bit"); 179 | 180 | b.Property("LockoutEnabled") 181 | .HasColumnType("bit"); 182 | 183 | b.Property("LockoutEnd") 184 | .HasColumnType("datetimeoffset"); 185 | 186 | b.Property("NormalizedEmail") 187 | .HasMaxLength(256) 188 | .HasColumnType("nvarchar(256)"); 189 | 190 | b.Property("NormalizedUserName") 191 | .HasMaxLength(256) 192 | .HasColumnType("nvarchar(256)"); 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("WebApplication1.Models.Cart", b => 227 | { 228 | b.Property("Id") 229 | .ValueGeneratedOnAdd() 230 | .HasColumnType("int"); 231 | 232 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 233 | 234 | b.Property("Customer_Id") 235 | .IsRequired() 236 | .HasColumnType("nvarchar(450)"); 237 | 238 | b.Property("IsDeleted") 239 | .HasColumnType("bit"); 240 | 241 | b.Property("Product_Id") 242 | .HasColumnType("int"); 243 | 244 | b.Property("Quantity") 245 | .HasColumnType("int"); 246 | 247 | b.HasKey("Id"); 248 | 249 | b.HasIndex("Customer_Id"); 250 | 251 | b.HasIndex("Product_Id"); 252 | 253 | b.ToTable("carts"); 254 | }); 255 | 256 | modelBuilder.Entity("WebApplication1.Models.Category", b => 257 | { 258 | b.Property("Id") 259 | .ValueGeneratedOnAdd() 260 | .HasColumnType("int"); 261 | 262 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 263 | 264 | b.Property("Name") 265 | .IsRequired() 266 | .HasColumnType("nvarchar(max)"); 267 | 268 | b.HasKey("Id"); 269 | 270 | b.ToTable("categories"); 271 | }); 272 | 273 | modelBuilder.Entity("WebApplication1.Models.Payment", b => 274 | { 275 | b.Property("Id") 276 | .ValueGeneratedOnAdd() 277 | .HasColumnType("int"); 278 | 279 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 280 | 281 | b.Property("Amount") 282 | .HasColumnType("float"); 283 | 284 | b.Property("Customer_Id") 285 | .IsRequired() 286 | .HasColumnType("nvarchar(450)"); 287 | 288 | b.Property("Date") 289 | .HasColumnType("datetime2"); 290 | 291 | b.Property("IsDeleted") 292 | .HasColumnType("bit"); 293 | 294 | b.Property("Method") 295 | .IsRequired() 296 | .HasColumnType("nvarchar(max)"); 297 | 298 | b.HasKey("Id"); 299 | 300 | b.HasIndex("Customer_Id"); 301 | 302 | b.ToTable("payments"); 303 | }); 304 | 305 | modelBuilder.Entity("WebApplication1.Models.Product", b => 306 | { 307 | b.Property("Id") 308 | .ValueGeneratedOnAdd() 309 | .HasColumnType("int"); 310 | 311 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 312 | 313 | b.Property("Category_Id") 314 | .HasColumnType("int"); 315 | 316 | b.Property("Description") 317 | .IsRequired() 318 | .HasColumnType("nvarchar(max)"); 319 | 320 | b.Property("Name") 321 | .IsRequired() 322 | .HasColumnType("nvarchar(max)"); 323 | 324 | b.Property("Price") 325 | .HasColumnType("int"); 326 | 327 | b.HasKey("Id"); 328 | 329 | b.HasIndex("Category_Id"); 330 | 331 | b.ToTable("products"); 332 | 333 | b.HasData( 334 | new 335 | { 336 | Id = 1, 337 | Description = "Description1", 338 | Name = "Product1", 339 | Price = 10 340 | }, 341 | new 342 | { 343 | Id = 2, 344 | Description = "Description2", 345 | Name = "Product2", 346 | Price = 20 347 | }); 348 | }); 349 | 350 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 351 | { 352 | b.Property("Id") 353 | .ValueGeneratedOnAdd() 354 | .HasColumnType("int"); 355 | 356 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 357 | 358 | b.Property("Address") 359 | .IsRequired() 360 | .HasColumnType("nvarchar(max)"); 361 | 362 | b.Property("City") 363 | .IsRequired() 364 | .HasColumnType("nvarchar(max)"); 365 | 366 | b.Property("Country") 367 | .IsRequired() 368 | .HasColumnType("nvarchar(max)"); 369 | 370 | b.Property("Customer_Id") 371 | .IsRequired() 372 | .HasColumnType("nvarchar(450)"); 373 | 374 | b.Property("Date") 375 | .HasColumnType("datetime2"); 376 | 377 | b.Property("IsDeleted") 378 | .HasColumnType("bit"); 379 | 380 | b.Property("State") 381 | .IsRequired() 382 | .HasColumnType("nvarchar(max)"); 383 | 384 | b.Property("Zip_Code") 385 | .IsRequired() 386 | .HasColumnType("nvarchar(max)"); 387 | 388 | b.HasKey("Id"); 389 | 390 | b.HasIndex("Customer_Id"); 391 | 392 | b.ToTable("shipments"); 393 | }); 394 | 395 | modelBuilder.Entity("WebApplication1.Models.WishList", b => 396 | { 397 | b.Property("Id") 398 | .ValueGeneratedOnAdd() 399 | .HasColumnType("int"); 400 | 401 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 402 | 403 | b.Property("Customer_Id") 404 | .IsRequired() 405 | .HasColumnType("nvarchar(450)"); 406 | 407 | b.Property("IsDeleted") 408 | .HasColumnType("bit"); 409 | 410 | b.Property("Product_Id") 411 | .HasColumnType("int"); 412 | 413 | b.HasKey("Id"); 414 | 415 | b.HasIndex("Customer_Id"); 416 | 417 | b.HasIndex("Product_Id"); 418 | 419 | b.ToTable("wishLists"); 420 | }); 421 | 422 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 423 | { 424 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 425 | .WithMany() 426 | .HasForeignKey("RoleId") 427 | .OnDelete(DeleteBehavior.Cascade) 428 | .IsRequired(); 429 | }); 430 | 431 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 432 | { 433 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 434 | .WithMany() 435 | .HasForeignKey("UserId") 436 | .OnDelete(DeleteBehavior.Cascade) 437 | .IsRequired(); 438 | }); 439 | 440 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 441 | { 442 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 443 | .WithMany() 444 | .HasForeignKey("UserId") 445 | .OnDelete(DeleteBehavior.Cascade) 446 | .IsRequired(); 447 | }); 448 | 449 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 450 | { 451 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 452 | .WithMany() 453 | .HasForeignKey("RoleId") 454 | .OnDelete(DeleteBehavior.Cascade) 455 | .IsRequired(); 456 | 457 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 458 | .WithMany() 459 | .HasForeignKey("UserId") 460 | .OnDelete(DeleteBehavior.Cascade) 461 | .IsRequired(); 462 | }); 463 | 464 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 465 | { 466 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 467 | .WithMany() 468 | .HasForeignKey("UserId") 469 | .OnDelete(DeleteBehavior.Cascade) 470 | .IsRequired(); 471 | }); 472 | 473 | modelBuilder.Entity("WebApplication1.Models.Cart", b => 474 | { 475 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 476 | .WithMany("carts") 477 | .HasForeignKey("Customer_Id") 478 | .OnDelete(DeleteBehavior.Cascade) 479 | .IsRequired(); 480 | 481 | b.HasOne("WebApplication1.Models.Product", "product") 482 | .WithMany("carts") 483 | .HasForeignKey("Product_Id") 484 | .OnDelete(DeleteBehavior.Cascade) 485 | .IsRequired(); 486 | 487 | b.Navigation("customer"); 488 | 489 | b.Navigation("product"); 490 | }); 491 | 492 | modelBuilder.Entity("WebApplication1.Models.Payment", b => 493 | { 494 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 495 | .WithMany("payments") 496 | .HasForeignKey("Customer_Id") 497 | .OnDelete(DeleteBehavior.Cascade) 498 | .IsRequired(); 499 | 500 | b.Navigation("customer"); 501 | }); 502 | 503 | modelBuilder.Entity("WebApplication1.Models.Product", b => 504 | { 505 | b.HasOne("WebApplication1.Models.Category", "category") 506 | .WithMany("products") 507 | .HasForeignKey("Category_Id"); 508 | 509 | b.Navigation("category"); 510 | }); 511 | 512 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 513 | { 514 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 515 | .WithMany("shipments") 516 | .HasForeignKey("Customer_Id") 517 | .OnDelete(DeleteBehavior.Cascade) 518 | .IsRequired(); 519 | 520 | b.Navigation("customer"); 521 | }); 522 | 523 | modelBuilder.Entity("WebApplication1.Models.WishList", b => 524 | { 525 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 526 | .WithMany("wishLists") 527 | .HasForeignKey("Customer_Id") 528 | .OnDelete(DeleteBehavior.Cascade) 529 | .IsRequired(); 530 | 531 | b.HasOne("WebApplication1.Models.Product", "product") 532 | .WithMany("wishLists") 533 | .HasForeignKey("Product_Id") 534 | .OnDelete(DeleteBehavior.Cascade) 535 | .IsRequired(); 536 | 537 | b.Navigation("customer"); 538 | 539 | b.Navigation("product"); 540 | }); 541 | 542 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 543 | { 544 | b.Navigation("carts"); 545 | 546 | b.Navigation("payments"); 547 | 548 | b.Navigation("shipments"); 549 | 550 | b.Navigation("wishLists"); 551 | }); 552 | 553 | modelBuilder.Entity("WebApplication1.Models.Category", b => 554 | { 555 | b.Navigation("products"); 556 | }); 557 | 558 | modelBuilder.Entity("WebApplication1.Models.Product", b => 559 | { 560 | b.Navigation("carts"); 561 | 562 | b.Navigation("wishLists"); 563 | }); 564 | #pragma warning restore 612, 618 565 | } 566 | } 567 | } 568 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/20240410155050_WishListClass.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace WebApplication1.Migrations 6 | { 7 | /// 8 | public partial class WishListClass : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.CreateTable( 14 | name: "wishLists", 15 | columns: table => new 16 | { 17 | Id = table.Column(type: "int", nullable: false) 18 | .Annotation("SqlServer:Identity", "1, 1"), 19 | IsDeleted = table.Column(type: "bit", nullable: false), 20 | Customer_Id = table.Column(type: "nvarchar(450)", nullable: false), 21 | Product_Id = table.Column(type: "int", nullable: false) 22 | }, 23 | constraints: table => 24 | { 25 | table.PrimaryKey("PK_wishLists", x => x.Id); 26 | table.ForeignKey( 27 | name: "FK_wishLists_AspNetUsers_Customer_Id", 28 | column: x => x.Customer_Id, 29 | principalTable: "AspNetUsers", 30 | principalColumn: "Id", 31 | onDelete: ReferentialAction.Cascade); 32 | table.ForeignKey( 33 | name: "FK_wishLists_products_Product_Id", 34 | column: x => x.Product_Id, 35 | principalTable: "products", 36 | principalColumn: "Id", 37 | onDelete: ReferentialAction.Cascade); 38 | }); 39 | 40 | migrationBuilder.CreateIndex( 41 | name: "IX_wishLists_Customer_Id", 42 | table: "wishLists", 43 | column: "Customer_Id"); 44 | 45 | migrationBuilder.CreateIndex( 46 | name: "IX_wishLists_Product_Id", 47 | table: "wishLists", 48 | column: "Product_Id"); 49 | } 50 | 51 | /// 52 | protected override void Down(MigrationBuilder migrationBuilder) 53 | { 54 | migrationBuilder.DropTable( 55 | name: "wishLists"); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /WebApplication1/Migrations/ContextModelSnapshot.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 WebApplication1.Models; 8 | 9 | #nullable disable 10 | 11 | namespace WebApplication1.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("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")); 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")); 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("WebApplication1.Models.ApplicationUser", 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("PasswordHash") 192 | .HasColumnType("nvarchar(max)"); 193 | 194 | b.Property("PhoneNumber") 195 | .HasColumnType("nvarchar(max)"); 196 | 197 | b.Property("PhoneNumberConfirmed") 198 | .HasColumnType("bit"); 199 | 200 | b.Property("SecurityStamp") 201 | .HasColumnType("nvarchar(max)"); 202 | 203 | b.Property("TwoFactorEnabled") 204 | .HasColumnType("bit"); 205 | 206 | b.Property("UserName") 207 | .HasMaxLength(256) 208 | .HasColumnType("nvarchar(256)"); 209 | 210 | b.HasKey("Id"); 211 | 212 | b.HasIndex("NormalizedEmail") 213 | .HasDatabaseName("EmailIndex"); 214 | 215 | b.HasIndex("NormalizedUserName") 216 | .IsUnique() 217 | .HasDatabaseName("UserNameIndex") 218 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 219 | 220 | b.ToTable("AspNetUsers", (string)null); 221 | }); 222 | 223 | modelBuilder.Entity("WebApplication1.Models.Cart", b => 224 | { 225 | b.Property("Id") 226 | .ValueGeneratedOnAdd() 227 | .HasColumnType("int"); 228 | 229 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 230 | 231 | b.Property("Customer_Id") 232 | .IsRequired() 233 | .HasColumnType("nvarchar(450)"); 234 | 235 | b.Property("IsDeleted") 236 | .HasColumnType("bit"); 237 | 238 | b.Property("Product_Id") 239 | .HasColumnType("int"); 240 | 241 | b.Property("Quantity") 242 | .HasColumnType("int"); 243 | 244 | b.HasKey("Id"); 245 | 246 | b.HasIndex("Customer_Id"); 247 | 248 | b.HasIndex("Product_Id"); 249 | 250 | b.ToTable("carts"); 251 | }); 252 | 253 | modelBuilder.Entity("WebApplication1.Models.Category", b => 254 | { 255 | b.Property("Id") 256 | .ValueGeneratedOnAdd() 257 | .HasColumnType("int"); 258 | 259 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 260 | 261 | b.Property("Name") 262 | .IsRequired() 263 | .HasColumnType("nvarchar(max)"); 264 | 265 | b.HasKey("Id"); 266 | 267 | b.ToTable("categories"); 268 | }); 269 | 270 | modelBuilder.Entity("WebApplication1.Models.Payment", b => 271 | { 272 | b.Property("Id") 273 | .ValueGeneratedOnAdd() 274 | .HasColumnType("int"); 275 | 276 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 277 | 278 | b.Property("Amount") 279 | .HasColumnType("float"); 280 | 281 | b.Property("Customer_Id") 282 | .IsRequired() 283 | .HasColumnType("nvarchar(450)"); 284 | 285 | b.Property("Date") 286 | .HasColumnType("datetime2"); 287 | 288 | b.Property("IsDeleted") 289 | .HasColumnType("bit"); 290 | 291 | b.Property("Method") 292 | .IsRequired() 293 | .HasColumnType("nvarchar(max)"); 294 | 295 | b.HasKey("Id"); 296 | 297 | b.HasIndex("Customer_Id"); 298 | 299 | b.ToTable("payments"); 300 | }); 301 | 302 | modelBuilder.Entity("WebApplication1.Models.Product", b => 303 | { 304 | b.Property("Id") 305 | .ValueGeneratedOnAdd() 306 | .HasColumnType("int"); 307 | 308 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 309 | 310 | b.Property("Category_Id") 311 | .HasColumnType("int"); 312 | 313 | b.Property("Description") 314 | .IsRequired() 315 | .HasColumnType("nvarchar(max)"); 316 | 317 | b.Property("Name") 318 | .IsRequired() 319 | .HasColumnType("nvarchar(max)"); 320 | 321 | b.Property("Price") 322 | .HasColumnType("int"); 323 | 324 | b.HasKey("Id"); 325 | 326 | b.HasIndex("Category_Id"); 327 | 328 | b.ToTable("products"); 329 | 330 | b.HasData( 331 | new 332 | { 333 | Id = 1, 334 | Description = "Description1", 335 | Name = "Product1", 336 | Price = 10 337 | }, 338 | new 339 | { 340 | Id = 2, 341 | Description = "Description2", 342 | Name = "Product2", 343 | Price = 20 344 | }); 345 | }); 346 | 347 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 348 | { 349 | b.Property("Id") 350 | .ValueGeneratedOnAdd() 351 | .HasColumnType("int"); 352 | 353 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 354 | 355 | b.Property("Address") 356 | .IsRequired() 357 | .HasColumnType("nvarchar(max)"); 358 | 359 | b.Property("City") 360 | .IsRequired() 361 | .HasColumnType("nvarchar(max)"); 362 | 363 | b.Property("Country") 364 | .IsRequired() 365 | .HasColumnType("nvarchar(max)"); 366 | 367 | b.Property("Customer_Id") 368 | .IsRequired() 369 | .HasColumnType("nvarchar(450)"); 370 | 371 | b.Property("Date") 372 | .HasColumnType("datetime2"); 373 | 374 | b.Property("IsDeleted") 375 | .HasColumnType("bit"); 376 | 377 | b.Property("State") 378 | .IsRequired() 379 | .HasColumnType("nvarchar(max)"); 380 | 381 | b.Property("Zip_Code") 382 | .IsRequired() 383 | .HasColumnType("nvarchar(max)"); 384 | 385 | b.HasKey("Id"); 386 | 387 | b.HasIndex("Customer_Id"); 388 | 389 | b.ToTable("shipments"); 390 | }); 391 | 392 | modelBuilder.Entity("WebApplication1.Models.WishList", b => 393 | { 394 | b.Property("Id") 395 | .ValueGeneratedOnAdd() 396 | .HasColumnType("int"); 397 | 398 | SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); 399 | 400 | b.Property("Customer_Id") 401 | .IsRequired() 402 | .HasColumnType("nvarchar(450)"); 403 | 404 | b.Property("IsDeleted") 405 | .HasColumnType("bit"); 406 | 407 | b.Property("Product_Id") 408 | .HasColumnType("int"); 409 | 410 | b.HasKey("Id"); 411 | 412 | b.HasIndex("Customer_Id"); 413 | 414 | b.HasIndex("Product_Id"); 415 | 416 | b.ToTable("wishLists"); 417 | }); 418 | 419 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 420 | { 421 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 422 | .WithMany() 423 | .HasForeignKey("RoleId") 424 | .OnDelete(DeleteBehavior.Cascade) 425 | .IsRequired(); 426 | }); 427 | 428 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 429 | { 430 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 431 | .WithMany() 432 | .HasForeignKey("UserId") 433 | .OnDelete(DeleteBehavior.Cascade) 434 | .IsRequired(); 435 | }); 436 | 437 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 438 | { 439 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 440 | .WithMany() 441 | .HasForeignKey("UserId") 442 | .OnDelete(DeleteBehavior.Cascade) 443 | .IsRequired(); 444 | }); 445 | 446 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 447 | { 448 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 449 | .WithMany() 450 | .HasForeignKey("RoleId") 451 | .OnDelete(DeleteBehavior.Cascade) 452 | .IsRequired(); 453 | 454 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 455 | .WithMany() 456 | .HasForeignKey("UserId") 457 | .OnDelete(DeleteBehavior.Cascade) 458 | .IsRequired(); 459 | }); 460 | 461 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 462 | { 463 | b.HasOne("WebApplication1.Models.ApplicationUser", null) 464 | .WithMany() 465 | .HasForeignKey("UserId") 466 | .OnDelete(DeleteBehavior.Cascade) 467 | .IsRequired(); 468 | }); 469 | 470 | modelBuilder.Entity("WebApplication1.Models.Cart", b => 471 | { 472 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 473 | .WithMany("carts") 474 | .HasForeignKey("Customer_Id") 475 | .OnDelete(DeleteBehavior.Cascade) 476 | .IsRequired(); 477 | 478 | b.HasOne("WebApplication1.Models.Product", "product") 479 | .WithMany("carts") 480 | .HasForeignKey("Product_Id") 481 | .OnDelete(DeleteBehavior.Cascade) 482 | .IsRequired(); 483 | 484 | b.Navigation("customer"); 485 | 486 | b.Navigation("product"); 487 | }); 488 | 489 | modelBuilder.Entity("WebApplication1.Models.Payment", b => 490 | { 491 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 492 | .WithMany("payments") 493 | .HasForeignKey("Customer_Id") 494 | .OnDelete(DeleteBehavior.Cascade) 495 | .IsRequired(); 496 | 497 | b.Navigation("customer"); 498 | }); 499 | 500 | modelBuilder.Entity("WebApplication1.Models.Product", b => 501 | { 502 | b.HasOne("WebApplication1.Models.Category", "category") 503 | .WithMany("products") 504 | .HasForeignKey("Category_Id"); 505 | 506 | b.Navigation("category"); 507 | }); 508 | 509 | modelBuilder.Entity("WebApplication1.Models.Shipment", b => 510 | { 511 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 512 | .WithMany("shipments") 513 | .HasForeignKey("Customer_Id") 514 | .OnDelete(DeleteBehavior.Cascade) 515 | .IsRequired(); 516 | 517 | b.Navigation("customer"); 518 | }); 519 | 520 | modelBuilder.Entity("WebApplication1.Models.WishList", b => 521 | { 522 | b.HasOne("WebApplication1.Models.ApplicationUser", "customer") 523 | .WithMany("wishLists") 524 | .HasForeignKey("Customer_Id") 525 | .OnDelete(DeleteBehavior.Cascade) 526 | .IsRequired(); 527 | 528 | b.HasOne("WebApplication1.Models.Product", "product") 529 | .WithMany("wishLists") 530 | .HasForeignKey("Product_Id") 531 | .OnDelete(DeleteBehavior.Cascade) 532 | .IsRequired(); 533 | 534 | b.Navigation("customer"); 535 | 536 | b.Navigation("product"); 537 | }); 538 | 539 | modelBuilder.Entity("WebApplication1.Models.ApplicationUser", b => 540 | { 541 | b.Navigation("carts"); 542 | 543 | b.Navigation("payments"); 544 | 545 | b.Navigation("shipments"); 546 | 547 | b.Navigation("wishLists"); 548 | }); 549 | 550 | modelBuilder.Entity("WebApplication1.Models.Category", b => 551 | { 552 | b.Navigation("products"); 553 | }); 554 | 555 | modelBuilder.Entity("WebApplication1.Models.Product", b => 556 | { 557 | b.Navigation("carts"); 558 | 559 | b.Navigation("wishLists"); 560 | }); 561 | #pragma warning restore 612, 618 562 | } 563 | } 564 | } 565 | -------------------------------------------------------------------------------- /WebApplication1/Models/ApplicationUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace WebApplication1.Models 4 | { 5 | public class ApplicationUser : IdentityUser 6 | { 7 | public List? shipments { get; set; } 8 | public List? payments { get; set; } 9 | public List? carts { get; set; } 10 | public List? wishLists { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /WebApplication1/Models/Cart.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations.Schema; 2 | 3 | namespace WebApplication1.Models 4 | { 5 | public class Cart 6 | { 7 | public int Id { get; set; } 8 | public int Quantity { get; set; } 9 | public bool IsDeleted { get; set; } = false; 10 | 11 | // Change Customer_Id to string 12 | [ForeignKey("customer")] 13 | public string Customer_Id { get; set; } 14 | 15 | public ApplicationUser customer { get; set; } 16 | 17 | [ForeignKey("product")] 18 | public int Product_Id { get; set; } 19 | public Product? product { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /WebApplication1/Models/Category.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1.Models 2 | { 3 | public class Category 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | 8 | public List? products { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /WebApplication1/Models/Context.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace WebApplication1.Models 5 | { 6 | public class Context : IdentityDbContext 7 | { 8 | public DbSet products { set; get; } 9 | public DbSet categories { set; get; } 10 | public DbSet shipments { set; get; } 11 | public DbSet payments { set; get; } 12 | public DbSet carts { set; get; } 13 | 14 | public DbSet wishLists { set; get; } 15 | public Context() : base() 16 | { 17 | 18 | } 19 | //constructor inject dbcontextOption 20 | public Context(DbContextOptions options) : base(options) 21 | { 22 | 23 | } 24 | protected override void OnModelCreating(ModelBuilder modelBuilder) 25 | { 26 | 27 | modelBuilder.Entity().HasData( 28 | new Product { Id = 1, Name = "Product1", Price = 10, Description = "Description1" }, 29 | new Product { Id = 2, Name = "Product2", Price = 20, Description = "Description2" } 30 | 31 | ); 32 | 33 | base.OnModelCreating(modelBuilder); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /WebApplication1/Models/Payment.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations.Schema; 2 | 3 | namespace WebApplication1.Models 4 | { 5 | public class Payment 6 | { 7 | public int Id { get; set; } 8 | public DateTime Date { get; set; } 9 | public string Method { get; set; } 10 | public Double Amount { get; set; } 11 | public bool IsDeleted { get; set; } = false; 12 | 13 | [ForeignKey("customer")] 14 | public string Customer_Id { get; set; } 15 | public ApplicationUser customer { get; set; } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WebApplication1/Models/Product.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations.Schema; 2 | 3 | namespace WebApplication1.Models 4 | { 5 | public class Product 6 | { 7 | public int Id { get; set; } 8 | public string Name { get; set; } 9 | public int Price { get; set; } 10 | public string Description { get; set; } 11 | public List? carts { get; set; } 12 | public List? wishLists { get; set; } 13 | 14 | [ForeignKey("category")] 15 | public int? Category_Id { get; set; } 16 | 17 | public Category? category { set; get; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WebApplication1/Models/Shipment.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations.Schema; 2 | 3 | namespace WebApplication1.Models 4 | { 5 | public class Shipment 6 | { 7 | public int Id { get; set; } 8 | public DateTime Date { get; set; } 9 | public string Address { get; set; } 10 | public string City { get; set; } 11 | public string State { get; set; } 12 | public string Country { get; set; } 13 | public string Zip_Code { get; set; } 14 | public bool IsDeleted { get; set; } = false; 15 | [ForeignKey("customer")] 16 | public string Customer_Id { get; set; } 17 | public ApplicationUser customer { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /WebApplication1/Models/WishList.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations.Schema; 2 | 3 | namespace WebApplication1.Models 4 | { 5 | public class WishList 6 | { 7 | public int Id { get; set; } 8 | public bool IsDeleted { get; set; } = false; 9 | [ForeignKey("customer")] 10 | public string Customer_Id { get; set; } 11 | public ApplicationUser customer { get; set; } 12 | [ForeignKey("product")] 13 | public int? Product_Id { get; set; } 14 | public Product? product { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /WebApplication1/Program.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sarah-sameh/E-Commerce_Web-API/ae388d1ad3a009560b1ddda432ba2753d9277103/WebApplication1/Program.cs -------------------------------------------------------------------------------- /WebApplication1/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:45422", 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:5032", 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 | -------------------------------------------------------------------------------- /WebApplication1/Repository/CartRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using WebApplication1.Models; 3 | 4 | namespace WebApplication1.Repository 5 | { 6 | public class CartRepository : ICartRepository 7 | { 8 | Context context; 9 | 10 | // inject Context 11 | public CartRepository(Context _context)//ask context not create 12 | { 13 | context = _context; 14 | } 15 | public List GetAll() 16 | { 17 | return context.carts 18 | .Include(c => c.product) 19 | .Include(c => c.customer) 20 | .Where(c => !c.IsDeleted) 21 | .ToList(); 22 | } 23 | 24 | public Cart GetById(int id) 25 | { 26 | return context.carts 27 | .Include(c => c.product) 28 | .FirstOrDefault(c => c.Id == id && !c.IsDeleted); 29 | } 30 | 31 | public List GetCartItemsOfCustomer(string customerId) 32 | { 33 | 34 | return GetAll().Where(items => items.Customer_Id == customerId).ToList(); 35 | } 36 | public int GetTotalPrice(string customerId) 37 | { 38 | int totalPrice = 0; 39 | foreach (Cart cartItem in GetCartItemsOfCustomer(customerId)) 40 | { 41 | totalPrice += (cartItem.product.Price * cartItem.Quantity); 42 | } 43 | 44 | return totalPrice; 45 | } 46 | 47 | public void Insert(Cart obj) 48 | { 49 | context.Add(obj); 50 | } 51 | public void Update(Cart obj) 52 | { 53 | context.Update(obj); 54 | } 55 | 56 | public void Delete(int id) 57 | { 58 | Cart crs = GetById(id); 59 | crs.IsDeleted = true; 60 | Update(crs); 61 | 62 | 63 | } 64 | 65 | public void Save() 66 | { 67 | context.SaveChanges(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /WebApplication1/Repository/CategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using WebApplication1.Models; 3 | 4 | namespace WebApplication1.Repository 5 | { 6 | public class CategoryRepository : ICategoryRepository 7 | { 8 | Context context; 9 | 10 | // inject Context 11 | public CategoryRepository(Context _context)//ask context not create 12 | { 13 | context = _context; 14 | } 15 | public List GetAll() 16 | { 17 | return context.categories.Include(c => c.products).ToList(); 18 | } 19 | 20 | public Category GetById(int id) 21 | { 22 | return context.categories 23 | .Include(c => c.products) 24 | .FirstOrDefault(p => p.Id == id); 25 | } 26 | public void Insert(Category obj) 27 | { 28 | context.Add(obj); 29 | } 30 | public void Update(Category obj) 31 | { 32 | context.Update(obj); 33 | } 34 | 35 | public void Delete(int id) 36 | { 37 | Category crs = GetById(id); 38 | context.Remove(crs); 39 | } 40 | 41 | public void Save() 42 | { 43 | context.SaveChanges(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WebApplication1/Repository/ICartRepository.cs: -------------------------------------------------------------------------------- 1 | using WebApplication1.Models; 2 | 3 | namespace WebApplication1.Repository 4 | { 5 | public interface ICartRepository 6 | { 7 | List GetAll(); 8 | 9 | Cart GetById(int id); 10 | public int GetTotalPrice(string customerId); 11 | 12 | public List GetCartItemsOfCustomer(string customerId); 13 | void Insert(Cart obj); 14 | 15 | void Update(Cart obj); 16 | 17 | void Delete(int id); 18 | 19 | void Save(); 20 | } 21 | } -------------------------------------------------------------------------------- /WebApplication1/Repository/ICategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using WebApplication1.Models; 2 | 3 | namespace WebApplication1.Repository 4 | { 5 | public interface ICategoryRepository 6 | { 7 | List GetAll(); 8 | 9 | Category GetById(int id); 10 | 11 | void Insert(Category obj); 12 | 13 | void Update(Category obj); 14 | 15 | void Delete(int id); 16 | 17 | void Save(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /WebApplication1/Repository/IPaymentRepository.cs: -------------------------------------------------------------------------------- 1 | using WebApplication1.Models; 2 | 3 | namespace WebApplication1.Repository 4 | { 5 | public interface IPaymentRepository 6 | { 7 | List GetAll(); 8 | 9 | Payment GetById(int id); 10 | 11 | void Insert(Payment obj); 12 | 13 | void Update(Payment obj); 14 | 15 | void Delete(int id); 16 | 17 | void Save(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /WebApplication1/Repository/IProductRepository.cs: -------------------------------------------------------------------------------- 1 | using WebApplication1.Models; 2 | 3 | namespace WebApplication1.Repository 4 | { 5 | public interface IProductRepository 6 | { 7 | List GetAll(); 8 | 9 | Product GetById(int id); 10 | 11 | void Insert(Product obj); 12 | 13 | void Update(Product obj); 14 | 15 | void Delete(int id); 16 | 17 | void Save(); 18 | } 19 | } -------------------------------------------------------------------------------- /WebApplication1/Repository/IShipmentRepository.cs: -------------------------------------------------------------------------------- 1 | using WebApplication1.Models; 2 | 3 | namespace WebApplication1.Repository 4 | { 5 | public interface IShipmentRepository 6 | { 7 | List GetAll(); 8 | 9 | Shipment GetById(int id); 10 | 11 | void Insert(Shipment obj); 12 | 13 | void Update(Shipment obj); 14 | 15 | void Delete(int id); 16 | 17 | void Save(); 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /WebApplication1/Repository/IWishListRepository.cs: -------------------------------------------------------------------------------- 1 | using WebApplication1.Models; 2 | 3 | namespace WebApplication1.Repository 4 | { 5 | public interface IWishListRepository 6 | { 7 | List GetAll(); 8 | 9 | WishList GetById(int id); 10 | 11 | void Insert(WishList obj); 12 | 13 | void Update(WishList obj); 14 | 15 | void Delete(int id); 16 | 17 | void Save(); 18 | public List GetAllbyCustomerId(string id); 19 | } 20 | } -------------------------------------------------------------------------------- /WebApplication1/Repository/PaymentRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using WebApplication1.Models; 3 | 4 | namespace WebApplication1.Repository 5 | { 6 | public class PaymentRepository : IPaymentRepository 7 | { 8 | Context context; 9 | 10 | // inject Context 11 | public PaymentRepository(Context _context)//ask context not create 12 | { 13 | context = _context; 14 | } 15 | public List GetAll() 16 | { 17 | return context.payments.Include(c => c.customer).ToList(); 18 | } 19 | 20 | public Payment GetById(int id) 21 | { 22 | return context.payments 23 | .Include(c => c.customer) 24 | .FirstOrDefault(p => p.Id == id); 25 | } 26 | public void Insert(Payment obj) 27 | { 28 | context.Add(obj); 29 | } 30 | public void Update(Payment obj) 31 | { 32 | context.Update(obj); 33 | } 34 | 35 | public void Delete(int id) 36 | { 37 | Payment crs = GetById(id); 38 | context.Remove(crs); 39 | } 40 | 41 | public void Save() 42 | { 43 | context.SaveChanges(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /WebApplication1/Repository/ProductRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using WebApplication1.Models; 3 | 4 | namespace WebApplication1.Repository 5 | { 6 | public class ProductRepository : IProductRepository 7 | { 8 | Context context; 9 | 10 | // inject Context 11 | public ProductRepository(Context _context)//ask context not create 12 | { 13 | context = _context; 14 | } 15 | public List GetAll() 16 | { 17 | return context.products 18 | .Include(p => p.category) 19 | .ToList(); 20 | } 21 | 22 | public Product GetById(int id) 23 | { 24 | return context.products 25 | .Include(p => p.category) 26 | .FirstOrDefault(p => p.Id == id); 27 | } 28 | public void Insert(Product obj) 29 | { 30 | context.Add(obj); 31 | } 32 | public void Update(Product obj) 33 | { 34 | context.Update(obj); 35 | } 36 | 37 | public void Delete(int id) 38 | { 39 | Product crs = GetById(id); 40 | context.Remove(crs); 41 | } 42 | 43 | public void Save() 44 | { 45 | context.SaveChanges(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /WebApplication1/Repository/ShipmentRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using WebApplication1.Models; 3 | 4 | namespace WebApplication1.Repository 5 | { 6 | public class ShipmentRepository : IShipmentRepository 7 | { 8 | Context context; 9 | 10 | // inject Context 11 | public ShipmentRepository(Context _context) 12 | { 13 | context = _context; 14 | } 15 | public List GetAll() 16 | { 17 | return context.shipments.Include(s => s.customer).ToList(); 18 | } 19 | 20 | public Shipment GetById(int id) 21 | { 22 | return context.shipments 23 | 24 | .FirstOrDefault(p => p.Id == id); 25 | } 26 | public void Insert(Shipment obj) 27 | { 28 | context.Add(obj); 29 | } 30 | public void Update(Shipment obj) 31 | { 32 | context.Update(obj); 33 | } 34 | 35 | public void Delete(int id) 36 | { 37 | Shipment crs = GetById(id); 38 | context.Remove(crs); 39 | } 40 | 41 | public void Save() 42 | { 43 | context.SaveChanges(); 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /WebApplication1/Repository/WishListRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using WebApplication1.Models; 3 | 4 | namespace WebApplication1.Repository 5 | { 6 | public class WishListRepository : IWishListRepository 7 | { 8 | Context context; 9 | 10 | // inject Context 11 | public WishListRepository(Context _context)//ask context not create 12 | { 13 | context = _context; 14 | } 15 | public List GetAll() 16 | { 17 | return context.wishLists 18 | .Include(p => p.customer) 19 | .Include(p => p.product) 20 | .ToList(); 21 | } 22 | 23 | public WishList GetById(int id) 24 | { 25 | return context.wishLists 26 | .Include(p => p.product) 27 | .Include(p => p.customer) 28 | .FirstOrDefault(p => p.Id == id); 29 | } 30 | public void Insert(WishList obj) 31 | { 32 | context.Add(obj); 33 | } 34 | public void Update(WishList obj) 35 | { 36 | context.Update(obj); 37 | } 38 | 39 | public void Delete(int id) 40 | { 41 | WishList crs = GetById(id); 42 | crs.IsDeleted = true; 43 | Update(crs); 44 | 45 | } 46 | 47 | public void Save() 48 | { 49 | context.SaveChanges(); 50 | } 51 | public List GetAllbyCustomerId(string id) 52 | { 53 | List wishLists = context.wishLists. 54 | Where(item => item.Customer_Id == id && item.IsDeleted == false).ToList(); 55 | return wishLists; 56 | } 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /WebApplication1/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace WebApplication1 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 | -------------------------------------------------------------------------------- /WebApplication1/WebApplication1.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 | -------------------------------------------------------------------------------- /WebApplication1/WebApplication1.http: -------------------------------------------------------------------------------- 1 | @WebApplication1_HostAddress = http://localhost:5032 2 | 3 | GET {{WebApplication1_HostAddress}}/weatherforecast/ 4 | Accept: application/json 5 | 6 | ### 7 | -------------------------------------------------------------------------------- /WebApplication1/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /WebApplication1/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "ConnectionStrings": { "cs": "Data Source=.;initial catalog=CorAPI;Integrated Security=True;trustservercertificate=true" }, 10 | "JWT": { 11 | "ValidIss": "http://localhost:45422/", 12 | "ValidAud": "http://localhost:4200", 13 | "SecritKey": "ssssssssssssssssssssssssssssssssssssssssssssssssssssss" 14 | } 15 | } 16 | --------------------------------------------------------------------------------