diff --git a/Course/Contracts/SearchModels/MachineSearchModel.cs b/Course/Contracts/SearchModels/MachineSearchModel.cs index 2cae028..34a2f2d 100644 --- a/Course/Contracts/SearchModels/MachineSearchModel.cs +++ b/Course/Contracts/SearchModels/MachineSearchModel.cs @@ -5,5 +5,8 @@ public int? Id { get; set; } public string? Title { get; set; } public int? UserId { get; set; } - } + public int? WorkerId { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } } diff --git a/Course/Contracts/SearchModels/ProductSearchModel.cs b/Course/Contracts/SearchModels/ProductSearchModel.cs index 296327b..57ec6cf 100644 --- a/Course/Contracts/SearchModels/ProductSearchModel.cs +++ b/Course/Contracts/SearchModels/ProductSearchModel.cs @@ -12,6 +12,6 @@ namespace Contracts.SearchModels public string? Name { get; set; } public int? UserId { get; set; } public int? MachineId { get; set; } - public int? DetailId { get; set; } + public int? WorkerId { get; set; } } } diff --git a/Course/Contracts/SearchModels/WorkerSearchModel.cs b/Course/Contracts/SearchModels/WorkerSearchModel.cs index b139435..4a03a46 100644 --- a/Course/Contracts/SearchModels/WorkerSearchModel.cs +++ b/Course/Contracts/SearchModels/WorkerSearchModel.cs @@ -5,5 +5,5 @@ 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 index 33ae887..a38fd03 100644 --- a/Course/Contracts/SearchModels/WorkshopSearchModel.cs +++ b/Course/Contracts/SearchModels/WorkshopSearchModel.cs @@ -6,5 +6,7 @@ public string? Title { get; set; } public int? UserId { get; set; } public int? DetailId { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/Course/DatabaseImplement/Implements/MachineStorage.cs b/Course/DatabaseImplement/Implements/MachineStorage.cs index 4808a36..78edaea 100644 --- a/Course/DatabaseImplement/Implements/MachineStorage.cs +++ b/Course/DatabaseImplement/Implements/MachineStorage.cs @@ -29,12 +29,15 @@ namespace DatabaseImplement.Implements public List GetFilteredList(MachineSearchModel model) { - if (!model.UserId.HasValue) - { - return new(); - } - using var context = new FactoryGoWorkDatabase(); - return context.Machines.Include(p => p.Workers).ThenInclude(p => p.Worker).Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); + if (!model.UserId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + { + return new(); + } + using var context = new FactoryGoWorkDatabase(); + if (model.DateFrom.HasValue) + return context.Machines.Where(x => x.UserId == model.Id).Where(x => x.DateCreate < model.DateTo && x.DateCreate > model.DateFrom).Select(x => x.GetViewModel).ToList(); + else + return context.Machines.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/Course/DatabaseImplement/Implements/ProductStorage.cs b/Course/DatabaseImplement/Implements/ProductStorage.cs index 59c0631..1622719 100644 --- a/Course/DatabaseImplement/Implements/ProductStorage.cs +++ b/Course/DatabaseImplement/Implements/ProductStorage.cs @@ -29,13 +29,13 @@ namespace DatabaseImplement.Implements public List GetFilteredList(ProductSearchModel model) { - if (!model.UserId.HasValue && !model.DetailId.HasValue) + if (!model.UserId.HasValue && !model.WorkerId.HasValue) { return new(); } using var context = new FactoryGoWorkDatabase(); - if (model.DetailId.HasValue) - return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Where(x => x.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Select(x => x.GetViewModel).ToList(); + if (model.WorkerId.HasValue) + return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Where(x => x.Details.FirstOrDefault(y => y.DetailId == model.WorkerId) != null).Select(x => x.GetViewModel).ToList(); else return context.Products.Include(p => p.Details).ThenInclude(p => p.Detail).Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); } diff --git a/Course/DatabaseImplement/Implements/WorkshopStorage.cs b/Course/DatabaseImplement/Implements/WorkshopStorage.cs index eb29fcd..fcd1c42 100644 --- a/Course/DatabaseImplement/Implements/WorkshopStorage.cs +++ b/Course/DatabaseImplement/Implements/WorkshopStorage.cs @@ -30,15 +30,15 @@ namespace DatabaseImplement.Implements public List GetFilteredList(WorkshopSearchModel model) { - if (!model.UserId.HasValue && !model.DetailId.HasValue) - { - return new(); - } - using var context = new FactoryGoWorkDatabase(); - if (model.DetailId.HasValue) - return context.Workshops.Where(x => x.ProductionId != null).Include(x => x.Production).Where(x => x.Production!.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); - else - return context.Workshops.Include(x => x.Workers).ThenInclude(x => x.Worker).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); + if (!model.UserId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + { + return new(); + } + using var context = new FactoryGoWorkDatabase(); + if (model.DateFrom.HasValue) + return context.Workshops.Where(x => x.UserId == model.Id).Where(x => x.DateCreate < model.DateTo && x.DateCreate > model.DateFrom).Select(x => x.GetViewModel).ToList(); + else + return context.Workshops.Where(x => x.UserId == model.Id).Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/Course/DatabaseImplement/Models/Machine.cs b/Course/DatabaseImplement/Models/Machine.cs index e20974a..2604a85 100644 --- a/Course/DatabaseImplement/Models/Machine.cs +++ b/Course/DatabaseImplement/Models/Machine.cs @@ -19,7 +19,9 @@ namespace DatabaseImplement.Models public string Title { get; private set; } = string.Empty; [Required] public string Country { get; private set; } = string.Empty; - [Required] + [Required] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Required] public int UserId { get; private set; } private Dictionary? _workerMachines = null; [NotMapped] diff --git a/Course/DatabaseImplement/Models/Workshop.cs b/Course/DatabaseImplement/Models/Workshop.cs index 06ca1b9..742483c 100644 --- a/Course/DatabaseImplement/Models/Workshop.cs +++ b/Course/DatabaseImplement/Models/Workshop.cs @@ -15,7 +15,9 @@ namespace DatabaseImplement.Models public string Address { get; set; } = string.Empty; [Required] public string Director { get; set; } = string.Empty; - [Required] + [Required] + public DateTime DateCreate { get; set; } = DateTime.Now; + [Required] public int UserId { get; set; } public int? ProductionId { get; set; } public virtual Production? Production { get; set; } diff --git a/Course/TestingDatabase/Program.cs b/Course/TestingDatabase/Program.cs index 45e0f61..c9643df 100644 --- a/Course/TestingDatabase/Program.cs +++ b/Course/TestingDatabase/Program.cs @@ -14,3 +14,8 @@ ProductionStorage productionionStorage = new ProductionStorage(); ProductStorage productStorage = new ProductStorage(); MachineStorage machineStorage = new MachineStorage(); GuarantorStorage guarantorStorage = new GuarantorStorage(); +WorkerStorage workerStorage = new WorkerStorage(); +WorkshopStorage workshopStorage = new WorkshopStorage(); + + +