This commit is contained in:
Ismailov_Rovshan 2023-04-08 16:14:43 +04:00
parent f3703bfff3
commit 2119b1cc33
17 changed files with 470 additions and 14 deletions

View File

@ -19,6 +19,6 @@ namespace FurnitureContracts.BindingModels
public string MasterName { get; set; } = string.Empty; public string MasterName { get; set; } = string.Empty;
public Dictionary<int, IMaterialModel> HeadsetModuleMaterial { get; set; }; public Dictionary<int, IMaterialModel> HeadsetModuleMaterial { get; set; }
} }
} }

View File

@ -10,5 +10,9 @@ namespace FurnitureContracts.SearchModels
{ {
public string? Name { get; set; } public string? Name { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
public int? MasterId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
} }
} }

View File

@ -8,8 +8,10 @@ namespace FurnitureContracts.SearchModels
{ {
public class HeadsetModuleSearchModel public class HeadsetModuleSearchModel
{ {
public string? Title { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
public int ? MasterId { get; set; }
} }
} }

View File

@ -9,6 +9,7 @@ namespace FurnitureContracts.SearchModels
public class MasterSearchModel public class MasterSearchModel
{ {
public string? Name { get; set; } public string? Name { get; set; }
public string? Login { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
} }
} }

View File

@ -10,5 +10,6 @@ namespace FurnitureContracts.SearchModels
{ {
public string? Name { get; set; } public string? Name { get; set; }
public int? Id { get; set; } public int? Id { get; set; }
public int? MasterId { get; set; }
} }
} }

View File

@ -36,8 +36,12 @@ namespace FurnitureFactoryDataBaseImplement
public virtual DbSet<HeadsetSalesSalons> HeadsetSalesSalons { set; get; } public virtual DbSet<HeadsetSalesSalons> HeadsetSalesSalons { set; get; }
public virtual DbSet<Orders> Orders { set; get; } public virtual DbSet<Orders> Orders { set; get; }
public virtual DbSet<OrdersSalesSalons> OrdersSalesSalons { set; get; } public virtual DbSet<OrdersSalesSalons> OrdersSalesSalons { set; get; }
public virtual DbSet<HeadsetModule> HeadsetModules { set; get; }
public virtual DbSet<FurnitureMaterial> FurnitureMaterials { set; get; }
public virtual DbSet<Furniture> Furnitures { set; get; }
public virtual DbSet<Master> Masters { set; get; }
//public virtual DbSet<Master> Masters { set; get; } public virtual DbSet<HeadsetModuleMaterial> HeadsetModuleMaterials { set; get; }
public virtual DbSet<Material> Materials { set; get; } public virtual DbSet<Material> Materials { set; get; }

View File

