20
This commit is contained in:
parent
fef0d95c7a
commit
4b0700dee1
@ -11,6 +11,9 @@ namespace FurnitureAssemblyContracts.BindingModels
|
|||||||
public class AdBindingModel
|
public class AdBindingModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
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; }
|
public int FurnitureId { get; set; }
|
||||||
|
|
||||||
|
@ -16,6 +16,6 @@ namespace FurnitureAssemblyContracts.BindingModels
|
|||||||
|
|
||||||
public double Price { get; set; }
|
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
|
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("Номер")]
|
[DisplayName("Номер")]
|
||||||
public int Id { get; set; }
|
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; }
|
public int FurnitureId { get; set; }
|
||||||
|
|
||||||
[DisplayName("Изделие")]
|
[DisplayName("Название обьявления")]
|
||||||
public string UsersName { get; set; } = string.Empty;
|
public string UsersName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Количество")]
|
[DisplayName("Количество")]
|
||||||
|
@ -9,16 +9,16 @@ using System.Threading.Tasks;
|
|||||||
namespace FurnitureAssemblyContracts.ViewModels
|
namespace FurnitureAssemblyContracts.ViewModels
|
||||||
{
|
{
|
||||||
// Класс для отображения пользователю информации о продуктах (изделиях)
|
// Класс для отображения пользователю информации о продуктах (изделиях)
|
||||||
public class FurnitureViewModel : IUsersModel
|
public class UsersViewModel : IUsersModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[DisplayName("Название изделия")]
|
[DisplayName("имя юзера")]
|
||||||
public string UsersName { get; set; } = string.Empty;
|
public string UsersName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Цена")]
|
[DisplayName("Цена")]
|
||||||
public double Price { get; set; }
|
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
|
public interface IAdModel : IId
|
||||||
{
|
{
|
||||||
// id продукта
|
// id
|
||||||
int FurnitureId { get; }
|
int RegionId { get; }
|
||||||
|
int CategoryId { get; }
|
||||||
|
int UsersId { get; }
|
||||||
// кол-во продуктов
|
// кол-во продуктов
|
||||||
int Count { get; }
|
int Count { get; }
|
||||||
|
|
||||||
|
@ -16,6 +16,6 @@ namespace FurnitureAssemblyDataModels.Models
|
|||||||
double Price { get; }
|
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)
|
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);
|
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();
|
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)
|
FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
@ -37,8 +37,8 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
|
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
return context.Orders
|
return context.Ads
|
||||||
.Include(x => x.Furniture)
|
.Include(x => x.Users)
|
||||||
.Where(x => x.Id == model.Id)
|
.Where(x => x.Id == model.Id)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -48,7 +48,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
return context.Orders.Include(x => x.Furniture)
|
return context.Ads.Include(x => x.Users)
|
||||||
.Select(x => x.GetViewModel).ToList();
|
.Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,17 +62,17 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
context.Orders.Add(newOrder);
|
context.Ads.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
return context.Orders.Include(x => x.Furniture)
|
return context.Ads.Include(x => x.Users)
|
||||||
.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AdViewModel? Update(AdBindingModel model)
|
public AdViewModel? Update(AdBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
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)
|
if (order == null)
|
||||||
{
|
{
|
||||||
@ -82,17 +82,17 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
order.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
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)
|
public AdViewModel? Delete(AdBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
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)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Orders.Remove(element);
|
context.Ads.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
return element.GetViewModel;
|
return element.GetViewModel;
|
||||||
|
@ -17,7 +17,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
return context.WorkPieces
|
return context.Komments
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
|
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
return context.WorkPieces
|
return context.Komments
|
||||||
.Where(x => x.WorkPieceName.Contains(model.WorkPieceName))
|
.Where(x => x.WorkPieceName.Contains(model.WorkPieceName))
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -46,7 +46,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
|
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
return context.WorkPieces
|
return context.Komments
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkPieceName) && x.WorkPieceName == model.WorkPieceName) ||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkPieceName) && x.WorkPieceName == model.WorkPieceName) ||
|
||||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
context.WorkPieces.Add(newWorkPiece);
|
context.Komments.Add(newWorkPiece);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
return newWorkPiece.GetViewModel;
|
return newWorkPiece.GetViewModel;
|
||||||
@ -70,7 +70,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
public KommentViewModel? Update(KommentBindingModel model)
|
public KommentViewModel? Update(KommentBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
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)
|
if (workPiece == null)
|
||||||
{
|
{
|
||||||
@ -86,11 +86,11 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
public KommentViewModel? Delete(KommentBindingModel model)
|
public KommentViewModel? Delete(KommentBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
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)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.WorkPieces.Remove(element);
|
context.Komments.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
return element.GetViewModel;
|
return element.GetViewModel;
|
||||||
|
@ -15,19 +15,19 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
public class UsersStorage : IUsersStorage
|
public class UsersStorage : IUsersStorage
|
||||||
{
|
{
|
||||||
public List<FurnitureViewModel> GetFullList()
|
public List<UsersViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
return context.Furnitures
|
return context.Userss
|
||||||
.Include(x => x.WorkPieces)
|
.Include(x => x.Komments)
|
||||||
.ThenInclude(x => x.WorkPiece)
|
.ThenInclude(x => x.Komment)
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FurnitureViewModel> GetFilteredList(UsersSearchModel model)
|
public List<UsersViewModel> GetFilteredList(UsersSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.UsersName))
|
if (string.IsNullOrEmpty(model.UsersName))
|
||||||
{
|
{
|
||||||
@ -36,16 +36,16 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
|
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
return context.Furnitures
|
return context.Userss
|
||||||
.Include(x => x.WorkPieces)
|
.Include(x => x.Komments)
|
||||||
.ThenInclude(x => x.WorkPiece)
|
.ThenInclude(x => x.Komment)
|
||||||
.Where(x => x.UsersName.Contains(model.UsersName))
|
.Where(x => x.UsersName.Contains(model.UsersName))
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FurnitureViewModel? GetElement(UsersSearchModel model)
|
public UsersViewModel? GetElement(UsersSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.UsersName) && !model.Id.HasValue)
|
if (string.IsNullOrEmpty(model.UsersName) && !model.Id.HasValue)
|
||||||
{
|
{
|
||||||
@ -54,49 +54,49 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
|
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
|
||||||
return context.Furnitures
|
return context.Userss
|
||||||
.Include(x => x.WorkPieces)
|
.Include(x => x.Komments)
|
||||||
.ThenInclude(x => x.WorkPiece)
|
.ThenInclude(x => x.Komment)
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.UsersName) && x.UsersName == model.UsersName) ||
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.UsersName) && x.UsersName == model.UsersName) ||
|
||||||
model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FurnitureViewModel? Insert(UsersBindingModel model)
|
public UsersViewModel? Insert(UsersBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Furnitures.Add(newFurniture);
|
context.Userss.Add(newUser);
|
||||||
context.SaveChanges();
|
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 context = new FurnitureAssemblyDatabase();
|
||||||
using var transaction = context.Database.BeginTransaction();
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
|
||||||
try
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
furniture.Update(model);
|
user.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
furniture.UpdateWorkPieces(context, model);
|
user.UpdateWorkPieces(context, model);
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
|
|
||||||
return furniture.GetViewModel;
|
return user.GetViewModel;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -105,17 +105,17 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public FurnitureViewModel? Delete(UsersBindingModel model)
|
public UsersViewModel? Delete(UsersBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
var element = context.Furnitures
|
var element = context.Userss
|
||||||
.Include(x => x.WorkPieces)
|
.Include(x => x.Komments)
|
||||||
.Include(x => x.Orders)
|
.Include(x => x.Ads)
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Furnitures.Remove(element);
|
context.Userss.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
return element.GetViewModel;
|
return element.GetViewModel;
|
||||||
|
@ -16,8 +16,12 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
[Required]
|
[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]
|
[Required]
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|
||||||
@ -32,7 +36,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
|
|
||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
public virtual Users Furniture { get; set; }
|
public virtual Users Users { get; set; }
|
||||||
|
|
||||||
public static Ad? Create(AdBindingModel model)
|
public static Ad? Create(AdBindingModel model)
|
||||||
{
|
{
|
||||||
@ -44,7 +48,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
return new Ad()
|
return new Ad()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
FurnitureId = model.FurnitureId,
|
UsersId = model.UsersId,
|
||||||
|
RegionId = model.RegionId,
|
||||||
|
CategoryId = model.CategoryId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -67,13 +73,15 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
public AdViewModel GetViewModel => new()
|
public AdViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
FurnitureId = FurnitureId,
|
UsersId = UsersId,
|
||||||
|
RegionId = RegionId,
|
||||||
|
CategoryId = CategoryId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
UsersName = Furniture.UsersName
|
UsersName = Users.UsersName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,28 +22,28 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public double Price { get; set; }
|
public double Price { get; set; }
|
||||||
|
|
||||||
public Dictionary<int, (IKommentModel, int)>? _furnitureWorkPieces = null;
|
public Dictionary<int, (IKommentModel, int)>? _usersKomments = null;
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IKommentModel, int)> FurnitureWorkPieces
|
public Dictionary<int, (IKommentModel, int)> UsersKomments
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_furnitureWorkPieces == null)
|
if (_usersKomments == null)
|
||||||
{
|
{
|
||||||
_furnitureWorkPieces = WorkPieces
|
_usersKomments = Komments
|
||||||
.ToDictionary(recPC => recPC.WorkPieceId, recPC => (recPC.WorkPiece as IKommentModel, recPC.Count));
|
.ToDictionary(recPC => recPC.KommentId, recPC => (recPC.Komment as IKommentModel, recPC.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
return _furnitureWorkPieces;
|
return _usersKomments;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ForeignKey("FurnitureId")]
|
[ForeignKey("UsersId")]
|
||||||
public virtual List<UsersKomment> WorkPieces { get; set; } = new();
|
public virtual List<UsersKomment> Komments { get; set; } = new();
|
||||||
|
|
||||||
[ForeignKey("FurnitureId")]
|
[ForeignKey("UsersId")]
|
||||||
public virtual List<Ad> Orders { get; set; } = new();
|
public virtual List<Ad> Ads { get; set; } = new();
|
||||||
|
|
||||||
public static Users Create(FurnitureAssemblyDatabase context, UsersBindingModel model)
|
public static Users Create(FurnitureAssemblyDatabase context, UsersBindingModel model)
|
||||||
{
|
{
|
||||||
@ -52,9 +52,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
UsersName = model.UsersName,
|
UsersName = model.UsersName,
|
||||||
Price = model.Price,
|
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
|
Count = x.Value.Item2
|
||||||
}).ToList()
|
}).ToList()
|
||||||
};
|
};
|
||||||
@ -66,52 +66,52 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FurnitureViewModel GetViewModel => new()
|
public UsersViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
UsersName = UsersName,
|
UsersName = UsersName,
|
||||||
Price = Price,
|
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)
|
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();
|
context.SaveChanges();
|
||||||
|
|
||||||
// обновили количество у существующих записей
|
// обновили количество у существующих записей
|
||||||
foreach (var updateFurniture in furnitureWorkPieces)
|
foreach (var updateUsers in usersKomments)
|
||||||
{
|
{
|
||||||
updateFurniture.Count = model.FurnitureWorkPieces[updateFurniture.FurnitureId].Item2;
|
updateUsers.Count = model.UsersKomments[updateUsers.UsersId].Item2;
|
||||||
model.FurnitureWorkPieces.Remove(updateFurniture.FurnitureId);
|
model.UsersKomments.Remove(updateUsers.UsersId);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.SaveChanges();
|
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,
|
Users = user,
|
||||||
WorkPiece = context.WorkPieces.First(x => x.Id == pc.Key),
|
Komment = context.Komments.First(x => x.Id == pc.Key),
|
||||||
Count = pc.Value.Item2
|
Count = pc.Value.Item2
|
||||||
});
|
});
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
_furnitureWorkPieces = null;
|
_usersKomments = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,16 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int FurnitureId { get; set; }
|
public int UsersId { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int WorkPieceId { get; set; }
|
public int KommentId { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int Count { get; set; }
|
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 class Ad : IAdModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
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; }
|
public int FurnitureId { get; private set; }
|
||||||
|
|
||||||
@ -37,7 +40,8 @@ namespace FurnitureAssemblyFileImplement.Models
|
|||||||
return new Ad()
|
return new Ad()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
FurnitureId = model.FurnitureId,
|
UsersId = model.UsersId,
|
||||||
|
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
|
@ -18,23 +18,23 @@ namespace FurnitureAssemblyFileImplement.Models
|
|||||||
|
|
||||||
public double Price { get; private set; }
|
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
|
get
|
||||||
{
|
{
|
||||||
if (_furnitureWorkPieces == null)
|
if (_usersKomments == null)
|
||||||
{
|
{
|
||||||
var source = DataFileSingleton.GetInstance();
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
|
||||||
_furnitureWorkPieces = WorkPieces.ToDictionary(x => x.Key,
|
_usersKomments = Komments.ToDictionary(x => x.Key,
|
||||||
y => ((source.WorkPieces.FirstOrDefault(z => z.Id == y.Key) as IKommentModel)!, y.Value));
|
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,
|
Id = model.Id,
|
||||||
UsersName = model.UsersName,
|
UsersName = model.UsersName,
|
||||||
Price = model.Price,
|
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),
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
UsersName = element.Element("UsersName")!.Value,
|
UsersName = element.Element("UsersName")!.Value,
|
||||||
Price = Convert.ToDouble(element.Element("Price")!.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),
|
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||||
y => Convert.ToInt32(y.Element("Value")?.Value))
|
y => Convert.ToInt32(y.Element("Value")?.Value))
|
||||||
};
|
};
|
||||||
@ -81,24 +81,24 @@ namespace FurnitureAssemblyFileImplement.Models
|
|||||||
|
|
||||||
UsersName = model.UsersName;
|
UsersName = model.UsersName;
|
||||||
Price = model.Price;
|
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);
|
||||||
_furnitureWorkPieces = null;
|
_usersKomments = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FurnitureViewModel GetViewModel => new()
|
public UsersViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
UsersName = UsersName,
|
UsersName = UsersName,
|
||||||
Price = Price,
|
Price = Price,
|
||||||
FurnitureWorkPieces = FurnitureWorkPieces
|
UsersKomments = UsersKomments
|
||||||
};
|
};
|
||||||
|
|
||||||
public XElement GetXElement => new("Furniture",
|
public XElement GetXElement => new("User",
|
||||||
new XAttribute("Id", Id),
|
new XAttribute("Id", Id),
|
||||||
new XElement("UsersName", UsersName),
|
new XElement("UsersName", UsersName),
|
||||||
new XElement("Price", Price.ToString()),
|
new XElement("Price", Price.ToString()),
|
||||||
new XElement("FurnitureWorkPieces", WorkPieces.Select(
|
new XElement("UsersKomments", Komments.Select(
|
||||||
x => new XElement("FurnitureWorkPieces",
|
x => new XElement("UsersKomments",
|
||||||
new XElement("Key", x.Key),
|
new XElement("Key", x.Key),
|
||||||
new XElement("Value", x.Value))
|
new XElement("Value", x.Value))
|
||||||
).ToArray()));
|
).ToArray()));
|
||||||
|
@ -19,7 +19,7 @@ namespace FurnitureAssemblyListImplement.Models
|
|||||||
|
|
||||||
public double Price { get; private set; }
|
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
|
// Метод для создания объекта от класса-компонента на основе класса-BindingModel
|
||||||
public static Users? Create(UsersBindingModel? model)
|
public static Users? Create(UsersBindingModel? model)
|
||||||
@ -34,7 +34,7 @@ namespace FurnitureAssemblyListImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
UsersName = model.UsersName,
|
UsersName = model.UsersName,
|
||||||
Price = model.Price,
|
Price = model.Price,
|
||||||
FurnitureWorkPieces = model.FurnitureWorkPieces
|
UsersKomments = model.UsersKomments
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,16 +48,16 @@ namespace FurnitureAssemblyListImplement.Models
|
|||||||
|
|
||||||
UsersName = model.UsersName;
|
UsersName = model.UsersName;
|
||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
FurnitureWorkPieces = model.FurnitureWorkPieces;
|
UsersKomments = model.UsersKomments;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
|
// Метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
|
||||||
public FurnitureViewModel GetViewModel => new()
|
public UsersViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
UsersName = UsersName,
|
UsersName = UsersName,
|
||||||
Price = Price,
|
Price = Price,
|
||||||
FurnitureWorkPieces = FurnitureWorkPieces
|
UsersKomments = UsersKomments
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user