This commit is contained in:
Ismailov_Rovshan 2023-04-08 00:35:02 +04:00
parent 741fb376a5
commit a0c8eb42c8
18 changed files with 394 additions and 21 deletions

View File

@ -18,5 +18,13 @@ namespace FurnitureContracts.BindingModels
public Dictionary<int, IMaterialModel> FurnitureMaterial { get; set; }
public int Id { get; set; }
public int MasterId { get; set; }
public int OrdersId { get; set; }
public string OrdersName { get; set; } = string.Empty;
public string MasterName { get; set; } = string.Empty;
}
}

View File

@ -13,8 +13,12 @@ namespace FurnitureContracts.BindingModels
public int Cost { get; set; }
public int UserID { get; set; }
public int MasterId { get; set; }
public int Id { get; set; }
public string MasterName { get; set; } = string.Empty;
public Dictionary<int, IMaterialModel> HeadsetModuleMaterial { get; set; };
}
}

View File

@ -8,7 +8,7 @@ namespace FurnitureContracts.BindingModels
{
public class MasterBindingModel : IMasterModel
{
public string UserName { 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;
public string Email { get; set; } = string.Empty;

View File

@ -13,7 +13,7 @@ namespace FurnitureContracts.BindingModels
public int Cost { get; set; }
public int UserID { get; set; }
public int MasterId { get; set; }
public int Id { get; set; }
}

View File

@ -22,5 +22,11 @@ namespace FurnitureContracts.ViewModel
public Dictionary<int, IMaterialModel> FurnitureMaterial { get; set; }
public int Id { get; set; }
public int MasterId { get; set; }
public string MasterName { get; set; } = string.Empty;
public int OrdersId { get; set; }
public string OrdersName { get; set; } = string.Empty;
}
}

View File

@ -15,8 +15,12 @@ namespace FurnitureContracts.ViewModel
[DisplayName("Цена")]
public int Cost { get; set; }
public int UserID { get; set; }
public int MasterId { get; set; }
public int Id { get; set; }
public Dictionary<int, IMaterialModel> HeadsetModuleMaterial { get; set; }
public string MasterName { get; set; } = string.Empty;
}
}

View File

@ -16,7 +16,7 @@ namespace FurnitureContracts.ViewModel
public string Password { get; set; }
[DisplayName("Имя пользователя")]
public string Email { get; set; }
public string UserName { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public int Id { get; set; }
}
}

View File

@ -16,7 +16,7 @@ namespace FurnitureContracts.ViewModel
[DisplayName("Цена")]
public int Cost { get; set; }
public int UserID { get; set; }
public int MasterId { get; set; }
public int Id { get; set; }
}

View File

