From 4b0700dee10fe7598dcaf742b999edc5baa98140 Mon Sep 17 00:00:00 2001 From: platoff aeeee Date: Fri, 24 May 2024 14:23:37 +0400 Subject: [PATCH] 20 --- .../BindingModels/AdBindingModel.cs | 3 + .../BindingModels/UsersBindingModel.cs | 2 +- .../StoragesContracts/IUsersStorage.cs | 12 ++-- .../ViewModels/AdViewModel.cs | 6 +- .../ViewModels/UsersViewModel.cs | 6 +- .../Models/IAdModel.cs | 7 ++- .../Models/IUsersModel.cs | 2 +- .../FurnitureAssemblyDatabase.cs | 10 ++-- .../Implements/AdStorage.cs | 20 +++---- .../Implements/KommentStorage.cs | 14 ++--- .../Implements/UsersStorage.cs | 56 +++++++++---------- .../Models/Ad.cs | 18 ++++-- .../Models/Users.cs | 54 +++++++++--------- .../Models/UsersKomment.cs | 8 +-- .../Models/Ad.cs | 6 +- .../Models/Users.cs | 32 +++++------ .../Models/Users.cs | 10 ++-- 17 files changed, 142 insertions(+), 124 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/AdBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/AdBindingModel.cs index 7ff91b9..a79d7d8 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/AdBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/AdBindingModel.cs @@ -11,6 +11,9 @@ namespace FurnitureAssemblyContracts.BindingModels public class AdBindingModel { public int Id { get; set; } + public int UsersId { get; set; } + public int CategoryId { get; set; } + public int RegionId { get; set; } public int FurnitureId { get; set; } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/UsersBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/UsersBindingModel.cs index 0063c7f..30cc6de 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/UsersBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/UsersBindingModel.cs @@ -16,6 +16,6 @@ namespace FurnitureAssemblyContracts.BindingModels public double Price { get; set; } - public Dictionary FurnitureWorkPieces { get; set; } = new(); + public Dictionary UsersKomments { get; set; } = new(); } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IUsersStorage.cs b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IUsersStorage.cs index a76c07d..89eb1fc 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IUsersStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/StoragesContracts/IUsersStorage.cs @@ -12,16 +12,16 @@ namespace FurnitureAssemblyContracts.StoragesContracts // Класс для хранилища продуктов (изделий) public interface IUsersStorage { - List GetFullList(); + List GetFullList(); - List GetFilteredList(UsersSearchModel model); + List GetFilteredList(UsersSearchModel model); - FurnitureViewModel? GetElement(UsersSearchModel model); + UsersViewModel? GetElement(UsersSearchModel model); - FurnitureViewModel? Insert(UsersBindingModel model); + UsersViewModel? Insert(UsersBindingModel model); - FurnitureViewModel? Update(UsersBindingModel model); + UsersViewModel? Update(UsersBindingModel model); - FurnitureViewModel? Delete(UsersBindingModel model); + UsersViewModel? Delete(UsersBindingModel model); } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/AdViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/AdViewModel.cs index 2d9e6da..a8e76d7 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/AdViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/AdViewModel.cs @@ -14,10 +14,12 @@ namespace FurnitureAssemblyContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } - + public int UsersId { get; set; } + public int CategoryId { get; set; } + public int RegionId { get; set; } public int FurnitureId { get; set; } - [DisplayName("Изделие")] + [DisplayName("Название обьявления")] public string UsersName { get; set; } = string.Empty; [DisplayName("Количество")] diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/UsersViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/UsersViewModel.cs index 16e5991..b635599 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/UsersViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/UsersViewModel.cs @@ -9,16 +9,16 @@ using System.Threading.Tasks; namespace FurnitureAssemblyContracts.ViewModels { // Класс для отображения пользователю информации о продуктах (изделиях) - public class FurnitureViewModel : IUsersModel + public class UsersViewModel : IUsersModel { public int Id { get; set; } - [DisplayName("Название изделия")] + [DisplayName("имя юзера")] public string UsersName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } - public Dictionary FurnitureWorkPieces { get; set; } = new(); + public Dictionary UsersKomments { get; set; } = new(); } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IAdModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IAdModel.cs index 5bcfa02..3f23ec3 100644 --- a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IAdModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IAdModel.cs @@ -10,9 +10,10 @@ namespace FurnitureAssemblyDataModels.Models // Интерфейс, отвечающий за заказ public interface IAdModel : IId { - // id продукта - int FurnitureId { get; } - + // id + int RegionId { get; } + int CategoryId { get; } + int UsersId { get; } // кол-во продуктов int Count { get; } diff --git a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IUsersModel.cs b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IUsersModel.cs index 6585ed7..429b5c1 100644 --- a/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IUsersModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyDataModels/Models/IUsersModel.cs @@ -16,6 +16,6 @@ namespace FurnitureAssemblyDataModels.Models double Price { get; } // словарь, хранящий пары кол-во + компонент и его цена - Dictionary FurnitureWorkPieces { get; } + Dictionary UsersKomments { get; } } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs index cf331e9..5c9fdaa 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/FurnitureAssemblyDatabase.cs @@ -14,18 +14,18 @@ namespace FurnitureAssemblyDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=WIN-N21FHIN3LLR\SQLEXPRESS;Initial Catalog=FurnitureAssemblyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=WIN-N21FHIN3LLR\SQLEXPRESS;Initial Catalog=AdDatabase4;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } - public virtual DbSet WorkPieces { set; get; } + public virtual DbSet Komments { set; get; } - public virtual DbSet Furnitures { set; get; } + public virtual DbSet Userss { set; get; } - public virtual DbSet FurnitureWorkPieces { set; get; } + public virtual DbSet UsersKomments { set; get; } - public virtual DbSet Orders { set; get; } + public virtual DbSet Ads { set; get; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/AdStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/AdStorage.cs index d6ab77c..47204f2 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/AdStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/AdStorage.cs @@ -23,7 +23,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements using var context = new FurnitureAssemblyDatabase(); - return context.Orders.Include(x => x.Furniture). + return context.Ads.Include(x => x.Users). FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; } @@ -37,8 +37,8 @@ namespace FurnitureAssemblyDatabaseImplement.Implements using var context = new FurnitureAssemblyDatabase(); - return context.Orders - .Include(x => x.Furniture) + return context.Ads + .Include(x => x.Users) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -48,7 +48,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { using var context = new FurnitureAssemblyDatabase(); - return context.Orders.Include(x => x.Furniture) + return context.Ads.Include(x => x.Users) .Select(x => x.GetViewModel).ToList(); } @@ -62,17 +62,17 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } using var context = new FurnitureAssemblyDatabase(); - context.Orders.Add(newOrder); + context.Ads.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Furniture) + return context.Ads.Include(x => x.Users) .FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public AdViewModel? Update(AdBindingModel model) { using var context = new FurnitureAssemblyDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + var order = context.Ads.FirstOrDefault(x => x.Id == model.Id); if (order == null) { @@ -82,17 +82,17 @@ namespace FurnitureAssemblyDatabaseImplement.Implements order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Furniture).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Ads.Include(x => x.Users).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public AdViewModel? Delete(AdBindingModel model) { using var context = new FurnitureAssemblyDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Ads.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { - context.Orders.Remove(element); + context.Ads.Remove(element); context.SaveChanges(); return element.GetViewModel; diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/KommentStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/KommentStorage.cs index 151852c..3c1f88e 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/KommentStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/KommentStorage.cs @@ -17,7 +17,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { using var context = new FurnitureAssemblyDatabase(); - return context.WorkPieces + return context.Komments .Select(x => x.GetViewModel) .ToList(); } @@ -31,7 +31,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements using var context = new FurnitureAssemblyDatabase(); - return context.WorkPieces + return context.Komments .Where(x => x.WorkPieceName.Contains(model.WorkPieceName)) .Select(x => x.GetViewModel) .ToList(); @@ -46,7 +46,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements using var context = new FurnitureAssemblyDatabase(); - return context.WorkPieces + return context.Komments .FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkPieceName) && x.WorkPieceName == model.WorkPieceName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } @@ -61,7 +61,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } using var context = new FurnitureAssemblyDatabase(); - context.WorkPieces.Add(newWorkPiece); + context.Komments.Add(newWorkPiece); context.SaveChanges(); return newWorkPiece.GetViewModel; @@ -70,7 +70,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements public KommentViewModel? Update(KommentBindingModel model) { using var context = new FurnitureAssemblyDatabase(); - var workPiece = context.WorkPieces.FirstOrDefault(x => x.Id == model.Id); + var workPiece = context.Komments.FirstOrDefault(x => x.Id == model.Id); if (workPiece == null) { @@ -86,11 +86,11 @@ namespace FurnitureAssemblyDatabaseImplement.Implements public KommentViewModel? Delete(KommentBindingModel model) { using var context = new FurnitureAssemblyDatabase(); - var element = context.WorkPieces.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Komments.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { - context.WorkPieces.Remove(element); + context.Komments.Remove(element); context.SaveChanges(); return element.GetViewModel; diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/UsersStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/UsersStorage.cs index 930a57a..21bdda6 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/UsersStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/UsersStorage.cs @@ -15,19 +15,19 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { public class UsersStorage : IUsersStorage { - public List GetFullList() + public List GetFullList() { using var context = new FurnitureAssemblyDatabase(); - return context.Furnitures - .Include(x => x.WorkPieces) - .ThenInclude(x => x.WorkPiece) + return context.Userss + .Include(x => x.Komments) + .ThenInclude(x => x.Komment) .ToList() .Select(x => x.GetViewModel) .ToList(); } - public List GetFilteredList(UsersSearchModel model) + public List GetFilteredList(UsersSearchModel model) { if (string.IsNullOrEmpty(model.UsersName)) { @@ -36,16 +36,16 @@ namespace FurnitureAssemblyDatabaseImplement.Implements using var context = new FurnitureAssemblyDatabase(); - return context.Furnitures - .Include(x => x.WorkPieces) - .ThenInclude(x => x.WorkPiece) + return context.Userss + .Include(x => x.Komments) + .ThenInclude(x => x.Komment) .Where(x => x.UsersName.Contains(model.UsersName)) .ToList() .Select(x => x.GetViewModel) .ToList(); } - public FurnitureViewModel? GetElement(UsersSearchModel model) + public UsersViewModel? GetElement(UsersSearchModel model) { if (string.IsNullOrEmpty(model.UsersName) && !model.Id.HasValue) { @@ -54,49 +54,49 @@ namespace FurnitureAssemblyDatabaseImplement.Implements using var context = new FurnitureAssemblyDatabase(); - return context.Furnitures - .Include(x => x.WorkPieces) - .ThenInclude(x => x.WorkPiece) + return context.Userss + .Include(x => x.Komments) + .ThenInclude(x => x.Komment) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.UsersName) && x.UsersName == model.UsersName) || model.Id.HasValue && x.Id == model.Id)?.GetViewModel; } - public FurnitureViewModel? Insert(UsersBindingModel model) + public UsersViewModel? Insert(UsersBindingModel model) { using var context = new FurnitureAssemblyDatabase(); - var newFurniture = Users.Create(context, model); + var newUser = Users.Create(context, model); - if (newFurniture == null) + if (newUser == null) { return null; } - context.Furnitures.Add(newFurniture); + context.Userss.Add(newUser); context.SaveChanges(); - return newFurniture.GetViewModel; + return newUser.GetViewModel; } - public FurnitureViewModel? Update(UsersBindingModel model) + public UsersViewModel? Update(UsersBindingModel model) { using var context = new FurnitureAssemblyDatabase(); using var transaction = context.Database.BeginTransaction(); try { - var furniture = context.Furnitures.FirstOrDefault(rec => rec.Id == model.Id); + var user = context.Userss.FirstOrDefault(rec => rec.Id == model.Id); - if (furniture == null) + if (user == null) { return null; } - furniture.Update(model); + user.Update(model); context.SaveChanges(); - furniture.UpdateWorkPieces(context, model); + user.UpdateWorkPieces(context, model); transaction.Commit(); - return furniture.GetViewModel; + return user.GetViewModel; } catch { @@ -105,17 +105,17 @@ namespace FurnitureAssemblyDatabaseImplement.Implements } } - public FurnitureViewModel? Delete(UsersBindingModel model) + public UsersViewModel? Delete(UsersBindingModel model) { using var context = new FurnitureAssemblyDatabase(); - var element = context.Furnitures - .Include(x => x.WorkPieces) - .Include(x => x.Orders) + var element = context.Userss + .Include(x => x.Komments) + .Include(x => x.Ads) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { - context.Furnitures.Remove(element); + context.Userss.Remove(element); context.SaveChanges(); return element.GetViewModel; diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Ad.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Ad.cs index 6cd445c..93046d1 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Ad.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Ad.cs @@ -16,8 +16,12 @@ namespace FurnitureAssemblyDatabaseImplement.Models public int Id { get; private set; } [Required] - public int FurnitureId { get; private set; } + public int UsersId { get; private set; } + [Required] + public int CategoryId { get; private set; } + [Required] + public int RegionId { get; private set; } [Required] public int Count { get; private set; } @@ -32,7 +36,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models public DateTime? DateImplement { get; private set; } - public virtual Users Furniture { get; set; } + public virtual Users Users { get; set; } public static Ad? Create(AdBindingModel model) { @@ -44,7 +48,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models return new Ad() { Id = model.Id, - FurnitureId = model.FurnitureId, + UsersId = model.UsersId, + RegionId = model.RegionId, + CategoryId = model.CategoryId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -67,13 +73,15 @@ namespace FurnitureAssemblyDatabaseImplement.Models public AdViewModel GetViewModel => new() { Id = Id, - FurnitureId = FurnitureId, + UsersId = UsersId, + RegionId = RegionId, + CategoryId = CategoryId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - UsersName = Furniture.UsersName + UsersName = Users.UsersName }; } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Users.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Users.cs index f5d0019..5829442 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Users.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/Users.cs @@ -22,28 +22,28 @@ namespace FurnitureAssemblyDatabaseImplement.Models [Required] public double Price { get; set; } - public Dictionary? _furnitureWorkPieces = null; + public Dictionary? _usersKomments = null; [NotMapped] - public Dictionary FurnitureWorkPieces + public Dictionary UsersKomments { get { - if (_furnitureWorkPieces == null) + if (_usersKomments == null) { - _furnitureWorkPieces = WorkPieces - .ToDictionary(recPC => recPC.WorkPieceId, recPC => (recPC.WorkPiece as IKommentModel, recPC.Count)); + _usersKomments = Komments + .ToDictionary(recPC => recPC.KommentId, recPC => (recPC.Komment as IKommentModel, recPC.Count)); } - return _furnitureWorkPieces; + return _usersKomments; } } - [ForeignKey("FurnitureId")] - public virtual List WorkPieces { get; set; } = new(); + [ForeignKey("UsersId")] + public virtual List Komments { get; set; } = new(); - [ForeignKey("FurnitureId")] - public virtual List Orders { get; set; } = new(); + [ForeignKey("UsersId")] + public virtual List Ads { get; set; } = new(); public static Users Create(FurnitureAssemblyDatabase context, UsersBindingModel model) { @@ -52,9 +52,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models Id = model.Id, UsersName = model.UsersName, Price = model.Price, - WorkPieces = model.FurnitureWorkPieces.Select(x => new UsersKomment + Komments = model.UsersKomments.Select(x => new UsersKomment { - WorkPiece = context.WorkPieces.First(y => y.Id == x.Key), + Komment = context.Komments.First(y => y.Id == x.Key), Count = x.Value.Item2 }).ToList() }; @@ -66,52 +66,52 @@ namespace FurnitureAssemblyDatabaseImplement.Models Price = model.Price; } - public FurnitureViewModel GetViewModel => new() + public UsersViewModel GetViewModel => new() { Id = Id, UsersName = UsersName, Price = Price, - FurnitureWorkPieces = FurnitureWorkPieces + UsersKomments = UsersKomments }; - Dictionary IUsersModel.FurnitureWorkPieces => throw new NotImplementedException(); + Dictionary IUsersModel.UsersKomments => throw new NotImplementedException(); public void UpdateWorkPieces(FurnitureAssemblyDatabase context, UsersBindingModel model) { - var furnitureWorkPieces = context.FurnitureWorkPieces.Where(rec => rec.FurnitureId == model.Id).ToList(); + var usersKomments = context.UsersKomments.Where(rec => rec.UsersId == model.Id).ToList(); - if (furnitureWorkPieces != null && furnitureWorkPieces.Count > 0) + if (usersKomments != null && usersKomments.Count > 0) { // удалили те, которых нет в модели - context.FurnitureWorkPieces.RemoveRange(furnitureWorkPieces.Where(rec => !model.FurnitureWorkPieces.ContainsKey(rec.FurnitureId))); + context.UsersKomments.RemoveRange(usersKomments.Where(rec => !model.UsersKomments.ContainsKey(rec.UsersId))); context.SaveChanges(); // обновили количество у существующих записей - foreach (var updateFurniture in furnitureWorkPieces) + foreach (var updateUsers in usersKomments) { - updateFurniture.Count = model.FurnitureWorkPieces[updateFurniture.FurnitureId].Item2; - model.FurnitureWorkPieces.Remove(updateFurniture.FurnitureId); + updateUsers.Count = model.UsersKomments[updateUsers.UsersId].Item2; + model.UsersKomments.Remove(updateUsers.UsersId); } context.SaveChanges(); } - var furniture = context.Furnitures.First(x => x.Id == Id); + var user = context.Userss.First(x => x.Id == Id); - foreach (var pc in model.FurnitureWorkPieces) + foreach (var pc in model.UsersKomments) { - context.FurnitureWorkPieces.Add(new UsersKomment + context.UsersKomments.Add(new UsersKomment { - Furniture = furniture, - WorkPiece = context.WorkPieces.First(x => x.Id == pc.Key), + Users = user, + Komment = context.Komments.First(x => x.Id == pc.Key), Count = pc.Value.Item2 }); context.SaveChanges(); } - _furnitureWorkPieces = null; + _usersKomments = null; } } } diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/UsersKomment.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/UsersKomment.cs index fc7525c..ad03374 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/UsersKomment.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Models/UsersKomment.cs @@ -12,16 +12,16 @@ namespace FurnitureAssemblyDatabaseImplement.Models public int Id { get; set; } [Required] - public int FurnitureId { get; set; } + public int UsersId { get; set; } [Required] - public int WorkPieceId { get; set; } + public int KommentId { get; set; } [Required] public int Count { get; set; } - public virtual Komment WorkPiece { get; set; } = new(); + public virtual Komment Komment { get; set; } = new(); - public virtual Users Furniture { get; set; } = new(); + public virtual Users Users { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Ad.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Ad.cs index 149eaac..7ef4bac 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Ad.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Ad.cs @@ -14,6 +14,9 @@ namespace FurnitureAssemblyFileImplement.Models public class Ad : IAdModel { public int Id { get; private set; } + public int UsersId { get; private set; } + public int CategoryId { get; private set; } + public int RegionId { get; private set; } public int FurnitureId { get; private set; } @@ -37,7 +40,8 @@ namespace FurnitureAssemblyFileImplement.Models return new Ad() { Id = model.Id, - FurnitureId = model.FurnitureId, + UsersId = model.UsersId, + Count = model.Count, Sum = model.Sum, Status = model.Status, diff --git a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Users.cs b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Users.cs index dd3eee7..36285ab 100644 --- a/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Users.cs +++ b/FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Users.cs @@ -18,23 +18,23 @@ namespace FurnitureAssemblyFileImplement.Models public double Price { get; private set; } - public Dictionary WorkPieces { get; private set; } = new(); + public Dictionary Komments { get; private set; } = new(); - private Dictionary? _furnitureWorkPieces = null; + private Dictionary? _usersKomments = null; - public Dictionary FurnitureWorkPieces + public Dictionary UsersKomments { get { - if (_furnitureWorkPieces == null) + if (_usersKomments == null) { var source = DataFileSingleton.GetInstance(); - _furnitureWorkPieces = WorkPieces.ToDictionary(x => x.Key, - y => ((source.WorkPieces.FirstOrDefault(z => z.Id == y.Key) as IKommentModel)!, y.Value)); + _usersKomments = Komments.ToDictionary(x => x.Key, + y => ((source.Komments.FirstOrDefault(z => z.Id == y.Key) as IKommentModel)!, y.Value)); } - return _furnitureWorkPieces; + return _usersKomments; } } @@ -50,7 +50,7 @@ namespace FurnitureAssemblyFileImplement.Models Id = model.Id, UsersName = model.UsersName, Price = model.Price, - WorkPieces = model.FurnitureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2) + Komments = model.UsersKomments.ToDictionary(x => x.Key, x => x.Value.Item2) }; } @@ -66,7 +66,7 @@ namespace FurnitureAssemblyFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), UsersName = element.Element("UsersName")!.Value, Price = Convert.ToDouble(element.Element("Price")!.Value), - WorkPieces = element.Element("FurnitureWorkPieces")!.Elements("FurnitureWorkPieces").ToDictionary( + Komments = element.Element("FurnitureWorkPieces")!.Elements("FurnitureWorkPieces").ToDictionary( x => Convert.ToInt32(x.Element("Key")?.Value), y => Convert.ToInt32(y.Element("Value")?.Value)) }; @@ -81,24 +81,24 @@ namespace FurnitureAssemblyFileImplement.Models UsersName = model.UsersName; Price = model.Price; - WorkPieces = model.FurnitureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2); - _furnitureWorkPieces = null; + Komments = model.UsersKomments.ToDictionary(x => x.Key, x => x.Value.Item2); + _usersKomments = null; } - public FurnitureViewModel GetViewModel => new() + public UsersViewModel GetViewModel => new() { Id = Id, UsersName = UsersName, Price = Price, - FurnitureWorkPieces = FurnitureWorkPieces + UsersKomments = UsersKomments }; - public XElement GetXElement => new("Furniture", + public XElement GetXElement => new("User", new XAttribute("Id", Id), new XElement("UsersName", UsersName), new XElement("Price", Price.ToString()), - new XElement("FurnitureWorkPieces", WorkPieces.Select( - x => new XElement("FurnitureWorkPieces", + new XElement("UsersKomments", Komments.Select( + x => new XElement("UsersKomments", new XElement("Key", x.Key), new XElement("Value", x.Value)) ).ToArray())); diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Users.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Users.cs index edd1947..4e5822b 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Users.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Users.cs @@ -19,7 +19,7 @@ namespace FurnitureAssemblyListImplement.Models public double Price { get; private set; } - public Dictionary FurnitureWorkPieces { get; private set; } = new Dictionary(); + public Dictionary UsersKomments { get; private set; } = new Dictionary(); // Метод для создания объекта от класса-компонента на основе класса-BindingModel public static Users? Create(UsersBindingModel? model) @@ -34,7 +34,7 @@ namespace FurnitureAssemblyListImplement.Models Id = model.Id, UsersName = model.UsersName, Price = model.Price, - FurnitureWorkPieces = model.FurnitureWorkPieces + UsersKomments = model.UsersKomments }; } @@ -48,16 +48,16 @@ namespace FurnitureAssemblyListImplement.Models UsersName = model.UsersName; Price = model.Price; - FurnitureWorkPieces = model.FurnitureWorkPieces; + UsersKomments = model.UsersKomments; } // Метод для создания объекта класса ViewModel на основе данных объекта класса-компонента - public FurnitureViewModel GetViewModel => new() + public UsersViewModel GetViewModel => new() { Id = Id, UsersName = UsersName, Price = Price, - FurnitureWorkPieces = FurnitureWorkPieces + UsersKomments = UsersKomments }; } } \ No newline at end of file