20
This commit is contained in:
parent
fef0d95c7a
commit
4b0700dee1
@ -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; }
|
||||
|
||||
|
@ -16,6 +16,6 @@ namespace FurnitureAssemblyContracts.BindingModels
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public Dictionary<int, (IKommentModel, int)> FurnitureWorkPieces { get; set; } = new();
|
||||
public Dictionary<int, (IKommentModel, int)> UsersKomments { get; set; } = new();
|
||||
}
|
||||
}
|
@ -12,16 +12,16 @@ namespace FurnitureAssemblyContracts.StoragesContracts
|
||||
// Класс для хранилища продуктов (изделий)
|
||||
public interface IUsersStorage
|
||||
{
|
||||
List<FurnitureViewModel> GetFullList();
|
||||
List<UsersViewModel> GetFullList();
|
||||
|
||||
List<FurnitureViewModel> GetFilteredList(UsersSearchModel model);
|
||||
List<UsersViewModel> 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);
|
||||
}
|
||||
}
|
@ -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("Количество")]
|
||||
|
@ -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<int, (IKommentModel, int)> FurnitureWorkPieces { get; set; } = new();
|
||||
public Dictionary<int, (IKommentModel, int)> UsersKomments { get; set; } = new();
|
||||
}
|
||||
}
|
@ -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; }
|
||||
|
||||
|
@ -16,6 +16,6 @@ namespace FurnitureAssemblyDataModels.Models
|
||||
double Price { get; }
|
||||
|
||||
// словарь, хранящий пары кол-во + компонент и его цена
|
||||
Dictionary<int, (IKommentModel, int)> FurnitureWorkPieces { get; }
|
||||
Dictionary<int, (IKommentModel, int)> UsersKomments { get; }
|
||||
}
|
||||
}
|
@ -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<Komment> WorkPieces { set; get; }
|
||||
public virtual DbSet<Komment> Komments { set; get; }
|
||||
|
||||
public virtual DbSet<Users> Furnitures { set; get; }
|
||||
public virtual DbSet<Users> Userss { set; get; }
|
||||
|
||||
public virtual DbSet<UsersKomment> FurnitureWorkPieces { set; get; }
|
||||
public virtual DbSet<UsersKomment> UsersKomments { set; get; }
|
||||
|
||||
public virtual DbSet<Ad> Orders { set; get; }
|
||||
public virtual DbSet<Ad> Ads { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -15,19 +15,19 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
public class UsersStorage : IUsersStorage
|
||||
{
|
||||
public List<FurnitureViewModel> GetFullList()
|
||||
public List<UsersViewModel> 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<FurnitureViewModel> GetFilteredList(UsersSearchModel model)
|
||||
public List<UsersViewModel> 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;
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -22,28 +22,28 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
public Dictionary<int, (IKommentModel, int)>? _furnitureWorkPieces = null;
|
||||
public Dictionary<int, (IKommentModel, int)>? _usersKomments = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IKommentModel, int)> FurnitureWorkPieces
|
||||
public Dictionary<int, (IKommentModel, int)> 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<UsersKomment> WorkPieces { get; set; } = new();
|
||||
[ForeignKey("UsersId")]
|
||||
public virtual List<UsersKomment> Komments { get; set; } = new();
|
||||
|
||||
[ForeignKey("FurnitureId")]
|
||||
public virtual List<Ad> Orders { get; set; } = new();
|
||||
[ForeignKey("UsersId")]
|
||||
public virtual List<Ad> 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<int, (IKommentModel, int)> IUsersModel.FurnitureWorkPieces => throw new NotImplementedException();
|
||||
Dictionary<int, (IKommentModel, int)> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -18,23 +18,23 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public Dictionary<int, int> WorkPieces { get; private set; } = new();
|
||||
public Dictionary<int, int> Komments { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IKommentModel, int)>? _furnitureWorkPieces = null;
|
||||
private Dictionary<int, (IKommentModel, int)>? _usersKomments = null;
|
||||
|
||||
public Dictionary<int, (IKommentModel, int)> FurnitureWorkPieces
|
||||
public Dictionary<int, (IKommentModel, int)> 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()));
|
||||
|
@ -19,7 +19,7 @@ namespace FurnitureAssemblyListImplement.Models
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public Dictionary<int, (IKommentModel, int)> FurnitureWorkPieces { get; private set; } = new Dictionary<int, (IKommentModel, int)>();
|
||||
public Dictionary<int, (IKommentModel, int)> UsersKomments { get; private set; } = new Dictionary<int, (IKommentModel, int)>();
|
||||
|
||||
// Метод для создания объекта от класса-компонента на основе класса-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
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user