@ -1,12 +1,116 @@
using System;
using FurnitureContracts.BindingModels;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataModels.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;
namespace FurnitureFactoryDataBaseImplement.Models
{
public class Furniture
public class Furniture : IFurnitureModel
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public int OrdersId { get; set; }
public string OrdersName { get; set; } = string.Empty;
public string Color { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;
public virtual Orders Orders { get; set; }
[Required]
public int MasterId { get; set; }
public string MasterName { get; set; } = string.Empty;
public virtual Master Master { get; set; }
private Dictionary<int, IMaterialModel>? _FurnitureMaterials = null;
[NotMapped]
public Dictionary<int, IMaterialModel> FurnitureMaterials
{
get
{
if (_FurnitureMaterials == null)
{
_FurnitureMaterials = Materials
.ToDictionary(recPC => recPC.MaterialId, recPC => (recPC.Material as IMaterialModel));
}
return _FurnitureMaterials;
}
}
public int Id { get; set; }
[ForeignKey("FurnitureId")]
public virtual List<FurnitureMaterial> Materials { get; set; } = new();
public static Furniture Create(SchoolDataBase context, FurnitureBindingModel model)
{
return new Furniture()
{
Id = model.Id,
Name = model.Name,
Color = model.Color,
Type = model.Type,
OrdersId = model.OrdersId,
OrdersName = model.OrdersName,
MasterId = model.MasterId,
MasterName = model.MasterName,
Materials = model.FurnitureMaterial.Select(x => new FurnitureMaterial
{
Material = context.Materials.First(y => y.Id == x.Key),
}).ToList()
};
}
public void Update(FurnitureBindingModel model)
{
Name = model.Name;
}
public FurnitureViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
OrdersId = OrdersId,
OrdersName = OrdersName,
MasterId = MasterId,
MasterName = MasterName,
FurnitureMaterial = FurnitureMaterials
};
public Dictionary<int, IMaterialModel> FurnitureMaterial => throw new NotImplementedException();
public void UpdateMaterials(SchoolDataBase context, FurnitureBindingModel model)
{
var FurnitureMaterials = context.FurnitureMaterials.Where(rec => rec.FurnitureId == model.Id).ToList();
if (FurnitureMaterials != null && FurnitureMaterials.Count > 0)
{
context.FurnitureMaterials.RemoveRange(FurnitureMaterials.Where(rec => !model.FurnitureMaterial.ContainsKey(rec.MaterialId)));
context.SaveChanges();
foreach (var updateMaterial in FurnitureMaterials)
{
model.FurnitureMaterial.Remove(updateMaterial.MaterialId);
}
context.SaveChanges();
}
var Furniture = context.Furnitures.First(x => x.Id == Id);
foreach (var pc in model.FurnitureMaterial)
{
context.FurnitureMaterials.Add(new FurnitureMaterial
{
Furniture = Furniture,
Material = context.Materials.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_FurnitureMaterials = null;
}
}
}

View File

@ -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 FurnitureFactoryDataBaseImplement.Models
{
public class FurnitureMaterial
{
public int Id { get; set; }
[Required]
public int FurnitureId { get; set; }
[Required]
public int MaterialId { get; set; }
public virtual Furniture Furniture { get; set; } = new();
public virtual Material Material { get; set; } = new();
}
}

View File

@ -1,12 +1,100 @@
using System;
using FurnitureContracts.BindingModels;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureFactoryDataBaseImplement.Models
{
public class HeadsetModule
public class HeadsetModule : IHeadsetModuleModel
{
[Required]
public string Style { get; set; } = string.Empty;
[Required]
public int Cost { get; set; }
[Required]
public int MasterId { get; set; }
public Dictionary<int, IMaterialModel> _HeadsetModuleMaterial = null;
public Dictionary<int, IMaterialModel> HeadsetModuleMaterial
{
get
{
if (_HeadsetModuleMaterial == null)
{
_HeadsetModuleMaterial = Materials.ToDictionary(recPC => recPC.MaterialId, recPC => (recPC.Material as IMaterialModel));
}
return _HeadsetModuleMaterial;
}
}
[ForeignKey("HeadsetModuleId")]
public virtual List<HeadsetModuleMaterial> Materials { get; set; } = new();
[ForeignKey("HeadsetModuleId")]
public virtual List<Headset> Headsets { get; set; } = new();
public int Id { get; set; }
public string MasterName { get; set; } = string.Empty;
public static HeadsetModule Create(DateBase context, HeadsetModuleBindingModel model)
{
return new HeadsetModule()
{
Id = model.Id,
Style = model.Style,
Cost = model.Cost,
MasterId = model.MasterId,
MasterName = model.MasterName,
Headsets = model.HeadsetModuleMaterial.Select(x => new HeadsetModuleMaterial
{
Material = context.Materials.First(y => y.Id == x.Key),
}).ToList()
};
}
public void Update(HeadsetModuleBindingModel model)
{
Style = model.Style;
Cost = model.Cost;
}
public HeadsetModuleViewModel GetViewModel => new()
{
Id = Id,
Style = Style,
Cost = Cost,
MasterId = MasterId,
MasterName = MasterName,
HeadsetModuleMaterial = HeadsetModuleMaterial
};
public void UpdateMaterials(FurnitureDataBase context, HeadsetModuleBindingModel model)
{
var headsetModule = context.HeadsetModulMaterial.Where(rec => rec.HeadsetModuleId == model.Id).ToList();
if (headsetModule != null && headsetModule.Count > 0)
{
context.HeadsetModuleMaterials.RemoveRange(headsetModule.Where(rec => !model.HeadsetModuleMaterial.ContainsKey(rec.MaterialId)));
context.SaveChanges();
foreach (var updateMaterial in headsetModule)
{
model.HeadsetModuleMaterial.Remove(updateMaterial.MaterialId);
}
context.SaveChanges();
}
var HeadsetModule = context.HeadsetModules.First(x => x.Id == Id);
foreach (var pc in model.HeadsetModuleMaterial)
{
context.HeadsetModuleMaterial.Add(new HeadsetModuleMaterial
{
HeadsetModule = HeadsetModule,
Material = context.Materials.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_HeadsetModuleMaterial = null;
}
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureFactoryDataBaseImplement.Models
{
public class HeadsetModuleMaterial
{
public int Id { get; set; }
[Required]
public int TaskId { get; set; }
[Required]
public int MaterialId { get; set; }
public virtual HeadsetModule HeadsetModule { get; set; } = new();
public virtual Material Material { get; set; } = new();
}
}

View File

@ -0,0 +1,57 @@
using FurnitureContracts.BindingModels;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataModels.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;
namespace FurnitureFactoryDataBaseImplement.Models
{
public class Master : IMasterModel
{
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
public int Id { get; set; }
[ForeignKey("MasterId")]
public virtual List<Material> Materials { get; set; } = new();
[ForeignKey("MasterId")]
public virtual List<Furniture> Furnitures { get; set; } = new();
[ForeignKey("MasterId")]
public virtual List<HeadsetModule> HeadsetModules { get; set; } = new();
public static Master Create(DateBase context, MasterBindingModel model)
{
return new Master()
{
Id = model.Id,
Name = model.Name,
Email = model.Email,
Password = model.Password,
};
}
public void Update(MasterBindingModel model)
{
Id = model.Id;
Name = model.Name;
Email = model.Email;
Password = model.Password;
}
public MasterViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Email = Email,
Password = Password,
};
}
}

View File

@ -1,20 +1,75 @@
using FurnitureFactoryDataModels.Models;
using FurnitureContracts.BindingModels;
using FurnitureContracts.ViewModel;
using FurnitureFactoryDataModels.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.Threading.HeadsetModules;
namespace FurnitureFactoryDataBaseImplement.Models
{
public class Material : IMaterialModel
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public int Cost { get; set; }
public int UserID { get; set; }
[Required]
public int MasterId { get; set; }
public virtual Master Master { get; set; }
public int Id { get; set; }
[ForeignKey("MaterialId")]
public virtual List<FurnitureMaterial> FurnitureMaterials { get; set; } = new();
[ForeignKey("MaterialId")]
public virtual List<HeadsetModuleMaterial> HeadsetModuleMaterial { get; set; } = new();
public static Material? Create(MaterialBindingModel model)
{
if (model == null)
{
return null;
}
return new Material()
{
Id = model.Id,
Name = model.Name,
Cost = model.Cost,
MasterId = model.MasterId,
};
}
public static Material Create(MaterialViewModel model)
{
return new Material
{
Id = model.Id,
Name = model.Name,
Cost = model.Cost,
MasterId = model.MasterId
};
}
public void Update(MaterialBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Cost = model.Cost;
}
public MaterialViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Cost = Cost,
MasterId = MasterId,
};
}
}

View File

@ -11,7 +11,11 @@ namespace FurnitureFactoryDataModels.Models
string Name { get;}
string Color { get; }
string Type { get; }
int UserID { get; }
int MasterId { get; }
int OrdersId { get; }
string OrdersName { get; }
string MasterName { get; }
public Dictionary<int, IMaterialModel> FurnitureMaterial { get; }
}
}

View File

@ -10,7 +10,8 @@ namespace FurnitureFactoryDataModels.Models
{
string Style { get;}
int Cost { get;}
int UserID { get;}
int MasterId { get;}
string MasterName { get; }
public Dictionary<int, IMaterialModel> HeadsetModuleMaterial { get; }
}
}

View File

@ -10,7 +10,7 @@ namespace FurnitureFactoryDataModels.Models
{
string Login { get; }
string Password { get; }
string UserName { get; }
string Name { get; }
string Email { get; }
}
}

View File

@ -10,6 +10,6 @@ namespace FurnitureFactoryDataModels.Models
{
string Name { get; }
int Cost { get; }
int UserID { get; }
int MasterId { get; }
}
}