From 79fa096185d8cd2f5e6255a5b327fcd070f58906 Mon Sep 17 00:00:00 2001 From: dofem Date: Thu, 30 Mar 2023 17:37:16 +0100 Subject: [PATCH] initial --- .../UserMan.API/Controllers/UserController.cs | 137 ++++++++++++++++++ .../UserMan/UserMan.API/Dto/ApiResponse.cs | 12 ++ .../UserMan/UserMan.API/Dto/UserDto.cs | 11 ++ .../UserMan/UserMan.API/Helper/Automapper.cs | 14 ++ UserManagement/UserMan/UserMan.API/Program.cs | 51 +++++++ .../Properties/launchSettings.json | 31 ++++ .../UserMan/UserMan.API/UserMan.API.csproj | 24 +++ .../UserMan.API/appsettings.Development.json | 8 + .../UserMan/UserMan.API/appsettings.json | 10 ++ .../UserMan.Application.csproj | 13 ++ .../Data/ApplicationDbContext.cs | 20 +++ .../Generator/DataGenerator.cs | 35 +++++ .../Implementation/GenericRepository.cs | 65 +++++++++ .../Implementation/UnitOfWork.cs | 33 +++++ .../Implementation/UserRepository.cs | 19 +++ .../Migrations/20230329200442_i.Designer.cs | 60 ++++++++ .../Migrations/20230329200442_i.cs | 35 +++++ .../ApplicationDbContextModelSnapshot.cs | 58 ++++++++ .../UserMan.DataAccess.csproj | 28 ++++ .../UserMan/UserMan.Domain/Entities/User.cs | 20 +++ .../Repository/IGenericRepository.cs | 21 +++ .../UserMan.Domain/Repository/IUnitOfWork.cs | 14 ++ .../Repository/IUserRepository.cs | 13 ++ .../UserMan.Domain/UserMan.Domain.csproj | 20 +++ UserManagement/UserMan/UserMan.sln | 37 +++++ 25 files changed, 789 insertions(+) create mode 100644 UserManagement/UserMan/UserMan.API/Controllers/UserController.cs create mode 100644 UserManagement/UserMan/UserMan.API/Dto/ApiResponse.cs create mode 100644 UserManagement/UserMan/UserMan.API/Dto/UserDto.cs create mode 100644 UserManagement/UserMan/UserMan.API/Helper/Automapper.cs create mode 100644 UserManagement/UserMan/UserMan.API/Program.cs create mode 100644 UserManagement/UserMan/UserMan.API/Properties/launchSettings.json create mode 100644 UserManagement/UserMan/UserMan.API/UserMan.API.csproj create mode 100644 UserManagement/UserMan/UserMan.API/appsettings.Development.json create mode 100644 UserManagement/UserMan/UserMan.API/appsettings.json create mode 100644 UserManagement/UserMan/UserMan.Application/UserMan.Application.csproj create mode 100644 UserManagement/UserMan/UserMan.DataAccess/Data/ApplicationDbContext.cs create mode 100644 UserManagement/UserMan/UserMan.DataAccess/Generator/DataGenerator.cs create mode 100644 UserManagement/UserMan/UserMan.DataAccess/Implementation/GenericRepository.cs create mode 100644 UserManagement/UserMan/UserMan.DataAccess/Implementation/UnitOfWork.cs create mode 100644 UserManagement/UserMan/UserMan.DataAccess/Implementation/UserRepository.cs create mode 100644 UserManagement/UserMan/UserMan.DataAccess/Migrations/20230329200442_i.Designer.cs create mode 100644 UserManagement/UserMan/UserMan.DataAccess/Migrations/20230329200442_i.cs create mode 100644 UserManagement/UserMan/UserMan.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs create mode 100644 UserManagement/UserMan/UserMan.DataAccess/UserMan.DataAccess.csproj create mode 100644 UserManagement/UserMan/UserMan.Domain/Entities/User.cs create mode 100644 UserManagement/UserMan/UserMan.Domain/Repository/IGenericRepository.cs create mode 100644 UserManagement/UserMan/UserMan.Domain/Repository/IUnitOfWork.cs create mode 100644 UserManagement/UserMan/UserMan.Domain/Repository/IUserRepository.cs create mode 100644 UserManagement/UserMan/UserMan.Domain/UserMan.Domain.csproj create mode 100644 UserManagement/UserMan/UserMan.sln diff --git a/UserManagement/UserMan/UserMan.API/Controllers/UserController.cs b/UserManagement/UserMan/UserMan.API/Controllers/UserController.cs new file mode 100644 index 0000000..4eafc9c --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/Controllers/UserController.cs @@ -0,0 +1,137 @@ +using AutoMapper; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System.Linq.Expressions; +using System.Net; +using System.Reflection; +using UserMan.API.Dto; +using UserMan.DataAccess.Implementation; +using UserMan.Domain.Entities; +using UserMan.Domain.Repository; + +namespace UserMan.API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class UserController : ControllerBase + { + private IUnitOfWork _unitOfWork; + private IMapper _mapper; + + public UserController(IUnitOfWork unitOfWork,IMapper mapper) + { + _unitOfWork = unitOfWork; + _mapper = mapper; + } + + [HttpGet] + [Route("GetAllUsers")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public ActionResult Get() + { + try + { + var users = _unitOfWork.User.GetAll(); + if (users == null) + { + return new ApiResponse { StatusCode = HttpStatusCode.NotFound, Messages = "No User Found"}; + } + return new ApiResponse { StatusCode = HttpStatusCode.OK, IsSuccess = true, Result = users }; + } + catch (Exception ex) + { + return new ApiResponse { StatusCode = HttpStatusCode.InternalServerError, Messages = ex.Message,IsSuccess=false }; + } + } + + + [HttpGet] + [Route("GetAUser")] + public ActionResult Get(int id) + { + try + { + var user = _unitOfWork.User.Get(id); + if (user == null) + { + return new ApiResponse { StatusCode = HttpStatusCode.NotFound, Messages = "No User Found" }; + } + return new ApiResponse { StatusCode = HttpStatusCode.OK, IsSuccess = true, Result = user }; + } + catch (Exception ex) + { + return new ApiResponse { StatusCode = HttpStatusCode.InternalServerError, Messages = ex.Message, IsSuccess = false }; + } + } + + + [HttpPost] + public ActionResult CreateUser(UserDto user) + { + try + { + if (user == null) + { + return new ApiResponse { StatusCode = HttpStatusCode.BadRequest, Messages = "Invalid Operation" }; + } + var newUser = _mapper.Map(user); + _unitOfWork.User.Add(newUser); + return new ApiResponse { StatusCode = HttpStatusCode.Created, IsSuccess = true, Messages = "User Profile Created Successfully" }; + } + catch (Exception ex) + { + return new ApiResponse { StatusCode = HttpStatusCode.InternalServerError, Messages = ex.Message, IsSuccess = false }; + } + } + + [HttpPut] + public IActionResult UpdateUser(UserDto user) + { + if (user == null) + { + return BadRequest(); + } + var updatedUser = _mapper.Map(user); + _unitOfWork.User.Update(updatedUser); + return Ok(); + } + + [HttpDelete] + public IActionResult DeleteUser(int id) + { + _unitOfWork.User.Delete(id); + return Ok(); + + } + + + [HttpGet("FindUser")] + public ActionResult FindUsers(int? age, string? gender, string? maritalStatus, string? location) + { + try + { + var users = _unitOfWork.User.Find(u => + (!age.HasValue || u.Age == age.Value) && + (string.IsNullOrEmpty(gender) || u.Gender.ToLower() == gender.ToLower()) && + (string.IsNullOrEmpty(maritalStatus) || u.MaritalStatus.ToLower() == maritalStatus.ToLower()) && + (string.IsNullOrEmpty(location) || u.Location.ToLower() == location.ToLower())).ToList(); + if (users.Count == 0) + { + return new ApiResponse { StatusCode = HttpStatusCode.NotFound, Messages = "No User Found", IsSuccess = false }; + } + else + { + return new ApiResponse { StatusCode = HttpStatusCode.OK, IsSuccess = true, Result = users }; + } + } + catch (Exception ex) + { + return new ApiResponse { StatusCode = HttpStatusCode.InternalServerError, IsSuccess = false, Messages = ex.Message }; + } + } + + + } +} diff --git a/UserManagement/UserMan/UserMan.API/Dto/ApiResponse.cs b/UserManagement/UserMan/UserMan.API/Dto/ApiResponse.cs new file mode 100644 index 0000000..923c7d5 --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/Dto/ApiResponse.cs @@ -0,0 +1,12 @@ +using System.Net; + +namespace UserMan.API.Dto +{ + public class ApiResponse + { + public HttpStatusCode StatusCode { get; set; } = HttpStatusCode.OK; + public bool IsSuccess { get; set; } = false; + public string Messages { get; set; } = string.Empty; + public object Result { get; set; } + } +} diff --git a/UserManagement/UserMan/UserMan.API/Dto/UserDto.cs b/UserManagement/UserMan/UserMan.API/Dto/UserDto.cs new file mode 100644 index 0000000..3d76383 --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/Dto/UserDto.cs @@ -0,0 +1,11 @@ +namespace UserMan.API.Dto +{ + public class UserDto + { + public string Name { get; set; } = string.Empty; + public int Age { get; set; } + public string Gender { get; set; } = string.Empty; + public string MaritalStatus { get; set; } = string.Empty; + public string Location { get; set; } = string.Empty; + } +} diff --git a/UserManagement/UserMan/UserMan.API/Helper/Automapper.cs b/UserManagement/UserMan/UserMan.API/Helper/Automapper.cs new file mode 100644 index 0000000..bc056a0 --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/Helper/Automapper.cs @@ -0,0 +1,14 @@ +using AutoMapper; +using UserMan.API.Dto; +using UserMan.Domain.Entities; + +namespace UserMan.API.Helper +{ + public class Automapper : Profile + { + public Automapper() + { + CreateMap().ReverseMap(); + } + } +} diff --git a/UserManagement/UserMan/UserMan.API/Program.cs b/UserManagement/UserMan/UserMan.API/Program.cs new file mode 100644 index 0000000..b967f66 --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/Program.cs @@ -0,0 +1,51 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using UserMan.DataAccess.Generator.DataGenerator; +using UserMan.DataAccess.Implementation; +using UserMan.Domain.Repository; +using UserMan.Infrastructure.Data.ApplicationDbContext; + +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.AddDbContext(options => +{ options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")); }); +builder.Services.AddScoped(); +builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); +builder.Services.AddScoped(); + + +var app = builder.Build(); + +using (var scope = app.Services.CreateScope()) +{ + var services = scope.ServiceProvider; + var context = services.GetRequiredService(); + var generator = services.GetRequiredService(); + generator.GenerateAndInsertFakeUsers(1000); +} + + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + + + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); + diff --git a/UserManagement/UserMan/UserMan.API/Properties/launchSettings.json b/UserManagement/UserMan/UserMan.API/Properties/launchSettings.json new file mode 100644 index 0000000..4030186 --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:60853", + "sslPort": 44372 + } + }, + "profiles": { + "UserMan.API": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7265;http://localhost:5062", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/UserManagement/UserMan/UserMan.API/UserMan.API.csproj b/UserManagement/UserMan/UserMan.API/UserMan.API.csproj new file mode 100644 index 0000000..0621a7d --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/UserMan.API.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/UserManagement/UserMan/UserMan.API/appsettings.Development.json b/UserManagement/UserMan/UserMan.API/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/UserManagement/UserMan/UserMan.API/appsettings.json b/UserManagement/UserMan/UserMan.API/appsettings.json new file mode 100644 index 0000000..2dd9776 --- /dev/null +++ b/UserManagement/UserMan/UserMan.API/appsettings.json @@ -0,0 +1,10 @@ +{ + "ConnectionStrings": { "DefaultConnection": "server=LAPTOP-C6680A7T\\SQLEXPRESS;database=UserMan;Integrated Security=true;" }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/UserManagement/UserMan/UserMan.Application/UserMan.Application.csproj b/UserManagement/UserMan/UserMan.Application/UserMan.Application.csproj new file mode 100644 index 0000000..3e119f9 --- /dev/null +++ b/UserManagement/UserMan/UserMan.Application/UserMan.Application.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/UserManagement/UserMan/UserMan.DataAccess/Data/ApplicationDbContext.cs b/UserManagement/UserMan/UserMan.DataAccess/Data/ApplicationDbContext.cs new file mode 100644 index 0000000..ca444b5 --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/Data/ApplicationDbContext.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UserMan.Domain.Entities; + +namespace UserMan.Infrastructure.Data.ApplicationDbContext +{ + public class ApplicationDbContext : DbContext + { + public ApplicationDbContext(DbContextOptions options) : base(options) + { + + } + + public DbSet Users { get; set; } + } +} diff --git a/UserManagement/UserMan/UserMan.DataAccess/Generator/DataGenerator.cs b/UserManagement/UserMan/UserMan.DataAccess/Generator/DataGenerator.cs new file mode 100644 index 0000000..bb75fe7 --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/Generator/DataGenerator.cs @@ -0,0 +1,35 @@ +using Bogus; +using UserMan.Domain.Entities; +using UserMan.Infrastructure.Data.ApplicationDbContext; + +namespace UserMan.DataAccess.Generator.DataGenerator +{ + public class DataGenerator + { + private readonly Faker _fakeUser; + private readonly ApplicationDbContext _context; + + public DataGenerator(ApplicationDbContext context) + { + _context = context; + + Randomizer.Seed = new Random(Seed: 123); + + _fakeUser = new Faker() + //.RuleFor(u => u.Id, f => f.Random.Int(min: 10, max: 1000000)) + .RuleFor(u => u.Name, f => f.Name.FullName()) + .RuleFor(u => u.Age, f => f.Random.Int(min: 18, max: 65)) + .RuleFor(u => u.Gender, f => f.PickRandom(new[] { "Male", "Female" })) + .RuleFor(u => u.MaritalStatus, f => f.PickRandom(new[] { "Single", "Married", "Divorced", "Widowed" })) + .RuleFor(u => u.Location, f => f.Address.City()); + } + + public void GenerateAndInsertFakeUsers(int count) + { + var users = _fakeUser.Generate(1000); + + _context.Users.UpdateRange(users); + _context.SaveChanges(); + } + } +} diff --git a/UserManagement/UserMan/UserMan.DataAccess/Implementation/GenericRepository.cs b/UserManagement/UserMan/UserMan.DataAccess/Implementation/GenericRepository.cs new file mode 100644 index 0000000..c7ec8ce --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/Implementation/GenericRepository.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using UserMan.Domain.Repository; +using UserMan.Infrastructure.Data.ApplicationDbContext; + +namespace UserMan.DataAccess.Implementation +{ + public class GenericRepository : IGenericRepository where T : class + { + private readonly ApplicationDbContext _context; + + public GenericRepository(ApplicationDbContext context) + { + _context = context; + } + public void Add(T entity) + { + _context.Set().Add(entity); + Save(); + } + + public void AddRange(IEnumerable entities) + { + _context.Set().AddRange(entities); + Save(); + } + + public void Delete(int id) + { + T entity = _context.Set().Find(id); + _context.Set().Remove(entity); + Save(); + } + + public IEnumerable Find(Expression> predicate) + { + return _context.Set().Where(predicate); + } + + public T Get(int id) + { + return _context.Set().Find(id); + } + + public IEnumerable GetAll() + { + return _context.Set().ToList(); + } + + public void Update(T entity) + { + _context.Set().Update(entity); + Save(); + } + + public void Save() + { + _context.SaveChanges(); + } + } +} diff --git a/UserManagement/UserMan/UserMan.DataAccess/Implementation/UnitOfWork.cs b/UserManagement/UserMan/UserMan.DataAccess/Implementation/UnitOfWork.cs new file mode 100644 index 0000000..5c8ca6e --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/Implementation/UnitOfWork.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UserMan.Domain.Repository; +using UserMan.Infrastructure.Data.ApplicationDbContext; + +namespace UserMan.DataAccess.Implementation +{ + public class UnitOfWork : IUnitOfWork + { + private ApplicationDbContext _context; + + public UnitOfWork(ApplicationDbContext context) + { + _context = context; + User = new UserRepository(_context); + } + + public IUserRepository User { get; private set; } + public IUserRepository UserRepository => throw new NotImplementedException(); + + public int Save() + { + return _context.SaveChanges(); + } + public void Dispose() + { + _context.Dispose(); + } + } +} diff --git a/UserManagement/UserMan/UserMan.DataAccess/Implementation/UserRepository.cs b/UserManagement/UserMan/UserMan.DataAccess/Implementation/UserRepository.cs new file mode 100644 index 0000000..c35e965 --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/Implementation/UserRepository.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UserMan.Domain.Entities; +using UserMan.Domain.Repository; +using UserMan.Infrastructure.Data.ApplicationDbContext; + +namespace UserMan.DataAccess.Implementation +{ + public class UserRepository : GenericRepository , IUserRepository + { + public UserRepository(ApplicationDbContext context) : base(context) + { + + } + } +} diff --git a/UserManagement/UserMan/UserMan.DataAccess/Migrations/20230329200442_i.Designer.cs b/UserManagement/UserMan/UserMan.DataAccess/Migrations/20230329200442_i.Designer.cs new file mode 100644 index 0000000..98d7ccd --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/Migrations/20230329200442_i.Designer.cs @@ -0,0 +1,60 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UserMan.Infrastructure.Data.ApplicationDbContext; + +#nullable disable + +namespace UserMan.DataAccess.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20230329200442_i")] + partial class i + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("UserMan.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Location") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MaritalStatus") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UserManagement/UserMan/UserMan.DataAccess/Migrations/20230329200442_i.cs b/UserManagement/UserMan/UserMan.DataAccess/Migrations/20230329200442_i.cs new file mode 100644 index 0000000..3daf564 --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/Migrations/20230329200442_i.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UserMan.DataAccess.Migrations +{ + public partial class i : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Age = table.Column(type: "int", nullable: false), + Gender = table.Column(type: "nvarchar(max)", nullable: false), + MaritalStatus = table.Column(type: "nvarchar(max)", nullable: false), + Location = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/UserManagement/UserMan/UserMan.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs b/UserManagement/UserMan/UserMan.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..350df18 --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,58 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UserMan.Infrastructure.Data.ApplicationDbContext; + +#nullable disable + +namespace UserMan.DataAccess.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("UserMan.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Location") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MaritalStatus") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UserManagement/UserMan/UserMan.DataAccess/UserMan.DataAccess.csproj b/UserManagement/UserMan/UserMan.DataAccess/UserMan.DataAccess.csproj new file mode 100644 index 0000000..4faf95a --- /dev/null +++ b/UserManagement/UserMan/UserMan.DataAccess/UserMan.DataAccess.csproj @@ -0,0 +1,28 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/UserManagement/UserMan/UserMan.Domain/Entities/User.cs b/UserManagement/UserMan/UserMan.Domain/Entities/User.cs new file mode 100644 index 0000000..e952d38 --- /dev/null +++ b/UserManagement/UserMan/UserMan.Domain/Entities/User.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace UserMan.Domain.Entities +{ + public class User + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public int Age { get; set; } + public string Gender { get; set; } = string.Empty; + public string MaritalStatus { get; set; } = string.Empty; + public string Location { get; set; } = string.Empty; + } + +} diff --git a/UserManagement/UserMan/UserMan.Domain/Repository/IGenericRepository.cs b/UserManagement/UserMan/UserMan.Domain/Repository/IGenericRepository.cs new file mode 100644 index 0000000..b38d142 --- /dev/null +++ b/UserManagement/UserMan/UserMan.Domain/Repository/IGenericRepository.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace UserMan.Domain.Repository +{ + public interface IGenericRepository where T : class + { + IEnumerable GetAll(); + T Get(int id); + IEnumerable Find(Expression> predicate); + void Add(T entity); + void AddRange(IEnumerable entities); + void Update(T entity); + void Delete(int id); + void Save(); + } +} diff --git a/UserManagement/UserMan/UserMan.Domain/Repository/IUnitOfWork.cs b/UserManagement/UserMan/UserMan.Domain/Repository/IUnitOfWork.cs new file mode 100644 index 0000000..f4ad71d --- /dev/null +++ b/UserManagement/UserMan/UserMan.Domain/Repository/IUnitOfWork.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UserMan.Domain.Repository +{ + public interface IUnitOfWork : IDisposable + { + IUserRepository User { get; } + int Save(); + } +} diff --git a/UserManagement/UserMan/UserMan.Domain/Repository/IUserRepository.cs b/UserManagement/UserMan/UserMan.Domain/Repository/IUserRepository.cs new file mode 100644 index 0000000..5cb85ad --- /dev/null +++ b/UserManagement/UserMan/UserMan.Domain/Repository/IUserRepository.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UserMan.Domain.Entities; + +namespace UserMan.Domain.Repository +{ + public interface IUserRepository : IGenericRepository + { + } +} diff --git a/UserManagement/UserMan/UserMan.Domain/UserMan.Domain.csproj b/UserManagement/UserMan/UserMan.Domain/UserMan.Domain.csproj new file mode 100644 index 0000000..ebd29af --- /dev/null +++ b/UserManagement/UserMan/UserMan.Domain/UserMan.Domain.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/UserManagement/UserMan/UserMan.sln b/UserManagement/UserMan/UserMan.sln new file mode 100644 index 0000000..7b8f3e2 --- /dev/null +++ b/UserManagement/UserMan/UserMan.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33516.290 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserMan.Domain", "UserMan.Domain\UserMan.Domain.csproj", "{3E0ABAE0-E614-4DDD-9760-1B389517AB9E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserMan.DataAccess", "UserMan.DataAccess\UserMan.DataAccess.csproj", "{A8FE7956-B5B1-44B6-99E9-224441828C65}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserMan.API", "UserMan.API\UserMan.API.csproj", "{2599220D-2A67-4018-8D5D-C7BDC261FDB2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3E0ABAE0-E614-4DDD-9760-1B389517AB9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E0ABAE0-E614-4DDD-9760-1B389517AB9E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E0ABAE0-E614-4DDD-9760-1B389517AB9E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E0ABAE0-E614-4DDD-9760-1B389517AB9E}.Release|Any CPU.Build.0 = Release|Any CPU + {A8FE7956-B5B1-44B6-99E9-224441828C65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8FE7956-B5B1-44B6-99E9-224441828C65}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8FE7956-B5B1-44B6-99E9-224441828C65}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8FE7956-B5B1-44B6-99E9-224441828C65}.Release|Any CPU.Build.0 = Release|Any CPU + {2599220D-2A67-4018-8D5D-C7BDC261FDB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2599220D-2A67-4018-8D5D-C7BDC261FDB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2599220D-2A67-4018-8D5D-C7BDC261FDB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2599220D-2A67-4018-8D5D-C7BDC261FDB2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C0513D43-2920-492D-9ACF-755B27E86039} + EndGlobalSection +EndGlobal