@ -0,0 +1,121 @@
using FurnitureContracts.BindingModels;
using FurnitureContracts.SearchModels;
using FurnitureContracts.StoragesContracts;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureFactoryDataBaseImplement.Implements
{
public class FurnitureStorage : IFurnitureStorage
{
public List<FurnitureViewModel> GetFullList()
{
using var context = new FurnitureDataBase();
return context.Furnitures
.Include(x => x.Materials)
.ThenInclude(x => x.Material)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<FurnitureViewModel> GetFilteredList( FurnitureSearchModel model)
{
if (!model.MasterId.HasValue)
{
return new();
}
using var context = new FurnitureDataBase();
if (model.MasterId.HasValue && model.DateTo.HasValue)
{
return context. Furnitures
.Include(x => x.Materials)
.ThenInclude(x => x.Material)
.Where(x => x.DateTo >= model.DateFrom && x.DateTo <= model.DateTo && x.MasterId == model.MasterId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context. Furnitures
.Include(x => x.Materials)
.ThenInclude(x => x.Material)
.Where(x => x.MasterId == model.MasterId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public FurnitureViewModel? GetElement( FurnitureSearchModel model)
{
if ((string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) || !model.MasterId.HasValue)
{
return null;
}
using var context = new FurnitureDataBase();
return context. Furnitures
.Include(x => x.Materials)
.ThenInclude(x => x.Material)
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id)) && x.MasterId == model.MasterId)
?.GetViewModel;
}
public FurnitureViewModel? Insert( FurnitureBindingModel model)
{
using var context = new FurnitureDataBase();
var newFurniture = Furniture.Create(context, model);
if (newFurniture == null)
{
return null;
}
context. Furnitures.Add(newFurniture);
context.SaveChanges();
return newFurniture.GetViewModel;
}
public FurnitureViewModel? Update( FurnitureBindingModel model)
{
using var context = new FurnitureDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var Furniture = context. Furnitures.FirstOrDefault(rec => rec.Id == model.Id);
if ( Furniture == null)
{
return null;
}
Furniture.Update(model);
context.SaveChanges();
Furniture.UpdateMaterials(context, model);
transaction.Commit();
return Furniture.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public FurnitureViewModel? Delete( FurnitureBindingModel model)
{
using var context = new FurnitureDataBase();
var element = context. Furnitures
.Include(x => x.Materials)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context. Furnitures.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,122 @@
using FurnitureContracts.BindingModels;
using FurnitureContracts.SearchModels;
using FurnitureContracts.StoragesContracts;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataBaseImplement.Models;
using FurnitureFactoryDataModels.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FurnitureFactoryDataBaseImplement.Implements
{
public class HeadsetModuleStorage : IHeadsetModuleStorage
{
public List<HeadsetModuleViewModel> GetFullList()
{
using var context = new FurnitureDataBase();
return context.HeadsetModules
.Include(x => x.Materials)
.ThenInclude(x => x.Material)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<HeadsetModuleViewModel> GetFilteredList(HeadsetModuleSearchModel model)
{
if (!model.MasterId.HasValue)
{
return new();
}
using var context = new FurnitureDataBase();
if (model.MasterId.HasValue )
{
return context.HeadsetModules
.Include(x => x.Materials)
.ThenInclude(x => x.Material)
.Where(x => x.DateIssue >= model.DateFrom && x.DateIssue <= model.DateTo && x.MasterId == model.MasterId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context.HeadsetModules
.Include(x => x.Materials)
.ThenInclude(x => x.Material)
.Where(x => x.MasterId == model.MasterId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public HeadsetModuleViewModel? GetElement(HeadsetModuleSearchModel model)
{
if ((string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) || !model.MasterId.HasValue)
{
return null;
}
using var context = new FurnitureDataBase();
return context.HeadsetModules
.Include(x => x.Materials)
.ThenInclude(x => x.Material)
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id)) && x.MasterId == model.MasterId)
?.GetViewModel;
}
public HeadsetModuleViewModel? Insert(HeadsetModuleBindingModel model)
{
using var context = new FurnitureDataBase();
var newHeadsetModule = HeadsetModule.Create(context, model);
if (newHeadsetModule == null)
{
return null;
}
context.HeadsetModules.Add(newHeadsetModule);
context.SaveChanges();
return newHeadsetModule.GetViewModel;
}
public HeadsetModuleViewModel? Update(HeadsetModuleBindingModel model)
{
using var context = new FurnitureDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var HeadsetModule = context.HeadsetModules.FirstOrDefault(rec => rec.Id == model.Id);
if (HeadsetModule == null)
{
return null;
}
HeadsetModule.Update(model);
context.SaveChanges();
HeadsetModule.UpdateMaterials(context, model);
transaction.Commit();
return HeadsetModule.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public HeadsetModuleViewModel? Delete(HeadsetModuleBindingModel model)
{
using var context = new FurnitureDataBase();
var element = context.HeadsetModules
.Include(x => x.Materials)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.HeadsetModules.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,101 @@
using FurnitureContracts.BindingModels;
using FurnitureContracts.SearchModels;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureFactoryDataBaseImplement.Implements
{
public class MasterStorage
{
public MasterViewModel? Delete(MasterBindingModel model)
{
using var context = new FurnitureDataBase();
var element = context.Masters
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Masters.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public MasterViewModel? GetElement(MasterSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && !model.Id.HasValue)
{
return null;
}
using var context = new FurnitureDataBase();
return context.Masters
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<MasterViewModel> GetFilteredList(MasterSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new FurnitureDataBase();
return context.Masters
.Where(x => x.Name.Contains(model.Name))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<MasterViewModel> GetFullList()
{
using var context = new FurnitureDataBase();
return context.Masters
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public MasterViewModel? Insert(MasterBindingModel model)
{
using var context = new FurnitureDataBase();
var newMaster = Master.Create(context, model);
if (newMaster == null)
{
return null;
}
context.Masters.Add(newMaster);
context.SaveChanges();
return newMaster.GetViewModel;
}
public MasterViewModel? Update(MasterBindingModel model)
{
using var context = new FurnitureDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var Master = context.Masters.FirstOrDefault(rec => rec.Id == model.Id);
if (Master == null)
{
return null;
}
Master.Update(model);
context.SaveChanges();
transaction.Commit();
return Master.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -0,0 +1,88 @@
using FurnitureContracts.BindingModels;
using FurnitureContracts.SearchModels;
using FurnitureContracts.StoragesContracts;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureFactoryDataBaseImplement.Implements
{
internal class MaterialStorage : IMaterialStorage
{
public List<MaterialViewModel> GetFullList()
{
using var context = new FurnitureDataBase();
return context.Materials
.Select(x => x.GetViewModel)
.ToList();
}
public List<MaterialViewModel> GetFilteredList(MaterialSearchModel model)
{
if (!model.MasterId.HasValue)
{
return new();
}
using var context = new FurnitureDataBase();
return context.Materials
.Where(x => x.MasterId == model.MasterId)
.Select(x => x.GetViewModel)
.ToList();
}
public MaterialViewModel? GetElement(MaterialSearchModel model)
{
if ((string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) || !model.MasterId.HasValue)
{
return null;
}
using var context = new FurnitureDataBase();
return context.Materials
.FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) ||
(model.Id.HasValue && x.Id == model.Id)) && x.MasterId == model.MasterId)
?.GetViewModel;
}
public MaterialViewModel? Insert(MaterialBindingModel model)
{
var newMaterial = Material.Create(model);
if (newMaterial == null)
{
return null;
}
using var context = new FurnitureDataBase();
context.Materials.Add(newMaterial);
context.SaveChanges();
return newMaterial.GetViewModel;
}
public MaterialViewModel? Update(MaterialBindingModel model)
{
using var context = new FurnitureDataBase();
var material = context.Materials.FirstOrDefault(x => x.Id == model.Id);
if (material == null)
{
return null;
}
material.Update(model);
context.SaveChanges();
return material.GetViewModel;
}
public MaterialViewModel? Delete(MaterialBindingModel model)
{
using var context = new FurnitureDataBase();
var element = context.Materials.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Materials.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -47,7 +47,7 @@ namespace FurnitureFactoryDataBaseImplement.Models
[ForeignKey("FurnitureId")] [ForeignKey("FurnitureId")]
public virtual List<FurnitureMaterial> Materials { get; set; } = new(); public virtual List<FurnitureMaterial> Materials { get; set; } = new();
public static Furniture Create(SchoolDataBase context, FurnitureBindingModel model) public static Furniture Create(FurnitureDataBase context, FurnitureBindingModel model)
{ {
return new Furniture() return new Furniture()
{ {
@ -84,9 +84,11 @@ namespace FurnitureFactoryDataBaseImplement.Models
public Dictionary<int, IMaterialModel> FurnitureMaterial => throw new NotImplementedException();
public void UpdateMaterials(SchoolDataBase context, FurnitureBindingModel model) public DateTime DateTo { get; set; }
public void UpdateMaterials(FurnitureDataBase context, FurnitureBindingModel model)
{ {
var FurnitureMaterials = context.FurnitureMaterials.Where(rec => rec.FurnitureId == model.Id).ToList(); var FurnitureMaterials = context.FurnitureMaterials.Where(rec => rec.FurnitureId == model.Id).ToList();
if (FurnitureMaterials != null && FurnitureMaterials.Count > 0) if (FurnitureMaterials != null && FurnitureMaterials.Count > 0)

View File

@ -17,6 +17,5 @@ namespace FurnitureFactoryDataBaseImplement.Models
public virtual Furniture Furniture { get; set; } = new(); public virtual Furniture Furniture { get; set; } = new();
public virtual Material Material { get; set; } = new(); public virtual Material Material { get; set; } = new();
} }
} }

View File

@ -41,7 +41,7 @@ namespace FurnitureFactoryDataBaseImplement.Models
public virtual List<Headset> Headsets { get; set; } = new(); public virtual List<Headset> Headsets { get; set; } = new();
public int Id { get; set; } public int Id { get; set; }
public string MasterName { get; set; } = string.Empty; public string MasterName { get; set; } = string.Empty;
public static HeadsetModule Create(DateBase context, HeadsetModuleBindingModel model) public static HeadsetModule Create(FurnitureDataBase context, HeadsetModuleBindingModel model)
{ {
return new HeadsetModule() return new HeadsetModule()
{ {
@ -50,7 +50,7 @@ namespace FurnitureFactoryDataBaseImplement.Models
Cost = model.Cost, Cost = model.Cost,
MasterId = model.MasterId, MasterId = model.MasterId,
MasterName = model.MasterName, MasterName = model.MasterName,
Headsets = model.HeadsetModuleMaterial.Select(x => new HeadsetModuleMaterial Materials = model.HeadsetModuleMaterial.Select(x => new HeadsetModuleMaterial
{ {
Material = context.Materials.First(y => y.Id == x.Key), Material = context.Materials.First(y => y.Id == x.Key),
}).ToList() }).ToList()
@ -70,9 +70,16 @@ namespace FurnitureFactoryDataBaseImplement.Models
MasterName = MasterName, MasterName = MasterName,
HeadsetModuleMaterial = HeadsetModuleMaterial HeadsetModuleMaterial = HeadsetModuleMaterial
}; };
public DateTime DateIssue { get; set; }
public DateTime DateDelivery { get; set; }
public string Name { get; set; } = string.Empty;
public void UpdateMaterials(FurnitureDataBase context, HeadsetModuleBindingModel model) public void UpdateMaterials(FurnitureDataBase context, HeadsetModuleBindingModel model)
{ {
var headsetModule = context.HeadsetModulMaterial.Where(rec => rec.HeadsetModuleId == model.Id).ToList(); var headsetModule = context.HeadsetModuleMaterials.Where(rec => rec.HeadsetModuleId == model.Id).ToList();
if (headsetModule != null && headsetModule.Count > 0) if (headsetModule != null && headsetModule.Count > 0)
{ {
context.HeadsetModuleMaterials.RemoveRange(headsetModule.Where(rec => !model.HeadsetModuleMaterial.ContainsKey(rec.MaterialId))); context.HeadsetModuleMaterials.RemoveRange(headsetModule.Where(rec => !model.HeadsetModuleMaterial.ContainsKey(rec.MaterialId)));
@ -87,7 +94,7 @@ namespace FurnitureFactoryDataBaseImplement.Models
var HeadsetModule = context.HeadsetModules.First(x => x.Id == Id); var HeadsetModule = context.HeadsetModules.First(x => x.Id == Id);
foreach (var pc in model.HeadsetModuleMaterial) foreach (var pc in model.HeadsetModuleMaterial)
{ {
context.HeadsetModuleMaterial.Add(new HeadsetModuleMaterial context.HeadsetModuleMaterials.Add(new HeadsetModuleMaterial
{ {
HeadsetModule = HeadsetModule, HeadsetModule = HeadsetModule,
Material = context.Materials.First(x => x.Id == pc.Key), Material = context.Materials.First(x => x.Id == pc.Key),

View File

@ -11,7 +11,7 @@ namespace FurnitureFactoryDataBaseImplement.Models
{ {
public int Id { get; set; } public int Id { get; set; }
[Required] [Required]
public int TaskId { get; set; } public int HeadsetModuleId { get; set; }
[Required] [Required]
public int MaterialId { get; set; } public int MaterialId { get; set; }
public virtual HeadsetModule HeadsetModule { get; set; } = new(); public virtual HeadsetModule HeadsetModule { get; set; } = new();

View File

@ -29,7 +29,7 @@ namespace FurnitureFactoryDataBaseImplement.Models
public virtual List<Furniture> Furnitures { get; set; } = new(); public virtual List<Furniture> Furnitures { get; set; } = new();
[ForeignKey("MasterId")] [ForeignKey("MasterId")]
public virtual List<HeadsetModule> HeadsetModules { get; set; } = new(); public virtual List<HeadsetModule> HeadsetModules { get; set; } = new();
public static Master Create(DateBase context, MasterBindingModel model) public static Master Create(FurnitureDataBase context, MasterBindingModel model)
{ {
return new Master() return new Master()
{ {

View File

@ -15,7 +15,8 @@ namespace FurnitureFactoryDataModels.Models
int OrdersId { get; } int OrdersId { get; }
string OrdersName { get; } string OrdersName { get; }
string MasterName { get; } string MasterName { get; }
public Dictionary<int, IMaterialModel> FurnitureMaterial { get; } public Dictionary<int, IMaterialModel> FurnitureMaterials { get; }
DateTime DateTo { get; }
} }
} }

View File

@ -8,10 +8,13 @@ namespace FurnitureFactoryDataModels.Models
{ {
public interface IHeadsetModuleModel : IId public interface IHeadsetModuleModel : IId
{ {
string Name { get; }
string Style { get;} string Style { get;}
int Cost { get;} int Cost { get;}
int MasterId { get;} int MasterId { get;}
string MasterName { get; } string MasterName { get; }
public Dictionary<int, IMaterialModel> HeadsetModuleMaterial { get; } public Dictionary<int, IMaterialModel> HeadsetModuleMaterial { get; }
DateTime DateIssue { get; }
DateTime DateDelivery { get; }
} }
} }