diff --git a/Course/Contracts/BindingModels/GuarantorBindingModel.cs b/Course/Contracts/BindingModels/GuarantorBindingModel.cs new file mode 100644 index 0000000..2806f53 --- /dev/null +++ b/Course/Contracts/BindingModels/GuarantorBindingModel.cs @@ -0,0 +1,13 @@ +using DataModels.Models; + +namespace Contracts.BindingModels +{ + public class GuarantorBindingModel : IGuarantorModel + { + public int Id { get; set; } + public string Email { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; + public string Login { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + } +} diff --git a/Course/Contracts/BindingModels/MachineBindingModel.cs b/Course/Contracts/BindingModels/MachineBindingModel.cs index 14cc6b8..f8e0999 100644 --- a/Course/Contracts/BindingModels/MachineBindingModel.cs +++ b/Course/Contracts/BindingModels/MachineBindingModel.cs @@ -1,9 +1,4 @@ using DataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Contracts.BindingModels { @@ -11,8 +6,9 @@ namespace Contracts.BindingModels { public int Id { get; set; } public int UserId { get; set; } - public string Title { get; set; } - public string Country { get; set; } + public string Title { get; set; } = string.Empty; + public string Country { get; set; } = string.Empty; + public int ProductId { get; set; } public Dictionary MachineWorker { get; set; } = new(); } } diff --git a/Course/Contracts/BindingModels/WorkerBindingModel.cs b/Course/Contracts/BindingModels/WorkerBindingModel.cs index 717cddc..73fa795 100644 --- a/Course/Contracts/BindingModels/WorkerBindingModel.cs +++ b/Course/Contracts/BindingModels/WorkerBindingModel.cs @@ -1,18 +1,16 @@ using DataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Contracts.BindingModels { public class WorkerBindingModel : IWorkerModel { public int Id { get; set; } - public string Name { get; set; } + public int UserId { get; set; } + public string Name { get; set; } = string.Empty; public DateTime Birthday { get; set; } - public string Specialization { get; set; } + public string Specialization { get; set; } = string.Empty; public double Salary { get; set; } - } + public Dictionary WorkerWorkshop { get; set; } = new(); + public Dictionary WorkerMachine { get; set; } = new(); + } } diff --git a/Course/Contracts/BindingModels/WorkshopBindingModel.cs b/Course/Contracts/BindingModels/WorkshopBindingModel.cs index 24395cc..3b262b7 100644 --- a/Course/Contracts/BindingModels/WorkshopBindingModel.cs +++ b/Course/Contracts/BindingModels/WorkshopBindingModel.cs @@ -1,18 +1,15 @@ using DataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Contracts.BindingModels { public class WorkshopBindingModel : IWorkshopModel { public int Id { get; set; } - public string Title { get; set; } - public string Address { get; set; } - public string Director { get; set; } - public Dictionary WorkshopWorker { get; set; } = new(); + public int UserId { get; set; } + public string Title { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public string Director { get; set; } = string.Empty; + public int ProductionId { get; set; } + public Dictionary WorkshopWorker { get; set; } = new(); } } diff --git a/Course/Contracts/BusinessLogicsContracts/IGuarantorLogic.cs b/Course/Contracts/BusinessLogicsContracts/IGuarantorLogic.cs new file mode 100644 index 0000000..7a8dca9 --- /dev/null +++ b/Course/Contracts/BusinessLogicsContracts/IGuarantorLogic.cs @@ -0,0 +1,15 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace Contracts.BusinessLogicsContracts +{ + public interface IGuarantorLogic + { + List? ReadList(ImplementerSearchModel? model); + ImplementerViewModel? ReadElement(ImplementerSearchModel? model); + bool Create(ImplementerBindingModel? model); + bool Update(ImplementerBindingModel? model); + bool Delete(ImplementerBindingModel? model); + } +} diff --git a/Course/Contracts/BusinessLogicsContracts/IMachineLogic.cs b/Course/Contracts/BusinessLogicsContracts/IMachineLogic.cs new file mode 100644 index 0000000..bc4d914 --- /dev/null +++ b/Course/Contracts/BusinessLogicsContracts/IMachineLogic.cs @@ -0,0 +1,15 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace Contracts.BusinessLogicsContracts +{ + public interface IMachineLogic + { + List? ReadList(MachineSearchModel? model); + MachineViewModel? ReadElement(MachineSearchModel? model); + bool Create(MachineBindingModel? model); + bool Update(MachineBindingModel? model); + bool Delete(MachineBindingModel? model); + } +} diff --git a/Course/Contracts/BusinessLogicsContracts/IWorkerLogic.cs b/Course/Contracts/BusinessLogicsContracts/IWorkerLogic.cs new file mode 100644 index 0000000..49d1b79 --- /dev/null +++ b/Course/Contracts/BusinessLogicsContracts/IWorkerLogic.cs @@ -0,0 +1,15 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace Contracts.BusinessLogicsContracts +{ + public interface IWorkerLogic + { + List? ReadList(WorkerSearchModel? model); + WorkerViewModel? ReadElement(WorkerSearchModel? model); + bool Create(WorkerBindingModel? model); + bool Update(WorkerBindingModel? model); + bool Delete(WorkerBindingModel? model); + } +} diff --git a/Course/Contracts/BusinessLogicsContracts/IWorkshopLogic.cs b/Course/Contracts/BusinessLogicsContracts/IWorkshopLogic.cs new file mode 100644 index 0000000..c0c1d2a --- /dev/null +++ b/Course/Contracts/BusinessLogicsContracts/IWorkshopLogic.cs @@ -0,0 +1,15 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace Contracts.BusinessLogicsContracts +{ + public interface IWorkshopLogic + { + List? ReadList(WorkshopSearchModel? model); + WorkshopViewModel? ReadElement(WorkshopSearchModel? model); + bool Create(WorkshopBindingModel? model); + bool Update(WorkshopBindingModel? model); + bool Delete(WorkshopBindingModel? model); + } +} diff --git a/Course/Contracts/SearchModels/GuarantorSearchModel.cs b/Course/Contracts/SearchModels/GuarantorSearchModel.cs new file mode 100644 index 0000000..31220d4 --- /dev/null +++ b/Course/Contracts/SearchModels/GuarantorSearchModel.cs @@ -0,0 +1,8 @@ +namespace Contracts.SearchModels +{ + public class GuarantorSearchModel + { + public int? Id { get; set; } + public string? Login { get; set; } + } +} diff --git a/Course/Contracts/SearchModels/MachineSearchModel.cs b/Course/Contracts/SearchModels/MachineSearchModel.cs new file mode 100644 index 0000000..2cae028 --- /dev/null +++ b/Course/Contracts/SearchModels/MachineSearchModel.cs @@ -0,0 +1,9 @@ +namespace Contracts.SearchModels +{ + public class MachineSearchModel + { + public int? Id { get; set; } + public string? Title { get; set; } + public int? UserId { get; set; } + } +} diff --git a/Course/Contracts/SearchModels/WorkerSearchModel.cs b/Course/Contracts/SearchModels/WorkerSearchModel.cs new file mode 100644 index 0000000..b139435 --- /dev/null +++ b/Course/Contracts/SearchModels/WorkerSearchModel.cs @@ -0,0 +1,9 @@ +namespace Contracts.SearchModels +{ + public class WorkerSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + public int? UserId { get; set; } + } +} diff --git a/Course/Contracts/SearchModels/WorkshopSearchModel.cs b/Course/Contracts/SearchModels/WorkshopSearchModel.cs new file mode 100644 index 0000000..1f1d125 --- /dev/null +++ b/Course/Contracts/SearchModels/WorkshopSearchModel.cs @@ -0,0 +1,9 @@ +namespace Contracts.SearchModels +{ + public class WorkshopSearchModel + { + public int? Id { get; set; } + public string? Title { get; set; } + public int? UserId { get; set; } + } +} diff --git a/Course/Contracts/StoragesContracts/IGuarantorStorage.cs b/Course/Contracts/StoragesContracts/IGuarantorStorage.cs new file mode 100644 index 0000000..5a7808f --- /dev/null +++ b/Course/Contracts/StoragesContracts/IGuarantorStorage.cs @@ -0,0 +1,16 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace Contracts.StoragesContracts +{ + public interface IGuarantorStorage + { + List GetFullList(); + List GetFilteredList(GuarantorSearchModel model); + GuarantorViewModel? GetElement(GuarantorSearchModel model); + GuarantorViewModel? Insert(GuarantorBindingModel model); + GuarantorViewModel? Update(GuarantorBindingModel model); + GuarantorViewModel? Delete(GuarantorBindingModel model); + } +} diff --git a/Course/Contracts/StoragesContracts/IMachineStorage.cs b/Course/Contracts/StoragesContracts/IMachineStorage.cs new file mode 100644 index 0000000..b30a882 --- /dev/null +++ b/Course/Contracts/StoragesContracts/IMachineStorage.cs @@ -0,0 +1,16 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace Contracts.StoragesContracts +{ + public interface IMachineStorage + { + List GetFullList(); + List GetFilteredList(MachineSearchModel model); + MachineViewModel? GetElement(MachineSearchModel model); + MachineViewModel? Insert(MachineBindingModel model); + MachineViewModel? Update(MachineBindingModel model); + MachineViewModel? Delete(MachineBindingModel model); + } +} diff --git a/Course/Contracts/StoragesContracts/IWorkerStorage.cs b/Course/Contracts/StoragesContracts/IWorkerStorage.cs new file mode 100644 index 0000000..8c5ce97 --- /dev/null +++ b/Course/Contracts/StoragesContracts/IWorkerStorage.cs @@ -0,0 +1,16 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace Contracts.StoragesContracts +{ + public interface IWorkerStorage + { + List GetFullList(); + List GetFilteredList(WorkerSearchModel model); + WorkerViewModel? GetElement(WorkerSearchModel model); + WorkerViewModel? Insert(WorkerBindingModel model); + WorkerViewModel? Update(WorkerBindingModel model); + WorkerViewModel? Delete(WorkerBindingModel model); + } +} diff --git a/Course/Contracts/StoragesContracts/IWorkshopStorage.cs b/Course/Contracts/StoragesContracts/IWorkshopStorage.cs new file mode 100644 index 0000000..a49fb17 --- /dev/null +++ b/Course/Contracts/StoragesContracts/IWorkshopStorage.cs @@ -0,0 +1,16 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; + +namespace Contracts.StoragesContracts +{ + public interface IWorkshopStorage + { + List GetFullList(); + List GetFilteredList(WorkshopSearchModel model); + WorkshopViewModel? GetElement(WorkshopSearchModel model); + WorkshopViewModel? Insert(WorkshopBindingModel model); + WorkshopViewModel? Update(WorkshopBindingModel model); + WorkshopViewModel? Delete(WorkshopBindingModel model); + } +} diff --git a/Course/Contracts/ViewModels/GuarantorViewModel.cs b/Course/Contracts/ViewModels/GuarantorViewModel.cs new file mode 100644 index 0000000..fe07410 --- /dev/null +++ b/Course/Contracts/ViewModels/GuarantorViewModel.cs @@ -0,0 +1,17 @@ +using System.ComponentModel; + +namespace Contracts.ViewModels +{ + public class GuarantorViewModel + { + public int Id { get; set; } + [DisplayName("Имя поручителя")] + public string Name { get; set; } = string.Empty; + [DisplayName("Почта")] + public string Email { get; set; } = string.Empty; + [DisplayName("Логин")] + public string Login { get; set; } = string.Empty; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + } +} diff --git a/Course/Contracts/ViewModels/MachineViewModel.cs b/Course/Contracts/ViewModels/MachineViewModel.cs new file mode 100644 index 0000000..24e6794 --- /dev/null +++ b/Course/Contracts/ViewModels/MachineViewModel.cs @@ -0,0 +1,16 @@ +using DataModels.Models; +using System.ComponentModel; + +namespace Contracts.ViewModels +{ + public class MachineViewModel : IMachineModel + { + public int Id { get; set; } + [DisplayName("Название станка")] + public string Title { get; set; } = string.Empty; + [DisplayName("Страна производитель")] + public string Country { get; set; } = string.Empty; + public int UserId { get; set; } + public int ProductId { get; set; } + } +} diff --git a/Course/Contracts/ViewModels/WorkerViewModel.cs b/Course/Contracts/ViewModels/WorkerViewModel.cs new file mode 100644 index 0000000..2b7a9f5 --- /dev/null +++ b/Course/Contracts/ViewModels/WorkerViewModel.cs @@ -0,0 +1,19 @@ +using DataModels.Models; +using System.ComponentModel; + +namespace Contracts.ViewModels +{ + public class WorkerViewModel : IWorkerModel + { + public int Id { get; set; } + [DisplayName("Имя работника")] + public string Name { get; set; } = string.Empty; + [DisplayName("Дата рождения")] + public DateTime Birthday { get; set; } + [DisplayName("Специальность")] + public string Specialization { get; set; } = string.Empty; + [DisplayName("Заработная плата")] + public double Salary { get; set; } + public int UserId { get; set; } + } +} diff --git a/Course/Contracts/ViewModels/WorkshopViewModel.cs b/Course/Contracts/ViewModels/WorkshopViewModel.cs new file mode 100644 index 0000000..b71d506 --- /dev/null +++ b/Course/Contracts/ViewModels/WorkshopViewModel.cs @@ -0,0 +1,18 @@ +using DataModels.Models; +using System.ComponentModel; + +namespace Contracts.ViewModels +{ + public class WorkshopViewModel : IWorkshopModel + { + public int Id { get; set; } + [DisplayName("Название цеха")] + public string Title { get; set; } = string.Empty; + [DisplayName("Адрес цеха")] + public string Address { get; set; } = string.Empty; + [DisplayName("ФИО директора цеха")] + public string Director { get; set; } = string.Empty; + public int UserId { get; set; } + public int ProductionId { get; set; } + } +} diff --git a/Course/DataModels/Models/IGuarantorModel.cs b/Course/DataModels/Models/IGuarantorModel.cs new file mode 100644 index 0000000..61a647d --- /dev/null +++ b/Course/DataModels/Models/IGuarantorModel.cs @@ -0,0 +1,6 @@ +namespace DataModels.Models +{ + public interface IGuarantorModel : IUserModel + { + } +} diff --git a/Course/DataModels/Models/IMachineModel.cs b/Course/DataModels/Models/IMachineModel.cs index 36a8712..e5c4380 100644 --- a/Course/DataModels/Models/IMachineModel.cs +++ b/Course/DataModels/Models/IMachineModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DataModels.Models +namespace DataModels.Models { public interface IMachineModel : IId { diff --git a/Course/DataModels/Models/IWorkerModel.cs b/Course/DataModels/Models/IWorkerModel.cs index d0a1fd0..bfaf7b4 100644 --- a/Course/DataModels/Models/IWorkerModel.cs +++ b/Course/DataModels/Models/IWorkerModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DataModels.Models +namespace DataModels.Models { public interface IWorkerModel : IId { diff --git a/Course/DataModels/Models/IWorkshopModel.cs b/Course/DataModels/Models/IWorkshopModel.cs index d3ddc13..ca276d8 100644 --- a/Course/DataModels/Models/IWorkshopModel.cs +++ b/Course/DataModels/Models/IWorkshopModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DataModels.Models +namespace DataModels.Models { public interface IWorkshopModel : IId { diff --git a/Course/DatabaseImplement/FactoryGoWorkDatabase.cs b/Course/DatabaseImplement/FactoryGoWorkDatabase.cs index 69716f4..d3cfb8d 100644 --- a/Course/DatabaseImplement/FactoryGoWorkDatabase.cs +++ b/Course/DatabaseImplement/FactoryGoWorkDatabase.cs @@ -15,5 +15,11 @@ namespace DatabaseImplement public virtual DbSet Productions { get; set; } public virtual DbSet DetailProductions { get; set; } public virtual DbSet Implementers { get; set; } + public virtual DbSet Guarantors { get; set; } + public virtual DbSet Machines { get; set; } + public virtual DbSet WorkerMachines { get; set; } + public virtual DbSet Workers { get; set; } + public virtual DbSet Workshops { get; set; } + public virtual DbSet WorkerWorkshops { get; set; } } } diff --git a/Course/DatabaseImplement/Models/Machine.cs b/Course/DatabaseImplement/Models/Machine.cs new file mode 100644 index 0000000..64527f9 --- /dev/null +++ b/Course/DatabaseImplement/Models/Machine.cs @@ -0,0 +1,71 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace DatabaseImplement.Models +{ + public class Machine : IMachineModel + { + public int Id { get; private set; } + [Required] + public string Title { get; private set; } = string.Empty; + [Required] + public string Country { get; private set; } = string.Empty; + [Required] + public int UserId { get; private set; } + [Required] + public int ProductId { get; private set; } + public virtual Product Product { get; set; } + [ForeignKey("WorkerId")] + public virtual List WorkerMachines { get; set; } = new(); + public static Machine? Create(MachineBindingModel model, FactoryGoWorkDatabase context) + { + if (model == null) + { + return null; + } + return new Machine() + { + Id = model.Id, + Title = model.Title, + Country = model.Country, + ProductId = model.ProductId, + Product = context.Products.FirstOrDefault(x => x.Id == model.ProductId)!, + UserId = model.UserId + }; + } + public static Machine Create(MachineViewModel model) + { + return new Machine + { + Id = model.Id, + Title = model.Title, + Country = model.Country, + UserId = model.UserId + }; + } + public void Update(MachineBindingModel model) + { + if (model == null) + return; + Title = model.Title; + Country = model.Country; + } + public MachineViewModel GetViewModel => new() + { + Id = Id, + Title = Title, + Country = Country, + UserId = UserId, + ProductId = ProductId + }; + } +} diff --git a/Course/DatabaseImplement/Models/WorkerMachine.cs b/Course/DatabaseImplement/Models/WorkerMachine.cs new file mode 100644 index 0000000..1e8b6b2 --- /dev/null +++ b/Course/DatabaseImplement/Models/WorkerMachine.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Models +{ + public class WorkerMachine + { + public int Id { get; set; } + [Required] + public int WorkerId { get; set; } + [Required] + public int MachineId { get; set; } + [Required] + public int Count { get; set; } + public virtual Worker Worker { get; set; } = new(); + public virtual Machine Machine { get; set; } = new(); + } +}