From 9999d257e0995b697991235e7fc22677b767c629 Mon Sep 17 00:00:00 2001 From: OlgunR Date: Fri, 28 Jun 2024 15:15:15 +0200 Subject: [PATCH] First commit --- .../DTOs/Incoming/CreatingCategoryDto.cs | 7 + .../DTOs/Incoming/CreatingProductDto.cs | 11 + .../DTOs/Incoming/UpdatingCategoryDto.cs | 8 + .../DTOs/Incoming/UpdatingProductDto.cs | 16 ++ .../DTOs/Outgoing/ReadingCategoryDto.cs | 8 + .../DTOs/Outgoing/ReadingProductDto.cs | 10 + .../Interfaces/ICategoryService.cs | 27 +++ .../Interfaces/IProductService.cs | 27 +++ .../MappingProfiles/BasicDtoMappingProfile.cs | 21 ++ .../Project.Application.csproj | 23 ++ .../Services/CategoryService.cs | 75 +++++++ .../Services/ProductService.cs | 75 +++++++ Project.Domain/Entities/Category.cs | 20 ++ Project.Domain/Entities/CategoryRole.cs | 22 ++ Project.Domain/Entities/Product.cs | 27 +++ Project.Domain/Entities/Role.cs | 20 ++ Project.Domain/Entities/User.cs | 27 +++ Project.Domain/Project.Domain.csproj | 18 ++ .../ApplicationDbContext.cs | 26 +++ .../Interfaces/ICategoryRepository.cs | 25 +++ .../Interfaces/IProductRepository.cs | 25 +++ .../Project.Infrastructure.csproj | 23 ++ .../Repositories/CategoryRepository.cs | 63 ++++++ .../Repositories/ProductRepository.cs | 64 ++++++ Project.Web/Controllers/CategoryController.cs | 112 ++++++++++ Project.Web/Controllers/ProductController.cs | 124 +++++++++++ .../20240619112737_Initial.Designer.cs | 206 +++++++++++++++++ .../Migrations/20240619112737_Initial.cs | 152 +++++++++++++ .../20240625110321_zwote.Designer.cs | 206 +++++++++++++++++ .../Migrations/20240625110321_zwote.cs | 82 +++++++ .../20240625135651_dritte.Designer.cs | 206 +++++++++++++++++ .../Migrations/20240625135651_dritte.cs | 22 ++ .../20240626064154_vierte.Designer.cs | 207 ++++++++++++++++++ .../Migrations/20240626064154_vierte.cs | 36 +++ .../20240627115130_fünfte.Designer.cs | 207 ++++++++++++++++++ .../Migrations/20240627115130_fünfte.cs | 22 ++ .../ApplicationDbContextModelSnapshot.cs | 204 +++++++++++++++++ Project.Web/Program.cs | 50 +++++ Project.Web/Project.Web.csproj | 25 +++ Project.Web/Project.Web.csproj.user | 8 + Project.Web/Project.http | 6 + Project.Web/Properties/launchSettings.json | 41 ++++ Project.Web/appsettings.Development.json | 8 + Project.Web/appsettings.json | 12 + Project.sln | 43 ++++ 45 files changed, 2647 insertions(+) create mode 100644 Project.Application/DTOs/Incoming/CreatingCategoryDto.cs create mode 100644 Project.Application/DTOs/Incoming/CreatingProductDto.cs create mode 100644 Project.Application/DTOs/Incoming/UpdatingCategoryDto.cs create mode 100644 Project.Application/DTOs/Incoming/UpdatingProductDto.cs create mode 100644 Project.Application/DTOs/Outgoing/ReadingCategoryDto.cs create mode 100644 Project.Application/DTOs/Outgoing/ReadingProductDto.cs create mode 100644 Project.Application/Interfaces/ICategoryService.cs create mode 100644 Project.Application/Interfaces/IProductService.cs create mode 100644 Project.Application/MappingProfiles/BasicDtoMappingProfile.cs create mode 100644 Project.Application/Project.Application.csproj create mode 100644 Project.Application/Services/CategoryService.cs create mode 100644 Project.Application/Services/ProductService.cs create mode 100644 Project.Domain/Entities/Category.cs create mode 100644 Project.Domain/Entities/CategoryRole.cs create mode 100644 Project.Domain/Entities/Product.cs create mode 100644 Project.Domain/Entities/Role.cs create mode 100644 Project.Domain/Entities/User.cs create mode 100644 Project.Domain/Project.Domain.csproj create mode 100644 Project.Infrastructure/ApplicationDbContext.cs create mode 100644 Project.Infrastructure/Interfaces/ICategoryRepository.cs create mode 100644 Project.Infrastructure/Interfaces/IProductRepository.cs create mode 100644 Project.Infrastructure/Project.Infrastructure.csproj create mode 100644 Project.Infrastructure/Repositories/CategoryRepository.cs create mode 100644 Project.Infrastructure/Repositories/ProductRepository.cs create mode 100644 Project.Web/Controllers/CategoryController.cs create mode 100644 Project.Web/Controllers/ProductController.cs create mode 100644 Project.Web/Migrations/20240619112737_Initial.Designer.cs create mode 100644 Project.Web/Migrations/20240619112737_Initial.cs create mode 100644 Project.Web/Migrations/20240625110321_zwote.Designer.cs create mode 100644 Project.Web/Migrations/20240625110321_zwote.cs create mode 100644 Project.Web/Migrations/20240625135651_dritte.Designer.cs create mode 100644 Project.Web/Migrations/20240625135651_dritte.cs create mode 100644 Project.Web/Migrations/20240626064154_vierte.Designer.cs create mode 100644 Project.Web/Migrations/20240626064154_vierte.cs create mode 100644 Project.Web/Migrations/20240627115130_fünfte.Designer.cs create mode 100644 Project.Web/Migrations/20240627115130_fünfte.cs create mode 100644 Project.Web/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 Project.Web/Program.cs create mode 100644 Project.Web/Project.Web.csproj create mode 100644 Project.Web/Project.Web.csproj.user create mode 100644 Project.Web/Project.http create mode 100644 Project.Web/Properties/launchSettings.json create mode 100644 Project.Web/appsettings.Development.json create mode 100644 Project.Web/appsettings.json create mode 100644 Project.sln diff --git a/Project.Application/DTOs/Incoming/CreatingCategoryDto.cs b/Project.Application/DTOs/Incoming/CreatingCategoryDto.cs new file mode 100644 index 0000000..b699f93 --- /dev/null +++ b/Project.Application/DTOs/Incoming/CreatingCategoryDto.cs @@ -0,0 +1,7 @@ +namespace Project.Application.DTOs.Incoming +{ + public class CreatingCategoryDto + { + public string Name { get; set; } + } +} diff --git a/Project.Application/DTOs/Incoming/CreatingProductDto.cs b/Project.Application/DTOs/Incoming/CreatingProductDto.cs new file mode 100644 index 0000000..ea72177 --- /dev/null +++ b/Project.Application/DTOs/Incoming/CreatingProductDto.cs @@ -0,0 +1,11 @@ +using Project.Domain.Entities; + +namespace Project.Application.DTOs.Incoming +{ + public class CreatingProductDto + { + public string Name { get; set; } + public decimal Price { get; set; } + public CreatingCategoryDto? Category { get; set; } + } +} diff --git a/Project.Application/DTOs/Incoming/UpdatingCategoryDto.cs b/Project.Application/DTOs/Incoming/UpdatingCategoryDto.cs new file mode 100644 index 0000000..f187c95 --- /dev/null +++ b/Project.Application/DTOs/Incoming/UpdatingCategoryDto.cs @@ -0,0 +1,8 @@ +namespace Project.Application.DTOs.Incoming +{ + public class UpdatingCategoryDto + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Project.Application/DTOs/Incoming/UpdatingProductDto.cs b/Project.Application/DTOs/Incoming/UpdatingProductDto.cs new file mode 100644 index 0000000..f0e3c66 --- /dev/null +++ b/Project.Application/DTOs/Incoming/UpdatingProductDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project.Application.DTOs.Incoming +{ + public class UpdatingProductDto + { + public int Id { get; set; } + public string Name { get; set; } + public decimal Price { get; set; } + public CreatingCategoryDto? Category { get; set; } + } +} diff --git a/Project.Application/DTOs/Outgoing/ReadingCategoryDto.cs b/Project.Application/DTOs/Outgoing/ReadingCategoryDto.cs new file mode 100644 index 0000000..bd4b059 --- /dev/null +++ b/Project.Application/DTOs/Outgoing/ReadingCategoryDto.cs @@ -0,0 +1,8 @@ +namespace Project.Application.DTOs.Outgoing +{ + public class ReadingCategoryDto + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Project.Application/DTOs/Outgoing/ReadingProductDto.cs b/Project.Application/DTOs/Outgoing/ReadingProductDto.cs new file mode 100644 index 0000000..9b481e4 --- /dev/null +++ b/Project.Application/DTOs/Outgoing/ReadingProductDto.cs @@ -0,0 +1,10 @@ +namespace Project.Application.DTOs.Outgoing +{ + public class ReadingProductDto + { + public int Id { get; set; } + public string Name { get; set; } + public decimal Price { get; set; } + public ReadingCategoryDto? Category { get; set; } + } +} diff --git a/Project.Application/Interfaces/ICategoryService.cs b/Project.Application/Interfaces/ICategoryService.cs new file mode 100644 index 0000000..995d3f5 --- /dev/null +++ b/Project.Application/Interfaces/ICategoryService.cs @@ -0,0 +1,27 @@ +using Project.Application.DTOs.Incoming; +using Project.Application.DTOs.Outgoing; +using Project.Domain.Entities; + +namespace Project.Application.Interfaces +{ + public interface ICategoryService + { + // CREATE + Task AddCategoryAsync(CreatingCategoryDto creatingCategoryDto); + + // READ ALL + Task> GetAllAsync(); + + // READ BY ID + Task GetByIdAsync(int id); + + // READ BY NAME + Task GetByNameAsync(string name); + + // UPDATE + Task UpdateCategoryAsync(UpdatingCategoryDto updatingCategoryDto); + + // DELETE + Task DeleteCategoryAsync(int id); + } +} diff --git a/Project.Application/Interfaces/IProductService.cs b/Project.Application/Interfaces/IProductService.cs new file mode 100644 index 0000000..f693003 --- /dev/null +++ b/Project.Application/Interfaces/IProductService.cs @@ -0,0 +1,27 @@ +using Project.Application.DTOs.Incoming; +using Project.Application.DTOs.Outgoing; +using Project.Domain.Entities; + +namespace Project.Application.Interfaces +{ + public interface IProductService + { + //CREATE + Task AddProductAsync(CreatingProductDto creatingProductDto); + + // READ ALL + Task> GetAllAsync(); + + // READ BY ID + Task GetByIdAsync(int id); + + // READ BY NAME + Task GetByNameAsync(string name); + + // UPDATE + Task UpdateProductAsync(UpdatingProductDto updatingProductDto); + + // DELETE + Task DeleteProductAsync(int id); + } +} diff --git a/Project.Application/MappingProfiles/BasicDtoMappingProfile.cs b/Project.Application/MappingProfiles/BasicDtoMappingProfile.cs new file mode 100644 index 0000000..06093a3 --- /dev/null +++ b/Project.Application/MappingProfiles/BasicDtoMappingProfile.cs @@ -0,0 +1,21 @@ +using AutoMapper; +using Project.Application.DTOs.Incoming; +using Project.Application.DTOs.Outgoing; +using Project.Domain.Entities; + +namespace Project.Application.MappingProfiles +{ + public class BasicDtoMappingProfile : Profile + { + public BasicDtoMappingProfile() + { + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + } + } +} diff --git a/Project.Application/Project.Application.csproj b/Project.Application/Project.Application.csproj new file mode 100644 index 0000000..39f7fcb --- /dev/null +++ b/Project.Application/Project.Application.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/Project.Application/Services/CategoryService.cs b/Project.Application/Services/CategoryService.cs new file mode 100644 index 0000000..360a232 --- /dev/null +++ b/Project.Application/Services/CategoryService.cs @@ -0,0 +1,75 @@ +using AutoMapper; +using Project.Application.DTOs.Incoming; +using Project.Application.DTOs.Outgoing; +using Project.Application.Interfaces; +using Project.Domain.Entities; +using Project.Infrastructure.Interfaces; + +namespace Project.Application.Services +{ + public class CategoryService : ICategoryService + { + // FIELDS FOR CTOR + private readonly ICategoryRepository _categoryRepository; + private readonly IMapper _mapper; + + // CTOR + public CategoryService(ICategoryRepository categoryService, IMapper mapper) + { + _categoryRepository = categoryService; + _mapper = mapper; + } + + // CREATE + public async Task AddCategoryAsync(CreatingCategoryDto creatingCategoryDto) + { + var category = _mapper.Map(creatingCategoryDto); + var created = await _categoryRepository.AddAsync(category); + return created; + } + + // READ ALL + public async Task> GetAllAsync() + { + var categories = await _categoryRepository.GetAllAsync(); + var readDto = _mapper.Map>(categories); + return readDto; + } + + // READ BY ID + public async Task GetByIdAsync(int id) + { + var category = await _categoryRepository.GetByIdAsync(id); + var readDto = _mapper.Map(category); + return readDto; + } + + // READ BY NAME + public async Task GetByNameAsync(string name) + { + var category = await _categoryRepository.GetByNameAsync(name); + var readDto = _mapper.Map(category); + return readDto; + } + + // UPDATE + public async Task UpdateCategoryAsync(UpdatingCategoryDto updatingCategoryDto) + { + var category = _mapper.Map(updatingCategoryDto); + bool isUpdated = await _categoryRepository.UpdateAsync(category); + return isUpdated; + } + + // DELETE + public async Task DeleteCategoryAsync(int id) + { + Category? category = await _categoryRepository.GetByIdAsync(id); + + if (category is null) + return false; + + bool isDeleted = await _categoryRepository.DeleteAsync(category); + return isDeleted; + } + } +} diff --git a/Project.Application/Services/ProductService.cs b/Project.Application/Services/ProductService.cs new file mode 100644 index 0000000..5d344d9 --- /dev/null +++ b/Project.Application/Services/ProductService.cs @@ -0,0 +1,75 @@ +using AutoMapper; +using Project.Application.DTOs.Incoming; +using Project.Application.DTOs.Outgoing; +using Project.Application.Interfaces; +using Project.Domain.Entities; +using Project.Infrastructure.Interfaces; + +namespace Project.Application.Services +{ + public class ProductService : IProductService + { + // FIELDS FOR CTOR + private readonly IProductRepository _productRepository; + private readonly IMapper _mapper; + + // CTOR + public ProductService(IProductRepository productRepository, IMapper mapper) + { + _productRepository = productRepository; + _mapper = mapper; + } + + // CREATE + public async Task AddProductAsync(CreatingProductDto creatingProductDto) + { + var product = _mapper.Map(creatingProductDto); + var created = await _productRepository.AddAsync(product); + return created; + } + + // READ ALL + public async Task> GetAllAsync() + { + var products = await _productRepository.GetAllAsync(); + var readDto = _mapper.Map>(products); + return readDto; + } + + // READ BY ID + public async Task GetByIdAsync(int id) + { + var product = await _productRepository.GetByIdAsync(id); + var readDto = _mapper.Map(product); + return readDto; + } + + // READ BY NAME + public async Task GetByNameAsync(string name) + { + var product = await _productRepository.GetByNameAsync(name); + var readDto = _mapper.Map(product); + return readDto; + } + + // UPDATE + public async Task UpdateProductAsync(UpdatingProductDto updatingProductDto) + { + var product = _mapper.Map(updatingProductDto); + bool idUpdated = await _productRepository.UpdateAsync(product); + return idUpdated; + } + + // DELETE + public async Task DeleteProductAsync(int id) + { + Product? product = await _productRepository.GetByIdAsync(id); + + if (product is null) + return false; + + bool isDeleted = await _productRepository.DeleteAsync(product); + return isDeleted; + } + } +} diff --git a/Project.Domain/Entities/Category.cs b/Project.Domain/Entities/Category.cs new file mode 100644 index 0000000..4fbd789 --- /dev/null +++ b/Project.Domain/Entities/Category.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Project.Domain.Entities +{ + [Table("CATEGORY", Schema = "dbo")] + public class Category + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("ID")] + public int Id { get; set; } = 0; + [Required] + [Column("CATEGORY_NAME")] + public string Name { get; set; } + [Required] + [Column("CREATION_DATE", TypeName = "datetime")] + public DateTime CreationDate { get; set; } = DateTime.Now; + } +} diff --git a/Project.Domain/Entities/CategoryRole.cs b/Project.Domain/Entities/CategoryRole.cs new file mode 100644 index 0000000..28bcaa6 --- /dev/null +++ b/Project.Domain/Entities/CategoryRole.cs @@ -0,0 +1,22 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Project.Domain.Entities +{ + [Table("CATEGORY_ROLE", Schema = "dbo")] + public class CategoryRole + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("ID")] + public int Id { get; set; } + public int CategoryId { get; set; } + public int RoleId { get; set; } + [ForeignKey("CategoryId")] + [Required] + [Column("PRODUCT_CATEGORY")] + public Category? Category { get; set; } + [ForeignKey("RoleId")] + public Role? Role { get; set; } + } +} diff --git a/Project.Domain/Entities/Product.cs b/Project.Domain/Entities/Product.cs new file mode 100644 index 0000000..05afaf1 --- /dev/null +++ b/Project.Domain/Entities/Product.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Project.Domain.Entities +{ + [Table("PRODUCT", Schema = "dbo")] + public class Product + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("ID")] + public int Id { get; set; } = 0; + [Required] + [Column("PRODUCT_NAME")] + public string Name { get; set; } + [Required] + [Column("PRICE", TypeName = "decimal(18,2)")] + public decimal Price { get; set; } + public int CategoryId { get; set; } + [ForeignKey("CategoryId")] + [Column("PRODUCT_CATEGORY")] + public Category? Category { get; set; } + + [Column("QUANTITY")] + public int Quantity { get; set; } + } +} diff --git a/Project.Domain/Entities/Role.cs b/Project.Domain/Entities/Role.cs new file mode 100644 index 0000000..7df6734 --- /dev/null +++ b/Project.Domain/Entities/Role.cs @@ -0,0 +1,20 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Project.Domain.Entities +{ + [Table("ROLE", Schema = "dbo")] + public class Role + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("ID")] + public int Id { get; set; } + [Required] + [Column("ROLE")] + public string Name { get; set; } + [Required] + [Column("CREATION_DATE", TypeName = "datetime")] + public DateTime CreationDate { get; set; } + } +} diff --git a/Project.Domain/Entities/User.cs b/Project.Domain/Entities/User.cs new file mode 100644 index 0000000..9cd8ad9 --- /dev/null +++ b/Project.Domain/Entities/User.cs @@ -0,0 +1,27 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Project.Domain.Entities +{ + [Table("USER", Schema = "dbo")] + public class User + { + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + [Column("ID")] + public int Id { get; set; } + [Required] + [Column("USER_NAME")] + public string UserName { get; set; } + [Required] + [Column("FIRST_NAME")] + public string FirstName { get; set; } + [Required] + [Column("LAST_NAME")] + public string LastName { get; set; } + + public int RoleId { get; set; } + [ForeignKey("RoleId")] + public Role? Role { get; set; } + } +} diff --git a/Project.Domain/Project.Domain.csproj b/Project.Domain/Project.Domain.csproj new file mode 100644 index 0000000..f67dbdd --- /dev/null +++ b/Project.Domain/Project.Domain.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Project.Infrastructure/ApplicationDbContext.cs b/Project.Infrastructure/ApplicationDbContext.cs new file mode 100644 index 0000000..4836c30 --- /dev/null +++ b/Project.Infrastructure/ApplicationDbContext.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore; +using Project.Domain.Entities; + +namespace Project.Infrastructure +{ + public class ApplicationDbContext : DbContext + { + public ApplicationDbContext(DbContextOptions options) : base(options) + { + + } + + public DbSet Users { get; set; } + public DbSet Roles { get; set; } + public DbSet Products { get; set; } + public DbSet Categories { get; set; } + public DbSet CategoriesRoles { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity(); + } + } +} diff --git a/Project.Infrastructure/Interfaces/ICategoryRepository.cs b/Project.Infrastructure/Interfaces/ICategoryRepository.cs new file mode 100644 index 0000000..fe8706c --- /dev/null +++ b/Project.Infrastructure/Interfaces/ICategoryRepository.cs @@ -0,0 +1,25 @@ +using Project.Domain.Entities; + +namespace Project.Infrastructure.Interfaces +{ + public interface ICategoryRepository + { + // CREATE + Task AddAsync(Category category); + + // READ ALL + Task> GetAllAsync(); + + // READ BY ID + Task GetByIdAsync(int id); + + // READ BY NAME + Task GetByNameAsync(string name); + + // UPDATE + Task UpdateAsync(Category category); + + // DELETE + Task DeleteAsync(Category category); + } +} diff --git a/Project.Infrastructure/Interfaces/IProductRepository.cs b/Project.Infrastructure/Interfaces/IProductRepository.cs new file mode 100644 index 0000000..40ea11f --- /dev/null +++ b/Project.Infrastructure/Interfaces/IProductRepository.cs @@ -0,0 +1,25 @@ +using Project.Domain.Entities; + +namespace Project.Infrastructure.Interfaces +{ + public interface IProductRepository + { + // CREATE + Task AddAsync(Product product); + + // READ ALL + Task> GetAllAsync(); + + // READ BY ID + Task GetByIdAsync(int id); + + // READ BY NAME + Task GetByNameAsync(string name); + + // UPDATE + Task UpdateAsync(Product product); + + // DELETE + Task DeleteAsync(Product product); + } +} diff --git a/Project.Infrastructure/Project.Infrastructure.csproj b/Project.Infrastructure/Project.Infrastructure.csproj new file mode 100644 index 0000000..259bc09 --- /dev/null +++ b/Project.Infrastructure/Project.Infrastructure.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/Project.Infrastructure/Repositories/CategoryRepository.cs b/Project.Infrastructure/Repositories/CategoryRepository.cs new file mode 100644 index 0000000..5dd98c5 --- /dev/null +++ b/Project.Infrastructure/Repositories/CategoryRepository.cs @@ -0,0 +1,63 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using Project.Domain.Entities; +using Project.Infrastructure.Interfaces; + +namespace Project.Infrastructure.Repositories +{ + public class CategoryRepository : ICategoryRepository + { + // FIELDS FOR CTOR + private readonly ApplicationDbContext _context; + private readonly IMapper _mapper; + + // CTOR + public CategoryRepository(ApplicationDbContext context, IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + // CREATE + public async Task AddAsync(Category category) + { + await _context.Categories.AddAsync(category); + await _context.SaveChangesAsync(); + return category; + } + + // READ ALL + public async Task> GetAllAsync() + { + return await _context.Categories.ToListAsync(); + } + + // READ BY ID + public async Task GetByIdAsync(int id) + { + return await _context.Categories.FindAsync(id); + } + + // READ BY NAME + public async Task GetByNameAsync(string name) + { + return await _context.Categories.FirstOrDefaultAsync(n => n.Name == name); + } + + // UPDATE + public async Task UpdateAsync(Category category) + { + _context.Entry(category).State = EntityState.Modified; + var results = await _context.SaveChangesAsync(); + return results > 0; + } + + // DELETE + public async Task DeleteAsync(Category category) + { + _context.Categories.Remove(category); + var result = await _context.SaveChangesAsync(); + return result > 0; + } + } +} diff --git a/Project.Infrastructure/Repositories/ProductRepository.cs b/Project.Infrastructure/Repositories/ProductRepository.cs new file mode 100644 index 0000000..9ed85dc --- /dev/null +++ b/Project.Infrastructure/Repositories/ProductRepository.cs @@ -0,0 +1,64 @@ +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using Project.Domain.Entities; +using Project.Infrastructure.Interfaces; + +namespace Project.Infrastructure.Repositories +{ + public class ProductRepository : IProductRepository + { + // FIELDS FOR CTOR + private readonly ApplicationDbContext _context; + private readonly IMapper _mapper; + + // CTOR + public ProductRepository(ApplicationDbContext context, IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + // CREATE + public async Task AddAsync(Product product) + { + await _context.Products.AddAsync(product); + await _context.SaveChangesAsync(); + return product; + } + + // READ ALL + [Authorize] + public async Task> GetAllAsync() + { + return await _context.Products.Include(p => p.Category).ToListAsync(); + } + + // READ BY ID + public async Task GetByIdAsync(int id) + { + return await _context.Products.FindAsync(id); + } + + // READ BY NAME + public async Task GetByNameAsync(string name) + { + return await _context.Products.FirstOrDefaultAsync(n => n.Name == name); + } + + // UPDATE + public async Task UpdateAsync(Product product) + { + _context.Entry(product).State = EntityState.Modified; + var results = await _context.SaveChangesAsync(); + return results > 0; + } + + // DELETE + public async Task DeleteAsync(Product product) + { + _context.Products.Remove(product); + var result = await _context.SaveChangesAsync(); + return result > 0; + } + } +} diff --git a/Project.Web/Controllers/CategoryController.cs b/Project.Web/Controllers/CategoryController.cs new file mode 100644 index 0000000..fc41692 --- /dev/null +++ b/Project.Web/Controllers/CategoryController.cs @@ -0,0 +1,112 @@ +using Microsoft.AspNetCore.Mvc; +using Project.Application.DTOs.Incoming; +using Project.Application.Interfaces; + +namespace Project.Web.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class CategoryController : ControllerBase + { + + // FIELDS FOR CTOR + private readonly ICategoryService _categoryService; + + // CTOR + public CategoryController(ICategoryService categoryService) + { + _categoryService = categoryService; + } + + // CREATE + [HttpPost] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task CreateCategory([FromBody] CreatingCategoryDto creatingCategoryDto) + { + var result = await _categoryService.AddCategoryAsync(creatingCategoryDto); + + if (result != null) + { + var id = result.Id; + var createdResource = new { Id = id }; + var actionName = nameof(GetCategoryById); + var routeValue = new { id = createdResource.Id }; + return CreatedAtAction(actionName, routeValue, createdResource); + } + else + { + return BadRequest("geht nix"); + } + } + + // READ ALL + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task GetCategories() + { + var categories = await _categoryService.GetAllAsync(); + return Ok(categories); + } + + // READ BY ID + [HttpGet("id/{id}", Name = "GetCategoryById")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetCategoryById(int id) + { + if (id <= 0) + { + return BadRequest("Invalid Id"); + } + var category = await _categoryService.GetByIdAsync(id); + if (category == null) + { + return NotFound(); + } + return Ok(category); + } + + // READ BY NAME + [HttpGet("name/{name}", Name = "GetCategoryByName")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetCategoryByName(string name) + { + if (string.IsNullOrEmpty(name)) + { + return BadRequest("Name cannot be empty"); + } + var category = await _categoryService.GetByNameAsync(name); + if (category == null) + { + return NotFound(); + } + return Ok(category); + } + + // UPDATE + [HttpPut("id/{id}", Name = "UpdateCategory")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task UpdateCategory(int id, UpdatingCategoryDto updatingCategoryDto) + { + var updated = await _categoryService.UpdateCategoryAsync(updatingCategoryDto); + return Ok(updated); + } + + // DELETE + [HttpDelete("id/{id}", Name = "DeleteCategory")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task DeleteCategory([FromRoute] int id) + { + await _categoryService.DeleteCategoryAsync(id); + return Ok(); + } + } +} diff --git a/Project.Web/Controllers/ProductController.cs b/Project.Web/Controllers/ProductController.cs new file mode 100644 index 0000000..39f8779 --- /dev/null +++ b/Project.Web/Controllers/ProductController.cs @@ -0,0 +1,124 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Project.Application.DTOs.Incoming; +using Project.Application.Interfaces; +using Project.Application.Services; +using System.Security.Claims; + +namespace Project.Web.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ProductController : ControllerBase + { + + // FIELDS FOR CTOR + private readonly IProductService _productService; + + // CTOR + public ProductController(IProductService productService) + { + _productService = productService; + } + + // CREATE + [HttpPost] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task CreateProduct([FromBody] CreatingProductDto creatingProductDto) // with form body + { + var result = await _productService.AddProductAsync(creatingProductDto); + + if (result != null) + { + var id = result.Id; + var createdResource = new { Id = id }; + var actionName = nameof(GetProductById); + var routeValue = new { id = createdResource.Id }; + return CreatedAtAction(actionName, routeValue, createdResource); + } + else + { + return BadRequest("geht nix"); + } + } + + // READ ALL + [Authorize(Roles ="Admin")] + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public async Task GetProducts() + { + var products = await _productService.GetAllAsync(); + return Ok(products); + } + + public async Task GetProducts() + { + var id = User.FindFirst(ClaimTypes.NameIdentifier); + + var products = await _productService.getproductbyuserid(id); + return Ok(products); + } + + // READ BY ID + [HttpGet("id/{id}", Name = "GetProductById")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetProductById(int id) + { + if (id <= 0) + { + return BadRequest("Invalid Id"); + } + var product = await _productService.GetByIdAsync(id); + if (product == null) + { + return NotFound(); + } + return Ok(product); + } + + // READ BY NAME + [HttpGet("name/{name}", Name = "GetProductByName")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetProductByName(string name) + { + if (string.IsNullOrEmpty(name)) + { + return BadRequest("Name cannot be empty"); + } + var product = await _productService.GetByNameAsync(name); + if (product == null) + { + return NotFound(); + } + return Ok(product); + } + + // UPDATE + [HttpPut("id/{id}", Name = "UpdateProduct")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task UpdateProduct(int id, UpdatingProductDto updatingProductDto) + { + var updated = await _productService.UpdateProductAsync(updatingProductDto); + return Ok(updated); + } + + // DELETE + [HttpDelete("id/{id}", Name = "DeleteProduct")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + public async Task DeleteProduct([FromRoute] int id) + { + await _productService.DeleteProductAsync(id); + return Ok(); + } + } +} diff --git a/Project.Web/Migrations/20240619112737_Initial.Designer.cs b/Project.Web/Migrations/20240619112737_Initial.Designer.cs new file mode 100644 index 0000000..ca10ef0 --- /dev/null +++ b/Project.Web/Migrations/20240619112737_Initial.Designer.cs @@ -0,0 +1,206 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Project.Infrastructure; + +#nullable disable + +namespace Project.Web.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240619112737_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Project.Domain.Entities.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .HasColumnType("int") + .HasColumnName("CATEGORY_NAME"); + + b.HasKey("Id"); + + b.ToTable("CATEGORY"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("RoleId"); + + b.ToTable("CATEGORY_ROLE"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("PRODUCT_NAME"); + + b.Property("Price") + .HasColumnType("decimal(18,2)") + .HasColumnName("CREATION_DATE"); + + b.Property("Quantity") + .HasColumnType("int") + .HasColumnName("QUANTITY"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("PRODUCT"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("ROLE"); + + b.HasKey("Id"); + + b.ToTable("ROLE"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("FIRST_NAME"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("LAST_NAME"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("USER_NAME"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("USER"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Project.Web/Migrations/20240619112737_Initial.cs b/Project.Web/Migrations/20240619112737_Initial.cs new file mode 100644 index 0000000..907a998 --- /dev/null +++ b/Project.Web/Migrations/20240619112737_Initial.cs @@ -0,0 +1,152 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Project.Web.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CATEGORY", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CATEGORY_NAME = table.Column(type: "int", nullable: false), + CREATION_DATE = table.Column(type: "datetime", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CATEGORY", x => x.ID); + }); + + migrationBuilder.CreateTable( + name: "ROLE", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ROLE = table.Column(type: "nvarchar(max)", nullable: false), + CREATION_DATE = table.Column(type: "datetime", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ROLE", x => x.ID); + }); + + migrationBuilder.CreateTable( + name: "PRODUCT", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PRODUCT_NAME = table.Column(type: "nvarchar(max)", nullable: false), + CREATION_DATE = table.Column(type: "decimal(18,2)", nullable: false), + CategoryId = table.Column(type: "int", nullable: false), + QUANTITY = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PRODUCT", x => x.ID); + table.ForeignKey( + name: "FK_PRODUCT_CATEGORY_CategoryId", + column: x => x.CategoryId, + principalTable: "CATEGORY", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CATEGORY_ROLE", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CategoryId = table.Column(type: "int", nullable: false), + RoleId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CATEGORY_ROLE", x => x.ID); + table.ForeignKey( + name: "FK_CATEGORY_ROLE_CATEGORY_CategoryId", + column: x => x.CategoryId, + principalTable: "CATEGORY", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CATEGORY_ROLE_ROLE_RoleId", + column: x => x.RoleId, + principalTable: "ROLE", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "USER", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + USER_NAME = table.Column(type: "nvarchar(max)", nullable: false), + FIRST_NAME = table.Column(type: "nvarchar(max)", nullable: false), + LAST_NAME = table.Column(type: "nvarchar(max)", nullable: false), + RoleId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_USER", x => x.ID); + table.ForeignKey( + name: "FK_USER_ROLE_RoleId", + column: x => x.RoleId, + principalTable: "ROLE", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_CATEGORY_ROLE_CategoryId", + table: "CATEGORY_ROLE", + column: "CategoryId"); + + migrationBuilder.CreateIndex( + name: "IX_CATEGORY_ROLE_RoleId", + table: "CATEGORY_ROLE", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "IX_PRODUCT_CategoryId", + table: "PRODUCT", + column: "CategoryId"); + + migrationBuilder.CreateIndex( + name: "IX_USER_RoleId", + table: "USER", + column: "RoleId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CATEGORY_ROLE"); + + migrationBuilder.DropTable( + name: "PRODUCT"); + + migrationBuilder.DropTable( + name: "USER"); + + migrationBuilder.DropTable( + name: "CATEGORY"); + + migrationBuilder.DropTable( + name: "ROLE"); + } + } +} diff --git a/Project.Web/Migrations/20240625110321_zwote.Designer.cs b/Project.Web/Migrations/20240625110321_zwote.Designer.cs new file mode 100644 index 0000000..3e7079b --- /dev/null +++ b/Project.Web/Migrations/20240625110321_zwote.Designer.cs @@ -0,0 +1,206 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Project.Infrastructure; + +#nullable disable + +namespace Project.Web.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240625110321_zwote")] + partial class zwote + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Project.Domain.Entities.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .HasColumnType("int") + .HasColumnName("CATEGORY_NAME"); + + b.HasKey("Id"); + + b.ToTable("CATEGORY", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("RoleId"); + + b.ToTable("CATEGORY_ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("PRODUCT_NAME"); + + b.Property("Price") + .HasColumnType("decimal(18,2)") + .HasColumnName("PRICE"); + + b.Property("Quantity") + .HasColumnType("int") + .HasColumnName("QUANTITY"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("PRODUCT", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("ROLE"); + + b.HasKey("Id"); + + b.ToTable("ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("FIRST_NAME"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("LAST_NAME"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("USER_NAME"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("USER", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Project.Web/Migrations/20240625110321_zwote.cs b/Project.Web/Migrations/20240625110321_zwote.cs new file mode 100644 index 0000000..dcad7b2 --- /dev/null +++ b/Project.Web/Migrations/20240625110321_zwote.cs @@ -0,0 +1,82 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Project.Web.Migrations +{ + /// + public partial class zwote : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.EnsureSchema( + name: "dbo"); + + migrationBuilder.RenameTable( + name: "USER", + newName: "USER", + newSchema: "dbo"); + + migrationBuilder.RenameTable( + name: "ROLE", + newName: "ROLE", + newSchema: "dbo"); + + migrationBuilder.RenameTable( + name: "PRODUCT", + newName: "PRODUCT", + newSchema: "dbo"); + + migrationBuilder.RenameTable( + name: "CATEGORY_ROLE", + newName: "CATEGORY_ROLE", + newSchema: "dbo"); + + migrationBuilder.RenameTable( + name: "CATEGORY", + newName: "CATEGORY", + newSchema: "dbo"); + + migrationBuilder.RenameColumn( + name: "CREATION_DATE", + schema: "dbo", + table: "PRODUCT", + newName: "PRICE"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameTable( + name: "USER", + schema: "dbo", + newName: "USER"); + + migrationBuilder.RenameTable( + name: "ROLE", + schema: "dbo", + newName: "ROLE"); + + migrationBuilder.RenameTable( + name: "PRODUCT", + schema: "dbo", + newName: "PRODUCT"); + + migrationBuilder.RenameTable( + name: "CATEGORY_ROLE", + schema: "dbo", + newName: "CATEGORY_ROLE"); + + migrationBuilder.RenameTable( + name: "CATEGORY", + schema: "dbo", + newName: "CATEGORY"); + + migrationBuilder.RenameColumn( + name: "PRICE", + table: "PRODUCT", + newName: "CREATION_DATE"); + } + } +} diff --git a/Project.Web/Migrations/20240625135651_dritte.Designer.cs b/Project.Web/Migrations/20240625135651_dritte.Designer.cs new file mode 100644 index 0000000..c994931 --- /dev/null +++ b/Project.Web/Migrations/20240625135651_dritte.Designer.cs @@ -0,0 +1,206 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Project.Infrastructure; + +#nullable disable + +namespace Project.Web.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240625135651_dritte")] + partial class dritte + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Project.Domain.Entities.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .HasColumnType("int") + .HasColumnName("CATEGORY_NAME"); + + b.HasKey("Id"); + + b.ToTable("CATEGORY", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("RoleId"); + + b.ToTable("CATEGORY_ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("PRODUCT_NAME"); + + b.Property("Price") + .HasColumnType("decimal(18,2)") + .HasColumnName("PRICE"); + + b.Property("Quantity") + .HasColumnType("int") + .HasColumnName("QUANTITY"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("PRODUCT", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("ROLE"); + + b.HasKey("Id"); + + b.ToTable("ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("FIRST_NAME"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("LAST_NAME"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("USER_NAME"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("USER", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Project.Web/Migrations/20240625135651_dritte.cs b/Project.Web/Migrations/20240625135651_dritte.cs new file mode 100644 index 0000000..aa5f907 --- /dev/null +++ b/Project.Web/Migrations/20240625135651_dritte.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Project.Web.Migrations +{ + /// + public partial class dritte : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Project.Web/Migrations/20240626064154_vierte.Designer.cs b/Project.Web/Migrations/20240626064154_vierte.Designer.cs new file mode 100644 index 0000000..21e8f02 --- /dev/null +++ b/Project.Web/Migrations/20240626064154_vierte.Designer.cs @@ -0,0 +1,207 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Project.Infrastructure; + +#nullable disable + +namespace Project.Web.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240626064154_vierte")] + partial class vierte + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Project.Domain.Entities.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("CATEGORY_NAME"); + + b.HasKey("Id"); + + b.ToTable("CATEGORY", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("RoleId"); + + b.ToTable("CATEGORY_ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("PRODUCT_NAME"); + + b.Property("Price") + .HasColumnType("decimal(18,2)") + .HasColumnName("PRICE"); + + b.Property("Quantity") + .HasColumnType("int") + .HasColumnName("QUANTITY"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("PRODUCT", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("ROLE"); + + b.HasKey("Id"); + + b.ToTable("ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("FIRST_NAME"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("LAST_NAME"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("USER_NAME"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("USER", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Project.Web/Migrations/20240626064154_vierte.cs b/Project.Web/Migrations/20240626064154_vierte.cs new file mode 100644 index 0000000..20d921f --- /dev/null +++ b/Project.Web/Migrations/20240626064154_vierte.cs @@ -0,0 +1,36 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Project.Web.Migrations +{ + /// + public partial class vierte : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "CATEGORY_NAME", + schema: "dbo", + table: "CATEGORY", + type: "nvarchar(max)", + nullable: false, + oldClrType: typeof(int), + oldType: "int"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "CATEGORY_NAME", + schema: "dbo", + table: "CATEGORY", + type: "int", + nullable: false, + oldClrType: typeof(string), + oldType: "nvarchar(max)"); + } + } +} diff --git a/Project.Web/Migrations/20240627115130_fünfte.Designer.cs b/Project.Web/Migrations/20240627115130_fünfte.Designer.cs new file mode 100644 index 0000000..46a7d9d --- /dev/null +++ b/Project.Web/Migrations/20240627115130_fünfte.Designer.cs @@ -0,0 +1,207 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Project.Infrastructure; + +#nullable disable + +namespace Project.Web.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240627115130_fünfte")] + partial class fünfte + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Project.Domain.Entities.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("CATEGORY_NAME"); + + b.HasKey("Id"); + + b.ToTable("CATEGORY", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("RoleId"); + + b.ToTable("CATEGORY_ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("PRODUCT_NAME"); + + b.Property("Price") + .HasColumnType("decimal(18,2)") + .HasColumnName("PRICE"); + + b.Property("Quantity") + .HasColumnType("int") + .HasColumnName("QUANTITY"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("PRODUCT", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("ROLE"); + + b.HasKey("Id"); + + b.ToTable("ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("FIRST_NAME"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("LAST_NAME"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("USER_NAME"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("USER", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Project.Web/Migrations/20240627115130_fünfte.cs b/Project.Web/Migrations/20240627115130_fünfte.cs new file mode 100644 index 0000000..c178b09 --- /dev/null +++ b/Project.Web/Migrations/20240627115130_fünfte.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Project.Web.Migrations +{ + /// + public partial class fünfte : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Project.Web/Migrations/ApplicationDbContextModelSnapshot.cs b/Project.Web/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..f23e94a --- /dev/null +++ b/Project.Web/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,204 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Project.Infrastructure; + +#nullable disable + +namespace Project.Web.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Project.Domain.Entities.Category", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("CATEGORY_NAME"); + + b.HasKey("Id"); + + b.ToTable("CATEGORY", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("RoleId"); + + b.ToTable("CATEGORY_ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("PRODUCT_NAME"); + + b.Property("Price") + .HasColumnType("decimal(18,2)") + .HasColumnName("PRICE"); + + b.Property("Quantity") + .HasColumnType("int") + .HasColumnName("QUANTITY"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.ToTable("PRODUCT", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime") + .HasColumnName("CREATION_DATE"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("ROLE"); + + b.HasKey("Id"); + + b.ToTable("ROLE", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("FIRST_NAME"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("LAST_NAME"); + + b.Property("RoleId") + .HasColumnType("int"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)") + .HasColumnName("USER_NAME"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("USER", "dbo"); + }); + + modelBuilder.Entity("Project.Domain.Entities.CategoryRole", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Project.Domain.Entities.Product", b => + { + b.HasOne("Project.Domain.Entities.Category", "Category") + .WithMany() + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + }); + + modelBuilder.Entity("Project.Domain.Entities.User", b => + { + b.HasOne("Project.Domain.Entities.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Project.Web/Program.cs b/Project.Web/Program.cs new file mode 100644 index 0000000..198645b --- /dev/null +++ b/Project.Web/Program.cs @@ -0,0 +1,50 @@ +using Microsoft.EntityFrameworkCore; +using Project.Application.Interfaces; +using Project.Application.MappingProfiles; +using Project.Application.Services; +using Project.Infrastructure; +using Project.Infrastructure.Interfaces; +using Project.Infrastructure.Repositories; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +builder.Services.AddAutoMapper(typeof(BasicDtoMappingProfile).Assembly); + +builder.Services.AddScoped(); +builder.Services.AddScoped(); + +builder.Services.AddScoped(); +builder.Services.AddScoped(); + +builder.Services.AddDbContext(options => +{ + options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Project.Web")); +}); +builder.Services.AddMemoryCache(); + +builder.Logging.ClearProviders(); +builder.Logging.AddConsole(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Project.Web/Project.Web.csproj b/Project.Web/Project.Web.csproj new file mode 100644 index 0000000..b894da4 --- /dev/null +++ b/Project.Web/Project.Web.csproj @@ -0,0 +1,25 @@ + + + + net8.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/Project.Web/Project.Web.csproj.user b/Project.Web/Project.Web.csproj.user new file mode 100644 index 0000000..2c8f5c1 --- /dev/null +++ b/Project.Web/Project.Web.csproj.user @@ -0,0 +1,8 @@ + + + + https + ApiControllerEmptyScaffolder + root/Common/Api + + \ No newline at end of file diff --git a/Project.Web/Project.http b/Project.Web/Project.http new file mode 100644 index 0000000..c6fec3b --- /dev/null +++ b/Project.Web/Project.http @@ -0,0 +1,6 @@ +@Project_HostAddress = http://localhost:5035 + +GET {{Project_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Project.Web/Properties/launchSettings.json b/Project.Web/Properties/launchSettings.json new file mode 100644 index 0000000..c1ea761 --- /dev/null +++ b/Project.Web/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:28621", + "sslPort": 44313 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5035", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7274;http://localhost:5035", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Project.Web/appsettings.Development.json b/Project.Web/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Project.Web/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Project.Web/appsettings.json b/Project.Web/appsettings.json new file mode 100644 index 0000000..a780be6 --- /dev/null +++ b/Project.Web/appsettings.json @@ -0,0 +1,12 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=Proje;Trusted_Connection=true;TrustServerCertificate=true;" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Project.sln b/Project.sln new file mode 100644 index 0000000..43a3297 --- /dev/null +++ b/Project.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34916.146 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Project.Domain", "Project.Domain\Project.Domain.csproj", "{DDF5C1C7-C621-4927-AF0F-85ED0E278006}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Project.Infrastructure", "Project.Infrastructure\Project.Infrastructure.csproj", "{EECBA4CC-4B15-4CF2-880A-0BEAEFE892E0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Project.Application", "Project.Application\Project.Application.csproj", "{E4D384D6-EE13-492B-99CA-57B0C31D6B2E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Project.Web", "Project.Web\Project.Web.csproj", "{4979AFF9-A038-49C4-9617-D0FF12E91AF2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DDF5C1C7-C621-4927-AF0F-85ED0E278006}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DDF5C1C7-C621-4927-AF0F-85ED0E278006}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DDF5C1C7-C621-4927-AF0F-85ED0E278006}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DDF5C1C7-C621-4927-AF0F-85ED0E278006}.Release|Any CPU.Build.0 = Release|Any CPU + {EECBA4CC-4B15-4CF2-880A-0BEAEFE892E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EECBA4CC-4B15-4CF2-880A-0BEAEFE892E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EECBA4CC-4B15-4CF2-880A-0BEAEFE892E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EECBA4CC-4B15-4CF2-880A-0BEAEFE892E0}.Release|Any CPU.Build.0 = Release|Any CPU + {E4D384D6-EE13-492B-99CA-57B0C31D6B2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E4D384D6-EE13-492B-99CA-57B0C31D6B2E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E4D384D6-EE13-492B-99CA-57B0C31D6B2E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E4D384D6-EE13-492B-99CA-57B0C31D6B2E}.Release|Any CPU.Build.0 = Release|Any CPU + {4979AFF9-A038-49C4-9617-D0FF12E91AF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4979AFF9-A038-49C4-9617-D0FF12E91AF2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4979AFF9-A038-49C4-9617-D0FF12E91AF2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4979AFF9-A038-49C4-9617-D0FF12E91AF2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {371AE6F0-9591-4D9D-BC1A-4CEE4E481C41} + EndGlobalSection +EndGlobal