├── .gitignore ├── Management.API ├── Controllers │ └── DepartmentsController.cs ├── Extensions │ └── IServiceCollectionExtensions.cs ├── Management.API.csproj ├── Program.cs ├── Properties │ └── launchSettings.json ├── Services │ └── DepartmentService.cs ├── Startup.cs ├── WeatherForecast.cs ├── appsettings.Development.json └── appsettings.json ├── Management.Domain ├── Base │ └── EntityBase.cs ├── Departments │ ├── Department.Aggregate.cs │ ├── Department.cs │ └── IDepartmentRepository.cs ├── Interfaces │ ├── IRepository.cs │ └── IUnitOfWork.cs ├── Management.Domain.csproj ├── Salaries │ ├── ISalaryRepository.cs │ ├── Salary.Aggregate.cs │ └── Salary.cs └── Users │ ├── IUserRepository.cs │ ├── User.Aggregate.cs │ └── User.cs ├── Management.Infrastructure ├── AppDbContext.cs ├── DbFactory.cs ├── Management.Infrastructure.csproj ├── Migrations │ ├── 20201124223229_InitCreate.Designer.cs │ ├── 20201124223229_InitCreate.cs │ ├── 20201125155843_UpdateAuditEntity.Designer.cs │ ├── 20201125155843_UpdateAuditEntity.cs │ └── AppDbContextModelSnapshot.cs ├── Repositories │ ├── DepartmentRepository.cs │ ├── SalaryRepository.cs │ └── UserRepository.cs ├── Repository.cs └── UnitOfWork.cs ├── Management.sln ├── README.md └── gitlab-ci.yml /.gitignore: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This .gitignore file was automatically created by Microsoft(R) Visual Studio. 3 | ################################################################################ 4 | 5 | /.vs 6 | /Management.API/bin 7 | /Management.API/obj 8 | /Management.Domain/bin 9 | /Management.Domain/obj 10 | /Management.Infrastructure/bin 11 | /Management.Infrastructure/obj 12 | -------------------------------------------------------------------------------- /Management.API/Controllers/DepartmentsController.cs: -------------------------------------------------------------------------------- 1 | using Management.API.Services; 2 | using Management.Domain.Departments; 3 | using Management.Infrastructure; 4 | using Microsoft.AspNetCore.Mvc; 5 | using Microsoft.EntityFrameworkCore; 6 | using System; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace Management.API.Controllers 11 | { 12 | [ApiController] 13 | [Route("departments")] 14 | public class DepartmentsController : ControllerBase 15 | { 16 | private readonly DepartmentService _service; 17 | public DepartmentsController(DepartmentService service) 18 | { 19 | _service = service; 20 | } 21 | 22 | [HttpGet] 23 | public async Task Get() 24 | { 25 | await _service.AddAllEntitiesAsync(); 26 | 27 | return Ok(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Management.API/Extensions/IServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Management.API.Services; 2 | using Management.Domain.Departments; 3 | using Management.Domain.Interfaces; 4 | using Management.Domain.Salaries; 5 | using Management.Domain.Users; 6 | using Management.Infrastructure; 7 | using Management.Infrastructure.Repositories; 8 | using Microsoft.EntityFrameworkCore; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using System; 12 | using System.Collections.Generic; 13 | using System.Linq; 14 | using System.Threading.Tasks; 15 | 16 | namespace Management.API.Extensions 17 | { 18 | public static class IServiceCollectionExtensions 19 | { 20 | public static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration) 21 | { 22 | // Configure DbContext with Scoped lifetime 23 | services.AddDbContext(options => 24 | { 25 | options.UseSqlServer(configuration.GetConnectionString("ManagementConnection")); 26 | options.UseLazyLoadingProxies(); 27 | } 28 | ); 29 | 30 | services.AddScoped>((provider) => () => provider.GetService()); 31 | services.AddScoped(); 32 | services.AddScoped(); 33 | 34 | return services; 35 | } 36 | 37 | public static IServiceCollection AddRepositories(this IServiceCollection services) 38 | { 39 | return services 40 | .AddScoped(typeof(IRepository<>), typeof(Repository<>)) 41 | .AddScoped() 42 | .AddScoped() 43 | .AddScoped(); 44 | } 45 | 46 | public static IServiceCollection AddServices(this IServiceCollection services) 47 | { 48 | return services 49 | .AddScoped(); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Management.API/Management.API.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Management.API/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Management.API 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Management.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:17546", 8 | "sslPort": 44329 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "Management.API": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "weatherforecast", 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Management.API/Services/DepartmentService.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Departments; 2 | using Management.Domain.Interfaces; 3 | using Management.Domain.Salaries; 4 | using Management.Domain.Users; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace Management.API.Services 11 | { 12 | public class DepartmentService 13 | { 14 | private readonly IUnitOfWork _unitOfWork; 15 | private readonly IDepartmentRepository _departmentRepository; 16 | private readonly IUserRepository _userRepository; 17 | private readonly ISalaryRepository _salaryRepository; 18 | 19 | public DepartmentService(IUnitOfWork unitOfWork 20 | , IDepartmentRepository departmentRepository 21 | , IUserRepository userRepository 22 | , ISalaryRepository salaryRepository) 23 | { 24 | _unitOfWork = unitOfWork; 25 | _departmentRepository = departmentRepository; 26 | _userRepository = userRepository; 27 | _salaryRepository = salaryRepository; 28 | } 29 | 30 | public async Task AddAllEntitiesAsync() 31 | { 32 | // create new Department 33 | var departMentName = $"department_{Guid.NewGuid():N}"; 34 | var department = _departmentRepository.AddDepartment(departMentName); 35 | 36 | // create new User with above Department 37 | var userName = $"user_{Guid.NewGuid():N}"; 38 | var userEmail = $"{Guid.NewGuid():N}@gmail.com"; 39 | var user = _userRepository.NewUser(userName, userEmail, department); 40 | 41 | // create new Salary with above User 42 | float coefficientsSalary = new Random().Next(1, 15); 43 | float workdays = 22; 44 | var salary = _salaryRepository.AddUserSalary(user, coefficientsSalary, workdays); 45 | 46 | // Commit all changes with one single commit 47 | var saved = await _unitOfWork.CommitAsync(); 48 | 49 | return saved > 0; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Management.API/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Management.API.Extensions; 6 | using Management.Infrastructure; 7 | using Microsoft.AspNetCore.Builder; 8 | using Microsoft.AspNetCore.Hosting; 9 | using Microsoft.AspNetCore.HttpsPolicy; 10 | using Microsoft.AspNetCore.Mvc; 11 | using Microsoft.EntityFrameworkCore; 12 | using Microsoft.Extensions.Configuration; 13 | using Microsoft.Extensions.DependencyInjection; 14 | using Microsoft.Extensions.Hosting; 15 | using Microsoft.Extensions.Logging; 16 | 17 | namespace Management.API 18 | { 19 | public class Startup 20 | { 21 | public Startup(IConfiguration configuration) 22 | { 23 | Configuration = configuration; 24 | } 25 | 26 | public IConfiguration Configuration { get; } 27 | 28 | // This method gets called by the runtime. Use this method to add services to the container. 29 | public void ConfigureServices(IServiceCollection services) 30 | { 31 | services.AddControllers(); 32 | 33 | services 34 | .AddDatabase(Configuration) 35 | .AddRepositories() 36 | .AddServices(); 37 | } 38 | 39 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 40 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 41 | { 42 | if (env.IsDevelopment()) 43 | { 44 | app.UseDeveloperExceptionPage(); 45 | } 46 | 47 | app.UseHttpsRedirection(); 48 | 49 | app.UseRouting(); 50 | 51 | app.UseAuthorization(); 52 | 53 | app.UseEndpoints(endpoints => 54 | { 55 | endpoints.MapControllers(); 56 | }); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Management.API/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Management.API 4 | { 5 | public class WeatherForecast 6 | { 7 | public DateTime Date { get; set; } 8 | 9 | public int TemperatureC { get; set; } 10 | 11 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 12 | 13 | public string Summary { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Management.API/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Management.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*", 10 | "ConnectionStrings": { 11 | "ManagementConnection": "Server=DESKTOP-G24SR03;Initial Catalog=Management;Trusted_Connection=True;" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Management.Domain/Base/EntityBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Text; 6 | 7 | namespace Management.Domain.Base 8 | { 9 | public interface IEntityBase 10 | { 11 | TKey Id { get; set; } 12 | } 13 | 14 | public interface IDeleteEntity 15 | { 16 | bool IsDeleted { get; set; } 17 | } 18 | 19 | public interface IDeleteEntity : IDeleteEntity, IEntityBase 20 | { 21 | } 22 | 23 | public interface IAuditEntity 24 | { 25 | DateTime CreatedDate { get; set; } 26 | string CreatedBy { get; set; } 27 | DateTime? UpdatedDate { get; set; } 28 | string UpdatedBy { get; set; } 29 | } 30 | public interface IAuditEntity : IAuditEntity, IDeleteEntity 31 | { 32 | } 33 | 34 | public abstract class EntityBase : IEntityBase 35 | { 36 | [Key] 37 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 38 | public virtual TKey Id { get; set; } 39 | } 40 | 41 | public abstract class DeleteEntity : EntityBase, IDeleteEntity 42 | { 43 | public bool IsDeleted { get; set; } 44 | } 45 | 46 | public abstract class AuditEntity : DeleteEntity, IAuditEntity 47 | { 48 | public DateTime CreatedDate { get; set; } 49 | public string CreatedBy { get; set; } 50 | public DateTime? UpdatedDate { get; set; } 51 | public string UpdatedBy { get; set; } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Management.Domain/Departments/Department.Aggregate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Management.Domain.Departments 6 | { 7 | public partial class Department 8 | { 9 | public Department(string departmentName) : base() 10 | { 11 | this.DepartmentName = departmentName; 12 | } 13 | 14 | public bool ValidOnAdd() 15 | { 16 | return !string.IsNullOrEmpty(DepartmentName); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Management.Domain/Departments/Department.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Base; 2 | using Management.Domain.Users; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | using System.Text; 8 | 9 | namespace Management.Domain.Departments 10 | { 11 | [Table("Departments")] 12 | public partial class Department : AuditEntity 13 | { 14 | public Department() 15 | { 16 | Users = new HashSet(); 17 | } 18 | 19 | public string DepartmentName { get; set; } 20 | 21 | public virtual ICollection Users { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Management.Domain/Departments/IDepartmentRepository.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Interfaces; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Management.Domain.Departments 8 | { 9 | public interface IDepartmentRepository : IRepository 10 | { 11 | Department AddDepartment(string departmentName); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Management.Domain/Interfaces/IRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Threading.Tasks; 6 | 7 | namespace Management.Domain.Interfaces 8 | { 9 | public interface IRepository where T : class 10 | { 11 | void Add(T entity); 12 | void Delete(T entity); 13 | void Update(T entity); 14 | IQueryable List(Expression> expression); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Management.Domain/Interfaces/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using System.Threading.Tasks; 3 | 4 | namespace Management.Domain.Interfaces 5 | { 6 | public interface IUnitOfWork 7 | { 8 | Task CommitAsync(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Management.Domain/Management.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Management.Domain/Salaries/ISalaryRepository.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Interfaces; 2 | using Management.Domain.Users; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Management.Domain.Salaries 9 | { 10 | public interface ISalaryRepository : IRepository 11 | { 12 | Salary AddUserSalary(User user, float coefficientsSalary, float workdays); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Management.Domain/Salaries/Salary.Aggregate.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Users; 2 | 3 | namespace Management.Domain.Salaries 4 | { 5 | public partial class Salary 6 | { 7 | const float DAY_PRICE = 100F; // 100$, just for example 8 | public Salary(User user 9 | , float coefficientsSalary 10 | , float workDays) : base() 11 | { 12 | User = user; 13 | CoefficientsSalary = coefficientsSalary; 14 | WorkDays = workDays; 15 | TotalSalary = (decimal)((workDays * DAY_PRICE) * coefficientsSalary); 16 | } 17 | 18 | public bool ValidOnAdd() 19 | { 20 | return (UserId != 0 || User != null); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Management.Domain/Salaries/Salary.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Base; 2 | using Management.Domain.Users; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | using System.Text; 7 | 8 | namespace Management.Domain.Salaries 9 | { 10 | [Table("Salaries")] 11 | public partial class Salary : AuditEntity 12 | { 13 | public Salary() 14 | { 15 | 16 | } 17 | public int UserId { get; set; } 18 | public float CoefficientsSalary { get; set; } 19 | public float WorkDays { get; set; } 20 | public decimal TotalSalary { get; set; } 21 | 22 | [ForeignKey(nameof(UserId))] 23 | public virtual User User { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Management.Domain/Users/IUserRepository.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Departments; 2 | using Management.Domain.Interfaces; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Management.Domain.Users 9 | { 10 | public interface IUserRepository : IRepository 11 | { 12 | User NewUser(string userName 13 | , string email 14 | , Department department); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Management.Domain/Users/User.Aggregate.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Departments; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace Management.Domain.Users 5 | { 6 | public partial class User 7 | { 8 | public User(string userName 9 | , string email 10 | , Department department) : base() 11 | { 12 | UserName = userName; 13 | Email = email; 14 | Department = department; 15 | } 16 | 17 | public bool ValidOnAdd() 18 | { 19 | return 20 | // Validate userName 21 | !string.IsNullOrEmpty(UserName) 22 | // Make sure email not null and correct email format 23 | && !string.IsNullOrEmpty(Email) 24 | && new EmailAddressAttribute().IsValid(Email) 25 | // Make sure department not null 26 | && ( 27 | Department != null 28 | || DepartmentId != 0 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Management.Domain/Users/User.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Base; 2 | using Management.Domain.Departments; 3 | using Management.Domain.Salaries; 4 | using System.Collections.Generic; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | 8 | namespace Management.Domain.Users 9 | { 10 | [Table("Users")] 11 | public partial class User : DeleteEntity 12 | { 13 | public User() 14 | { 15 | Salaries = new HashSet(); 16 | } 17 | 18 | public string UserName { get; set; } 19 | 20 | [EmailAddress] 21 | public string Email { get; set; } 22 | 23 | public short DepartmentId { get; set; } 24 | 25 | [ForeignKey(nameof(DepartmentId))] 26 | public virtual Department Department { get; set; } 27 | 28 | public virtual ICollection Salaries { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Management.Infrastructure/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Departments; 2 | using Management.Domain.Salaries; 3 | using Management.Domain.Users; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Management.Infrastructure 10 | { 11 | public class AppDbContext : DbContext 12 | { 13 | public DbSet Users { get; set; } 14 | public DbSet Departments { get; set; } 15 | public DbSet Salaries { get; set; } 16 | public AppDbContext(DbContextOptions options) : base(options) 17 | { 18 | 19 | } 20 | 21 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 22 | { 23 | } 24 | 25 | protected override void OnModelCreating(ModelBuilder modelBuilder) 26 | { 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Management.Infrastructure/DbFactory.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Interfaces; 2 | using Microsoft.EntityFrameworkCore; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Management.Infrastructure 8 | { 9 | public class DbFactory : IDisposable 10 | { 11 | private bool _disposed; 12 | private Func _instanceFunc; 13 | private DbContext _dbContext; 14 | public DbContext DbContext => _dbContext ?? (_dbContext = _instanceFunc.Invoke()); 15 | 16 | public DbFactory(Func dbContextFactory) 17 | { 18 | _instanceFunc = dbContextFactory; 19 | } 20 | 21 | public void Dispose() 22 | { 23 | if (!_disposed && _dbContext != null) 24 | { 25 | _disposed = true; 26 | _dbContext.Dispose(); 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Management.Infrastructure/Management.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Management.Infrastructure/Migrations/20201124223229_InitCreate.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Management.Infrastructure; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace Management.Infrastructure.Migrations 11 | { 12 | [DbContext(typeof(AppDbContext))] 13 | [Migration("20201124223229_InitCreate")] 14 | partial class InitCreate 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "3.1.10") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Management.Domain.Departments.Department", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("smallint") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("CreatedBy") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("CreatedDate") 35 | .HasColumnType("datetime2"); 36 | 37 | b.Property("DepartmentName") 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.Property("IsDeleted") 41 | .HasColumnType("bit"); 42 | 43 | b.Property("UpdatedBy") 44 | .HasColumnType("nvarchar(max)"); 45 | 46 | b.Property("UpdatedDate") 47 | .HasColumnType("datetime2"); 48 | 49 | b.HasKey("Id"); 50 | 51 | b.ToTable("Departments"); 52 | }); 53 | 54 | modelBuilder.Entity("Management.Domain.Salaries.Salary", b => 55 | { 56 | b.Property("Id") 57 | .ValueGeneratedOnAdd() 58 | .HasColumnType("bigint") 59 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 60 | 61 | b.Property("CoefficientsSalary") 62 | .HasColumnType("real"); 63 | 64 | b.Property("CreatedBy") 65 | .HasColumnType("nvarchar(max)"); 66 | 67 | b.Property("CreatedDate") 68 | .HasColumnType("datetime2"); 69 | 70 | b.Property("IsDeleted") 71 | .HasColumnType("bit"); 72 | 73 | b.Property("TotalSalary") 74 | .HasColumnType("decimal(18,2)"); 75 | 76 | b.Property("UpdatedBy") 77 | .HasColumnType("nvarchar(max)"); 78 | 79 | b.Property("UpdatedDate") 80 | .HasColumnType("datetime2"); 81 | 82 | b.Property("UserId") 83 | .HasColumnType("int"); 84 | 85 | b.Property("WorkDays") 86 | .HasColumnType("real"); 87 | 88 | b.HasKey("Id"); 89 | 90 | b.HasIndex("UserId"); 91 | 92 | b.ToTable("Salaries"); 93 | }); 94 | 95 | modelBuilder.Entity("Management.Domain.Users.User", b => 96 | { 97 | b.Property("Id") 98 | .ValueGeneratedOnAdd() 99 | .HasColumnType("int") 100 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 101 | 102 | b.Property("DepartmentId") 103 | .HasColumnType("smallint"); 104 | 105 | b.Property("Email") 106 | .HasColumnType("nvarchar(max)"); 107 | 108 | b.Property("IsDeleted") 109 | .HasColumnType("bit"); 110 | 111 | b.Property("UserName") 112 | .HasColumnType("nvarchar(max)"); 113 | 114 | b.HasKey("Id"); 115 | 116 | b.HasIndex("DepartmentId"); 117 | 118 | b.ToTable("Users"); 119 | }); 120 | 121 | modelBuilder.Entity("Management.Domain.Salaries.Salary", b => 122 | { 123 | b.HasOne("Management.Domain.Users.User", "User") 124 | .WithMany("Salaries") 125 | .HasForeignKey("UserId") 126 | .OnDelete(DeleteBehavior.Cascade) 127 | .IsRequired(); 128 | }); 129 | 130 | modelBuilder.Entity("Management.Domain.Users.User", b => 131 | { 132 | b.HasOne("Management.Domain.Departments.Department", "Department") 133 | .WithMany("Users") 134 | .HasForeignKey("DepartmentId") 135 | .OnDelete(DeleteBehavior.Cascade) 136 | .IsRequired(); 137 | }); 138 | #pragma warning restore 612, 618 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Management.Infrastructure/Migrations/20201124223229_InitCreate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace Management.Infrastructure.Migrations 5 | { 6 | public partial class InitCreate : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "Departments", 12 | columns: table => new 13 | { 14 | Id = table.Column(nullable: false) 15 | .Annotation("SqlServer:Identity", "1, 1"), 16 | IsDeleted = table.Column(nullable: false), 17 | CreatedDate = table.Column(nullable: false), 18 | CreatedBy = table.Column(nullable: true), 19 | UpdatedDate = table.Column(nullable: false), 20 | UpdatedBy = table.Column(nullable: true), 21 | DepartmentName = table.Column(nullable: true) 22 | }, 23 | constraints: table => 24 | { 25 | table.PrimaryKey("PK_Departments", x => x.Id); 26 | }); 27 | 28 | migrationBuilder.CreateTable( 29 | name: "Users", 30 | columns: table => new 31 | { 32 | Id = table.Column(nullable: false) 33 | .Annotation("SqlServer:Identity", "1, 1"), 34 | IsDeleted = table.Column(nullable: false), 35 | UserName = table.Column(nullable: true), 36 | Email = table.Column(nullable: true), 37 | DepartmentId = table.Column(nullable: false) 38 | }, 39 | constraints: table => 40 | { 41 | table.PrimaryKey("PK_Users", x => x.Id); 42 | table.ForeignKey( 43 | name: "FK_Users_Departments_DepartmentId", 44 | column: x => x.DepartmentId, 45 | principalTable: "Departments", 46 | principalColumn: "Id", 47 | onDelete: ReferentialAction.Cascade); 48 | }); 49 | 50 | migrationBuilder.CreateTable( 51 | name: "Salaries", 52 | columns: table => new 53 | { 54 | Id = table.Column(nullable: false) 55 | .Annotation("SqlServer:Identity", "1, 1"), 56 | IsDeleted = table.Column(nullable: false), 57 | CreatedDate = table.Column(nullable: false), 58 | CreatedBy = table.Column(nullable: true), 59 | UpdatedDate = table.Column(nullable: false), 60 | UpdatedBy = table.Column(nullable: true), 61 | UserId = table.Column(nullable: false), 62 | CoefficientsSalary = table.Column(nullable: false), 63 | WorkDays = table.Column(nullable: false), 64 | TotalSalary = table.Column(nullable: false) 65 | }, 66 | constraints: table => 67 | { 68 | table.PrimaryKey("PK_Salaries", x => x.Id); 69 | table.ForeignKey( 70 | name: "FK_Salaries_Users_UserId", 71 | column: x => x.UserId, 72 | principalTable: "Users", 73 | principalColumn: "Id", 74 | onDelete: ReferentialAction.Cascade); 75 | }); 76 | 77 | migrationBuilder.CreateIndex( 78 | name: "IX_Salaries_UserId", 79 | table: "Salaries", 80 | column: "UserId"); 81 | 82 | migrationBuilder.CreateIndex( 83 | name: "IX_Users_DepartmentId", 84 | table: "Users", 85 | column: "DepartmentId"); 86 | } 87 | 88 | protected override void Down(MigrationBuilder migrationBuilder) 89 | { 90 | migrationBuilder.DropTable( 91 | name: "Salaries"); 92 | 93 | migrationBuilder.DropTable( 94 | name: "Users"); 95 | 96 | migrationBuilder.DropTable( 97 | name: "Departments"); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Management.Infrastructure/Migrations/20201125155843_UpdateAuditEntity.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Management.Infrastructure; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace Management.Infrastructure.Migrations 11 | { 12 | [DbContext(typeof(AppDbContext))] 13 | [Migration("20201125155843_UpdateAuditEntity")] 14 | partial class UpdateAuditEntity 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "3.1.10") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Management.Domain.Departments.Department", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd() 28 | .HasColumnType("smallint") 29 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 30 | 31 | b.Property("CreatedBy") 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("CreatedDate") 35 | .HasColumnType("datetime2"); 36 | 37 | b.Property("DepartmentName") 38 | .HasColumnType("nvarchar(max)"); 39 | 40 | b.Property("IsDeleted") 41 | .HasColumnType("bit"); 42 | 43 | b.Property("UpdatedBy") 44 | .HasColumnType("nvarchar(max)"); 45 | 46 | b.Property("UpdatedDate") 47 | .HasColumnType("datetime2"); 48 | 49 | b.HasKey("Id"); 50 | 51 | b.ToTable("Departments"); 52 | }); 53 | 54 | modelBuilder.Entity("Management.Domain.Salaries.Salary", b => 55 | { 56 | b.Property("Id") 57 | .ValueGeneratedOnAdd() 58 | .HasColumnType("bigint") 59 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 60 | 61 | b.Property("CoefficientsSalary") 62 | .HasColumnType("real"); 63 | 64 | b.Property("CreatedBy") 65 | .HasColumnType("nvarchar(max)"); 66 | 67 | b.Property("CreatedDate") 68 | .HasColumnType("datetime2"); 69 | 70 | b.Property("IsDeleted") 71 | .HasColumnType("bit"); 72 | 73 | b.Property("TotalSalary") 74 | .HasColumnType("decimal(18,2)"); 75 | 76 | b.Property("UpdatedBy") 77 | .HasColumnType("nvarchar(max)"); 78 | 79 | b.Property("UpdatedDate") 80 | .HasColumnType("datetime2"); 81 | 82 | b.Property("UserId") 83 | .HasColumnType("int"); 84 | 85 | b.Property("WorkDays") 86 | .HasColumnType("real"); 87 | 88 | b.HasKey("Id"); 89 | 90 | b.HasIndex("UserId"); 91 | 92 | b.ToTable("Salaries"); 93 | }); 94 | 95 | modelBuilder.Entity("Management.Domain.Users.User", b => 96 | { 97 | b.Property("Id") 98 | .ValueGeneratedOnAdd() 99 | .HasColumnType("int") 100 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 101 | 102 | b.Property("DepartmentId") 103 | .HasColumnType("smallint"); 104 | 105 | b.Property("Email") 106 | .HasColumnType("nvarchar(max)"); 107 | 108 | b.Property("IsDeleted") 109 | .HasColumnType("bit"); 110 | 111 | b.Property("UserName") 112 | .HasColumnType("nvarchar(max)"); 113 | 114 | b.HasKey("Id"); 115 | 116 | b.HasIndex("DepartmentId"); 117 | 118 | b.ToTable("Users"); 119 | }); 120 | 121 | modelBuilder.Entity("Management.Domain.Salaries.Salary", b => 122 | { 123 | b.HasOne("Management.Domain.Users.User", "User") 124 | .WithMany("Salaries") 125 | .HasForeignKey("UserId") 126 | .OnDelete(DeleteBehavior.Cascade) 127 | .IsRequired(); 128 | }); 129 | 130 | modelBuilder.Entity("Management.Domain.Users.User", b => 131 | { 132 | b.HasOne("Management.Domain.Departments.Department", "Department") 133 | .WithMany("Users") 134 | .HasForeignKey("DepartmentId") 135 | .OnDelete(DeleteBehavior.Cascade) 136 | .IsRequired(); 137 | }); 138 | #pragma warning restore 612, 618 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Management.Infrastructure/Migrations/20201125155843_UpdateAuditEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | namespace Management.Infrastructure.Migrations 5 | { 6 | public partial class UpdateAuditEntity : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.AlterColumn( 11 | name: "UpdatedDate", 12 | table: "Salaries", 13 | nullable: true, 14 | oldClrType: typeof(DateTime), 15 | oldType: "datetime2"); 16 | 17 | migrationBuilder.AlterColumn( 18 | name: "UpdatedDate", 19 | table: "Departments", 20 | nullable: true, 21 | oldClrType: typeof(DateTime), 22 | oldType: "datetime2"); 23 | } 24 | 25 | protected override void Down(MigrationBuilder migrationBuilder) 26 | { 27 | migrationBuilder.AlterColumn( 28 | name: "UpdatedDate", 29 | table: "Salaries", 30 | type: "datetime2", 31 | nullable: false, 32 | oldClrType: typeof(DateTime), 33 | oldNullable: true); 34 | 35 | migrationBuilder.AlterColumn( 36 | name: "UpdatedDate", 37 | table: "Departments", 38 | type: "datetime2", 39 | nullable: false, 40 | oldClrType: typeof(DateTime), 41 | oldNullable: true); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Management.Infrastructure/Migrations/AppDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using Management.Infrastructure; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | namespace Management.Infrastructure.Migrations 10 | { 11 | [DbContext(typeof(AppDbContext))] 12 | partial class AppDbContextModelSnapshot : ModelSnapshot 13 | { 14 | protected override void BuildModel(ModelBuilder modelBuilder) 15 | { 16 | #pragma warning disable 612, 618 17 | modelBuilder 18 | .HasAnnotation("ProductVersion", "3.1.10") 19 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 20 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 21 | 22 | modelBuilder.Entity("Management.Domain.Departments.Department", b => 23 | { 24 | b.Property("Id") 25 | .ValueGeneratedOnAdd() 26 | .HasColumnType("smallint") 27 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 28 | 29 | b.Property("CreatedBy") 30 | .HasColumnType("nvarchar(max)"); 31 | 32 | b.Property("CreatedDate") 33 | .HasColumnType("datetime2"); 34 | 35 | b.Property("DepartmentName") 36 | .HasColumnType("nvarchar(max)"); 37 | 38 | b.Property("IsDeleted") 39 | .HasColumnType("bit"); 40 | 41 | b.Property("UpdatedBy") 42 | .HasColumnType("nvarchar(max)"); 43 | 44 | b.Property("UpdatedDate") 45 | .HasColumnType("datetime2"); 46 | 47 | b.HasKey("Id"); 48 | 49 | b.ToTable("Departments"); 50 | }); 51 | 52 | modelBuilder.Entity("Management.Domain.Salaries.Salary", b => 53 | { 54 | b.Property("Id") 55 | .ValueGeneratedOnAdd() 56 | .HasColumnType("bigint") 57 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 58 | 59 | b.Property("CoefficientsSalary") 60 | .HasColumnType("real"); 61 | 62 | b.Property("CreatedBy") 63 | .HasColumnType("nvarchar(max)"); 64 | 65 | b.Property("CreatedDate") 66 | .HasColumnType("datetime2"); 67 | 68 | b.Property("IsDeleted") 69 | .HasColumnType("bit"); 70 | 71 | b.Property("TotalSalary") 72 | .HasColumnType("decimal(18,2)"); 73 | 74 | b.Property("UpdatedBy") 75 | .HasColumnType("nvarchar(max)"); 76 | 77 | b.Property("UpdatedDate") 78 | .HasColumnType("datetime2"); 79 | 80 | b.Property("UserId") 81 | .HasColumnType("int"); 82 | 83 | b.Property("WorkDays") 84 | .HasColumnType("real"); 85 | 86 | b.HasKey("Id"); 87 | 88 | b.HasIndex("UserId"); 89 | 90 | b.ToTable("Salaries"); 91 | }); 92 | 93 | modelBuilder.Entity("Management.Domain.Users.User", b => 94 | { 95 | b.Property("Id") 96 | .ValueGeneratedOnAdd() 97 | .HasColumnType("int") 98 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 99 | 100 | b.Property("DepartmentId") 101 | .HasColumnType("smallint"); 102 | 103 | b.Property("Email") 104 | .HasColumnType("nvarchar(max)"); 105 | 106 | b.Property("IsDeleted") 107 | .HasColumnType("bit"); 108 | 109 | b.Property("UserName") 110 | .HasColumnType("nvarchar(max)"); 111 | 112 | b.HasKey("Id"); 113 | 114 | b.HasIndex("DepartmentId"); 115 | 116 | b.ToTable("Users"); 117 | }); 118 | 119 | modelBuilder.Entity("Management.Domain.Salaries.Salary", b => 120 | { 121 | b.HasOne("Management.Domain.Users.User", "User") 122 | .WithMany("Salaries") 123 | .HasForeignKey("UserId") 124 | .OnDelete(DeleteBehavior.Cascade) 125 | .IsRequired(); 126 | }); 127 | 128 | modelBuilder.Entity("Management.Domain.Users.User", b => 129 | { 130 | b.HasOne("Management.Domain.Departments.Department", "Department") 131 | .WithMany("Users") 132 | .HasForeignKey("DepartmentId") 133 | .OnDelete(DeleteBehavior.Cascade) 134 | .IsRequired(); 135 | }); 136 | #pragma warning restore 612, 618 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Management.Infrastructure/Repositories/DepartmentRepository.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Departments; 2 | using Management.Domain.Interfaces; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Management.Infrastructure.Repositories 8 | { 9 | public class DepartmentRepository : Repository, IDepartmentRepository 10 | { 11 | public DepartmentRepository(DbFactory dbFactory) : base(dbFactory) 12 | { 13 | } 14 | 15 | public Department AddDepartment(string departmentName) 16 | { 17 | var department = new Department(departmentName); 18 | if (department.ValidOnAdd()) 19 | { 20 | this.Add(department); 21 | return department; 22 | } 23 | else 24 | throw new Exception("Department invalid"); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Management.Infrastructure/Repositories/SalaryRepository.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Interfaces; 2 | using Management.Domain.Salaries; 3 | using Management.Domain.Users; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Management.Infrastructure.Repositories 9 | { 10 | public class SalaryRepository : Repository, ISalaryRepository 11 | { 12 | public SalaryRepository(DbFactory dbFactory) : base(dbFactory) 13 | { 14 | } 15 | 16 | public Salary AddUserSalary(User user, float coefficientsSalary, float workdays) 17 | { 18 | var salary = new Salary(user, coefficientsSalary, workdays); 19 | if (salary.ValidOnAdd()) 20 | { 21 | this.Add(salary); 22 | return salary; 23 | } 24 | else 25 | throw new Exception("Salary invalid"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Management.Infrastructure/Repositories/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Departments; 2 | using Management.Domain.Interfaces; 3 | using Management.Domain.Users; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | 8 | namespace Management.Infrastructure.Repositories 9 | { 10 | public class UserRepository : Repository, IUserRepository 11 | { 12 | public UserRepository(DbFactory dbFactory) : base(dbFactory) 13 | { 14 | } 15 | 16 | public User NewUser(string userName, string email, Department department) 17 | { 18 | var user = new User(userName, email, department); 19 | if (user.ValidOnAdd()) 20 | { 21 | this.Add(user); 22 | return user; 23 | } 24 | else 25 | throw new Exception("User invalid"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Management.Infrastructure/Repository.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Base; 2 | using Management.Domain.Interfaces; 3 | using Microsoft.EntityFrameworkCore; 4 | using System; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | 8 | namespace Management.Infrastructure 9 | { 10 | public class Repository : IRepository where T : class 11 | { 12 | private readonly DbFactory _dbFactory; 13 | private DbSet _dbSet; 14 | 15 | protected DbSet DbSet 16 | { 17 | get => _dbSet ?? (_dbSet = _dbFactory.DbContext.Set()); 18 | } 19 | 20 | public Repository(DbFactory dbFactory) 21 | { 22 | _dbFactory = dbFactory; 23 | } 24 | 25 | public void Add(T entity) 26 | { 27 | if (typeof(IAuditEntity).IsAssignableFrom(typeof(T))) 28 | { 29 | ((IAuditEntity)entity).CreatedDate = DateTime.UtcNow; 30 | } 31 | DbSet.Add(entity); 32 | } 33 | 34 | public void Delete(T entity) 35 | { 36 | if (typeof(IDeleteEntity).IsAssignableFrom(typeof(T))) 37 | { 38 | ((IDeleteEntity)entity).IsDeleted = true; 39 | DbSet.Update(entity); 40 | } 41 | else 42 | DbSet.Remove(entity); 43 | } 44 | 45 | public IQueryable List(Expression> expression) 46 | { 47 | return DbSet.Where(expression); 48 | } 49 | 50 | public void Update(T entity) 51 | { 52 | if (typeof(IAuditEntity).IsAssignableFrom(typeof(T))) 53 | { 54 | ((IAuditEntity)entity).UpdatedDate = DateTime.UtcNow; 55 | } 56 | DbSet.Update(entity); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Management.Infrastructure/UnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using Management.Domain.Interfaces; 2 | using Microsoft.EntityFrameworkCore; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Management.Infrastructure 9 | { 10 | public class UnitOfWork : IUnitOfWork 11 | { 12 | private DbFactory _dbFactory; 13 | 14 | public UnitOfWork(DbFactory dbFactory) 15 | { 16 | _dbFactory = dbFactory; 17 | } 18 | 19 | public Task CommitAsync() 20 | { 21 | return _dbFactory.DbContext.SaveChangesAsync(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Management.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30523.141 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Management.API", "Management.API\Management.API.csproj", "{3063C97B-E1B1-4542-B50F-15BDF89A0125}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Management.Domain", "Management.Domain\Management.Domain.csproj", "{33638CD1-6AF7-4B06-AD12-729DE9B72A97}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Management.Infrastructure", "Management.Infrastructure\Management.Infrastructure.csproj", "{EA6FD624-53CF-45F1-823A-BF7ABF27F007}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {3063C97B-E1B1-4542-B50F-15BDF89A0125}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {3063C97B-E1B1-4542-B50F-15BDF89A0125}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {3063C97B-E1B1-4542-B50F-15BDF89A0125}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {3063C97B-E1B1-4542-B50F-15BDF89A0125}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {33638CD1-6AF7-4B06-AD12-729DE9B72A97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {33638CD1-6AF7-4B06-AD12-729DE9B72A97}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {33638CD1-6AF7-4B06-AD12-729DE9B72A97}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {33638CD1-6AF7-4B06-AD12-729DE9B72A97}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {EA6FD624-53CF-45F1-823A-BF7ABF27F007}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {EA6FD624-53CF-45F1-823A-BF7ABF27F007}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {EA6FD624-53CF-45F1-823A-BF7ABF27F007}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {EA6FD624-53CF-45F1-823A-BF7ABF27F007}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {307747B9-B22D-4270-9B3B-1BFAAEF2194C} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Repository_UnitOfWork_Example 2 | This is just the basic framework of a DDD project using the Repository & UnitOfWork pattern. 3 | -------------------------------------------------------------------------------- /gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | # Define all pepeline stages names 2 | stages: 3 | - BE_Build 4 | 5 | # Accounting 6 | Accounting_Deploy: 7 | stage: BE_Build 8 | script: 9 | - echo 'hello' 10 | tags: 11 | - eldesk-dev 12 | 13 | --------------------------------------------------------------------------------