Добавил файлы. Сделал миграцию.
This commit is contained in:
parent
1ddd362ab7
commit
7847a4e41a
@ -1,31 +1,165 @@
|
||||
using EmployeeManagmentContracts.BindingModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using EmployeeManagmentContracts.BindingModels;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using EmployeeManagmentContracts.SearchModels;
|
||||
using EmployeeManagmentContracts.StoragesContracts;
|
||||
using EmployeeManagmentContracts.ViewModels;
|
||||
using EmployeeManagmentDataBaseImplement;
|
||||
using EmployeeManagmentDataBaseImplement.Models;
|
||||
|
||||
namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class EmployeeLogic : IEmployeeLogic
|
||||
{
|
||||
private readonly EmployeeManagementDbContext _context;
|
||||
|
||||
public EmployeeLogic(EmployeeManagementDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void CreateOrUpdate(EmployeeBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// Проверка на обязательные поля
|
||||
if (string.IsNullOrWhiteSpace(model.NameJob))
|
||||
{
|
||||
throw new ArgumentException("Job name cannot be empty.");
|
||||
}
|
||||
|
||||
// Ищем сотрудника по ID, если он уже существует
|
||||
var employee = _context.Employees.FirstOrDefault(e => e.Id == model.Id);
|
||||
|
||||
if (employee == null)
|
||||
{
|
||||
// Создаем нового сотрудника, если не найден
|
||||
employee = new Employee
|
||||
{
|
||||
NameJob = model.NameJob,
|
||||
StartJob = model.StartJob,
|
||||
EndJob = model.EndJob,
|
||||
PartTimeJob = model.PartTimeJob,
|
||||
Bid = model.Bid,
|
||||
PhisicalPersonsId = model.PhisicalPersonsId
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
_context.Employees.Add(employee);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Логирование ошибки и обработка
|
||||
throw new InvalidOperationException("Error while adding new employee: " + ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Обновляем данные существующего сотрудника
|
||||
employee.NameJob = model.NameJob;
|
||||
employee.StartJob = model.StartJob;
|
||||
employee.EndJob = model.EndJob;
|
||||
employee.PartTimeJob = model.PartTimeJob;
|
||||
employee.Bid = model.Bid;
|
||||
employee.PhisicalPersonsId = model.PhisicalPersonsId;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Логирование ошибки и обработка
|
||||
throw new InvalidOperationException("Error while updating employee: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var employee = _context.Employees.FirstOrDefault(e => e.Id == id);
|
||||
if (employee != null)
|
||||
{
|
||||
// Дополнительная проверка на связи с другими таблицами, если необходимо
|
||||
if (employee.Salaries.Any() || employee.Vacations.Any())
|
||||
{
|
||||
throw new InvalidOperationException("Employee cannot be deleted because they have related data (e.g., salaries or vacations).");
|
||||
}
|
||||
|
||||
_context.Employees.Remove(employee);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new KeyNotFoundException($"Employee with ID {id} not found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public EmployeeViewModel? GetEmployeeById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var employee = _context.Employees
|
||||
.Where(e => e.Id == id)
|
||||
.Select(e => new EmployeeViewModel
|
||||
{
|
||||
Id = e.Id,
|
||||
NameJob = e.NameJob,
|
||||
StartJob = e.StartJob,
|
||||
EndJob = e.EndJob,
|
||||
PartTimeJob = e.PartTimeJob,
|
||||
Bid = e.Bid,
|
||||
PhysicalPersonsId = e.PhisicalPersonsId,
|
||||
PhysicalPersonName = e.PhisicalPerson != null ? e.PhisicalPerson.Name : null
|
||||
})
|
||||
.FirstOrDefault();
|
||||
|
||||
return employee;
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetEmployees(EmployeeSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var query = _context.Employees.AsQueryable();
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
query = query.Where(e => e.Id == model.Id.Value);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(model.NameJob))
|
||||
{
|
||||
query = query.Where(e => e.NameJob.Contains(model.NameJob));
|
||||
}
|
||||
|
||||
if (model.StartDateFrom.HasValue)
|
||||
{
|
||||
query = query.Where(e => e.StartJob >= model.StartDateFrom.Value);
|
||||
}
|
||||
|
||||
if (model.StartDateTo.HasValue)
|
||||
{
|
||||
query = query.Where(e => e.StartJob <= model.StartDateTo.Value);
|
||||
}
|
||||
|
||||
if (model.Bid.HasValue)
|
||||
{
|
||||
query = query.Where(e => e.Bid == model.Bid.Value);
|
||||
}
|
||||
|
||||
return query
|
||||
.Select(e => new EmployeeViewModel
|
||||
{
|
||||
Id = e.Id,
|
||||
NameJob = e.NameJob,
|
||||
StartJob = e.StartJob,
|
||||
EndJob = e.EndJob,
|
||||
PartTimeJob = e.PartTimeJob,
|
||||
Bid = e.Bid,
|
||||
PhysicalPersonsId = e.PhisicalPersonsId,
|
||||
PhysicalPersonName = e.PhisicalPerson != null ? e.PhisicalPerson.Name : null
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using EmployeeManagmentContracts.SearchModels;
|
||||
using EmployeeManagmentContracts.ViewModels;
|
||||
using EmployeeManagmentDataBaseImplement.Models;
|
||||
using EmployeeManagmentDataBaseImplement;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -12,24 +14,110 @@ namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class PhisicalPersonLogic : IPhisicalPersonLogic
|
||||
{
|
||||
private readonly EmployeeManagementDbContext _context;
|
||||
|
||||
public PhisicalPersonLogic(EmployeeManagementDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public void CreateOrUpdate(PhisicalPersonBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
PhisicalPerson? person = _context.PhysicalPersons
|
||||
.FirstOrDefault(p => p.Id == model.Id);
|
||||
|
||||
if (person == null)
|
||||
{
|
||||
// Создание нового
|
||||
person = new PhisicalPerson
|
||||
{
|
||||
Name = model.Name,
|
||||
Surname = model.Surname,
|
||||
Patronymic = model.Patronomic,
|
||||
Birthday = model.Birthday,
|
||||
Gender = model.Gender,
|
||||
Address = model.Address,
|
||||
Telephone = model.Telephone
|
||||
};
|
||||
_context.PhysicalPersons.Add(person);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Обновление существующего
|
||||
person.Name = model.Name;
|
||||
person.Surname = model.Surname;
|
||||
person.Patronymic = model.Patronomic;
|
||||
person.Birthday = model.Birthday;
|
||||
person.Gender = model.Gender;
|
||||
person.Address = model.Address;
|
||||
person.Telephone = model.Telephone;
|
||||
}
|
||||
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var person = _context.PhysicalPersons.FirstOrDefault(p => p.Id == id);
|
||||
if (person != null)
|
||||
{
|
||||
_context.PhysicalPersons.Remove(person);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public PhisicalPersonViewModel? GetPhisicalPersonById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var person = _context.PhysicalPersons
|
||||
.Where(p => p.Id == id)
|
||||
.Select(p => new PhisicalPersonViewModel
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Name,
|
||||
Surname = p.Surname,
|
||||
Patronomic = p.Patronymic,
|
||||
Birthday = p.Birthday,
|
||||
Gender = p.Gender,
|
||||
Address = p.Address,
|
||||
Telephone = p.Telephone
|
||||
})
|
||||
.FirstOrDefault();
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
public List<PhisicalPersonViewModel> GetPhisicalPersons(PhisicalPersonSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var query = _context.PhysicalPersons.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
query = query.Where(p => p.Name.Contains(model.Name));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model.Surname))
|
||||
{
|
||||
query = query.Where(p => p.Surname.Contains(model.Surname));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model.Patronomic))
|
||||
{
|
||||
query = query.Where(p => p.Patronymic.Contains(model.Patronomic));
|
||||
}
|
||||
|
||||
return query
|
||||
.Select(p => new PhisicalPersonViewModel
|
||||
{
|
||||
Id = p.Id,
|
||||
Name = p.Name,
|
||||
Surname = p.Surname,
|
||||
Patronomic = p.Patronymic,
|
||||
Birthday = p.Birthday,
|
||||
Gender = p.Gender,
|
||||
Address = p.Address,
|
||||
Telephone = p.Telephone
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EmployeeManagmentContracts\EmployeeManagmentContracts.csproj" />
|
||||
<ProjectReference Include="..\EmployeeManagmentDataBaseImplement\EmployeeManagmentDataBaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -14,6 +14,6 @@ namespace EmployeeManagmentContracts.BindingModels
|
||||
public DateTime? EndJob { get; set; }
|
||||
public string? PartTimeJob { get; set; }
|
||||
public float Bid { get; set; }
|
||||
public int PhisicalPersonId { get; set; }
|
||||
public int PhisicalPersonsId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,12 @@ namespace EmployeeManagmentContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string NameJob { get; set; } = string.Empty;
|
||||
public DateTime StartJob { get; set; }
|
||||
public DateTime? StartJob { get; set; }
|
||||
public DateTime? EndJob { get; set; }
|
||||
public string? PartTimeJob { get; set; }
|
||||
public float Bid { get; set; }
|
||||
public string PhisicalPersonName { get; set; } = string.Empty;
|
||||
public int PhysicalPersonsId { get; set; }
|
||||
public string? PhysicalPersonName { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,23 +1,24 @@
|
||||
using EmployeeManagmentDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement
|
||||
{
|
||||
public class EmployeeManagementDbContext : DbContext
|
||||
{
|
||||
public DbSet<Employee> Employees { get; set; }
|
||||
public DbSet<PhisicalPerson> PhisicalPersons { get; set; }
|
||||
public DbSet<Salary> Salaries { get; set; }
|
||||
public DbSet<Vacation> Vacations { get; set; }
|
||||
// DbSets для моделей
|
||||
public virtual DbSet<Employee> Employees { get; set; }
|
||||
public virtual DbSet<PhisicalPerson> PhysicalPersons { get; set; }
|
||||
public virtual DbSet<Salary> Salaries { get; set; }
|
||||
public virtual DbSet<Vacation> Vacations { get; set; }
|
||||
|
||||
// Метод для настройки конфигурации
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseSqlServer("YourConnectionStringHere");
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
optionsBuilder.UseMySQL("Server=localhost;Port=3306;Database=EmployeeDB;User=root;Password=SuperSecretPasswork2003;");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="MySql.EntityFrameworkCore" Version="8.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
197
EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.Designer.cs
generated
Normal file
197
EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.Designer.cs
generated
Normal file
@ -0,0 +1,197 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using EmployeeManagmentDataBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(EmployeeManagementDbContext))]
|
||||
[Migration("20241113084724_InitialMigration")]
|
||||
partial class InitialMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<float>("Bid")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<DateTime?>("EndJob")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("NameJob")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("PartTimeJob")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("PhisicalPersonsId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("StartJob")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PhisicalPersonsId");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<DateTime>("Birthday")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Gender")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Patronymic")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Surname")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Telephone")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("PhysicalPersons");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Salary", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("CountHours")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("Data")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<int>("EmployeesId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Passed")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<float?>("Premium")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<float>("PriceHour")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeesId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Vacation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("EmployeesId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("EndData")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<bool>("Passed")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTime>("StartData")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeesId");
|
||||
|
||||
b.ToTable("Vacations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.HasOne("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", "PhisicalPerson")
|
||||
.WithMany("Employees")
|
||||
.HasForeignKey("PhisicalPersonsId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PhisicalPerson");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("EmployeeManagmentDataBaseImplement.Models.Employee", "Employee")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("EmployeesId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Vacation", b =>
|
||||
{
|
||||
b.HasOne("EmployeeManagmentDataBaseImplement.Models.Employee", "Employee")
|
||||
.WithMany("Vacations")
|
||||
.HasForeignKey("EmployeesId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("Vacations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", b =>
|
||||
{
|
||||
b.Navigation("Employees");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using MySql.EntityFrameworkCore.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PhysicalPersons",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(type: "longtext", nullable: false),
|
||||
Surname = table.Column<string>(type: "longtext", nullable: false),
|
||||
Patronymic = table.Column<string>(type: "longtext", nullable: true),
|
||||
Birthday = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
Gender = table.Column<string>(type: "longtext", nullable: false),
|
||||
Address = table.Column<string>(type: "longtext", nullable: false),
|
||||
Telephone = table.Column<string>(type: "longtext", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PhysicalPersons", x => x.Id);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Employees",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
||||
NameJob = table.Column<string>(type: "longtext", nullable: false),
|
||||
StartJob = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
EndJob = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
PartTimeJob = table.Column<string>(type: "longtext", nullable: true),
|
||||
Bid = table.Column<float>(type: "float", nullable: false),
|
||||
PhisicalPersonsId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Employees", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Employees_PhysicalPersons_PhisicalPersonsId",
|
||||
column: x => x.PhisicalPersonsId,
|
||||
principalTable: "PhysicalPersons",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Salaries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
||||
CountHours = table.Column<int>(type: "int", nullable: false),
|
||||
PriceHour = table.Column<float>(type: "float", nullable: false),
|
||||
Premium = table.Column<float>(type: "float", nullable: true),
|
||||
Data = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
Passed = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
EmployeesId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Salaries", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Salaries_Employees_EmployeesId",
|
||||
column: x => x.EmployeesId,
|
||||
principalTable: "Employees",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Vacations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
||||
StartData = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
EndData = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
Passed = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
EmployeesId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Vacations", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Vacations_Employees_EmployeesId",
|
||||
column: x => x.EmployeesId,
|
||||
principalTable: "Employees",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Employees_PhisicalPersonsId",
|
||||
table: "Employees",
|
||||
column: "PhisicalPersonsId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Salaries_EmployeesId",
|
||||
table: "Salaries",
|
||||
column: "EmployeesId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Vacations_EmployeesId",
|
||||
table: "Vacations",
|
||||
column: "EmployeesId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Salaries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Vacations");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Employees");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PhysicalPersons");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,194 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using EmployeeManagmentDataBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(EmployeeManagementDbContext))]
|
||||
partial class EmployeeManagementDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<float>("Bid")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<DateTime?>("EndJob")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("NameJob")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("PartTimeJob")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("PhisicalPersonsId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("StartJob")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PhisicalPersonsId");
|
||||
|
||||
b.ToTable("Employees");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<DateTime>("Birthday")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<string>("Gender")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Patronymic")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Surname")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<string>("Telephone")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("PhysicalPersons");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Salary", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("CountHours")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("Data")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<int>("EmployeesId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Passed")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<float?>("Premium")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<float>("PriceHour")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeesId");
|
||||
|
||||
b.ToTable("Salaries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Vacation", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("EmployeesId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("EndData")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<bool>("Passed")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<DateTime>("StartData")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("EmployeesId");
|
||||
|
||||
b.ToTable("Vacations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.HasOne("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", "PhisicalPerson")
|
||||
.WithMany("Employees")
|
||||
.HasForeignKey("PhisicalPersonsId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("PhisicalPerson");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Salary", b =>
|
||||
{
|
||||
b.HasOne("EmployeeManagmentDataBaseImplement.Models.Employee", "Employee")
|
||||
.WithMany("Salaries")
|
||||
.HasForeignKey("EmployeesId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Vacation", b =>
|
||||
{
|
||||
b.HasOne("EmployeeManagmentDataBaseImplement.Models.Employee", "Employee")
|
||||
.WithMany("Vacations")
|
||||
.HasForeignKey("EmployeesId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Employee");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Navigation("Salaries");
|
||||
|
||||
b.Navigation("Vacations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", b =>
|
||||
{
|
||||
b.Navigation("Employees");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using EmployeeManagmentDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EmployeeManagmentDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Models
|
||||
{
|
||||
public class Employee
|
||||
public class Employee : IEmployee
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string NameJob { get; set; } = string.Empty;
|
||||
|
||||
public DateTime? StartJob { get; set; }
|
||||
public DateTime? EndJob { get; set; }
|
||||
|
||||
public string? PartTimeJob { get; set; }
|
||||
|
||||
public float Bid { get; set; }
|
||||
|
||||
[ForeignKey("PhysicalPerson")]
|
||||
public int PhysicalPersonsId { get; set; }
|
||||
public PhysicalPerson? PhysicalPerson { get; set; }
|
||||
[ForeignKey("PhisicalPerson")]
|
||||
public int PhisicalPersonsId { get; set; }
|
||||
public PhisicalPerson? PhisicalPerson { get; set; }
|
||||
|
||||
public List<Salary> Salaries { get; set; } = new();
|
||||
public List<Vacation> Vacations { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using EmployeeManagmentDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
@ -7,21 +8,27 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Models
|
||||
{
|
||||
public class PhisicalPerson
|
||||
public class PhisicalPerson : IPhisicalPerson
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Surname { get; set; } = string.Empty;
|
||||
|
||||
public string? Patronymic { get; set; }
|
||||
[Required]
|
||||
public DateTime Birthday { get; set; }
|
||||
[Required]
|
||||
public string Gender { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Telephone { get; set; } = string.Empty;
|
||||
|
||||
// Связь с сотрудниками
|
||||
public List<Employee>? Employees { get; set; }
|
||||
public List<Employee> Employees { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EmployeeManagmentDataModels.Models;
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Models
|
||||
{
|
||||
public class Salary
|
||||
public class Salary : ISalary
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public int CountHours { get; set; }
|
||||
public float PriceHour { get; set; }
|
||||
public float? Premium { get; set; }
|
||||
public DateTime? Data { get; set; }
|
||||
public bool Passed { get; set; }
|
||||
|
||||
[ForeignKey("Employee")]
|
||||
public int EmployeesId { get; set; }
|
||||
public Employee? Employee { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using EmployeeManagmentDataModels.Models;
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Models
|
||||
{
|
||||
public class Vacation
|
||||
public class Vacation : IVacation
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime StartData { get; set; }
|
||||
public DateTime EndData { get; set; }
|
||||
public bool Passed { get; set; }
|
||||
|
||||
[ForeignKey("Employee")]
|
||||
public int EmployeesId { get; set; }
|
||||
public Employee? Employee { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,23 @@
|
||||
version: '3.9'
|
||||
|
||||
services:
|
||||
sqlserver-db:
|
||||
image: mcr.microsoft.com/mssql/server:2022-latest
|
||||
container_name: sqlserver-db
|
||||
environment:
|
||||
- ACCEPT_EULA=Y
|
||||
- SA_PASSWORD=YourStrong@Password123
|
||||
- MSSQL_PID=Express
|
||||
ports:
|
||||
- "1433:1433"
|
||||
volumes:
|
||||
- sql_data:/var/opt/mssql
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
container_name: employee_db
|
||||
restart: always
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: SuperSecretPasswork2003
|
||||
MYSQL_DATABASE: EmployeeDB
|
||||
ports:
|
||||
- "3306:3306"
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
networks:
|
||||
- employee_network
|
||||
|
||||
volumes:
|
||||
sql_data:
|
||||
mysql_data:
|
||||
|
||||
networks:
|
||||
employee_network:
|
||||
driver: bridge
|
@ -1,25 +0,0 @@
|
||||
using EmployeeManagmentDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataModels.Models
|
||||
{
|
||||
public class Employee
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string NameJob { get; set; } = string.Empty;
|
||||
public DateTime StartJob { get; set; }
|
||||
public DateTime? EndJob { get; set; }
|
||||
public JobType PartTimeJob { get; set; }
|
||||
public decimal Bid { get; set; } // Ставка
|
||||
public int PhysicalPersonId { get; set; }
|
||||
|
||||
// Связь с физическим лицом
|
||||
public PhysicalPerson? PhysicalPerson { get; set; }
|
||||
public List<Salary>? Salaries { get; set; }
|
||||
public List<Vacation>? Vacations { get; set; }
|
||||
}
|
||||
}
|
20
EmployeeManagmentDataModels/Models/IEmployee.cs
Normal file
20
EmployeeManagmentDataModels/Models/IEmployee.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using EmployeeManagmentDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataModels.Models
|
||||
{
|
||||
public interface IEmployee
|
||||
{
|
||||
int Id { get; set; }
|
||||
string NameJob { get; set; }
|
||||
DateTime? StartJob { get; set; }
|
||||
DateTime? EndJob { get; set; }
|
||||
string? PartTimeJob { get; set; }
|
||||
float Bid { get; set; }
|
||||
int PhisicalPersonsId { get; set; }
|
||||
}
|
||||
}
|
20
EmployeeManagmentDataModels/Models/IPhisicalPerson.cs
Normal file
20
EmployeeManagmentDataModels/Models/IPhisicalPerson.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataModels.Models
|
||||
{
|
||||
public interface IPhisicalPerson
|
||||
{
|
||||
int Id { get; set; }
|
||||
string Name { get; set; }
|
||||
string Surname { get; set; }
|
||||
string? Patronymic { get; set; }
|
||||
DateTime Birthday { get; set; }
|
||||
string Gender { get; set; }
|
||||
string Address { get; set; }
|
||||
string Telephone { get; set; }
|
||||
}
|
||||
}
|
19
EmployeeManagmentDataModels/Models/ISalary.cs
Normal file
19
EmployeeManagmentDataModels/Models/ISalary.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataModels.Models
|
||||
{
|
||||
public interface ISalary
|
||||
{
|
||||
int Id { get; set; }
|
||||
int CountHours { get; set; }
|
||||
float PriceHour { get; set; }
|
||||
float? Premium { get; set; }
|
||||
DateTime? Data { get; set; }
|
||||
bool Passed { get; set; }
|
||||
int EmployeesId { get; set; }
|
||||
}
|
||||
}
|
18
EmployeeManagmentDataModels/Models/IVacation.cs
Normal file
18
EmployeeManagmentDataModels/Models/IVacation.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using EmployeeManagmentDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataModels.Models
|
||||
{
|
||||
public interface IVacation
|
||||
{
|
||||
int Id { get; set; }
|
||||
DateTime StartData { get; set; }
|
||||
DateTime EndData { get; set; }
|
||||
bool Passed { get; set; }
|
||||
int EmployeesId { get; set; }
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataModels.Models
|
||||
{
|
||||
public class PhysicalPerson
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public DateTime BirthDate { get; set; }
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
// Связь с сотрудниками
|
||||
public List<Employee>? Employees { get; set; }
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataModels.Models
|
||||
{
|
||||
public class Salary
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int CountHours { get; set; }
|
||||
public decimal PriceHour { get; set; }
|
||||
public decimal Premium { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public bool Passed { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
// Связь с сотрудником
|
||||
public Employee? Employee { get; set; }
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
using EmployeeManagmentDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataModels.Models
|
||||
{
|
||||
public class Vacation
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime StartData { get; set; }
|
||||
public DateTime EndData { get; set; }
|
||||
public VacationStatus Passed { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
// Связь с сотрудником
|
||||
public Employee? Employee { get; set; }
|
||||
}
|
||||
}
|
@ -1,14 +1,47 @@
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using EmployeeManagmentDataBaseImplement;
|
||||
using EmployeeManagmentBusinessLogic.BusinessLogic;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Windows;
|
||||
|
||||
namespace EmployeeManagmentView
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
var serviceCollection = new ServiceCollection();
|
||||
ConfigureServices(serviceCollection);
|
||||
_serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
try
|
||||
{
|
||||
var mainWindow = _serviceProvider.GetRequiredService<MainWindow>();
|
||||
mainWindow.Show();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при открытии MainWindow", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
base.OnStartup(e);
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
// Регистрация контекста базы данных с использованием конфигурации
|
||||
services.AddLogging(configure => configure.AddConsole());
|
||||
// Регистрация бизнес-логики и других сервисов
|
||||
services.AddTransient<IPhisicalPersonLogic, PhisicalPersonLogic>();
|
||||
services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||
|
||||
// Регистрация окон
|
||||
services.AddTransient<MainWindow>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,4 +8,18 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.6.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EmployeeManagmentBusinessLogic\EmployeeManagmentBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\EmployeeManagmentContracts\EmployeeManagmentContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using EmployeeManagmentBusinessLogic.BusinessLogic;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -12,7 +12,11 @@
|
||||
FontSize="24"
|
||||
FontWeight="Bold"
|
||||
Margin="10"/>
|
||||
|
||||
<Button Content="Просмотр физических лиц"
|
||||
Width="200"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="ViewPhisicalPerson_Click"/>
|
||||
<Button Content="Просмотр сотрудников"
|
||||
Width="200"
|
||||
Height="40"
|
||||
|
@ -1,23 +1,20 @@
|
||||
using System.Text;
|
||||
using EmployeeManagmentBusinessLogic.BusinessLogic;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using EmployeeManagmentContracts.ViewModels;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace EmployeeManagmentView
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
|
||||
private readonly IEmployeeLogic _employeeLogic;
|
||||
|
||||
// Constructor with Dependency Injection
|
||||
public MainWindow(IPhisicalPersonLogic phisicalPersonLogic, IEmployeeLogic employeeLogic)
|
||||
{
|
||||
_phisicalPersonLogic = phisicalPersonLogic;
|
||||
_employeeLogic = employeeLogic;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@ -28,6 +25,13 @@ namespace EmployeeManagmentView
|
||||
employeesWindow.Show();
|
||||
}
|
||||
|
||||
private void ViewPhisicalPerson_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Передаем логику в конструктор окна
|
||||
var phisicalPersonWindow = new PhisicalPersonWindow(_phisicalPersonLogic);
|
||||
phisicalPersonWindow.Show();
|
||||
}
|
||||
|
||||
private void ManageSalaries_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Логика для открытия окна управления зарплатами
|
||||
@ -42,4 +46,4 @@ namespace EmployeeManagmentView
|
||||
vacationsWindow.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
EmployeeManagmentView/PhisicalPersonWindow.xaml
Normal file
30
EmployeeManagmentView/PhisicalPersonWindow.xaml
Normal file
@ -0,0 +1,30 @@
|
||||
<Window x:Class="EmployeeManagmentView.PhisicalPersonWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:EmployeeManagmentView"
|
||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
mc:Ignorable="d"
|
||||
Title="Physical Person Management" Height="450" Width="800">
|
||||
<Grid>
|
||||
<StackPanel>
|
||||
<!-- TextBoxes with Watermark for all fields -->
|
||||
<xctk:WatermarkTextBox Name="NameTextBox" Width="200" Margin="10" Watermark="Enter Name"/>
|
||||
<xctk:WatermarkTextBox Name="SurnameTextBox" Width="200" Margin="10" Watermark="Enter Surname"/>
|
||||
<xctk:WatermarkTextBox Name="AgeTextBox" Width="200" Margin="10" Watermark="Enter Age"/>
|
||||
<xctk:WatermarkTextBox Name="AddressTextBox" Width="200" Margin="10" Watermark="Enter Address"/>
|
||||
<xctk:WatermarkTextBox Name="TelephoneTextBox" Width="200" Margin="10" Watermark="Enter Telephone"/>
|
||||
<xctk:WatermarkTextBox Name="GenderTextBox" Width="200" Margin="10" Watermark="Enter Gender"/>
|
||||
<xctk:WatermarkTextBox Name="BirthdayTextBox" Width="200" Margin="10" Watermark="Enter Birthday (YYYY-MM-DD)"/>
|
||||
|
||||
<!-- Buttons for CRUD actions -->
|
||||
<Button Content="Add" Width="100" Margin="10" Click="AddButton_Click"/>
|
||||
<Button Content="Update" Width="100" Margin="10" Click="UpdateButton_Click"/>
|
||||
<Button Content="Delete" Width="100" Margin="10" Click="DeleteButton_Click"/>
|
||||
|
||||
<!-- DataGrid to display PhysicalPersons -->
|
||||
<DataGrid Name="PhysicalPersonsDataGrid" Margin="10" AutoGenerateColumns="True"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
149
EmployeeManagmentView/PhisicalPersonWindow.xaml.cs
Normal file
149
EmployeeManagmentView/PhisicalPersonWindow.xaml.cs
Normal file
@ -0,0 +1,149 @@
|
||||
using EmployeeManagmentContracts.BindingModels;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using EmployeeManagmentContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace EmployeeManagmentView
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для PhisicalPersonWindow.xaml
|
||||
/// </summary>
|
||||
public partial class PhisicalPersonWindow : Window
|
||||
{
|
||||
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
|
||||
|
||||
public PhisicalPersonWindow(IPhisicalPersonLogic phisicalPersonLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_phisicalPersonLogic = phisicalPersonLogic;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
// Загрузка данных в DataGrid
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var physicalPersons = _phisicalPersonLogic.GetPhisicalPersons(null); // Здесь можно передавать параметры для фильтрации
|
||||
PhysicalPersonsDataGrid.ItemsSource = physicalPersons;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error loading data: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var textBox = sender as TextBox;
|
||||
if (textBox != null && textBox.Text == "Enter Name")
|
||||
{
|
||||
textBox.Text = "";
|
||||
textBox.Foreground = new SolidColorBrush(Colors.Black); // Change text color to black
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var textBox = sender as TextBox;
|
||||
if (textBox != null && string.IsNullOrEmpty(textBox.Text))
|
||||
{
|
||||
textBox.Text = "Enter Name"; // Reset placeholder text
|
||||
textBox.Foreground = new SolidColorBrush(Colors.Gray); // Change text color to gray
|
||||
}
|
||||
}
|
||||
|
||||
// Обработчик для кнопки "Add"
|
||||
private void AddButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var model = new PhisicalPersonBindingModel
|
||||
{
|
||||
Name = NameTextBox.Text,
|
||||
Surname = SurnameTextBox.Text,
|
||||
Birthday = DateTime.TryParse(BirthdayTextBox.Text, out DateTime birthday) ? birthday : DateTime.Now,
|
||||
Address = AddressTextBox.Text,
|
||||
Telephone = TelephoneTextBox.Text,
|
||||
Gender = GenderTextBox.Text
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
_phisicalPersonLogic.CreateOrUpdate(model);
|
||||
MessageBox.Show("Physical person added successfully!");
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error adding data: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// Обработчик для кнопки "Update"
|
||||
private void UpdateButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Получаем выбранную запись в DataGrid
|
||||
var selectedPerson = PhysicalPersonsDataGrid.SelectedItem as PhisicalPersonViewModel;
|
||||
if (selectedPerson == null)
|
||||
{
|
||||
MessageBox.Show("No person selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
var model = new PhisicalPersonBindingModel
|
||||
{
|
||||
Id = selectedPerson.Id,
|
||||
Name = NameTextBox.Text,
|
||||
Surname = SurnameTextBox.Text,
|
||||
Birthday = DateTime.TryParse(BirthdayTextBox.Text, out DateTime birthday) ? birthday : DateTime.Now,
|
||||
Address = AddressTextBox.Text,
|
||||
Telephone = TelephoneTextBox.Text,
|
||||
Gender = GenderTextBox.Text
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
_phisicalPersonLogic.CreateOrUpdate(model);
|
||||
MessageBox.Show("Physical person updated successfully!");
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error updating data: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// Обработчик для кнопки "Delete"
|
||||
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedPerson = PhysicalPersonsDataGrid.SelectedItem as PhisicalPersonViewModel;
|
||||
if (selectedPerson == null)
|
||||
{
|
||||
MessageBox.Show("No person selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_phisicalPersonLogic.Delete(selectedPerson.Id);
|
||||
MessageBox.Show("Physical person deleted successfully!");
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error deleting data: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user