PIbd-21 Belianin N.N. LabWork08_Hard #16
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,6 +10,7 @@
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
*.dll
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
@ -13,13 +13,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyListImplem
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyView", "FurnitureAssemblyView\FurnitureAssemblyView.csproj", "{77944C5A-53FC-437B-A563-E7C09C769859}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyFileImplement", "FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj", "{2EF175D6-B6BD-442B-B81E-67E368553726}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyFileImplement", "FurnitureAssemblyFileImplement\FurnitureAssemblyFileImplement.csproj", "{C987B2B5-56C1-434F-BBCF-6453CF6E5193}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyDatabaseImplement", "FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj", "{C2302631-5038-4592-B75F-C03C3ABD510D}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyDatabaseImplement", "FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj", "{D236EEDD-7AAE-40FF-BE52-B637EEA89FA6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyRestApi", "FurnitureAssemblyRestApi\FurnitureAssemblyRestApi.csproj", "{8F808327-C893-4F7B-ACEC-A8F960D4C2F4}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyRestApi", "FurnitureAssemblyRestApi\FurnitureAssemblyRestApi.csproj", "{8622D3F5-AC1F-4D70-AA32-720447AB632F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyClientApp", "FurnitureAssemblyClientApp\FurnitureAssemblyClientApp.csproj", "{7125E0C7-C4DC-41D1-9365-06A8A7647302}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyClientApp", "FurnitureAssemblyClientApp\FurnitureAssemblyClientApp.csproj", "{14EBC846-F344-4D99-9594-43509A3C1861}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyShopApp", "FurnitureAssemblyShopApp\FurnitureAssemblyShopApp.csproj", "{9EC23C5C-03D2-4890-8FA0-7D42BE8802E2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -47,22 +49,26 @@ Global
|
||||
{77944C5A-53FC-437B-A563-E7C09C769859}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{77944C5A-53FC-437B-A563-E7C09C769859}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{77944C5A-53FC-437B-A563-E7C09C769859}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2EF175D6-B6BD-442B-B81E-67E368553726}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2EF175D6-B6BD-442B-B81E-67E368553726}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2EF175D6-B6BD-442B-B81E-67E368553726}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2EF175D6-B6BD-442B-B81E-67E368553726}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C2302631-5038-4592-B75F-C03C3ABD510D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2302631-5038-4592-B75F-C03C3ABD510D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2302631-5038-4592-B75F-C03C3ABD510D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C2302631-5038-4592-B75F-C03C3ABD510D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8F808327-C893-4F7B-ACEC-A8F960D4C2F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8F808327-C893-4F7B-ACEC-A8F960D4C2F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8F808327-C893-4F7B-ACEC-A8F960D4C2F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8F808327-C893-4F7B-ACEC-A8F960D4C2F4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7125E0C7-C4DC-41D1-9365-06A8A7647302}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7125E0C7-C4DC-41D1-9365-06A8A7647302}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7125E0C7-C4DC-41D1-9365-06A8A7647302}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7125E0C7-C4DC-41D1-9365-06A8A7647302}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C987B2B5-56C1-434F-BBCF-6453CF6E5193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C987B2B5-56C1-434F-BBCF-6453CF6E5193}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C987B2B5-56C1-434F-BBCF-6453CF6E5193}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C987B2B5-56C1-434F-BBCF-6453CF6E5193}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D236EEDD-7AAE-40FF-BE52-B637EEA89FA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D236EEDD-7AAE-40FF-BE52-B637EEA89FA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D236EEDD-7AAE-40FF-BE52-B637EEA89FA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D236EEDD-7AAE-40FF-BE52-B637EEA89FA6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8622D3F5-AC1F-4D70-AA32-720447AB632F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8622D3F5-AC1F-4D70-AA32-720447AB632F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8622D3F5-AC1F-4D70-AA32-720447AB632F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8622D3F5-AC1F-4D70-AA32-720447AB632F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{14EBC846-F344-4D99-9594-43509A3C1861}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{14EBC846-F344-4D99-9594-43509A3C1861}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{14EBC846-F344-4D99-9594-43509A3C1861}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{14EBC846-F344-4D99-9594-43509A3C1861}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9EC23C5C-03D2-4890-8FA0-7D42BE8802E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9EC23C5C-03D2-4890-8FA0-7D42BE8802E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9EC23C5C-03D2-4890-8FA0-7D42BE8802E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9EC23C5C-03D2-4890-8FA0-7D42BE8802E2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,41 @@
|
||||
using FurnitureAssemblyBusinessLogic.BussinessLogic;
|
||||
using FurnitureAssemblyBusinessLogic.MailWorker;
|
||||
using FurnitureAssemblyBusinessLogic.OfficePackage.Implements;
|
||||
using FurnitureAssemblyBusinessLogic.OfficePackage;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.DI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyBusinessLogic
|
||||
{
|
||||
public class BusinessLogicImplementationExtension : IBusinessLogicImplementationExtension
|
||||
{
|
||||
public int Priority => 0;
|
||||
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IWorkPieceLogic, WorkPieceLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IOrderLogic, OrderLogic>();
|
||||
DependencyManager.Instance.RegisterType<IFurnitureLogic, FurnitureLogic>();
|
||||
DependencyManager.Instance.RegisterType<IReportLogic, ReportLogic>();
|
||||
DependencyManager.Instance.RegisterType<IClientLogic, ClientLogic>();
|
||||
DependencyManager.Instance.RegisterType<IImplementerLogic, ImplementerLogic>();
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoLogic, MessageInfoLogic>();
|
||||
DependencyManager.Instance.RegisterType<IShopLogic, ShopLogic>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToExcel, SaveToExcel>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToWord, SaveToWord>();
|
||||
DependencyManager.Instance.RegisterType<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IWorkProcess, WorkModeling>();
|
||||
DependencyManager.Instance.RegisterType<AbstractMailWorker, MailKitWorker>(true);
|
||||
|
||||
DependencyManager.Instance.RegisterType<IBackUpLogic, BackUpLogic>();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyDataModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
{
|
||||
// Класс, реализующий логику для BackUp
|
||||
public class BackUpLogic : IBackUpLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IBackUpInfo _backUpInfo;
|
||||
|
||||
// Конструктор
|
||||
public BackUpLogic(ILogger<BackUpLogic> logger, IBackUpInfo backUpInfo)
|
||||
{
|
||||
_logger = logger;
|
||||
_backUpInfo = backUpInfo;
|
||||
}
|
||||
|
||||
public void CreateBackUp(BackUpSaveBindingModel model)
|
||||
{
|
||||
// Проверка наличия данных для бэкапа
|
||||
if (_backUpInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("Clear folder");
|
||||
|
||||
// Зачистка папки и удаление старого архива
|
||||
var dirInfo = new DirectoryInfo(model.FolderName);
|
||||
|
||||
if (dirInfo.Exists)
|
||||
{
|
||||
// ЛУЧШЕ ВЫБИРАТЬ ОТДЕЛЬНО СОЗДАННУЮ ПАПКУ (Рабочий стол не использовать, поскольку с него всё удалится)
|
||||
foreach (var file in dirInfo.GetFiles())
|
||||
{
|
||||
file.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogDebug("Delete archive");
|
||||
|
||||
string fileName = $"{model.FolderName}.zip";
|
||||
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
}
|
||||
|
||||
// Берём метод для сохранения
|
||||
_logger.LogDebug("Get assembly");
|
||||
|
||||
// Получение сборки и типов
|
||||
var typeIId = typeof(IId);
|
||||
var assembly = typeIId.Assembly;
|
||||
|
||||
if (assembly == null)
|
||||
{
|
||||
throw new ArgumentNullException("Сборка не найдена", nameof(assembly));
|
||||
}
|
||||
|
||||
var types = assembly.GetTypes();
|
||||
var method = GetType().GetMethod("SaveToFile", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
_logger.LogDebug("Find {count} types", types.Length);
|
||||
|
||||
// Перебор типов и вызов метода для сохранения данных
|
||||
foreach (var type in types)
|
||||
{
|
||||
// Проверка на то, является ли тип интерфейсом и унаследован ли он от IId
|
||||
if (type.IsInterface && type.GetInterface(typeIId.Name) != null)
|
||||
{
|
||||
var modelType = _backUpInfo.GetTypeByModelInterface(type.Name);
|
||||
|
||||
if (modelType == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Не найден класс - модель для {type.Name}");
|
||||
}
|
||||
|
||||
_logger.LogDebug("Call SaveToFile method for {name} type", type.Name);
|
||||
|
||||
// Вызываем метод на выполнение (Вызываем метод типа MethodInfo)
|
||||
method?.MakeGenericMethod(modelType).Invoke(this, new object[] { model.FolderName });
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogDebug("Create zip and remove folder");
|
||||
|
||||
// Архивируем
|
||||
ZipFile.CreateFromDirectory(model.FolderName, fileName);
|
||||
|
||||
// Удаляем папку
|
||||
dirInfo.Delete(true);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToFile<T>(string folderName) where T : class, new()
|
||||
{
|
||||
var records = _backUpInfo.GetList<T>();
|
||||
|
||||
if (records == null)
|
||||
{
|
||||
_logger.LogWarning("{type} type get null list", typeof(T).Name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Три строчки ниже - сериализация файлов в json
|
||||
var jsonFormatter = new DataContractJsonSerializer(typeof(List<T>));
|
||||
|
||||
using var fs = new FileStream(string.Format("{0}/{1}.json", folderName, typeof(T).Name), FileMode.OpenOrCreate);
|
||||
|
||||
jsonFormatter.WriteObject(fs, records);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,161 +14,161 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
{
|
||||
// Класс, реализующий логику для исполнителей
|
||||
public class ImplementerLogic : IImplementerLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IImplementerStorage _implementerStorage;
|
||||
private readonly IImplementerStorage _implementerStorage;
|
||||
|
||||
// Конструктор
|
||||
public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage implementerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_implementerStorage = implementerStorage;
|
||||
}
|
||||
// Конструктор
|
||||
public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage implementerStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_implementerStorage = implementerStorage;
|
||||
}
|
||||
|
||||
// Вывод всего отфильтрованного списка
|
||||
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model?.ImplementerFIO, model?.Id);
|
||||
// Вывод всего отфильтрованного списка
|
||||
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model?.ImplementerFIO, model?.Id);
|
||||
|
||||
// list хранит весь список в случае, если model пришло со значением null на вход метода
|
||||
var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
|
||||
// list хранит весь список в случае, если model пришло со значением null на вход метода
|
||||
var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// Вывод конкретного элемента
|
||||
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
// Вывод конкретного элемента
|
||||
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model.ImplementerFIO, model?.Id);
|
||||
_logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model.ImplementerFIO, model?.Id);
|
||||
|
||||
var element = _implementerStorage.GetElement(model);
|
||||
var element = _implementerStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
// Создание работника
|
||||
public bool Create(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
// Создание работника
|
||||
public bool Create(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_implementerStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
if (_implementerStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Обновление данных о работнике
|
||||
public bool Update(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
// Обновление данных о работнике
|
||||
public bool Update(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_implementerStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
if (_implementerStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Удаление работника
|
||||
public bool Delete(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
// Удаление работника
|
||||
public bool Delete(ImplementerBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_implementerStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
if (_implementerStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Проверка входного аргумента для методов Insert, Update и Delete
|
||||
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
// Проверка входного аргумента для методов Insert, Update и Delete
|
||||
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
// Так как при удалении передаём как параметр false
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Так как при удалении передаём как параметр false
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Проверка на наличие ФИО
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствие ФИО в учётной записи", nameof(model.ImplementerFIO));
|
||||
}
|
||||
// Проверка на наличие ФИО
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствие ФИО в учётной записи", nameof(model.ImplementerFIO));
|
||||
}
|
||||
|
||||
// Проверка на наличие пароля
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствие пароля в учётной записи", nameof(model.Password));
|
||||
}
|
||||
// Проверка на наличие пароля
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствие пароля в учётной записи", nameof(model.Password));
|
||||
}
|
||||
|
||||
// Проверка на наличие квалификации
|
||||
if (model.Qualification <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Указана некорректная квалификация", nameof(model.Qualification));
|
||||
}
|
||||
// Проверка на наличие квалификации
|
||||
if (model.Qualification <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Указана некорректная квалификация", nameof(model.Qualification));
|
||||
}
|
||||
|
||||
// Проверка на наличие квалификации
|
||||
if (model.WorkExperience < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Указан некорректный стаж работы", nameof(model.WorkExperience));
|
||||
}
|
||||
// Проверка на наличие квалификации
|
||||
if (model.WorkExperience < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Указан некорректный стаж работы", nameof(model.WorkExperience));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. " +
|
||||
"Qualification:{Qualification}. WorkExperience:{ WorkExperience}. Id:{Id}",
|
||||
model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience, model.Id);
|
||||
_logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. " +
|
||||
"Qualification:{Qualification}. WorkExperience:{ WorkExperience}. Id:{Id}",
|
||||
model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience, model.Id);
|
||||
|
||||
// Для проверка на наличие такого же аккаунта
|
||||
var element = _implementerStorage.GetElement(new ImplementerSearchModel
|
||||
{
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
});
|
||||
// Для проверка на наличие такого же аккаунта
|
||||
var element = _implementerStorage.GetElement(new ImplementerSearchModel
|
||||
{
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
});
|
||||
|
||||
// Если элемент найден и его Id не совпадает с Id переданного объекта
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Исполнитель с таким именем уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Если элемент найден и его Id не совпадает с Id переданного объекта
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Исполнитель с таким именем уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,30 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list.OrderByDescending(x => x.DateDelivery).ToList();
|
||||
return list;
|
||||
}
|
||||
|
||||
MessageInfoViewModel? IMessageInfoLogic.ReadElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. ClientId:{ClientId}. MessageId:{MessageId}", model.ClientId, model?.MessageId);
|
||||
|
||||
var element = _messageInfoStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.MessageId);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
@ -55,5 +78,17 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(MessageInfoBindingModel model)
|
||||
{
|
||||
if (_messageInfoStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,20 +21,25 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
private readonly IShopLogic _shopLogic;
|
||||
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
|
||||
private readonly IFurnitureStorage _furnitureStorage;
|
||||
|
||||
private readonly IClientLogic _clientLogic;
|
||||
|
||||
private readonly object locker = new object();
|
||||
|
||||
// Конструктор
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IFurnitureStorage furnitureStorage, IClientLogic clientLogic, AbstractMailWorker mailWorker)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_mailWorker = mailWorker;
|
||||
_shopLogic = shopLogic;
|
||||
_furnitureStorage = furnitureStorage;
|
||||
_clientLogic = clientLogic;
|
||||
|
||||
_mailWorker = mailWorker;
|
||||
}
|
||||
|
||||
// Вывод отфильтрованного списка компонентов
|
||||
@ -58,35 +63,35 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
}
|
||||
|
||||
// Вывод конкретного чека
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model?.Id);
|
||||
_logger.LogInformation("ReadElement. Id:{Id}", model?.Id);
|
||||
|
||||
var element = _orderStorage.GetElement(model);
|
||||
var element = _orderStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
// Создание чека
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
// Создание чека
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if(model.Status != OrderStatus.Неизвестен)
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed, incorrect order status");
|
||||
return false;
|
||||
@ -95,11 +100,11 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
model.Status = OrderStatus.Принят;
|
||||
|
||||
var result = _orderStorage.Insert(model);
|
||||
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
model.Status = OrderStatus.Неизвестен;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -170,7 +175,7 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.ClientId));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Order. OrderId:{Id}. Sum:{Sum}. ClientId:{ClientId}. FurnitureId:{Id}", model.Id, model.Sum, model.ClientId, model.FurnitureId);
|
||||
_logger.LogInformation("Order. OrderId:{Id}, Sum:{Sum}. FurnitureId:{Id}. Sum:{Sum}", model.Id, model.Sum, model.FurnitureId, model.Sum);
|
||||
}
|
||||
|
||||
// Обновление статуса заказа
|
||||
@ -179,13 +184,13 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
|
||||
// Если не смогли найти указанный заказ по его Id
|
||||
if(viewModel == null)
|
||||
if (viewModel == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
// Проверка на возможность обновления статуса на следующий
|
||||
if(viewModel.Status + 1 != newOrderStatus)
|
||||
if (viewModel.Status + 1 != newOrderStatus && viewModel.Status != OrderStatus.Ожидание)
|
||||
{
|
||||
_logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + "incorrect");
|
||||
return false;
|
||||
@ -193,16 +198,33 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
|
||||
model.Status = newOrderStatus;
|
||||
|
||||
// Помещаем id работника, не забываем про него...
|
||||
if (viewModel.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = viewModel.ImplementerId;
|
||||
}
|
||||
// Помещаем id работника, не забываем про него...
|
||||
if (viewModel.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = viewModel.ImplementerId;
|
||||
}
|
||||
|
||||
// Проверка на выдачу
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
// Проверка на выдачу
|
||||
if (model.Status == OrderStatus.Готов || viewModel.Status == OrderStatus.Ожидание)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
|
||||
var furniture = _furnitureStorage.GetElement(new() { Id = viewModel.FurnitureId });
|
||||
|
||||
if (furniture == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(furniture));
|
||||
}
|
||||
|
||||
if (!_shopLogic.AddFurnitures(furniture, viewModel.Count))
|
||||
{
|
||||
model.Status = OrderStatus.Ожидание;
|
||||
_logger.LogWarning($"Невозможно выдать изделия, магазины переполнены. AddFurnitures operation failed. Shop is full.");
|
||||
}
|
||||
else
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -214,10 +236,8 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
// Финальная проверка на возможность обновления
|
||||
var result = _orderStorage.Update(model);
|
||||
|
||||
if(result == null)
|
||||
if (result == null)
|
||||
{
|
||||
model.Status--;
|
||||
|
||||
_logger.LogWarning("Update operation failed");
|
||||
|
||||
return false;
|
||||
|
@ -20,6 +20,8 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
private readonly AbstractSaveToExcel _saveToExcel;
|
||||
|
||||
private readonly AbstractSaveToWord _saveToWord;
|
||||
@ -27,12 +29,12 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
private readonly AbstractSaveToPdf _saveToPdf;
|
||||
|
||||
// Инициализируем поля класса через контейнер
|
||||
public ReportLogic(IFurnitureStorage furnitureStorage,
|
||||
IOrderStorage orderStorage, AbstractSaveToExcel saveToExcel,
|
||||
AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
public ReportLogic(IFurnitureStorage furnitureStorage, IOrderStorage orderStorage, IShopStorage shopStorage,
|
||||
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf)
|
||||
{
|
||||
_furnitureStorage = furnitureStorage;
|
||||
_orderStorage = orderStorage;
|
||||
_shopStorage = shopStorage;
|
||||
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
@ -67,6 +69,34 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
return list;
|
||||
}
|
||||
|
||||
// Получение списка изделий с указанием, в каких магазинах в наличии
|
||||
public List<ReportShopFurnituresViewModel> GetShopFurnitures()
|
||||
{
|
||||
var shops = _shopStorage.GetFullList();
|
||||
|
||||
var list = new List<ReportShopFurnituresViewModel>();
|
||||
|
||||
foreach (var shop in shops)
|
||||
{
|
||||
var record = new ReportShopFurnituresViewModel
|
||||
{
|
||||
ShopName = shop.ShopName,
|
||||
Furnitures = new List<(string, int)>(),
|
||||
TotalCount = 0
|
||||
};
|
||||
|
||||
foreach (var furniture in shop.ShopFurnitures)
|
||||
{
|
||||
record.Furnitures.Add(new(furniture.Value.Item1.FurnitureName, furniture.Value.Item2));
|
||||
record.TotalCount += furniture.Value.Item2;
|
||||
}
|
||||
|
||||
list.Add(record);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// Получение списка заказов за определённый период
|
||||
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
|
||||
{
|
||||
@ -81,6 +111,20 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
// Получение списка заказов за весь период
|
||||
public List<ReportGroupedOrdersViewModel> GetGroupedOrders()
|
||||
{
|
||||
return _orderStorage.GetFullList()
|
||||
.GroupBy(x => x.DateCreate.Date)
|
||||
.Select(x => new ReportGroupedOrdersViewModel
|
||||
{
|
||||
DateCreate = x.Key,
|
||||
Count = x.Count(),
|
||||
Sum = x.Sum(x => x.Sum)
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Сохранение мебели в файл-Word
|
||||
public void SaveFurnituresToWordFile(ReportBindingModel model)
|
||||
{
|
||||
@ -92,6 +136,17 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
});
|
||||
}
|
||||
|
||||
// Сохранение магазинов в файл-Word
|
||||
public void SaveShopsToWordFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToWord.CreateTable(new WordInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Таблица магазинов",
|
||||
Shops = _shopStorage.GetFullList()
|
||||
});
|
||||
}
|
||||
|
||||
// Сохранение заготовок с указанием изделий в файл_Excel
|
||||
public void SaveFurnitureWorkPieceToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
@ -103,6 +158,17 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
});
|
||||
}
|
||||
|
||||
// Сохранение магазинов с указанием изделий в файл-Excel
|
||||
public void SaveShopFurnituresToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToExcel.CreateShopReport(new ExcelInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список магазинов",
|
||||
ShopFurnitures = GetShopFurnitures()
|
||||
});
|
||||
}
|
||||
|
||||
// Сохранение заказов в файл-Pdf
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
@ -115,5 +181,16 @@ namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
Orders = GetOrders(model)
|
||||
});
|
||||
}
|
||||
|
||||
//Сохранение заказов за весь период в файл-Pdf
|
||||
public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
_saveToPdf.CreateGroupedDoc(new PdfInfo
|
||||
{
|
||||
FileName = model.FileName,
|
||||
Title = "Список заказов",
|
||||
GroupedOrders = GetGroupedOrders()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,267 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.BusinessLogicsContracts;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
{
|
||||
// Класс, реализующий логику для магазинов
|
||||
public class ShopLogic : IShopLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IShopStorage _shopStorage;
|
||||
|
||||
// Конструктор
|
||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
// Вывод конкретного магазина
|
||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id);
|
||||
var element = _shopStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
// Вывод отфильтрованного списка компонентов
|
||||
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id);
|
||||
|
||||
// list хранит весь список в случае, если model пришло со значением null на вход метода
|
||||
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
// Пополнение магазина
|
||||
public bool AddFurniture(ShopSearchModel model, IFurnitureModel furniture, int count)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddFurniture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id);
|
||||
var shop = _shopStorage.GetElement(model);
|
||||
|
||||
if (shop == null)
|
||||
{
|
||||
_logger.LogWarning("Add Furniture operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (shop.MaxCountFurnitures - shop.ShopFurnitures.Select(x => x.Value.Item2).Sum() < count)
|
||||
{
|
||||
throw new ArgumentNullException("Слишком много изделий для одного магазина", nameof(count));
|
||||
}
|
||||
|
||||
if (!shop.ShopFurnitures.ContainsKey(furniture.Id))
|
||||
{
|
||||
shop.ShopFurnitures[furniture.Id] = (furniture, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.ShopFurnitures[furniture.Id] = (furniture, shop.ShopFurnitures[furniture.Id].Item2 + count);
|
||||
}
|
||||
|
||||
_shopStorage.Update(new ShopBindingModel()
|
||||
{
|
||||
Id = shop.Id,
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
DateOpen = shop.DateOpen,
|
||||
MaxCountFurnitures = shop.MaxCountFurnitures,
|
||||
ShopFurnitures = shop.ShopFurnitures
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Создание магазина
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_shopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Обновление магазина
|
||||
public bool Update(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_shopStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Удаление магазина
|
||||
public bool Delete(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_shopStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Проверка входного аргумента для методов Insert, Update и Delete
|
||||
private void CheckModel(ShopBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
// При удалении передаём как параметр false
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Проверка на наличие названия магазина
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствует названия магазина", nameof(model.ShopName));
|
||||
}
|
||||
|
||||
// Проверка на наличие адреса у магазина
|
||||
if (string.IsNullOrEmpty(model.Address))
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствует адреса магазина", nameof(model.Address));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Shop. ShopName:{ShopName}. Address:{Address}. Id: {Id}", model.ShopName, model.Address, model.Id);
|
||||
|
||||
// Проверка на наличие такого же магазина в списке
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
ShopName = model.ShopName
|
||||
});
|
||||
|
||||
// Если элемент найден и его Id не совпадает с Id переданного объекта
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool AddFurnitures(IFurnitureModel model, int count)
|
||||
{
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddFurnitures. Furniture: {Furniture}. Count: {Count}", model?.FurnitureName, count);
|
||||
|
||||
var capacity = _shopStorage.GetFullList().Select(x => x.MaxCountFurnitures - x.ShopFurnitures.Select(x => x.Value.Item2).Sum()).Sum() - count;
|
||||
|
||||
if (capacity < 0)
|
||||
{
|
||||
_logger.LogWarning("AddFurnitures operation failed. Sell {count} Furnitures ", -capacity);
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
if (shop.MaxCountFurnitures - shop.ShopFurnitures.Select(x => x.Value.Item2).Sum() < count)
|
||||
{
|
||||
if (!AddFurniture(new() { Id = shop.Id }, model, shop.MaxCountFurnitures - shop.ShopFurnitures.Select(x => x.Value.Item2).Sum()))
|
||||
{
|
||||
_logger.LogWarning("AddFurnitures operation failed.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
count -= shop.MaxCountFurnitures - shop.ShopFurnitures.Select(x => x.Value.Item2).Sum();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!AddFurniture(new() { Id = shop.Id }, model, count))
|
||||
{
|
||||
_logger.LogWarning("AddFurnitures operation failed.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
count -= count;
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SellFurnitures(IFurnitureModel model, int count)
|
||||
{
|
||||
return _shopStorage.SellFurnitures(model, count);
|
||||
}
|
||||
}
|
||||
}
|
@ -12,155 +12,188 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyBusinessLogic.BussinessLogic
|
||||
{
|
||||
public class WorkModeling : IWorkProcess
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
public class WorkModeling : IWorkProcess
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Random _rnd;
|
||||
private readonly Random _rnd;
|
||||
|
||||
private IOrderLogic? _orderLogic;
|
||||
private IOrderLogic? _orderLogic;
|
||||
|
||||
// Конструктор
|
||||
public WorkModeling(ILogger<WorkModeling> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_rnd = new Random(1000);
|
||||
}
|
||||
// Конструктор
|
||||
public WorkModeling(ILogger<WorkModeling> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_rnd = new Random(1000);
|
||||
}
|
||||
|
||||
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
|
||||
{
|
||||
_orderLogic = orderLogic;
|
||||
var implementers = implementerLogic.ReadList(null);
|
||||
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
|
||||
{
|
||||
_orderLogic = orderLogic;
|
||||
var implementers = implementerLogic.ReadList(null);
|
||||
|
||||
if (implementers == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
return;
|
||||
}
|
||||
if (implementers == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Implementers is null");
|
||||
return;
|
||||
}
|
||||
|
||||
var orders = _orderLogic.ReadList(new OrderSearchModel
|
||||
{
|
||||
Status = OrderStatus.Принят
|
||||
});
|
||||
var orders = _orderLogic.ReadList(new() { Status = OrderStatus.Принят });
|
||||
if (orders == null)
|
||||
{
|
||||
_logger.LogWarning("DoWork. Orders is null or empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if (orders == null || orders.Count == 0)
|
||||
{
|
||||
_logger.LogWarning("Dowork. Orders is null or empty");
|
||||
return;
|
||||
}
|
||||
_logger.LogDebug("DoWork for {count} orders", orders.Count);
|
||||
|
||||
_logger.LogDebug("DoWork for {count} orders", orders.Count);
|
||||
foreach (var implementer in implementers)
|
||||
{
|
||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var implementer in implementers)
|
||||
{
|
||||
Task.Run(() => WorkerWorkAsync(implementer, orders));
|
||||
}
|
||||
}
|
||||
// Имитация работы исполнителя
|
||||
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
|
||||
{
|
||||
if (_orderLogic == null || implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Имитация работы исполнителя
|
||||
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
|
||||
{
|
||||
if (_orderLogic == null || implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var runOrder = _orderLogic.ReadList(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = implementer.Id,
|
||||
Status = OrderStatus.Ожидание
|
||||
});
|
||||
|
||||
await RunOrderInWork(implementer);
|
||||
if (runOrder == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var order in orders)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
|
||||
foreach (var order in runOrder)
|
||||
{
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
});
|
||||
}
|
||||
}
|
||||
// Заказа может не быть, просто игнорируем ошибку
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
// Может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
});
|
||||
|
||||
// Пытаемся назначить заказ на исполнителя
|
||||
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
ImplementerId = implementer.Id
|
||||
});
|
||||
await RunOrderInWork(implementer);
|
||||
|
||||
// Работу работаем, делаем-делаем
|
||||
Thread.Sleep(implementer.WorkExperience * order.Count);
|
||||
await Task.Run(() =>
|
||||
{
|
||||
foreach (var order in orders)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
|
||||
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
||||
// Пытаемся назначить заказ на исполнителя
|
||||
_orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id,
|
||||
ImplementerId = implementer.Id
|
||||
});
|
||||
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
});
|
||||
// Работу работаем, делаем-делаем
|
||||
Thread.Sleep(implementer.WorkExperience * order.Count);
|
||||
|
||||
// Усёёё отдыхаем
|
||||
Thread.Sleep(implementer.Qualification);
|
||||
}
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
|
||||
|
||||
// Игнорируем ошибку, если с заказом что-то случится
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
});
|
||||
|
||||
// В случае ошибки прервём выполнение имитации работы
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Усёёё отдыхаем
|
||||
Thread.Sleep(implementer.Qualification);
|
||||
}
|
||||
|
||||
// Ищем заказ, который уже во всю в работе (вдруг прервали исполнителя)
|
||||
private async Task RunOrderInWork(ImplementerViewModel implementer)
|
||||
{
|
||||
if (_orderLogic == null || implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Игнорируем ошибку, если с заказом что-то случится
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = implementer.Id,
|
||||
Status = OrderStatus.Выполняется
|
||||
}));
|
||||
// Заканчиваем выполнение имитации в случае иной ошибки
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (runOrder == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
|
||||
private async Task RunOrderInWork(ImplementerViewModel implementer)
|
||||
{
|
||||
if (_orderLogic == null || implementer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("DoWork {Id} back to order {Order}", implementer.Id, runOrder.Id);
|
||||
try
|
||||
{
|
||||
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
|
||||
{
|
||||
ImplementerId = implementer.Id,
|
||||
Status = OrderStatus.Выполняется
|
||||
}));
|
||||
|
||||
// Доделываем работу
|
||||
Thread.Sleep(implementer.WorkExperience * runOrder.Count);
|
||||
if (runOrder == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
|
||||
_logger.LogDebug("DoWork {Id} back to order {Order}", implementer.Id, runOrder.Id);
|
||||
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = runOrder.Id
|
||||
});
|
||||
// Доделываем работу
|
||||
Thread.Sleep(implementer.WorkExperience * runOrder.Count);
|
||||
|
||||
// Отдыхаем, хватит работы
|
||||
Thread.Sleep(implementer.Qualification);
|
||||
}
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
|
||||
|
||||
// Заказа может не быть, просто игнорируем ошибку
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = runOrder.Id
|
||||
});
|
||||
|
||||
// Просто возникнет тупая ошибка, тогда заканчиваем выполнение имитации
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Отдыхаем, хватит работы
|
||||
Thread.Sleep(implementer.Qualification);
|
||||
}
|
||||
|
||||
// Заказа может не быть, просто игнорируем ошибку
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Error try get work");
|
||||
}
|
||||
|
||||
// Просто возникнет тупая ошибка, тогда заканчиваем выполнение имитации
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while do work");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,13 +8,18 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
||||
<PackageReference Include="MailKit" Version="4.0.0" />
|
||||
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="1.50.5147" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)BusinessLogicImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -86,6 +86,81 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage
|
||||
SaveExcel(info);
|
||||
}
|
||||
|
||||
public void CreateShopReport(ExcelInfo info)
|
||||
{
|
||||
CreateExcel(info);
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = 1,
|
||||
Text = info.Title,
|
||||
StyleInfo = ExcelStyleInfoType.Title
|
||||
});
|
||||
|
||||
MergeCells(new ExcelMergeParameters
|
||||
{
|
||||
CellFromName = "A1",
|
||||
CellToName = "C1"
|
||||
});
|
||||
|
||||
uint rowIndex = 2;
|
||||
|
||||
foreach (var sm in info.ShopFurnitures)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = sm.ShopName,
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
|
||||
foreach (var (Furniture, Count) in sm.Furnitures)
|
||||
{
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "B",
|
||||
RowIndex = rowIndex,
|
||||
Text = Furniture,
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = Count.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.TextWithBorder
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "A",
|
||||
RowIndex = rowIndex,
|
||||
Text = "Итого",
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
InsertCellInWorksheet(new ExcelCellParameters
|
||||
{
|
||||
ColumnName = "C",
|
||||
RowIndex = rowIndex,
|
||||
Text = sm.TotalCount.ToString(),
|
||||
StyleInfo = ExcelStyleInfoType.Text
|
||||
});
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
SaveExcel(info);
|
||||
}
|
||||
|
||||
// Создание Excel-файла
|
||||
protected abstract void CreateExcel(ExcelInfo info);
|
||||
|
||||
|
@ -58,6 +58,36 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
public void CreateGroupedDoc(PdfInfo info)
|
||||
{
|
||||
CreatePdf(info);
|
||||
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "3cm", "3cm", "3cm" });
|
||||
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Дата заказа", "Количество заказов", "Сумма" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
||||
foreach (var order in info.GroupedOrders)
|
||||
{
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { order.DateCreate.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() },
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
|
||||
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.GroupedOrders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
SavePdf(info);
|
||||
}
|
||||
|
||||
/// Создание Pdf-файла
|
||||
protected abstract void CreatePdf(PdfInfo info);
|
||||
|
||||
|
@ -44,12 +44,64 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
public void CreateTable(WordInfo info)
|
||||
{
|
||||
CreateWord(info);
|
||||
|
||||
CreateParagraph(new WordParagraph
|
||||
{
|
||||
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24" }) },
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
List<List<(string, WordTextProperties)>> rowList = new()
|
||||
{
|
||||
new()
|
||||
{
|
||||
new("Название", new WordTextProperties { Bold = true, Size = "24" } ),
|
||||
new("Адрес", new WordTextProperties { Bold = true, Size = "24" } ),
|
||||
new("Дата открытия", new WordTextProperties { Bold = true, Size = "24" } )
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var shop in info.Shops)
|
||||
{
|
||||
List<(string, WordTextProperties)> cellList = new()
|
||||
{
|
||||
new(shop.ShopName, new WordTextProperties { Size = "24" }),
|
||||
new(shop.Address, new WordTextProperties { Size = "24" }),
|
||||
new(shop.DateOpen.ToShortDateString(), new WordTextProperties { Size = "24"})
|
||||
};
|
||||
|
||||
rowList.Add(cellList);
|
||||
}
|
||||
|
||||
CreateTable(new WordParagraph
|
||||
{
|
||||
RowTexts = rowList,
|
||||
TextProperties = new WordTextProperties
|
||||
{
|
||||
Size = "24",
|
||||
JustificationType = WordJustificationType.Center
|
||||
}
|
||||
});
|
||||
|
||||
SaveWord(info);
|
||||
}
|
||||
|
||||
// Создание Doc-файла
|
||||
protected abstract void CreateWord(WordInfo info);
|
||||
|
||||
// Создание абзаца с текстом
|
||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||
|
||||
// Создание таблицы
|
||||
protected abstract void CreateTable(WordParagraph paragraph);
|
||||
|
||||
// Сохранение файла
|
||||
protected abstract void SaveWord(WordInfo info);
|
||||
}
|
||||
|
@ -18,5 +18,8 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
|
||||
|
||||
// Список заготовок по изделиям
|
||||
public List<ReportFurnitureWorkPieceViewModel> FurnitureWorkPieces { get; set; } = new();
|
||||
|
||||
// Список магазинов с изделиями
|
||||
public List<ReportShopFurnituresViewModel> ShopFurnitures { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,8 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
|
||||
|
||||
// Перечень заказов за указанный период для вывода/сохранения
|
||||
public List<ReportOrdersViewModel> Orders { get; set; } = new();
|
||||
|
||||
// Перечень заказов за весь период для вывода и сохранения
|
||||
public List<ReportGroupedOrdersViewModel> GroupedOrders { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,10 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
//список заготовок для вывода и сохранения
|
||||
// Cписок заготовок для вывода и сохранения
|
||||
public List<FurnitureViewModel> Furnitures { get; set; } = new();
|
||||
|
||||
// Список магазинов для вывода и сохранения
|
||||
public List<ShopViewModel> Shops { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
|
||||
// Набор текстов в абзаце (для случая, если в абзаце текст разных стилей)
|
||||
public List<(string, WordTextProperties)> Texts { get; set; } = new();
|
||||
|
||||
//свойства параграфа, если они есть
|
||||
// Cвойства параграфа, если они есть
|
||||
public WordTextProperties? TextProperties { get; set; }
|
||||
|
||||
public List<List<(string, WordTextProperties)>> RowTexts { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -73,10 +73,7 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements
|
||||
|
||||
if (!string.IsNullOrEmpty(paragraphProperties.Size))
|
||||
{
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize
|
||||
{
|
||||
Val = paragraphProperties.Size
|
||||
});
|
||||
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
|
||||
}
|
||||
|
||||
properties.AppendChild(paragraphMarkRunProperties);
|
||||
@ -127,11 +124,7 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements
|
||||
|
||||
docRun.AppendChild(properties);
|
||||
|
||||
docRun.AppendChild(new Text
|
||||
{
|
||||
Text = run.Item1,
|
||||
Space = SpaceProcessingModeValues.Preserve
|
||||
});
|
||||
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||
|
||||
docParagraph.AppendChild(docRun);
|
||||
}
|
||||
@ -155,5 +148,75 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements
|
||||
|
||||
_wordDocument.Dispose();
|
||||
}
|
||||
|
||||
protected override void CreateTable(WordParagraph paragraph)
|
||||
{
|
||||
if (_docBody == null || paragraph == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Table table = new Table();
|
||||
|
||||
var tableProp = new TableProperties();
|
||||
|
||||
tableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed });
|
||||
tableProp.AppendChild(new TableBorders(
|
||||
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
|
||||
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 }
|
||||
));
|
||||
tableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto });
|
||||
|
||||
table.AppendChild(tableProp);
|
||||
|
||||
TableGrid tableGrid = new TableGrid();
|
||||
|
||||
for (int j = 0; j < paragraph.RowTexts[0].Count; ++j)
|
||||
{
|
||||
tableGrid.AppendChild(new GridColumn() { Width = "3000" });
|
||||
}
|
||||
|
||||
table.AppendChild(tableGrid);
|
||||
|
||||
for (int i = 0; i < paragraph.RowTexts.Count; ++i)
|
||||
{
|
||||
TableRow docRow = new TableRow();
|
||||
|
||||
for (int j = 0; j < paragraph.RowTexts[i].Count; ++j)
|
||||
{
|
||||
var docParagraph = new Paragraph();
|
||||
|
||||
docParagraph.AppendChild(CreateParagraphProperties(paragraph.RowTexts[i][j].Item2));
|
||||
|
||||
var docRun = new Run();
|
||||
|
||||
var properties = new RunProperties();
|
||||
|
||||
properties.AppendChild(new FontSize { Val = paragraph.RowTexts[i][j].Item2.Size });
|
||||
|
||||
if (paragraph.RowTexts[i][j].Item2.Bold)
|
||||
{
|
||||
properties.AppendChild(new Bold());
|
||||
}
|
||||
|
||||
docRun.AppendChild(properties);
|
||||
|
||||
docRun.AppendChild(new Text { Text = paragraph.RowTexts[i][j].Item1, Space = SpaceProcessingModeValues.Preserve });
|
||||
|
||||
docParagraph.AppendChild(docRun);
|
||||
TableCell docCell = new TableCell();
|
||||
docCell.AppendChild(docParagraph);
|
||||
docRow.AppendChild(docCell);
|
||||
}
|
||||
|
||||
table.AppendChild(docRow);
|
||||
}
|
||||
|
||||
_docBody.AppendChild(table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,9 @@ namespace FurnitureAssemblyClientApp
|
||||
// Поле, хранящее клиента, которого необходимо авторизовать
|
||||
public static ClientViewModel? Client { get; set; } = null;
|
||||
|
||||
// Для пагинации
|
||||
public static int CurrentPage { get; set; } = 0;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
|
@ -3,6 +3,7 @@ using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace FurnitureAssemblyClientApp.Controllers
|
||||
{
|
||||
@ -174,7 +175,6 @@ namespace FurnitureAssemblyClientApp.Controllers
|
||||
|
||||
// Для работы с письмами
|
||||
[HttpGet]
|
||||
[HttpGet]
|
||||
public IActionResult Mails()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
@ -184,5 +184,48 @@ namespace FurnitureAssemblyClientApp.Controllers
|
||||
|
||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
// Возвращает кортеж с таблицой в html, текущей страницей писем, выключать ли кнопку пред. страницы, выключать ли кнопку след. страницы
|
||||
[HttpGet]
|
||||
public Tuple<string?, string?, bool, bool>? SwitchPage(bool isNext)
|
||||
{
|
||||
if (isNext)
|
||||
{
|
||||
APIClient.CurrentPage++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (APIClient.CurrentPage == 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
APIClient.CurrentPage--;
|
||||
}
|
||||
|
||||
var res = APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client!.Id}&page={APIClient.CurrentPage}");
|
||||
|
||||
if (isNext && (res == null || res.Count == 0))
|
||||
{
|
||||
APIClient.CurrentPage--;
|
||||
|
||||
return Tuple.Create<string?, string?, bool, bool>(null, null, APIClient.CurrentPage != 1, false);
|
||||
}
|
||||
|
||||
StringBuilder htmlTable = new();
|
||||
|
||||
foreach (var mail in res)
|
||||
{
|
||||
htmlTable.Append("<tr>" +
|
||||
$"<td>{mail.DateDelivery}</td>" +
|
||||
$"<td>{mail.Subject}</td>" +
|
||||
$"<td>{mail.Body}</td>" +
|
||||
"<td>" + (mail.IsRead ? "Прочитано" : "Непрочитано") + "</td>" +
|
||||
$"<td>{mail.Answer}</td>" +
|
||||
"</tr>");
|
||||
}
|
||||
|
||||
return Tuple.Create<string?, string?, bool, bool>(htmlTable.ToString(), APIClient.CurrentPage.ToString(), APIClient.CurrentPage != 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.16" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -3,8 +3,8 @@
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:24381",
|
||||
"sslPort": 44337
|
||||
"applicationUrl": "http://localhost:44103",
|
||||
"sslPort": 44394
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
@ -12,7 +12,7 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7046;http://localhost:5147",
|
||||
"applicationUrl": "https://localhost:7218;http://localhost:5100",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
@ -1,51 +1,84 @@
|
||||
@using FurnitureAssemblyContracts.ViewModels
|
||||
|
||||
@model List<MessageInfoViewModel>
|
||||
|
||||
@{
|
||||
@{
|
||||
ViewData["Title"] = "Mails";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Заказы</h1>
|
||||
<h1 class="display-4">Письма</h1>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Дата письма
|
||||
</th>
|
||||
<th>
|
||||
Заголовок
|
||||
</th>
|
||||
<th>
|
||||
Текст
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DateDelivery)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Subject)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Body)
|
||||
</td>
|
||||
</tr>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Дата письма
|
||||
</th>
|
||||
<th>
|
||||
Заголовок
|
||||
</th>
|
||||
<th>
|
||||
Текст
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
</th>
|
||||
<th>
|
||||
Ответ
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="mails-table-body">
|
||||
</tbody>
|
||||
</table>
|
||||
<ul class="pagination justify-content-center">
|
||||
<li id="prev-page" class="page-item">
|
||||
<a class="page-link" href="#" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
<span class="sr-only">Предыдущая</span>
|
||||
</a>
|
||||
</li>
|
||||
<li class="page-item">
|
||||
<a id="current-page" class="page-link"></a>
|
||||
</li>
|
||||
<li id="next-page" class="page-item">
|
||||
<a class="page-link" href="#" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
<span class="sr-only">Следующая</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function onClicked(isNext) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/SwitchPage",
|
||||
data: { isNext: isNext },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
|
||||
if (result.item1 != null && result.item2 != null) {
|
||||
$("#mails-table-body").html(result.item1);
|
||||
$("#current-page").text(result.item2);
|
||||
}
|
||||
|
||||
if (result.item3)
|
||||
$("#prev-page").removeClass("page-item disabled");
|
||||
else
|
||||
$("#prev-page").addClass("page-item disabled");
|
||||
|
||||
if (result.item4)
|
||||
$("#next-page").removeClass("page-item disabled");
|
||||
else
|
||||
$("#next-page").addClass("page-item disabled");
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
});
|
||||
}
|
||||
</div>
|
||||
|
||||
// Чтобы в первый раз загрузить данные и попасть на первую страницу
|
||||
onClicked(true);
|
||||
$("#prev-page").on('click', () => onClicked(false));
|
||||
$("#next-page").on('click', () => onClicked(true));
|
||||
</script>
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
<title>@ViewData["Title"] - FurnitureAssemblyClientApp</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" />
|
||||
<link rel="stylesheet" href="~/FurnitureAssemblyClientApp.styles.css" asp-append-version="true" />
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.Attributes
|
||||
{
|
||||
// Укажем, что данный атрибут можно прописать только в Property
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public class ColumnAttribute : Attribute
|
||||
{
|
||||
public ColumnAttribute(string title = "", bool visible = true, int width = 0,
|
||||
GridViewAutoSize gridViewAutoSize = GridViewAutoSize.None, bool isUseAutoSize = false, string format = "")
|
||||
{
|
||||
Title = title;
|
||||
Visible = visible;
|
||||
Width = width;
|
||||
GridViewAutoSize = gridViewAutoSize;
|
||||
IsUseAutoSize = isUseAutoSize;
|
||||
Format = format;
|
||||
}
|
||||
|
||||
public string Title { get; private set; }
|
||||
|
||||
public bool Visible { get; private set; }
|
||||
|
||||
public int Width { get; private set; }
|
||||
|
||||
public GridViewAutoSize GridViewAutoSize { get; private set; }
|
||||
|
||||
public bool IsUseAutoSize { get; private set; }
|
||||
|
||||
public string Format { get; private set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.Attributes
|
||||
{
|
||||
public enum GridViewAutoSize
|
||||
{
|
||||
NotSet = 0,
|
||||
|
||||
None = 1,
|
||||
|
||||
ColumnHeader = 2,
|
||||
|
||||
AllCellsExceptHeader = 4,
|
||||
|
||||
AllCells = 6,
|
||||
|
||||
DisplayedCellsExceptHeader = 8,
|
||||
|
||||
DisplayedCells = 10,
|
||||
|
||||
Fill = 16
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.BindingModels
|
||||
{
|
||||
public class BackUpSaveBindingModel
|
||||
{
|
||||
public string FolderName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -7,9 +7,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.BindingModels
|
||||
{
|
||||
// Реализации сущности "Сообщение"
|
||||
// Реализация сущности "Сообщение"
|
||||
public class MessageInfoBindingModel : IMessageInfoModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
@ -21,5 +23,9 @@ namespace FurnitureAssemblyContracts.BindingModels
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public bool IsRead { get; set; } = false;
|
||||
|
||||
public string? Answer { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.BindingModels
|
||||
{
|
||||
// Реализация сущности "Магазин"
|
||||
public class ShopBindingModel : IShopModel
|
||||
{
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||||
|
||||
public Dictionary<int, (IFurnitureModel, int)> ShopFurnitures { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public int MaxCountFurnitures { get; set; }
|
||||
}
|
||||
}
|
@ -15,4 +15,4 @@ namespace FurnitureAssemblyContracts.BindingModels
|
||||
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
||||
{
|
||||
// Интерфейс создания бекапа
|
||||
public interface IBackUpLogic
|
||||
{
|
||||
// Путь и имя файла для архивации
|
||||
void CreateBackUp(BackUpSaveBindingModel model);
|
||||
}
|
||||
}
|
@ -14,6 +14,10 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
||||
{
|
||||
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||
|
||||
MessageInfoViewModel? ReadElement(MessageInfoSearchModel model);
|
||||
|
||||
bool Create(MessageInfoBindingModel model);
|
||||
|
||||
bool Update(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -13,16 +13,31 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
||||
// Получение списка заготовок с указанием, в каких изделиях используются
|
||||
List<ReportFurnitureWorkPieceViewModel> GetFurnitureWorkPiece();
|
||||
|
||||
//Получение списка мороженых с указанием, в каких магазинах в наличии
|
||||
List<ReportShopFurnituresViewModel> GetShopFurnitures();
|
||||
|
||||
// Получение списка заказов за определённый период
|
||||
List<ReportOrdersViewModel> GetOrders(ReportBindingModel model);
|
||||
|
||||
//Получение списка заказов за весь период
|
||||
List<ReportGroupedOrdersViewModel> GetGroupedOrders();
|
||||
|
||||
// Сохранение изделий в файл-Word
|
||||
void SaveFurnituresToWordFile(ReportBindingModel model);
|
||||
|
||||
//Сохранение магазинов в виде таблицы в файл-Word
|
||||
void SaveShopsToWordFile(ReportBindingModel model);
|
||||
|
||||
// Сохранение заготовок с указанием изделий в файл-Excel
|
||||
void SaveFurnitureWorkPieceToExcelFile(ReportBindingModel model);
|
||||
|
||||
//Сохранение магазинов с указанием мороженых в файл-Excel
|
||||
void SaveShopFurnituresToExcelFile(ReportBindingModel model);
|
||||
|
||||
// Сохранение заказов в файл-Pdf
|
||||
void SaveOrdersToPdfFile(ReportBindingModel model);
|
||||
|
||||
//Сохранение заказов за весь период в файл-Pdf
|
||||
void SaveGroupedOrdersToPdfFile(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
||||
{
|
||||
// Бизнес-логика для магазина
|
||||
public interface IShopLogic
|
||||
{
|
||||
List<ShopViewModel>? ReadList(ShopSearchModel? model);
|
||||
|
||||
ShopViewModel? ReadElement(ShopSearchModel model);
|
||||
|
||||
bool Create(ShopBindingModel model);
|
||||
|
||||
bool Update(ShopBindingModel model);
|
||||
|
||||
bool Delete(ShopBindingModel model);
|
||||
|
||||
bool AddFurniture(ShopSearchModel model, IFurnitureModel furniture, int count);
|
||||
|
||||
bool SellFurnitures(IFurnitureModel model, int count);
|
||||
|
||||
bool AddFurnitures(IFurnitureModel model, int count);
|
||||
}
|
||||
}
|
@ -6,10 +6,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.BusinessLogicsContracts
|
||||
{
|
||||
// Интерфейс для класса, имитирующего работу
|
||||
public interface IWorkProcess
|
||||
{
|
||||
// Запуск работы
|
||||
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
|
||||
}
|
||||
// Интерфейс для класса, имитирующего работу
|
||||
public interface IWorkProcess
|
||||
{
|
||||
// Запуск работы
|
||||
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,70 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DI
|
||||
{
|
||||
// Менеджер для работы с зависимостями
|
||||
public class DependencyManager
|
||||
{
|
||||
private readonly IDependencyContainer _dependencyManager;
|
||||
|
||||
private static DependencyManager? _manager;
|
||||
|
||||
private static readonly object _locjObject = new();
|
||||
|
||||
private DependencyManager()
|
||||
{
|
||||
_dependencyManager = new UnityDependencyContainer();
|
||||
}
|
||||
|
||||
public static DependencyManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_manager == null) { lock (_locjObject) { _manager = new DependencyManager(); } }
|
||||
|
||||
return _manager;
|
||||
}
|
||||
}
|
||||
|
||||
// Инициализация библиотек, в которых идут установки зависимостей
|
||||
public static void InitDependency()
|
||||
{
|
||||
var ext = ServiceProviderLoader.GetImplementationExtensions();
|
||||
|
||||
if (ext == null)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||
}
|
||||
|
||||
// Регистрируем зависимости
|
||||
ext.RegisterServices();
|
||||
|
||||
var extBusiness = ServiceProviderLoader.GetBusinessLogicImplementationExtensions();
|
||||
|
||||
if (extBusiness == null)
|
||||
{
|
||||
throw new ArgumentNullException("Отсутствуют компоненты для загрузки зависимостей по модулям");
|
||||
}
|
||||
|
||||
// Регистрируем зависимости бизнес-логики
|
||||
extBusiness.RegisterServices();
|
||||
}
|
||||
|
||||
// Регистрация логгера
|
||||
public void AddLogging(Action<ILoggingBuilder> configure) => _dependencyManager.AddLogging(configure);
|
||||
|
||||
// Добавление зависимости
|
||||
public void RegisterType<T, U>(bool isSingle = false) where U : class, T where T : class => _dependencyManager.RegisterType<T, U>(isSingle);
|
||||
|
||||
// Добавление зависимости
|
||||
public void RegisterType<T>(bool isSingle = false) where T : class => _dependencyManager.RegisterType<T>(isSingle);
|
||||
|
||||
// Получение класса со всеми зависимостями
|
||||
public T Resolve<T>() => _dependencyManager.Resolve<T>();
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DI
|
||||
{
|
||||
public interface IBusinessLogicImplementationExtension
|
||||
{
|
||||
public int Priority { get; }
|
||||
|
||||
// Регистрация сервисов
|
||||
public void RegisterServices();
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DI
|
||||
{
|
||||
// Интерфейс установки зависимости между элементами
|
||||
public interface IDependencyContainer
|
||||
{
|
||||
// Регистрация логгера
|
||||
void AddLogging(Action<ILoggingBuilder> configure);
|
||||
|
||||
// Добавление зависимости
|
||||
void RegisterType<T, U>(bool isSingle) where U : class, T where T :
|
||||
class;
|
||||
|
||||
// Добавление зависимости
|
||||
void RegisterType<T>(bool isSingle) where T : class;
|
||||
|
||||
// Получение класса со всеми зависимостями
|
||||
T Resolve<T>();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DI
|
||||
{
|
||||
// Интерфейс для регистрации зависимостей в модулях
|
||||
public interface IImplementationExtension
|
||||
{
|
||||
// Для установления приоритета
|
||||
public int Priority { get; }
|
||||
|
||||
// Регистрация сервисов
|
||||
public void RegisterServices();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DI
|
||||
{
|
||||
public class ServiceDependencyContainer : IDependencyContainer
|
||||
{
|
||||
private ServiceProvider? _serviceProvider;
|
||||
|
||||
private readonly ServiceCollection _serviceCollection;
|
||||
|
||||
public ServiceDependencyContainer()
|
||||
{
|
||||
_serviceCollection = new ServiceCollection();
|
||||
}
|
||||
|
||||
public void AddLogging(Action<ILoggingBuilder> configure)
|
||||
{
|
||||
_serviceCollection.AddLogging(configure);
|
||||
}
|
||||
|
||||
public void RegisterType<T, U>(bool isSingle) where U : class, T where T : class
|
||||
{
|
||||
if (isSingle)
|
||||
{
|
||||
_serviceCollection.AddSingleton<T, U>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_serviceCollection.AddTransient<T, U>();
|
||||
}
|
||||
|
||||
_serviceProvider = null;
|
||||
}
|
||||
|
||||
public void RegisterType<T>(bool isSingle) where T : class
|
||||
{
|
||||
if (isSingle)
|
||||
{
|
||||
_serviceCollection.AddSingleton<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_serviceCollection.AddTransient<T>();
|
||||
}
|
||||
|
||||
_serviceProvider = null;
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
if (_serviceProvider == null)
|
||||
{
|
||||
_serviceProvider = _serviceCollection.BuildServiceProvider();
|
||||
}
|
||||
|
||||
return _serviceProvider.GetService<T>()!;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DI
|
||||
{
|
||||
// Загрузчик данных
|
||||
public static partial class ServiceProviderLoader
|
||||
{
|
||||
// Загрузка всех классов-реализаций IImplementationExtension
|
||||
public static IImplementationExtension? GetImplementationExtensions()
|
||||
{
|
||||
IImplementationExtension? source = null;
|
||||
|
||||
var files = Directory.GetFiles(TryGetImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
|
||||
|
||||
foreach (var file in files.Distinct())
|
||||
{
|
||||
Assembly asm = Assembly.LoadFrom(file);
|
||||
|
||||
foreach (var t in asm.GetExportedTypes())
|
||||
{
|
||||
if (t.IsClass && typeof(IImplementationExtension).IsAssignableFrom(t))
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
source = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource = (IImplementationExtension)Activator.CreateInstance(t)!;
|
||||
|
||||
if (newSource.Priority > source.Priority)
|
||||
{
|
||||
source = newSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
private static string TryGetImplementationExtensionsFolder()
|
||||
{
|
||||
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
|
||||
while (directory != null && !directory.GetDirectories("ImplementationExtensions",
|
||||
SearchOption.AllDirectories).Any(x => x.Name == "ImplementationExtensions"))
|
||||
{
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
return $"{directory?.FullName}\\ImplementationExtensions";
|
||||
}
|
||||
|
||||
public static IBusinessLogicImplementationExtension? GetBusinessLogicImplementationExtensions()
|
||||
{
|
||||
IBusinessLogicImplementationExtension? source = null;
|
||||
|
||||
var files = Directory.GetFiles(TryGetBusinessLogicImplementationExtensionsFolder(), "*.dll", SearchOption.AllDirectories);
|
||||
|
||||
foreach (var file in files.Distinct())
|
||||
{
|
||||
Assembly asm = Assembly.LoadFrom(file);
|
||||
|
||||
foreach (var t in asm.GetExportedTypes())
|
||||
{
|
||||
if (t.IsClass && typeof(IBusinessLogicImplementationExtension).IsAssignableFrom(t))
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
source = (IBusinessLogicImplementationExtension)Activator.CreateInstance(t)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSource = (IBusinessLogicImplementationExtension)Activator.CreateInstance(t)!;
|
||||
|
||||
if (newSource.Priority > source.Priority)
|
||||
{
|
||||
source = newSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
private static string TryGetBusinessLogicImplementationExtensionsFolder()
|
||||
{
|
||||
var directory = new DirectoryInfo(Directory.GetCurrentDirectory());
|
||||
|
||||
while (directory != null && !directory.GetDirectories("BusinessLogicImplementationExtensions", SearchOption.AllDirectories).Any(x => x.Name == "BusinessLogicImplementationExtensions"))
|
||||
{
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
return $"{directory?.FullName}\\BusinessLogicImplementationExtensions";
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Unity.Microsoft.Logging;
|
||||
using Unity;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DI
|
||||
{
|
||||
public class UnityDependencyContainer : IDependencyContainer
|
||||
{
|
||||
private readonly IUnityContainer _container;
|
||||
|
||||
public UnityDependencyContainer()
|
||||
{
|
||||
_container = new UnityContainer();
|
||||
}
|
||||
|
||||
public void AddLogging(Action<ILoggingBuilder> configure)
|
||||
{
|
||||
var factory = LoggerFactory.Create(configure);
|
||||
_container.AddExtension(new LoggingExtension(factory));
|
||||
}
|
||||
|
||||
public void RegisterType<T>(bool isSingle) where T : class
|
||||
{
|
||||
_container.RegisterType<T>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
|
||||
}
|
||||
|
||||
public T Resolve<T>()
|
||||
{
|
||||
return _container.Resolve<T>();
|
||||
}
|
||||
|
||||
void IDependencyContainer.RegisterType<T, U>(bool isSingle)
|
||||
{
|
||||
_container.RegisterType<T, U>(isSingle ? TypeLifetime.Singleton : TypeLifetime.Transient);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.10.0" />
|
||||
<PackageReference Include="Unity.Microsoft.Logging" Version="5.10.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -13,6 +13,8 @@ namespace FurnitureAssemblyContracts.SearchModels
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? ClientFIO { get; set; }
|
||||
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -8,15 +8,15 @@ namespace FurnitureAssemblyContracts.SearchModels
|
||||
{
|
||||
// Модель для поиска исполнителя
|
||||
public class ImplementerSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? ImplementerFIO { get; set; }
|
||||
public string? ImplementerFIO { get; set; }
|
||||
|
||||
public string? Password { get; set; }
|
||||
public string? Password { get; set; }
|
||||
|
||||
public int? WorkExperience { get; set; }
|
||||
public int? WorkExperience { get; set; }
|
||||
|
||||
public int? Qualification { get; set; }
|
||||
}
|
||||
public int? Qualification { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,9 @@ namespace FurnitureAssemblyContracts.SearchModels
|
||||
public string? MessageId { get; set; }
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public int? Page { get; set; }
|
||||
|
||||
public int? PageSize { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.SearchModels
|
||||
{
|
||||
// Для поиска сущности "Магазин"
|
||||
public class ShopSearchModel
|
||||
{
|
||||
// Для поиска по идентификатору
|
||||
public int? Id { get; set; }
|
||||
|
||||
// Для поиска по названию
|
||||
public string? ShopName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.StoragesContracts
|
||||
{
|
||||
// Интерфейс получения данных по всем сущностям
|
||||
public interface IBackUpInfo
|
||||
{
|
||||
// Метод получения данных по всем сущностям
|
||||
List<T>? GetList<T>() where T : class, new();
|
||||
|
||||
Type? GetTypeByModelInterface(string modelInterfaceName);
|
||||
}
|
||||
}
|
@ -11,17 +11,17 @@ namespace FurnitureAssemblyContracts.StoragesContracts
|
||||
{
|
||||
// Класс для хранилища исполнителей
|
||||
public interface IImplementerStorage
|
||||
{
|
||||
List<ImplementerViewModel> GetFullList();
|
||||
{
|
||||
List<ImplementerViewModel> GetFullList();
|
||||
|
||||
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model);
|
||||
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model);
|
||||
|
||||
ImplementerViewModel? GetElement(ImplementerSearchModel model);
|
||||
ImplementerViewModel? GetElement(ImplementerSearchModel model);
|
||||
|
||||
ImplementerViewModel? Insert(ImplementerBindingModel model);
|
||||
ImplementerViewModel? Insert(ImplementerBindingModel model);
|
||||
|
||||
ImplementerViewModel? Update(ImplementerBindingModel model);
|
||||
ImplementerViewModel? Update(ImplementerBindingModel model);
|
||||
|
||||
ImplementerViewModel? Delete(ImplementerBindingModel model);
|
||||
}
|
||||
ImplementerViewModel? Delete(ImplementerBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -19,5 +19,7 @@ namespace FurnitureAssemblyContracts.StoragesContracts
|
||||
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||
|
||||
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||
|
||||
MessageInfoViewModel? Update(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.StoragesContracts
|
||||
{
|
||||
// Класс для хранилища магазинов
|
||||
public interface IShopStorage
|
||||
{
|
||||
List<ShopViewModel> GetFullList();
|
||||
|
||||
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||
|
||||
ShopViewModel? GetElement(ShopSearchModel model);
|
||||
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
|
||||
bool SellFurnitures(IFurnitureModel model, int count);
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemblyContracts.Attributes;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -11,15 +12,16 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
// Класс для отображения информации о клиентах
|
||||
public class ClientViewModel : IClientModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("ФИО клиента")]
|
||||
[Column(title: "ФИО клиента", width: 150)]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Логин (эл. почта)")]
|
||||
[Column(title: "Логин (эл. почта)", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
[Column(title: "Пароль", width: 150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemblyContracts.Attributes;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -11,14 +12,16 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
// Класс для отображения пользователю информации о продуктах (изделиях)
|
||||
public class FurnitureViewModel : IFurnitureModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название изделия")]
|
||||
[Column(title: "Название изделия", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string FurnitureName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
[Column(title: "Цена", width: 150, format: "0.00")]
|
||||
public double Price { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public Dictionary<int, (IWorkPieceModel, int)> FurnitureWorkPieces { get; set; } = new();
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemblyContracts.Attributes;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -10,19 +11,20 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
{
|
||||
// Класс для отображения информации об исполнителях
|
||||
public class ImplementerViewModel : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("ФИО исполнителя")]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
[Column(title: "ФИО исполнителя", width: 150)]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[Column(title: "Пароль", width: 150)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стаж")]
|
||||
public int WorkExperience { get; set; }
|
||||
[Column(title: "Стаж", width: 150)]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[DisplayName("Квалификация")]
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
[Column(title: "Квалификация", width: 150)]
|
||||
public int Qualification { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemblyContracts.Attributes;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -11,20 +12,31 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
// Класс для отображения пользователю информации о сообщениях
|
||||
public class MessageInfoViewModel : IMessageInfoModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
[Column(visible: false)]
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
[DisplayName("Отправитель")]
|
||||
[Column(title: "Отправитель", width: 150)]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата отправки")]
|
||||
[Column(title: "Дата отправки", width: 150, format: "D")]
|
||||
public DateTime DateDelivery { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Заголовок")]
|
||||
[Column(title: "Заголовок", width: 150)]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Текст")]
|
||||
[Column(title: "Текст", width: 150)]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
[Column(title: "Прочитано", width: 150)]
|
||||
public bool IsRead { get; set; } = false;
|
||||
|
||||
[Column(title: "Ответ", width: 150)]
|
||||
public string? Answer { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using FurnitureAssemblyDataModels.Enums;
|
||||
using FurnitureAssemblyContracts.Attributes;
|
||||
using FurnitureAssemblyDataModels.Enums;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -12,37 +13,40 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
// Класс для отображения пользователю информации о заказах
|
||||
public class OrderViewModel : IOrderModel
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public int ClientId { get; set; }
|
||||
|
||||
[DisplayName("ФИО клиента")]
|
||||
[Column(title: "ФИО клиента", width: 150)]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[Column(visible: false)]
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
[DisplayName("ФИО исполнителя")]
|
||||
[Column(title: "ФИО исполнителя", width: 150)]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[Column(visible: false)]
|
||||
public int FurnitureId { get; set; }
|
||||
|
||||
[DisplayName("Изделие")]
|
||||
[Column(title: "Изделие", width: 150)]
|
||||
public string FurnitureName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Количество")]
|
||||
[Column(title: "Количество", width: 150)]
|
||||
public int Count { get; set; }
|
||||
|
||||
[DisplayName("Сумма")]
|
||||
[Column(title: "Сумма", width: 150, format: "0.00")]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[DisplayName("Статус")]
|
||||
[Column(title: "Статус", width: 150)]
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[DisplayName("Дата создания")]
|
||||
[Column(title: "Дата создания", width: 150, format: "D")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
[DisplayName("Дата выполнения")]
|
||||
[Column(title: "Дата выполнения", width: 150, format: "f")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.ViewModels
|
||||
{
|
||||
public class ReportGroupedOrdersViewModel
|
||||
{
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public double Sum { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.ViewModels
|
||||
{
|
||||
public class ReportShopFurnituresViewModel
|
||||
{
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
public List<(string Furniture, int Count)> Furnitures { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using FurnitureAssemblyContracts.Attributes;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyContracts.ViewModels
|
||||
{
|
||||
// Класс для отображения пользователю информации о магазинах
|
||||
public class ShopViewModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column(title: "Название магазина", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true)]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
[Column(title: "Адрес магазина", gridViewAutoSize: GridViewAutoSize.Fill, isUseAutoSize: true)]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[Column(title: "Дата открытия", gridViewAutoSize: GridViewAutoSize.AllCells, isUseAutoSize: true, format: "f")]
|
||||
public DateTime DateOpen { get; set; } = DateTime.Now;
|
||||
|
||||
[Column(visible: false)]
|
||||
public Dictionary<int, (IFurnitureModel, int)> ShopFurnitures { get; set; } = new();
|
||||
|
||||
[Column(title: "Вместимость магазина", gridViewAutoSize: GridViewAutoSize.DisplayedCells, isUseAutoSize: true)]
|
||||
public int MaxCountFurnitures { get; set; }
|
||||
|
||||
[Column(visible: false)]
|
||||
public List<Tuple<string, int>>? FurnitureCount { get; set; } = new();
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemblyContracts.Attributes;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -11,12 +12,13 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
// Класс для отображения пользователю данных о заготовке (заготовках)
|
||||
public class WorkPieceViewModel : IWorkPieceModel
|
||||
{
|
||||
[Column(visible: false)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название заготовки")]
|
||||
[Column(title: "Название заготовки", width: 150, format: "0.00")]
|
||||
public string WorkPieceName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена")]
|
||||
[Column(title: "Цена", width: 150)]
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
@ -17,6 +17,8 @@ namespace FurnitureAssemblyDataModels.Enums
|
||||
|
||||
Готов = 2,
|
||||
|
||||
Выдан = 3
|
||||
Выдан = 3,
|
||||
|
||||
Ожидание = 4
|
||||
}
|
||||
}
|
@ -8,13 +8,13 @@ namespace FurnitureAssemblyDataModels.Models
|
||||
{
|
||||
// Интерфейс, отвечающий за исполнителя
|
||||
public interface IImplementerModel : IId
|
||||
{
|
||||
string ImplementerFIO { get; }
|
||||
{
|
||||
string ImplementerFIO { get; }
|
||||
|
||||
string Password { get; }
|
||||
string Password { get; }
|
||||
|
||||
int WorkExperience { get; }
|
||||
int WorkExperience { get; }
|
||||
|
||||
int Qualification { get; }
|
||||
}
|
||||
int Qualification { get; }
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace FurnitureAssemblyDataModels.Models
|
||||
{
|
||||
// Интерфейс, отвечающий за сообщения
|
||||
public interface IMessageInfoModel
|
||||
public interface IMessageInfoModel : IId
|
||||
{
|
||||
string MessageId { get; }
|
||||
|
||||
@ -20,5 +20,9 @@ namespace FurnitureAssemblyDataModels.Models
|
||||
string Subject { get; }
|
||||
|
||||
string Body { get; }
|
||||
|
||||
public bool IsRead { get; }
|
||||
|
||||
public string Answer { get; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDataModels.Models
|
||||
{
|
||||
// Интерфейс сущности "Магазин"
|
||||
public interface IShopModel : IId
|
||||
{
|
||||
// Название магазина
|
||||
string ShopName { get; }
|
||||
|
||||
// Адрес магазина
|
||||
string Address { get; }
|
||||
|
||||
// Дата открытия магазина
|
||||
DateTime DateOpen { get; }
|
||||
|
||||
//максимальное кол-во изделий в магазине
|
||||
int MaxCountFurnitures { get; }
|
||||
|
||||
// Изделия в магазине
|
||||
Dictionary<int, (IFurnitureModel, int)> ShopFurnitures { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using FurnitureAssemblyContracts.DI;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyDatabaseImplement.Implements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement
|
||||
{
|
||||
public class DataBaseImplementationExtension : IImplementationExtension
|
||||
{
|
||||
public int Priority => 2;
|
||||
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IWorkPieceStorage, WorkPieceStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IFurnitureStorage, FurnitureStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace FurnitureAssemblyDatabaseImplement
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=FurnitureAssemblyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=FurnitureAssemblyDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
@ -28,6 +28,10 @@ namespace FurnitureAssemblyDatabaseImplement
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
|
||||
public virtual DbSet<Shop> Shops { set; get; }
|
||||
|
||||
public virtual DbSet<ShopFurniture> ShopFurnitures { get; set; }
|
||||
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
|
@ -1,23 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Migrations\" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,35 @@
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
public class BackUpInfo : IBackUpInfo
|
||||
{
|
||||
public List<T>? GetList<T>() where T : class, new()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Set<T>().ToList();
|
||||
}
|
||||
|
||||
public Type? GetTypeByModelInterface(string modelInterfaceName)
|
||||
{
|
||||
var assembly = typeof(BackUpInfo).Assembly;
|
||||
var types = assembly.GetTypes();
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,96 +12,120 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
if (model.Id.HasValue)
|
||||
return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Implementers
|
||||
.Include(x => x.Orders)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return context.Implementers
|
||||
.Include(x => x.Orders)
|
||||
.FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
if (model.ImplementerFIO != null && model.Password != null)
|
||||
return context.Implementers.FirstOrDefault(x => x.ImplementerFIO
|
||||
.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel;
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
return context.Implementers.FirstOrDefault(x => x.ImplementerFIO
|
||||
.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return null;
|
||||
}
|
||||
return context.Implementers
|
||||
.Include(x => x.Orders)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Implementers
|
||||
.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return context.Implementers
|
||||
.Include(x => x.Orders)
|
||||
.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
var newImplementer = Implementer.Create(model);
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (newImplementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return context.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
context.Implementers.Add(newImplementer);
|
||||
context.SaveChanges();
|
||||
|
||||
var res = Implementer.Create(model);
|
||||
return context.Implementers
|
||||
.Include(x => x.Orders)
|
||||
.FirstOrDefault(x => x.Id == newImplementer.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
context.Implementers.Add(res);
|
||||
context.SaveChanges();
|
||||
}
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
var order = context.Implementers
|
||||
.Include(x => x.Orders)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
res.Update(model);
|
||||
context.SaveChanges();
|
||||
}
|
||||
return context.Implementers
|
||||
.Include(x => x.Orders)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context.Implementers
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
// для отображения КОРРЕКТНОЙ ViewModel-и
|
||||
var deletedElement = context.Implementers
|
||||
.Include(x => x.Orders)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
context.Implementers.Remove(res);
|
||||
context.SaveChanges();
|
||||
}
|
||||
context.Implementers.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
return deletedElement;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Messages
|
||||
.FirstOrDefault(x => (x.MessageId == model.MessageId))
|
||||
.FirstOrDefault(x => (x.MessageId.Equals(model.MessageId)))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
@ -32,10 +32,26 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Messages
|
||||
.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
var list = new List<MessageInfoViewModel>();
|
||||
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
list = context.Messages
|
||||
.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
list = context.Messages
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
if (!(model.Page.HasValue && model.PageSize.HasValue))
|
||||
{
|
||||
return list.ToList();
|
||||
}
|
||||
|
||||
return list.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
@ -63,5 +79,25 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
var message = context.Messages
|
||||
.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
|
||||
|
||||
if (message == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
message.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Messages
|
||||
.FirstOrDefault(x => x.MessageId.Equals(model.MessageId))
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,45 +16,56 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
if (model.ImplementerId.HasValue && model.Status.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)
|
||||
?.GetViewModel;
|
||||
}
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
|
||||
}
|
||||
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Orders.Include(x => x.Furniture)
|
||||
.Include(x => x.Client).Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => (model.Status == null || model.Status != null && model.Status.Equals(x.Status)) &&
|
||||
(model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture).Include(x => x.Client).Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return context.Orders
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo ||
|
||||
x.ClientId == model.ClientId || model.Status.Equals(x.Status))
|
||||
.Include(x => x.Furniture).Include(x => x.Client)
|
||||
.Include(x => x.Implementer).Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
}
|
||||
return context.Orders
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo ||
|
||||
x.ClientId == model.ClientId || model.Status.Equals(x.Status))
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
.Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
@ -67,22 +78,17 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
}
|
||||
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client)
|
||||
.Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
.Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var order = context.Orders
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
@ -92,24 +98,23 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client)
|
||||
.Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
var element = context.Orders.Include(x => x.Furniture).Include(x => x.Client)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
// для более корректного отображения модели
|
||||
var deletedElement = context.Orders.Include(x => x.Furniture).Include(x => x.Client)
|
||||
.Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
// для отображения корректной ViewModel-и
|
||||
var deletedElement = context.Orders
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client).Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
@ -0,0 +1,179 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDatabaseImplement.Models;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Shops
|
||||
.Include(x => x.Furnitures)
|
||||
.ThenInclude(x => x.Furniture)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Shops
|
||||
.Include(x => x.Furnitures)
|
||||
.ThenInclude(x => x.Furniture)
|
||||
.Where(x => x.ShopName.Contains(model.ShopName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
return context.Shops
|
||||
.Include(x => x.Furnitures)
|
||||
.ThenInclude(x => x.Furniture)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
var newShop = Shop.Create(context, model);
|
||||
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Shops.Add(newShop);
|
||||
context.SaveChanges();
|
||||
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var shop = context.Shops.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
shop.Update(model);
|
||||
context.SaveChanges();
|
||||
shop.UpdateFurnitures(context, model);
|
||||
transaction.Commit();
|
||||
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
|
||||
var element = context.Shops
|
||||
.Include(x => x.Furnitures)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Shops.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellFurnitures(IFurnitureModel model, int count)
|
||||
{
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var shops = context.ShopFurnitures
|
||||
.Include(x => x.Shop)
|
||||
.ToList()
|
||||
.Where(rec => rec.FurnitureId == model.Id);
|
||||
|
||||
if (shops == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in shops)
|
||||
{
|
||||
if (shop.Count < count)
|
||||
{
|
||||
count -= shop.Count;
|
||||
shop.Count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.Count = shop.Count - count;
|
||||
count -= count;
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
transaction.Rollback();
|
||||
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FurnitureAssemblyDatabase))]
|
||||
[Migration("20240511234747_InitialCreate")]
|
||||
[Migration("20240518232845_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -128,6 +128,9 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.Property<string>("MessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Answer")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
@ -138,6 +141,9 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.Property<DateTime>("DateDelivery")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsRead")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
@ -196,6 +202,59 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("DateOpen")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("MaxCountFurnitures")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("FurnitureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopFurnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.WorkPiece", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -259,7 +318,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Order")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.Navigation("Client");
|
||||
@ -269,6 +328,25 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.Navigation("Implementer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
|
||||
.WithMany("Shops")
|
||||
.HasForeignKey("FurnitureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Furnitures")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Furniture");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Messages");
|
||||
@ -280,12 +358,19 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Shops");
|
||||
|
||||
b.Navigation("WorkPieces");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Order");
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Furnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.WorkPiece", b =>
|
@ -56,6 +56,22 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
table.PrimaryKey("PK_Implementers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateOpen = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
MaxCountFurnitures = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "WorkPieces",
|
||||
columns: table => new
|
||||
@ -76,10 +92,12 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
{
|
||||
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: true),
|
||||
IsRead = table.Column<bool>(type: "bit", nullable: false),
|
||||
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Body = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
Body = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Answer = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -128,6 +146,33 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopFurnitures",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
FurnitureId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopFurnitures", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopFurnitures_Furnitures_FurnitureId",
|
||||
column: x => x.FurnitureId,
|
||||
principalTable: "Furnitures",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopFurnitures_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FurnitureWorkPieces",
|
||||
columns: table => new
|
||||
@ -184,6 +229,16 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
name: "IX_Orders_ImplementerId",
|
||||
table: "Orders",
|
||||
column: "ImplementerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopFurnitures_FurnitureId",
|
||||
table: "ShopFurnitures",
|
||||
column: "FurnitureId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopFurnitures_ShopId",
|
||||
table: "ShopFurnitures",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -198,17 +253,23 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopFurnitures");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "WorkPieces");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Implementers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Furnitures");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Implementers");
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
@ -125,6 +125,9 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.Property<string>("MessageId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Answer")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Body")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
@ -135,6 +138,9 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.Property<DateTime>("DateDelivery")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<bool>("IsRead")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("SenderName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
@ -193,6 +199,59 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("DateOpen")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("MaxCountFurnitures")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("FurnitureId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FurnitureId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopFurnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.WorkPiece", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -256,7 +315,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Implementer", "Implementer")
|
||||
.WithMany("Order")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.Navigation("Client");
|
||||
@ -266,6 +325,25 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
b.Navigation("Implementer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.ShopFurniture", b =>
|
||||
{
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Furniture", "Furniture")
|
||||
.WithMany("Shops")
|
||||
.HasForeignKey("FurnitureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FurnitureAssemblyDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Furnitures")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Furniture");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Messages");
|
||||
@ -277,12 +355,19 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("Shops");
|
||||
|
||||
b.Navigation("WorkPieces");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Implementer", b =>
|
||||
{
|
||||
b.Navigation("Order");
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Furnitures");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FurnitureAssemblyDatabaseImplement.Models.WorkPiece", b =>
|
||||
|
@ -8,20 +8,26 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
// Для реализации связи многие-ко-многим с заказами (клиенты могу сделать одинаковый заказ)
|
||||
|
@ -7,30 +7,36 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Furniture : IFurnitureModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string FurnitureName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Price { get; set; }
|
||||
|
||||
public Dictionary<int, (IWorkPieceModel, int)>? _furnitureWorkPieces = null;
|
||||
|
||||
// Это поле не будет "мапиться" в бд
|
||||
[NotMapped]
|
||||
[DataMember]
|
||||
public Dictionary<int, (IWorkPieceModel, int)> FurnitureWorkPieces
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_furnitureWorkPieces == null)
|
||||
if (_furnitureWorkPieces == null)
|
||||
{
|
||||
_furnitureWorkPieces = WorkPieces
|
||||
.ToDictionary(recPC => recPC.WorkPieceId, recPC => (recPC.WorkPiece as IWorkPieceModel, recPC.Count));
|
||||
@ -47,6 +53,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
[ForeignKey("FurnitureId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
[ForeignKey("FurnitureId")]
|
||||
public virtual List<ShopFurniture> Shops { get; set; } = new();
|
||||
|
||||
public static Furniture Create(FurnitureAssemblyDatabase context, FurnitureBindingModel model)
|
||||
{
|
||||
return new Furniture()
|
||||
@ -76,14 +85,11 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
FurnitureWorkPieces = FurnitureWorkPieces
|
||||
};
|
||||
|
||||
Dictionary<int, (IWorkPieceModel, int)> IFurnitureModel.FurnitureWorkPieces => throw new NotImplementedException();
|
||||
|
||||
|
||||
public void UpdateWorkPieces(FurnitureAssemblyDatabase context, FurnitureBindingModel model)
|
||||
{
|
||||
var furnitureWorkPieces = context.FurnitureWorkPieces.Where(rec => rec.FurnitureId == model.Id).ToList();
|
||||
|
||||
if(furnitureWorkPieces != null && furnitureWorkPieces.Count > 0)
|
||||
if (furnitureWorkPieces != null && furnitureWorkPieces.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.FurnitureWorkPieces.RemoveRange(furnitureWorkPieces.Where(rec => !model.FurnitureWorkPieces.ContainsKey(rec.FurnitureId)));
|
||||
@ -101,13 +107,13 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
|
||||
var furniture = context.Furnitures.First(x => x.Id == Id);
|
||||
|
||||
foreach(var pc in model.FurnitureWorkPieces)
|
||||
foreach (var fwp in model.FurnitureWorkPieces)
|
||||
{
|
||||
context.FurnitureWorkPieces.Add(new FurnitureWorkPiece
|
||||
{
|
||||
Furniture = furniture,
|
||||
WorkPiece = context.WorkPieces.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
WorkPiece = context.WorkPieces.First(x => x.Id == fwp.Key),
|
||||
Count = fwp.Value.Item2
|
||||
});
|
||||
|
||||
context.SaveChanges();
|
||||
|
@ -2,11 +2,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class FurnitureWorkPiece
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
@ -8,79 +8,86 @@ using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DataContract]
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int WorkExperience { get; set; }
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Qualification { get; set; }
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int Qualification { get; set; }
|
||||
|
||||
// Для реализации связи один ко многим с заказами
|
||||
[ForeignKey("ImplementerId")]
|
||||
public virtual List<Order> Order { get; set; } = new();
|
||||
//для реализации связи один ко многим с заказами
|
||||
[ForeignKey("ImplementerId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public static Implementer? Create(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Implementer()
|
||||
{
|
||||
Id = model.Id,
|
||||
Password = model.Password,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Qualification = model.Qualification,
|
||||
WorkExperience = model.WorkExperience
|
||||
};
|
||||
}
|
||||
return new Implementer()
|
||||
{
|
||||
Id = model.Id,
|
||||
Password = model.Password,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Qualification = model.Qualification,
|
||||
WorkExperience = model.WorkExperience
|
||||
};
|
||||
}
|
||||
|
||||
public static Implementer Create(ImplementerViewModel model)
|
||||
{
|
||||
return new Implementer
|
||||
{
|
||||
Id = model.Id,
|
||||
Password = model.Password,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Qualification = model.Qualification,
|
||||
WorkExperience = model.WorkExperience
|
||||
};
|
||||
}
|
||||
public static Implementer Create(ImplementerViewModel model)
|
||||
{
|
||||
return new Implementer
|
||||
{
|
||||
Id = model.Id,
|
||||
Password = model.Password,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Qualification = model.Qualification,
|
||||
WorkExperience = model.WorkExperience
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void Update(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Id = model.Id;
|
||||
Password = model.Password;
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Qualification = model.Qualification;
|
||||
WorkExperience = model.WorkExperience;
|
||||
}
|
||||
Id = model.Id;
|
||||
Password = model.Password;
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Qualification = model.Qualification;
|
||||
WorkExperience = model.WorkExperience;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Password = Password,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Qualification = Qualification,
|
||||
WorkExperience = WorkExperience
|
||||
};
|
||||
}
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Password = Password,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Qualification = Qualification,
|
||||
WorkExperience = WorkExperience
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -5,31 +5,44 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
public int Id => throw new NotImplementedException();
|
||||
|
||||
[Key]
|
||||
[DataMember]
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public bool IsRead { get; private set; } = false;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public DateTime DateDelivery { get; set; } = DateTime.Now;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public string? Answer { get; private set; } = string.Empty;
|
||||
|
||||
public virtual Client? Client { get; set; }
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
@ -46,10 +59,23 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
SenderName = model.SenderName,
|
||||
Body = model.Body,
|
||||
DateDelivery = model.DateDelivery,
|
||||
Subject = model.Subject
|
||||
Subject = model.Subject,
|
||||
IsRead = model.IsRead,
|
||||
Answer = model.Answer
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsRead = model.IsRead;
|
||||
Answer = model.Answer;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
MessageId = MessageId,
|
||||
@ -57,7 +83,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
SenderName = SenderName,
|
||||
Body = Body,
|
||||
DateDelivery = DateDelivery,
|
||||
Subject = Subject
|
||||
Subject = Subject,
|
||||
IsRead = IsRead,
|
||||
Answer = Answer
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -6,35 +6,46 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int FurnitureId { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
[DataMember]
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
// Для передачи названия изделия
|
||||
|
@ -0,0 +1,132 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.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 FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime DateOpen { get; set; }
|
||||
|
||||
[Required]
|
||||
public int MaxCountFurnitures { get; set; }
|
||||
|
||||
private Dictionary<int, (IFurnitureModel, int)>? _shopFurnitures = null;
|
||||
|
||||
[Required]
|
||||
public Dictionary<int, (IFurnitureModel, int)> ShopFurnitures
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopFurnitures == null)
|
||||
{
|
||||
_shopFurnitures = new();
|
||||
|
||||
Furnitures.ForEach(x =>
|
||||
{
|
||||
if (_shopFurnitures.ContainsKey(x.FurnitureId))
|
||||
{
|
||||
_shopFurnitures[x.FurnitureId] = (x.Furniture as IFurnitureModel, _shopFurnitures[x.FurnitureId].Item2 + x.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shopFurnitures[x.FurnitureId] = (x.Furniture as IFurnitureModel, x.Count);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return _shopFurnitures;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("ShopId")]
|
||||
public virtual List<ShopFurniture> Furnitures { get; set; } = new();
|
||||
|
||||
public static Shop? Create(FurnitureAssemblyDatabase context, ShopBindingModel model)
|
||||
{
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateOpen = model.DateOpen,
|
||||
Furnitures = model.ShopFurnitures.Select(x => new ShopFurniture
|
||||
{
|
||||
Furniture = context.Furnitures.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
MaxCountFurnitures = model.MaxCountFurnitures
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel model)
|
||||
{
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpen = model.DateOpen;
|
||||
MaxCountFurnitures = model.MaxCountFurnitures;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
DateOpen = DateOpen,
|
||||
MaxCountFurnitures = MaxCountFurnitures,
|
||||
ShopFurnitures = ShopFurnitures
|
||||
};
|
||||
|
||||
public void UpdateFurnitures(FurnitureAssemblyDatabase context, ShopBindingModel model)
|
||||
{
|
||||
var shopFurnitures = context.ShopFurnitures.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
|
||||
if (shopFurnitures != null && shopFurnitures.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.ShopFurnitures.RemoveRange(shopFurnitures.Where(rec => !model.ShopFurnitures.ContainsKey(rec.FurnitureId)));
|
||||
context.SaveChanges();
|
||||
|
||||
// обновили количество у существующих записей
|
||||
foreach (var _shopFurnitures in shopFurnitures)
|
||||
{
|
||||
_shopFurnitures.Count = model.ShopFurnitures[_shopFurnitures.FurnitureId].Item2;
|
||||
model.ShopFurnitures.Remove(_shopFurnitures.FurnitureId);
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
var shop = context.Shops.First(x => x.Id == Id);
|
||||
|
||||
foreach (var sm in model.ShopFurnitures)
|
||||
{
|
||||
context.ShopFurnitures.Add(new ShopFurniture
|
||||
{
|
||||
Shop = shop,
|
||||
Furniture = context.Furnitures.First(x => x.Id == sm.Key),
|
||||
Count = sm.Value.Item2
|
||||
});
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
_shopFurnitures = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
public class ShopFurniture
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int FurnitureId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
|
||||
public virtual Furniture Furniture { get; set; } = new();
|
||||
}
|
||||
}
|
@ -6,19 +6,24 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class WorkPiece : IWorkPieceModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public string WorkPieceName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[DataMember]
|
||||
public double Cost { get; set; }
|
||||
|
||||
// для реализации связи многие ко многим с изделиями
|
||||
@ -27,7 +32,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
|
||||
public static WorkPiece? Create(WorkPieceBindingModel model)
|
||||
{
|
||||
if(model == null)
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -52,7 +57,7 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
|
||||
public void Update(WorkPieceBindingModel model)
|
||||
{
|
||||
if(model == null)
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ namespace FurnitureAssemblyFileImplement
|
||||
|
||||
private readonly string FurnitureFileName = "Furniture.xml";
|
||||
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
|
||||
private readonly string ImplementerFileName = "Implementer.xml";
|
||||
@ -30,6 +32,8 @@ namespace FurnitureAssemblyFileImplement
|
||||
|
||||
public List<Furniture> Furnitures { get; private set; }
|
||||
|
||||
public List<Shop> Shops { get; private set; }
|
||||
|
||||
public List<Client> Clients { get; private set; }
|
||||
|
||||
public List<Implementer> Implementers { get; private set; }
|
||||
@ -52,20 +56,23 @@ namespace FurnitureAssemblyFileImplement
|
||||
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||
|
||||
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||
public void SaveImplementers() => SaveData(Orders, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||
|
||||
public void SaveMessages() => SaveData(Messages, MessageFileName, "Messages", x => x.GetXElement);
|
||||
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!;
|
||||
Furnitures = LoadData(FurnitureFileName, "Furniture", x => Furniture.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
Implementers = LoadData(ImplementerFileName, "Impleneter", x => Implementer.Create(x)!)!;
|
||||
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||
Messages = LoadData(MessageFileName, "Messages", x => MessageInfo.Create(x)!)!;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,36 @@
|
||||
using FurnitureAssemblyContracts.DI;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyFileImplement.Implements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement
|
||||
{
|
||||
// Для реализации нужных нам зависимостей в данном варианте хранения информации
|
||||
public class FileImplementationExtension : IImplementationExtension
|
||||
{
|
||||
public int Priority => 1;
|
||||
|
||||
public void RegisterServices()
|
||||
{
|
||||
DependencyManager.Instance.RegisterType<IClientStorage, ClientStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IWorkPieceStorage, WorkPieceStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IImplementerStorage, ImplementerStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IMessageInfoStorage, MessageInfoStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IOrderStorage, OrderStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IFurnitureStorage, FurnitureStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IShopStorage, ShopStorage>();
|
||||
|
||||
DependencyManager.Instance.RegisterType<IBackUpInfo, BackUpInfo>();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||
<ProjectReference Include="..\FurnitureAssemblyDataModels\FurnitureAssemblyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)ImplementationExtensions\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
@ -0,0 +1,37 @@
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Implements
|
||||
{
|
||||
public class BackUpInfo : IBackUpInfo
|
||||
{
|
||||
public List<T>? GetList<T>() where T : class, new()
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
|
||||
return (List<T>?)source.GetType().GetProperties()
|
||||
.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == typeof(T))
|
||||
?.GetValue(source);
|
||||
}
|
||||
|
||||
public Type? GetTypeByModelInterface(string modelInterfaceName)
|
||||
{
|
||||
var assembly = typeof(BackUpInfo).Assembly;
|
||||
var types = assembly.GetTypes();
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (type.IsClass && type.GetInterface(modelInterfaceName) != null)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,102 +11,74 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (model.Id.HasValue) return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
if (model.ImplementerFIO != null && model.Password != null) return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel;
|
||||
if (model.ImplementerFIO != null) return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ImplementerStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
if (model.ImplementerFIO != null)
|
||||
{
|
||||
return _source.Implementers
|
||||
.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
if (model.Id.HasValue)
|
||||
return source.Implementers
|
||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
|
||||
if (model.ImplementerFIO != null && model.Password != null)
|
||||
return source.Implementers.FirstOrDefault(x => x.ImplementerFIO
|
||||
.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel;
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
return source.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||
|
||||
return null;
|
||||
}
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
|
||||
var res = Implementer.Create(model);
|
||||
if (res != null)
|
||||
{
|
||||
_source.Implementers.Add(res);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
return source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res != null)
|
||||
{
|
||||
res.Update(model);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
if (model.ImplementerFIO != null)
|
||||
{
|
||||
return source.Implementers
|
||||
.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newImplementer = Implementer.Create(model);
|
||||
|
||||
if (newImplementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Implementers.Add(newImplementer);
|
||||
source.SaveImplementers();
|
||||
|
||||
return newImplementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (implementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
implementer.Update(model);
|
||||
source.SaveImplementers();
|
||||
|
||||
return implementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
source.Implementers.Remove(element);
|
||||
source.SaveImplementers();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res != null)
|
||||
{
|
||||
_source.Implementers.Remove(res);
|
||||
_source.SaveImplementers();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,64 +13,62 @@ namespace FurnitureAssemblyFileImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
private readonly DataFileSingleton _source;
|
||||
public MessageInfoStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
return source.Messages.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue)
|
||||
{
|
||||
return source.Messages
|
||||
.Select(x => GetViewModel(x))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return source.Messages
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => GetViewModel(x))
|
||||
.ToList();
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (!model.ClientId.HasValue)
|
||||
if (model.MessageId != null)
|
||||
{
|
||||
return null;
|
||||
return _source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return source.Messages.FirstOrDefault(x => (model.ClientId.HasValue && x.ClientId == model.ClientId))?.GetViewModel;
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
var res = _source.Messages
|
||||
.Where(x => !model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel);
|
||||
if (!(model.Page.HasValue && model.PageSize.HasValue))
|
||||
{
|
||||
return res.ToList();
|
||||
}
|
||||
return res.Skip((model.Page.Value - 1) * model.PageSize.Value).Take(model.PageSize.Value).ToList();
|
||||
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
return _source.Messages
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
model.MessageId = source.Messages.Count > 0 ? Convert.ToString(source.Messages.Count + 1) : "1";
|
||||
|
||||
var newMessage = MessageInfo.Create(model);
|
||||
|
||||
if (newMessage == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
source.Messages.Add(newMessage);
|
||||
source.SaveOrders();
|
||||
|
||||
return GetViewModel(newMessage);
|
||||
_source.Messages.Add(newMessage);
|
||||
_source.SaveMessages();
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
|
||||
// Для загрузки названий и имён в заказ
|
||||
private MessageInfoViewModel GetViewModel(MessageInfo message)
|
||||
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||
{
|
||||
return message.GetViewModel;
|
||||
var res = _source.Messages.FirstOrDefault(x => x.MessageId.Equals(model.MessageId));
|
||||
if (res != null)
|
||||
{
|
||||
res.Update(model);
|
||||
_source.SaveMessages();
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,21 @@ namespace FurnitureAssemblyFileImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
if (model.ImplementerId.HasValue && model.Status != null)
|
||||
return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && model.Status
|
||||
.Equals(x.Status))?.GetViewModel;
|
||||
if (model.ImplementerId.HasValue && model.Status.HasValue)
|
||||
{
|
||||
return source.Orders
|
||||
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
return source.Orders
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return source.Orders
|
||||
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
@ -44,7 +53,7 @@ namespace FurnitureAssemblyFileImplement.Implements
|
||||
}
|
||||
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo
|
||||
|| x.ClientId == model.ClientId || model.Status.Equals(x.Status))
|
||||
.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
@ -54,7 +63,7 @@ namespace FurnitureAssemblyFileImplement.Implements
|
||||
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
// Для загрузки названий изделия и исполнителя в заказе
|
||||
// Для загрузки названий изделия в заказе
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
@ -63,9 +72,9 @@ namespace FurnitureAssemblyFileImplement.Implements
|
||||
|
||||
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
|
||||
|
||||
var implementer = source.Implementers.FirstOrDefault(x => x.Id == order.ImplementerId);
|
||||
var implementer = source.Implementers.FirstOrDefault(x => x.Id == order.ImplementerId);
|
||||
|
||||
if (furniture != null)
|
||||
if (furniture != null)
|
||||
{
|
||||
viewModel.FurnitureName = furniture.FurnitureName;
|
||||
}
|
||||
@ -75,12 +84,12 @@ namespace FurnitureAssemblyFileImplement.Implements
|
||||
viewModel.ClientFIO = client.ClientFIO;
|
||||
}
|
||||
|
||||
if (implementer != null)
|
||||
{
|
||||
viewModel.ImplementerFIO = implementer.ImplementerFIO;
|
||||
}
|
||||
if (implementer != null)
|
||||
{
|
||||
viewModel.ImplementerFIO = implementer.ImplementerFIO;
|
||||
}
|
||||
|
||||
return viewModel;
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
@ -104,7 +113,7 @@ namespace FurnitureAssemblyFileImplement.Implements
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if(order == null)
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -119,7 +128,7 @@ namespace FurnitureAssemblyFileImplement.Implements
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if(order != null)
|
||||
if (order != null)
|
||||
{
|
||||
source.Orders.Remove(order);
|
||||
source.SaveOrders();
|
||||
|
@ -0,0 +1,139 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.SearchModels;
|
||||
using FurnitureAssemblyContracts.StoragesContracts;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using FurnitureAssemblyFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Implements
|
||||
{
|
||||
// Реализация интерфейса хранилища магазинов
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
|
||||
public ShopStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return _source.Shops.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
return _source.Shops.Where(x => x.ShopName.Contains(model.ShopName))
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _source.Shops.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
|
||||
var newShop = Shop.Create(model);
|
||||
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_source.Shops.Add(newShop);
|
||||
_source.SaveShops();
|
||||
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
var shop = _source.Shops.FirstOrDefault(x => x.ShopName.Contains(model.ShopName) || x.Id == model.Id);
|
||||
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
shop.Update(model);
|
||||
_source.SaveShops();
|
||||
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
_source.Shops.Remove(element);
|
||||
_source.SaveShops();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellFurnitures(IFurnitureModel model, int count)
|
||||
{
|
||||
if (_source.Shops.Select(x => x.ShopFurnitures.FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum() < count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var list = _source.Shops.Where(x => x.ShopFurnitures.ContainsKey(model.Id));
|
||||
|
||||
foreach (var shop in list)
|
||||
{
|
||||
if (shop.ShopFurnitures[model.Id].Item2 < count)
|
||||
{
|
||||
count -= shop.ShopFurnitures[model.Id].Item2;
|
||||
shop.ShopFurnitures[model.Id] = (shop.ShopFurnitures[model.Id].Item1, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.ShopFurnitures[model.Id] = (shop.ShopFurnitures[model.Id].Item1, shop.ShopFurnitures[model.Id].Item2 - count);
|
||||
count -= count;
|
||||
}
|
||||
|
||||
Update(new()
|
||||
{
|
||||
ShopName = shop.ShopName,
|
||||
Address = shop.Address,
|
||||
DateOpen = shop.DateOpen,
|
||||
MaxCountFurnitures = shop.MaxCountFurnitures,
|
||||
ShopFurnitures = shop.ShopFurnitures
|
||||
});
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,20 +4,26 @@ using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class Client : IClientModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
|
@ -4,6 +4,7 @@ using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
@ -11,18 +12,23 @@ using System.Xml.Linq;
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
// Класс, реализующий интерфейс модели изделия
|
||||
[DataContract]
|
||||
public class Furniture : IFurnitureModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string FurnitureName { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public double Price { get; private set; }
|
||||
|
||||
public Dictionary<int, int> WorkPieces { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IWorkPieceModel, int)>? _furnitureWorkPieces = null;
|
||||
|
||||
[DataMember]
|
||||
public Dictionary<int, (IWorkPieceModel, int)> FurnitureWorkPieces
|
||||
{
|
||||
get
|
||||
|
@ -4,86 +4,92 @@ using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[DataContract]
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
[DataMember]
|
||||
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[DataMember]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public int WorkExperience { get; private set; }
|
||||
[DataMember]
|
||||
public int WorkExperience { get; private set; }
|
||||
|
||||
public int Qualification { get; private set; }
|
||||
[DataMember]
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public static Implementer? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Implementer()
|
||||
{
|
||||
Id = model.Id,
|
||||
Password = model.Password,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Qualification = model.Qualification,
|
||||
WorkExperience = model.WorkExperience
|
||||
};
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ImplementerFIO = element.Element("FIO")!.Value,
|
||||
Password = element.Element("Password")!.Value,
|
||||
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
|
||||
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
|
||||
};
|
||||
}
|
||||
|
||||
public static Implementer? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public static Implementer? Create(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Implementer()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
Password = element.Element("Password")!.Value,
|
||||
ImplementerFIO = element.Element("ImplementerFIO")!.Value,
|
||||
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
|
||||
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value)
|
||||
};
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = model.Id,
|
||||
ImplementerFIO = model.ImplementerFIO,
|
||||
Password = model.Password,
|
||||
Qualification = model.Qualification,
|
||||
WorkExperience = model.WorkExperience,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public void Update(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Id = model.Id;
|
||||
Password = model.Password;
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Qualification = model.Qualification;
|
||||
WorkExperience = model.WorkExperience;
|
||||
}
|
||||
ImplementerFIO = model.ImplementerFIO;
|
||||
Password = model.Password;
|
||||
Qualification = model.Qualification;
|
||||
WorkExperience = model.WorkExperience;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Password = Password,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Qualification = Qualification,
|
||||
WorkExperience = WorkExperience
|
||||
};
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Password = Password,
|
||||
Qualification = Qualification,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("Password", Password),
|
||||
new XElement("ImplementerFIO", ImplementerFIO),
|
||||
new XElement("Qualification", Qualification),
|
||||
new XElement("WorkExperience", WorkExperience));
|
||||
}
|
||||
public XElement GetXElement => new("Client",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("FIO", ImplementerFIO),
|
||||
new XElement("Password", Password),
|
||||
new XElement("Qualification", Qualification),
|
||||
new XElement("WorkExperience", WorkExperience)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -11,20 +12,34 @@ using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string MessageId { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public int? ClientId { get; private set; }
|
||||
|
||||
public bool IsRead { get; private set; } = false;
|
||||
|
||||
[DataMember]
|
||||
public string SenderName { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public DateTime DateDelivery { get; private set; } = DateTime.Now;
|
||||
|
||||
[DataMember]
|
||||
public string Subject { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public string Body { get; private set; } = string.Empty;
|
||||
|
||||
public string? Answer { get; private set; } = string.Empty;
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -39,7 +54,9 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
SenderName = model.SenderName,
|
||||
Body = model.Body,
|
||||
Subject = model.Subject,
|
||||
DateDelivery = model.DateDelivery
|
||||
DateDelivery = model.DateDelivery,
|
||||
IsRead = model.IsRead,
|
||||
Answer = model.Answer
|
||||
};
|
||||
}
|
||||
|
||||
@ -57,7 +74,9 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
SenderName = element.Element("SenderName")!.Value,
|
||||
Body = element.Element("Body")!.Value,
|
||||
Subject = element.Element("Subject")!.Value,
|
||||
DateDelivery = Convert.ToDateTime(element.Element("DateDelivery")!.Value)
|
||||
DateDelivery = Convert.ToDateTime(element.Element("DateDelivery")!.Value),
|
||||
IsRead = Convert.ToBoolean(element.Element("IsRead")!.Value),
|
||||
Answer = element.Element("Answer")!.Value
|
||||
};
|
||||
}
|
||||
|
||||
@ -74,6 +93,9 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
Body = model.Body;
|
||||
Subject = model.Subject;
|
||||
DateDelivery = model.DateDelivery;
|
||||
IsRead = model.IsRead;
|
||||
Answer = model.Answer;
|
||||
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
@ -83,7 +105,9 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
SenderName = SenderName,
|
||||
Body = Body,
|
||||
Subject = Subject,
|
||||
DateDelivery = DateDelivery
|
||||
DateDelivery = DateDelivery,
|
||||
IsRead = IsRead,
|
||||
Answer = Answer
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("MessageInfo",
|
||||
@ -92,6 +116,8 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
new XElement("SenderName", SenderName),
|
||||
new XElement("Body", Body),
|
||||
new XElement("Subject", Subject),
|
||||
new XElement("DateDelivery", DateDelivery.ToString()));
|
||||
new XElement("DateDelivery", DateDelivery.ToString()),
|
||||
new XElement("IsRead", IsRead),
|
||||
new XElement("Answer", Answer));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
@ -12,24 +13,34 @@ using System.Xml.Linq;
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
// Класс, реализующий интерфейс модели заказа
|
||||
[DataContract]
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int FurnitureId { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[DataMember]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
[DataMember]
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
@ -65,7 +76,7 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
FurnitureId = Convert.ToInt32(element.Element("FurnitureId")!.Value),
|
||||
ClientId = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ImplementerId = Convert.ToInt32(element.Attribute("ImplementerId")!.Value),
|
||||
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
@ -82,6 +93,7 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
return;
|
||||
}
|
||||
|
||||
ImplementerId = model.ImplementerId;
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
@ -92,6 +104,7 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
FurnitureId = FurnitureId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
ImplementerFIO = DataFileSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
@ -103,7 +116,7 @@ namespace FurnitureAssemblyFileImplement.Models
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("FurnitureId", FurnitureId.ToString()),
|
||||
new XElement("ClientId", ClientId.ToString()),
|
||||
new XElement("ImplementerId", ImplementerId.ToString()),
|
||||
new XElement("ImplementerId", ImplementerId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
|
111
FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Shop.cs
Normal file
111
FurnitureAssembly/FurnitureAssemblyFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,111 @@
|
||||
using FurnitureAssemblyContracts.BindingModels;
|
||||
using FurnitureAssemblyContracts.ViewModels;
|
||||
using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
// Класс, реализующий интерфейс модели магазина
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateOpen { get; set; }
|
||||
|
||||
public int MaxCountFurnitures { get; set; }
|
||||
|
||||
public Dictionary<int, int> countFurniture { get; private set; } = new();
|
||||
|
||||
public Dictionary<int, (IFurnitureModel, int)> _furnitures = null;
|
||||
|
||||
public Dictionary<int, (IFurnitureModel, int)> ShopFurnitures
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_furnitures == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_furnitures = countFurniture.ToDictionary(x => x.Key, y => ((source.Furnitures.FirstOrDefault(z => z.Id == y.Key) as IFurnitureModel)!, y.Value));
|
||||
}
|
||||
|
||||
return _furnitures;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop? Create(ShopBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateOpen = model.DateOpen,
|
||||
MaxCountFurnitures = model.MaxCountFurnitures,
|
||||
countFurniture = model.ShopFurnitures.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Shop? Create(XElement element)
|
||||
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ShopName = element.Element("ShopName")!.Value,
|
||||
Address = element.Element("Address")!.Value,
|
||||
DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value),
|
||||
MaxCountFurnitures = Convert.ToInt32(element.Element("MaxCountFurnitures")!.Value),
|
||||
countFurniture = element.Element("Furnitures")!.Elements("Furnitures").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpen = model.DateOpen;
|
||||
MaxCountFurnitures = model.MaxCountFurnitures;
|
||||
countFurniture = model.ShopFurnitures.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_furnitures = null;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
DateOpen = DateOpen,
|
||||
MaxCountFurnitures = MaxCountFurnitures,
|
||||
ShopFurnitures = ShopFurnitures
|
||||
};
|
||||
public XElement GetXElement => new("Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ShopName", ShopName),
|
||||
new XElement("Address", Address),
|
||||
new XElement("DateOpen", DateOpen.ToString()),
|
||||
new XElement("MaxCountFurnitures", MaxCountFurnitures.ToString()),
|
||||
new XElement("Furnitures", countFurniture.Select(x => new XElement("Furnitures",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))).ToArray()));
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using FurnitureAssemblyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
@ -11,12 +12,16 @@ using System.Xml.Linq;
|
||||
namespace FurnitureAssemblyFileImplement.Models
|
||||
{
|
||||
// Класс, реализующий интерфейс модели заготовки
|
||||
[DataContract]
|
||||
public class WorkPiece : IWorkPieceModel
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public string WorkPieceName { get; private set; } = string.Empty;
|
||||
|
||||
[DataMember]
|
||||
public double Cost { get; set; }
|
||||
|
||||
public static WorkPiece? Create(WorkPieceBindingModel model)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user