Compare commits

..

82 Commits

Author SHA1 Message Date
Аришина)
d402b05d5f 1 2024-11-24 19:51:40 +04:00
82308fd351 Курсач: Война Бесконечности 2024-07-30 18:41:27 +04:00
af14af2496 Курсовая: Война Бесконечности 2024-07-26 02:46:29 +04:00
4c0b6d983d Промежуточная 2024-06-28 00:43:29 +04:00
62372eb2a4 it's over... 2024-06-26 08:04:07 +04:00
the
83d1365b68 статистика по поставщикам 2024-06-25 23:28:09 +04:00
the
2f245da975 всё?????? 2024-06-25 23:10:00 +04:00
the
2f1866659c 123 2024-06-25 23:02:50 +04:00
the
49853d94de дизззззззаааааааааааааааааайн 2024-06-25 22:48:02 +04:00
the
24ac6da8cc ffffffffffff 2024-06-25 22:34:53 +04:00
the
47f012cfda дизайн это моё всё 2024-06-25 22:22:21 +04:00
the
8ed478c392 какой же я дизайнер всё таки 2024-06-25 22:09:51 +04:00
the
00af193095 великий дизайнер 2024-06-25 21:50:28 +04:00
the
146deadf89 Прайс-лист 2024-06-25 21:12:06 +04:00
the
6a6aabdf86 смол фикс 2024-06-25 20:40:10 +04:00
the
3f1d56bcfc Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-25 20:29:43 +04:00
the
fab303ad1d смол фикс 2024-06-25 20:29:36 +04:00
1dd2a00964 Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-25 20:26:52 +04:00
0d08c87f0b Картинки и всё такое 2024-06-25 20:26:34 +04:00
the
5678ff27d5 чек на отдельный товар 2024-06-25 20:24:29 +04:00
the
472b98ba57 имбища 2024-06-25 19:23:43 +04:00
the
a3390f0576 ФАК Е ОНО РАБОТАЕТ 2024-06-25 18:43:20 +04:00
the
794931d97b простейшая статистика по поставкам 2024-06-25 18:32:16 +04:00
the
464ab47941 фиксес 2024-06-25 16:21:15 +04:00
the
8bb0d37211 Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-25 16:01:15 +04:00
the
5cf65ccdb2 ещё больше автогенерации штрих кодов + их отображение в реальном времени 2024-06-25 16:01:10 +04:00
882a46ba3b Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-25 15:51:01 +04:00
28437690c0 Просмотр каталожечка 2024-06-25 15:50:56 +04:00
the
7776de448b промпт о создании отчёта 2024-06-25 15:47:50 +04:00
the
5eaeef8528 ну его нахер этот ваш адоб короче я решил по другому делать 2024-06-25 15:30:02 +04:00
eeec81593b Пора 2024-06-25 15:03:16 +04:00
e1673bca2c Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-25 15:03:07 +04:00
the
933a3bf3ea он внезапно перестал отображать пдф документ и я не знаю почему но коммит надо сделать 2024-06-25 14:27:20 +04:00
the
424703e397 Предварительный просмотр печати 2024-06-25 13:37:33 +04:00
the
57a28d9baf Даты изменения поставок 2024-06-25 13:14:23 +04:00
the
a1575b150d более приятный на вид док 2024-06-25 09:00:46 +04:00
bca6631aab Коммит для проверки 2024-06-24 23:22:03 +04:00
the
17403f4ce9 принтер принтит принты 2024-06-24 22:04:04 +04:00
the
1fa7832bd7 логи (надо не забыть скопировать в bin) 2024-06-24 20:57:48 +04:00
the
489be1deb8 самый стандартный пдф документ который работает 2024-06-24 19:26:39 +04:00
the
c716bda901 кошмар 2024-06-24 18:53:31 +04:00
the
4f5c9f4b71 Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-24 18:08:58 +04:00
the
ebc61c5ef4 теперь точно автогенерация штрихкода при создании продукта + начало работы над документами 2024-06-24 18:08:53 +04:00
dfbbdb049a Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-24 17:13:11 +04:00
98de25531e тварь ли я дрожащая или право имею 2024-06-24 17:13:06 +04:00
the
b055d523bf фиксы для красоты 2024-06-24 17:09:03 +04:00
the
8706337153 Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-24 16:23:47 +04:00
the
3c0bfa50ef barebones медиафайлы 2024-06-24 16:23:42 +04:00
5119290baa Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-24 16:04:56 +04:00
7938a755b7 Да уж духотища но я начал хотя бы контроллеры и вьюшки 2024-06-24 16:04:51 +04:00
the
93abfa5de5 Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-24 15:09:02 +04:00
the
d10d633a65 медиа файлы: контракты и модели 2024-06-24 15:08:29 +04:00
d2d51532a4 Для плотной фиксации 2024-06-24 15:07:37 +04:00
5dbfe140db важно 2024-06-24 15:06:42 +04:00
the
5ab60a79f9 неважно 2024-06-24 14:14:50 +04:00
the
df6cabddb3 Добавил автоматическую генерацию штрих-кода при создании продукта 2024-06-24 14:12:09 +04:00
the
f8f28c3cfd Создание и чтение (получение товара) штрих-кодов 2024-06-24 14:09:32 +04:00
the
da4de1eb95 исправление/комментирование ошибок 2024-06-24 10:40:14 +04:00
8dc6f43608 ЗАФИКСИРОВАЛ 2024-06-24 01:08:20 +04:00
cddde78b59 Всё только начинается друзья мои 2024-06-24 01:07:53 +04:00
the
6d686b4851 похер сойдёт 2024-06-23 23:07:41 +04:00
the
ac6ab33e2c Заказы готовы, максимум осталось дату завершения добавить 2024-06-23 22:32:43 +04:00
the
c87d686110 Статус поставки 2024-06-23 22:18:51 +04:00
the
8a1732026c rating -> rate, пофикси свой sellLogic 2024-06-23 21:38:53 +04:00
the
3525772c45 Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-23 21:35:44 +04:00
the
f1417ad554 помогите 2024-06-23 21:35:37 +04:00
b2b2922acf Диман сделай пж SupplyDoc 2024-06-23 20:39:28 +04:00
the
a42202f627 я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим я ненавижу связи многие ко многим 2024-06-23 19:31:00 +04:00
the
abe9f95aae когда же это закончится 2024-06-23 18:55:46 +04:00
the
3de3f75776 Merge branch 'main' of https://git.is.ulstu.ru/mfnefd/PIAPS_CW 2024-06-23 17:04:35 +04:00
the
09a8d45482 Наполовину работает 2024-06-23 17:04:26 +04:00
3b5447e760 Миграция для изменения связей 2024-06-23 17:04:11 +04:00
545ab2321e Фиксация 2024-06-23 16:11:47 +04:00
258dd5055d Осталось еще всего лишь сделать примерно 95% от всей работы 2024-06-23 16:10:45 +04:00
the
a2f733ce8e ура товар 2024-06-23 14:27:50 +04:00
the
1c2130203d more 2024-06-23 14:21:59 +04:00
the
86a0b43a9a какая же у меня огромная жопа 2024-06-23 14:01:09 +04:00
the
d0e0776717 Самое время начать тестить круд друзья 2024-06-23 12:07:01 +04:00
cb37c8ab52 Добавлена возможность захватывать небольшие европейские государства 2024-06-23 01:24:47 +04:00
c113e8f1a7 Жопа 2024-06-23 00:37:34 +04:00
05b0fb35d6 Ладно 2024-06-23 00:33:26 +04:00
825ad31759 Merge pull request 'registration' (#18) from registration into main
Reviewed-on: #18
2024-06-22 21:17:48 +04:00
209 changed files with 22495 additions and 389 deletions

View File

@ -11,13 +11,18 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BarCode" Version="2024.6.1" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" /> <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="IronPrint" Version="2024.6.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Contracts\Contracts.csproj" /> <ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Contracts.BindingModels;
using IronBarCode;
namespace BusinessLogic.BusinessLogic
{
public class BarcodeLogic
{
public GeneratedBarcode CreateBarcode(ProductBindingModel model, bool save)
{
var barCode = IronBarCode.BarcodeWriter.CreateBarcode(model.Id.ToString(), BarcodeEncoding.Code128);
var path = $"product{model.Id}.png";
if (save) return barCode.SaveAsPng(path);
return barCode;
}
}
}

View File

@ -0,0 +1,124 @@
using MigraDoc;
using PdfSharp;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using PdfSharp.Pdf;
using Contracts.BusinessLogicContracts;
using Contracts.ViewModels;
using System.Security.Cryptography.X509Certificates;
using BusinessLogic.Tools.Mail.MailTemplates;
using BusinessLogic.Tools.Mail;
using MigraDoc.DocumentObjectModel.Tables;
namespace BusinessLogic.BusinessLogic
{
public class BillLogic : IBillLogic
{
public void CreateBill(BillViewModel model)
{
string basePath = AppDomain.CurrentDomain.BaseDirectory;
string h1 = "АО \"21 guns\"";
string h2 = "г. Ульяновск, ул. Северный Венец, 32";
Document document = new Document();
// Изменение стиля Normal для установки шрифта Arial по умолчанию для всего документа
Style styleNormal = document.Styles["Normal"];
styleNormal.Font.Name = "Arial";
//document.Info.Title = $"{model.PurchaseId}";
Section section = document.AddSection();
section.PageSetup.PageFormat = PageFormat.A5;
section.PageSetup.Orientation = Orientation.Portrait;
section.PageSetup.BottomMargin = 10;
section.PageSetup.TopMargin = 10;
Paragraph h1Paragraph = section.AddParagraph(); // Заголовок
h1Paragraph.Format.Font.Bold = true;
h1Paragraph.Format.Font.Size = 16;
h1Paragraph.AddText(h1); // Текст заголовка
h1Paragraph.Format.Alignment = ParagraphAlignment.Center;
Paragraph h2Paragraph = section.AddParagraph();
h2Paragraph.Format.Font.Bold = true;
h2Paragraph.Format.Font.Size = 12;
h2Paragraph.AddText(h2);
Paragraph userParagraph = section.AddParagraph();
userParagraph.Format.Font.Size = 12;
userParagraph.AddText("Покупатель: " + model.UserLastName + ' ' + model.UserFirstName + ' ' + model.UserId
+ "\n" + "Чек отправлен на почту: " + model.UserEmail);
Paragraph producth1Paragraph = section.AddParagraph();
producth1Paragraph.Format.Font.Size = 16;
producth1Paragraph.AddText("Товары:");
Paragraph productListParagraph = section.AddParagraph();
productListParagraph.Format.Font.Size = 12;
Table table = section.AddTable();
table.Style = "Table";
table.Borders.Width = 0.75;
// Определение колонок
Column columnProduct = table.AddColumn(Unit.FromCentimeter(3));
Column columnPrice = table.AddColumn(Unit.FromCentimeter(2));
// Добавление строк с товарами
foreach (var product in model.Products)
{
var row = table.AddRow();
var cell0 = row[0];
cell0.AddParagraph(product.Name);
var cell1 = row[1];
cell1.AddParagraph($"{product.ActualPrice} руб.");
}
Paragraph totalParagraph = section.AddParagraph();
totalParagraph.Format.Font.Size = 16;
totalParagraph.Format.Font.Bold = true;
totalParagraph.AddText("ИТОГ:");
Paragraph totalTextParagraph = section.AddParagraph();
totalTextParagraph.Format.Font.Size = 16;
totalTextParagraph.AddText(model.Count + " товаров на сумму " + model.Cost + " руб.");
// Определение стилей для заголовков
Style styleHeading1 = document.Styles["Heading1"];
styleHeading1.Font.Name = "Arial";
styleHeading1.Font.Size = 14;
styleHeading1.Font.Bold = true;
Style styleHeading2 = document.Styles["Heading2"];
styleHeading2.Font.Name = "Arial";
styleHeading2.Font.Size = 12;
styleHeading2.Font.Bold = true;
// Применение стилей к параграфам
h1Paragraph.Style = "Heading1";
h2Paragraph.Style = "Heading2";
var pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
byte[] file = null;
// Сохраняем PDF в MemoryStream вместо файла
using (var stream = new MemoryStream())
{
pdfRenderer.PdfDocument.Save(stream);
file = stream.ToArray();
}
MailSender.Send(new MailBillSender(model.UserEmail, file));
}
}
}

View File

@ -0,0 +1,113 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Implements;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic
{
public class CartItemLogic : ICartItemLogic
{
private readonly ICartItemStorage _cartItemStorage;
private readonly ILogger _logger;
public CartItemLogic(ICartItemStorage cartItemStorage, ILogger<CartItemLogic> logger)
{
_cartItemStorage = cartItemStorage;
_logger = logger;
}
public bool Create(CartItemBindingModel model)
{
CheckModel(model);
if (_cartItemStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CartItemBindingModel model)
{
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_cartItemStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public CartItemViewModel ReadElement(CartItemSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _cartItemStorage.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<CartItemViewModel> ReadElements(CartItemSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _cartItemStorage.GetFullList() : _cartItemStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(CartItemBindingModel model)
{
CheckModel(model);
if (_cartItemStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public void CheckModel(CartItemBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ProductName))
{
throw new ArgumentNullException("Нет категории", nameof(model.ProductName));
}
_logger.LogInformation("Cart Item. Id: { Id}", model.Id);
}
public void CloseItem(CartItemViewModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_cartItemStorage.CloseItem(model);
}
}
}

View File

@ -0,0 +1,107 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Implements;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic
{
public class MediaFileLogic : IMediaFileLogic
{
private readonly IMediaFileStorage _mediafileStorage;
private readonly ILogger _logger;
public MediaFileLogic(IMediaFileStorage mediafileStorage, ILogger<MediaFileLogic> logger)
{
_mediafileStorage = mediafileStorage;
_logger = logger;
}
public bool Create(MediaFileBindingModel model)
{
CheckModel(model);
_logger.LogInformation("Работа идёт нормально, криэйт в логике");
if (_mediafileStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(MediaFileBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_mediafileStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public MediaFileViewModel? ReadElement(MediaFileSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement .Id:{ Id}", model.Id);
var element = _mediafileStorage.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<MediaFileViewModel>? ReadList(MediaFileSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _mediafileStorage.GetFullList() : _mediafileStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(MediaFileBindingModel model)
{
CheckModel(model);
if (_mediafileStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(MediaFileBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Image == null)
{
//throw new ArgumentNullException("Нет изображения", nameof(model.Name));
}
_logger.LogError("Проверка модели медиа файла выдала ошибку.");
}
}
}

View File

@ -23,6 +23,7 @@ namespace BusinessLogic.BusinessLogic
} }
public bool Create(ProductBindingModel model) public bool Create(ProductBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_productStorage.Insert(model) == null) if (_productStorage.Insert(model) == null)
{ {

View File

@ -0,0 +1,125 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.Converters;
using Contracts.Exceptions;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Implements;
using DatabaseImplement.Migrations;
using DatabaseImplement.Models;
using DataModels.Enums;
using DataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic
{
public class PurchaseLogic : IPurchaseLogic
{
private readonly IPurchaseStorage _purchaseStorage;
private readonly ILogger _logger;
public PurchaseLogic(IPurchaseStorage purchaseStorage, ILogger<PurchaseLogic> logger)
{
_purchaseStorage = purchaseStorage;
_logger = logger;
}
public PurchaseViewModel Create(PurchaseBindingModel model)
{
ArgumentNullException.ThrowIfNull(model);
var purchase = _purchaseStorage.Insert(model);
if (purchase is null)
{
throw new Exception("Insert operation failed.");
}
return purchase;
}
public PurchaseViewModel Delete(PurchaseSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
_logger.LogInformation("Delete purchase. Id: {0}", model.Id);
var purchase = _purchaseStorage.Delete(model);
if (purchase is null)
{
throw new Exception("Delete operation failed.");
}
return purchase;
}
public PurchaseViewModel ReadElement(PurchaseSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
_logger.LogInformation("ReadElement. Id: {0}", model.Id);
var purchase = _purchaseStorage.GetElement(model);
if (purchase is null)
{
throw new ElementNotFoundException();
}
_logger.LogInformation("ReadElement find. Id: {0}", purchase.Id);
return purchase;
}
public List<PurchaseViewModel> ReadElements(PurchaseSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
var purchase_list = model == null ? _purchaseStorage.GetFullList(model) : _purchaseStorage.GetFilteredList(model);
if (purchase_list is null || purchase_list.Count() == 0)
{
_logger.LogWarning("ReadList return null list");
return [];
}
_logger.LogInformation("ReadList. Count: {Count}", purchase_list.Count());
return purchase_list;
}
public PurchaseViewModel Update(PurchaseBindingModel model)
{
ArgumentNullException.ThrowIfNull(model);
var purchase = _purchaseStorage.Update(model);
if (purchase is null)
{
throw new Exception("Update operation failed.");
}
return purchase;
}
public List<CartItemViewModel> GetCartItems(PurchaseSearchModel model)
{
var items = _purchaseStorage.GetCartItems(model);
if (items is null)
{
throw new Exception("Get operation failed.");
}
return items;
}
public List<ProductViewModel> GetProducts(PurchaseSearchModel model)
{
var products = _purchaseStorage.GetProducts(model);
if (products is null)
{
throw new Exception("Get operation failed.");
}
return products;
}
}
}

View File

@ -0,0 +1,104 @@
using BusinessLogic.OfficePackage.HelperModels;
using BusinessLogic.OfficePackage;
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using Contracts.SearchModels;
namespace BusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
private readonly IProductStorage _productStorage;
private readonly ISupplyStorage _supplyStorage;
private readonly IMediaFileStorage _mediaFileStorage;
private readonly AbstractSaveToPdf _saveToPdf;
private readonly AbstractSaveToPdfCheque _saveToCheque;
private readonly AbstractSaveToPdfPricelist _savePricelist;
public ReportLogic(IProductStorage productStorage, ISupplyStorage supplyStorage, AbstractSaveToPdf saveToPdf, AbstractSaveToPdfCheque saveToPdfCheque, IMediaFileStorage mediaFileStorage, AbstractSaveToPdfPricelist savePricelist)
{
_productStorage = productStorage;
_supplyStorage = supplyStorage;
_saveToPdf = saveToPdf;
_saveToCheque = saveToPdfCheque;
_mediaFileStorage = mediaFileStorage;
_savePricelist = savePricelist;
}
/// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются
/// </summary>
/// <returns></returns>
public List<ReportSupplyProductViewModel> GetSupplyProduct()
{
var products = _productStorage.GetFullList();
var supplies = _supplyStorage.GetFullList();
var list = new List<ReportSupplyProductViewModel>();
foreach (var supply in supplies)
{
var record = new ReportSupplyProductViewModel
{
SupplyName = supply.Name,
Products = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach (var product in products)
{
if (supply.Products.ContainsKey(product.Id))
{
record.Products.Add(new Tuple<string, int>(product.Name, supply.Products[product.Id].Item2));
record.TotalCount += supply.Products[product.Id].Item2;
}
}
list.Add(record);
}
return list;
}
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
public void SaveSuppliesToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Накладная",
Date = model.Date!.Value,
Supply = _supplyStorage.GetElement(new SupplySearchModel()
{
Id = model.SupplyId,
})
});
}
public void SaveProductToPdfFile(ReportBindingModel model)
{
_saveToCheque.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Чек на товар",
Product = _productStorage.GetElement(new ProductSearchModel()
{
Id = model.ProductId
}),
//MediaFiles = _mediaFileStorage.GetFilteredList(new MediaFileSearchModel() { ProductId = model.ProductId })
});
}
public void SavePriceListToPdfFile(ReportBindingModel model)
{
_savePricelist.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Прайс-лист",
Date = model.Date,
Products = _productStorage.GetFullList()
});
}
}
}

View File

@ -0,0 +1,116 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Implements;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic
{
public class SaleLogic : ISaleLogic
{
private readonly ISaleStorage _saleStorage;
private readonly ILogger _logger;
public SaleLogic(ISaleStorage saleStorage, ILogger<SaleLogic> logger)
{
_saleStorage = saleStorage;
_logger = logger;
}
public bool Create(SaleBindingModel model)
{
CheckModel(model);
if (_saleStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(SaleBindingModel model)
{
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_saleStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public SaleViewModel ReadElement(SaleSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _saleStorage.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<SaleViewModel> ReadElements(SaleSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _saleStorage.GetFullList() : _saleStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(SaleBindingModel model)
{
CheckModel(model);
if (_saleStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public void CheckModel(SaleBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Category))
{
throw new ArgumentNullException("Нет категории", nameof(model.Category));
}
_logger.LogInformation("Sale. Id: { Id}", model.Id);
var element = _saleStorage.GetElement(new SaleSearchModel
{
Description = model.Description
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Акция с таким описанием уже есть");
}
}
}
}

View File

@ -0,0 +1,80 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.Converters;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic
{
public class SellLogic : ISellLogic
{
private readonly ISellStorage _sellStorage;
private readonly ILogger _logger;
public SellLogic(ISellStorage sellStorage, ILogger<SellLogic> logger)
{
_sellStorage = sellStorage;
_logger = logger;
}
public SellViewModel Create(SellBindingModel model)
{
ArgumentNullException.ThrowIfNull(model);
var sell = _sellStorage.Insert(model);
if (sell is null)
{
throw new Exception("Insert operation failed.");
}
return sell;
}
public SellViewModel ReadElement(SellSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
var sell = _sellStorage.GetElement(model);
if (sell is null)
{
throw new Exception("Get element operation failed.");
}
return sell;
}
public IEnumerable<SellViewModel> ReadElements(SellSearchModel? model)
{
var sell_list = _sellStorage.GetFullList(model);
if (sell_list is null || sell_list.Count() == 0)
{
_logger.LogWarning("ReadList return null list");
return [];
}
return sell_list;
}
public SellViewModel Update(SellSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
var sell = _sellStorage.GetElement(model);
if (sell is null)
{
throw new Exception("Update operation failed.");
}
return sell;
}
public SellViewModel Delete(SellSearchModel model)
{
ArgumentNullException.ThrowIfNull(model);
var sell = _sellStorage.Delete(model);
if (sell is null)
{
throw new Exception("Update operation failed.");
}
return sell;
}
}
}

View File

@ -3,6 +3,7 @@ using Contracts.BusinessLogicContracts;
using Contracts.SearchModels; using Contracts.SearchModels;
using Contracts.StorageContracts; using Contracts.StorageContracts;
using Contracts.ViewModels; using Contracts.ViewModels;
using DataModels.Enums;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -101,5 +102,30 @@ namespace BusinessLogic.BusinessLogic
throw new ArgumentNullException("Нет названия поставки", nameof(model.Name)); throw new ArgumentNullException("Нет названия поставки", nameof(model.Name));
} }
} }
public bool StatusUpdate(SupplyBindingModel model, SupplyStatus newStatus)
{
if (model.Status + 1 != newStatus)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Supply status incorrect.");
return false;
}
model.Status = newStatus;
if (newStatus == SupplyStatus.Arriving)
{
model.DateArriving = DateTime.UtcNow;
}
if (newStatus == SupplyStatus.Completed)
{
model.DateComplete = DateTime.UtcNow;
}
if (_supplyStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
} }
} }

View File

@ -181,5 +181,10 @@ namespace BusinessLogic.BusinessLogic
{ {
return _twoFactorAuthService.Verify(code); return _twoFactorAuthService.Verify(code);
} }
public void UpdateBonus(BonusUpdateBindingModel model)
{
_userStorage.UpdateBonus(model);
}
} }
} }

View File

@ -0,0 +1,80 @@
using BusinessLogic.BusinessLogic;
using BusinessLogic.OfficePackage.HelperEnums;
using BusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = $"{info.Title}\nОт {DateTime.UtcNow}",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
string dateArriving = info.Supply.DateArriving.HasValue ? info.Supply.DateArriving.ToString() : "-";
string dateComplete = info.Supply.DateComplete.HasValue ? info.Supply.DateComplete.ToString() : "-";
CreateParagraph(new PdfParagraph
{
Text = $"Поставщик: {info.Supply.SupplierName}\nДата создания поставки: {info.Supply.Date}\nДата отправления поставки: {dateArriving}\nДата получения поставки: {dateComplete}\nСтатус: {info.Supply.Status}",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
CreateTable(new List<string> { "5cm", "10cm"});
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Id", "Информация" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateRow(new PdfRowParameters
{
Texts = new List<string> { info.Supply.Id.ToString(), info.Supply.Name, },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
CreateParagraph(new PdfParagraph
{
Text = "Товары",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "5cm", "5cm", "3cm", "2cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Id", "Название", "Цена", "Кол-во" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var product in info.Supply.Products.Values)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { product.Item1.Id.ToString(), product.Item1.Name, product.Item1.Price.ToString(), product.Item2.ToString() },
});
}
CreateParagraph(new PdfParagraph
{
Text = $"Итого: {info.Supply.Price.ToString("0.00")} руб.",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreateParagraph(PdfParagraph paragraph);
protected abstract void CreateTable(List<string> columns);
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void CreateImage(string path);
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -0,0 +1,57 @@
using BusinessLogic.OfficePackage.HelperEnums;
using BusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdfCheque
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = $"{info.Title}\n{info.Product.Name}",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = $"Id: {info.Product.Id}",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
//CreateParagraph(new PdfParagraph
//{
// Text = "Список прилагаемых файлов",
// Style = "NormalTitle",
// ParagraphAlignment = PdfParagraphAlignmentType.Center
//});
//CreateTable(new List<string> { "10cm", "5cm" });
//CreateRow(new PdfRowParameters
//{
// Texts = new List<string> { "Название", "расширение" },
// Style = "NormalTitle",
// ParagraphAlignment = PdfParagraphAlignmentType.Center
//});
CreateImage($"product{info.Product.Id}.png");
CreateParagraph(new PdfParagraph
{
Text = $"Цена: {info.Product.Price.ToString("0.00")} руб.",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Right
});
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreateParagraph(PdfParagraph paragraph);
protected abstract void CreateTable(List<string> columns);
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void CreateImage(string path);
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -0,0 +1,51 @@
using BusinessLogic.OfficePackage.HelperEnums;
using BusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdfPricelist
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = $"{info.Title}\nОт {info.Date}",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = "Товары",
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "5cm", "5cm", "3cm", "2cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Id", "Название", "Цена", "Кол-во на складе" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var product in info.Products)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { product.Id.ToString(), product.Name, product.Price.ToString(), product.Amount.ToString() },
});
}
SavePdf(info);
}
protected abstract void CreatePdf(PdfInfo info);
protected abstract void CreateParagraph(PdfParagraph paragraph);
protected abstract void CreateTable(List<string> columns);
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void CreateImage(string path);
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage.HelperEnums
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Right
}
}

View File

@ -0,0 +1,20 @@
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage.HelperModels
{
public class PdfInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public DateTime? Date { get; set; }
public SupplyViewModel? Supply { get; set; } = new();
public ProductViewModel? Product { get; set; } = new();
public List<MediaFileViewModel>? MediaFiles { get; set; } = new();
public List<ProductViewModel>? Products { get; set; } = new();
}
}

View File

@ -0,0 +1,16 @@
using BusinessLogic.OfficePackage.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage.HelperModels
{
public class PdfParagraph
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using BusinessLogic.OfficePackage.HelperEnums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage.HelperModels
{
public class PdfRowParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,111 @@
using BusinessLogic.OfficePackage.HelperEnums;
using BusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using System.Text;
namespace BusinessLogic.OfficePackage.Implements
{
public class SaveToPdf : AbstractSaveToPdf
{
private Document? _document;
private Section? _section;
private Table? _table;
private Image _image;
private static ParagraphAlignment
GetParagraphAlignment(PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
/// <summary>
/// Создание стилей для документа
/// </summary>
/// <param name="document"></param>
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_section == null)
{
return;
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
protected override void CreateTable(List<string> columns)
{
if (_document == null)
{
return;
}
_table = _document.LastSection.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
{
return;
}
var row = _table.AddRow();
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
if (!string.IsNullOrEmpty(rowParameters.Style))
{
row.Cells[i].Style = rowParameters.Style;
}
Unit borderWidth = 0.5;
row.Cells[i].Borders.Left.Width = borderWidth;
row.Cells[i].Borders.Right.Width = borderWidth;
row.Cells[i].Borders.Top.Width = borderWidth;
row.Cells[i].Borders.Bottom.Width = borderWidth;
row.Cells[i].Format.Alignment =
GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
}
}
protected override void CreateImage(string path)
{
if (_document == null)
{
return;
}
_document.LastSection.AddImage(path);
}
protected override void SavePdf(PdfInfo info)
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
}
}

View File

@ -0,0 +1,118 @@
using BusinessLogic.OfficePackage.HelperEnums;
using BusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage.Implements
{
public class SaveToPdfCheque : AbstractSaveToPdfCheque
{
private Document? _document;
private Section? _section;
private PdfPage? _page;
private Table? _table;
private Image _image;
private static ParagraphAlignment
GetParagraphAlignment(PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
/// <summary>
/// Создание стилей для документа
/// </summary>
/// <param name="document"></param>
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_section == null)
{
return;
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
protected override void CreateTable(List<string> columns)
{
if (_document == null)
{
return;
}
_table = _document.LastSection.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
{
return;
}
var row = _table.AddRow();
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
if (!string.IsNullOrEmpty(rowParameters.Style))
{
row.Cells[i].Style = rowParameters.Style;
}
Unit borderWidth = 0.5;
row.Cells[i].Borders.Left.Width = borderWidth;
row.Cells[i].Borders.Right.Width = borderWidth;
row.Cells[i].Borders.Top.Width = borderWidth;
row.Cells[i].Borders.Bottom.Width = borderWidth;
row.Cells[i].Format.Alignment =
GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
}
}
protected override void CreateImage(string path)
{
if (_document == null)
{
return;
}
_document.LastSection.AddImage(path);
}
protected override void SavePdf(PdfInfo info)
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
}
}

View File

@ -0,0 +1,115 @@
using BusinessLogic.OfficePackage.HelperEnums;
using BusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.OfficePackage.Implements
{
public class SaveToPdfPricelist : AbstractSaveToPdfPricelist
{
private Document? _document;
private Section? _section;
private Table? _table;
private Image _image;
private static ParagraphAlignment
GetParagraphAlignment(PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
/// <summary>
/// Создание стилей для документа
/// </summary>
/// <param name="document"></param>
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_section == null)
{
return;
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
protected override void CreateTable(List<string> columns)
{
if (_document == null)
{
return;
}
_table = _document.LastSection.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
{
return;
}
var row = _table.AddRow();
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
if (!string.IsNullOrEmpty(rowParameters.Style))
{
row.Cells[i].Style = rowParameters.Style;
}
Unit borderWidth = 0.5;
row.Cells[i].Borders.Left.Width = borderWidth;
row.Cells[i].Borders.Right.Width = borderWidth;
row.Cells[i].Borders.Top.Width = borderWidth;
row.Cells[i].Borders.Bottom.Width = borderWidth;
row.Cells[i].Format.Alignment =
GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
}
}
protected override void CreateImage(string path)
{
if (_document == null)
{
return;
}
_document.LastSection.AddImage(path);
}
protected override void SavePdf(PdfInfo info)
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
}
}

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Mail;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -12,5 +13,6 @@ namespace BusinessLogic.Tools.Mail
public string Title { get; set; } = null!; public string Title { get; set; } = null!;
public string Body { get; set; } = null!; public string Body { get; set; } = null!;
public bool IsSendable { get; set; } = true; public bool IsSendable { get; set; } = true;
public List<Attachment>? Attachments { get; set; } = new List<Attachment>();
} }
} }

View File

@ -42,6 +42,11 @@ namespace BusinessLogic.Tools.Mail
message.Subject = mail.Title; message.Subject = mail.Title;
message.Body = mail.Body; message.Body = mail.Body;
foreach (var attachment in mail.Attachments)
{
message.Attachments.Add(attachment);
}
client.Send(message); client.Send(message);
} }
} }

View File

@ -0,0 +1,28 @@
using Contracts.BindingModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using DatabaseImplement.Models;
namespace BusinessLogic.Tools.Mail.MailTemplates
{
public class MailBillSender : Mail
{
public MailBillSender(string recipientEmail, byte[] invoicePdfBytes)
{
To = [recipientEmail];
Title = "Ваш чек";
Body = "";
// Создаем MemoryStream из байтового массива инвойса
var memoryStream = new MemoryStream(invoicePdfBytes);
// Создаем Attachment, используя MemoryStream
var attachment = new Attachment(memoryStream, "invoice.pdf", "application/pdf");
Attachments.Add(attachment);
}
}
}

View File

@ -15,7 +15,7 @@ namespace BusinessLogic.Tools.Mail.MailTemplates
Title = "Ваш код для подтверждения"; Title = "Ваш код для подтверждения";
Body = $"Здравствуйте, {user.SecondName} {user.FirstName}! Вот Ваш код для подтверждения:\n" + Body = $"Здравствуйте, {user.SecondName} {user.FirstName}! Вот Ваш код для подтверждения:\n" +
$"{code}\n" + $"{code}\n" +
$"Если это не Вы, игноритруйте это сообщение."; $"Если это не Вы, игнорируйте это сообщение.";
} }
} }
} }

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BindingModels
{
public class BonusUpdateBindingModel
{
public Guid UserId { get; set; }
public int BonusPlus { get; set; }
public int BonusMinus { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BindingModels
{
public class CartItemBindingModel : ICartItem
{
public Guid Id { get; set; }
public Guid ProductId { get; set; }
public string ProductName { get; set; } = string.Empty;
public DateTime DateCreated { get; set; }
public int Count { get; set; }
public Guid UserId { get; set; }
public Guid? PurchaseId { get; set; }
public IPurchase? Purchase { get; set; }
public bool IsClosed { get; set; }
}
}

View File

@ -11,7 +11,6 @@ namespace Contracts.BindingModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public Guid ProductId { get; set; } public Guid ProductId { get; set; }
public string Name { get; set; } = string.Empty; public required byte[] Image { get; set; }
public string Location { get; set; } = string.Empty;
} }
} }

View File

@ -15,5 +15,8 @@ namespace Contracts.BindingModels
public int Amount { get; set; } public int Amount { get; set; }
public bool IsBeingSold { get; set; } public bool IsBeingSold { get; set; }
public double Rate { get; set; } public double Rate { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public Guid? SaleId { get; set; }
} }
} }

View File

@ -1,4 +1,6 @@
using System; using DataModels.Enums;
using DataModels.Models;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -9,6 +11,12 @@ namespace Contracts.BindingModels
public class PurchaseBindingModel public class PurchaseBindingModel
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DatePurchase { get; set; } public DateTime DateCreated { get; set; }
public DateTime? DateClosed { get; set; }
public Guid UserId { get; set; }
public PurchaseStatus Status { get; set; }
public int ProductCount { get; set; }
public double Cost { get; set; }
public bool IsPaid { get; set; }
} }
} }

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BindingModels
{
public class ReportBindingModel
{
public string FileName { get; set; } = string.Empty;
public DateTime? Date { get; set; }
public Guid? SupplyId { get; set; }
public Guid? ProductId { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BindingModels
{
public class SaleBindingModel : ISale
{
public string Category { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string FullDescription { get; set; } = string.Empty;
public DateTime Start { get; set; }
public DateTime End { get; set; }
public string Name { get; set; } = string.Empty;
public int Value { get; set; }
public Guid Id { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System; using DataModels.Models;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -10,5 +11,7 @@ namespace Contracts.BindingModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DateSell { get; set; } public DateTime DateSell { get; set; }
public Guid? UserId { get; set; }
public Dictionary<Guid, (IProduct, int)> SellProducts { get; set; } = new();
} }
} }

View File

@ -14,6 +14,8 @@ namespace Contracts.BindingModels
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public Guid SupplierId { get; set; } public Guid SupplierId { get; set; }
public DateTime Date { get; set; } public DateTime Date { get; set; }
public DateTime? DateArriving { get; set; }
public DateTime? DateComplete { get; set; }
public double Price { get; set; } public double Price { get; set; }
public SupplyStatus Status { get; set; } public SupplyStatus Status { get; set; }
public Dictionary<Guid, (IProduct, int)> SupplyProducts { get; set; } = new(); public Dictionary<Guid, (IProduct, int)> SupplyProducts { get; set; } = new();

View File

@ -17,5 +17,6 @@ namespace Contracts.BindingModels
public DateTime Birthday { get; set; } public DateTime Birthday { get; set; }
public bool OnlyImportantMails { get; set; } public bool OnlyImportantMails { get; set; }
public RoleBindingModel Role { get; set; } = null!; public RoleBindingModel Role { get; set; } = null!;
public int Bonus { get; set; }
} }
} }

View File

@ -0,0 +1,14 @@
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface IBillLogic
{
void CreateBill(BillViewModel model);
}
}

View File

@ -0,0 +1,25 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface ICartItemLogic
{
bool Create(CartItemBindingModel model);
bool Update(CartItemBindingModel model);
CartItemViewModel ReadElement(CartItemSearchModel model);
List<CartItemViewModel> ReadElements(CartItemSearchModel? model);
bool Delete(CartItemBindingModel model);
void CloseItem(CartItemViewModel model);
}
}

View File

@ -0,0 +1,20 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface IMediaFileLogic
{
bool Create(MediaFileBindingModel model);
bool Update(MediaFileBindingModel model);
bool Delete(MediaFileBindingModel model);
List<MediaFileViewModel>? ReadList(MediaFileSearchModel? model);
MediaFileViewModel? ReadElement(MediaFileSearchModel model);
}
}

View File

@ -1,6 +1,7 @@
using Contracts.BindingModels; using Contracts.BindingModels;
using Contracts.SearchModels; using Contracts.SearchModels;
using Contracts.ViewModels; using Contracts.ViewModels;
using DataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -17,8 +18,10 @@ namespace Contracts.BusinessLogicContracts
PurchaseViewModel ReadElement(PurchaseSearchModel model); PurchaseViewModel ReadElement(PurchaseSearchModel model);
IEnumerable<PurchaseViewModel> ReadElements(PurchaseSearchModel? model); List<PurchaseViewModel> ReadElements(PurchaseSearchModel? model);
PurchaseViewModel Delete(PurchaseSearchModel model); PurchaseViewModel Delete(PurchaseSearchModel model);
List<CartItemViewModel> GetCartItems(PurchaseSearchModel model);
List<ProductViewModel> GetProducts(PurchaseSearchModel model);
} }
} }

View File

@ -0,0 +1,26 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface IReportLogic
{
/// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются
/// </summary>
/// <returns></returns>
List<ReportSupplyProductViewModel> GetSupplyProduct();
/// <summary>
/// Сохранение заказов в файл-Pdf
/// </summary>
/// <param name="model"></param>
void SaveSuppliesToPdfFile(ReportBindingModel model);
void SaveProductToPdfFile(ReportBindingModel model);
void SavePriceListToPdfFile(ReportBindingModel model);
}
}

View File

@ -0,0 +1,24 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface ISaleLogic
{
bool Create(SaleBindingModel model);
bool Update(SaleBindingModel model);
SaleViewModel ReadElement(SaleSearchModel model);
List<SaleViewModel> ReadElements(SaleSearchModel? model);
bool Delete(SaleBindingModel model);
}
}

View File

@ -13,7 +13,7 @@ namespace Contracts.BusinessLogicContracts
{ {
SellViewModel Create(SellBindingModel model); SellViewModel Create(SellBindingModel model);
SellViewModel Update(SellBindingModel model); SellViewModel Update(SellSearchModel model);
SellViewModel ReadElement(SellSearchModel model); SellViewModel ReadElement(SellSearchModel model);

View File

@ -1,6 +1,7 @@
using Contracts.BindingModels; using Contracts.BindingModels;
using Contracts.SearchModels; using Contracts.SearchModels;
using Contracts.ViewModels; using Contracts.ViewModels;
using DataModels.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -16,5 +17,6 @@ namespace Contracts.BusinessLogicContracts
bool Create(SupplyBindingModel model); bool Create(SupplyBindingModel model);
bool Update(SupplyBindingModel model); bool Update(SupplyBindingModel model);
bool Delete(SupplyBindingModel model); bool Delete(SupplyBindingModel model);
bool StatusUpdate(SupplyBindingModel model, SupplyStatus status);
} }
} }

View File

@ -25,5 +25,6 @@ namespace Contracts.BusinessLogicContracts
IEnumerable<UserViewModel> ReadElements(UserSearchModel? model); IEnumerable<UserViewModel> ReadElements(UserSearchModel? model);
UserViewModel Delete(UserSearchModel model); UserViewModel Delete(UserSearchModel model);
void UpdateBonus(BonusUpdateBindingModel model);
} }
} }

View File

@ -0,0 +1,33 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.Converters
{
public class PurchaseConverter
{
public static PurchaseViewModel ToView(PurchaseBindingModel model) => new()
{
Id = model.Id,
DateCreated = model.DateCreated,
UserId = model.UserId,
Status = model.Status,
ProductCount = model.ProductCount,
Cost = model.Cost
};
public static PurchaseBindingModel ToBinding(PurchaseViewModel model) => new()
{
Id = model.Id,
DateCreated = model.DateCreated,
UserId = model.UserId,
Status = model.Status,
ProductCount = model.ProductCount,
Cost = model.Cost
};
}
}

View File

@ -19,6 +19,7 @@ namespace Contracts.Converters
Birthday = model.Birthday, Birthday = model.Birthday,
OnlyImportantMails = model.OnlyImportantMails, OnlyImportantMails = model.OnlyImportantMails,
Role = RoleConverter.ToView(model.Role), Role = RoleConverter.ToView(model.Role),
Bonus = model.Bonus,
}; };
public static UserBindingModel ToBinding(UserViewModel model) => new() public static UserBindingModel ToBinding(UserViewModel model) => new()
@ -30,6 +31,7 @@ namespace Contracts.Converters
Birthday = model.Birthday, Birthday = model.Birthday,
OnlyImportantMails = model.OnlyImportantMails, OnlyImportantMails = model.OnlyImportantMails,
Role = RoleConverter.ToBinding(model.Role), Role = RoleConverter.ToBinding(model.Role),
Bonus = model.Bonus,
}; };
} }
} }

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.SearchModels
{
public class CartItemSearchModel
{
public Guid? Id { get; set; }
public Guid? ProductId { get; set; }
public string? ProductName { get; set; }
public Guid? UserId { get; set; }
public bool? isClosed { get; set; }
}
}

View File

@ -11,8 +11,11 @@ namespace Contracts.SearchModels
public Guid? Id { get; set; } public Guid? Id { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public double? Price { get; set; } public double? Price { get; set; }
public double? PriceFrom { get; set; }
public double? PriceTo { get; set; }
public double? Rate { get; set; } public double? Rate { get; set; }
public int? Amount { get; set; } public int? Amount { get; set; }
public bool? IsBeingSold { get; set; } public bool? IsBeingSold { get; set; }
public string? Category { get; set; }
} }
} }

View File

@ -13,8 +13,9 @@ namespace Contracts.SearchModels
public Guid? Id { get; set; } public Guid? Id { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public double? PriceFrom { get; set; } public double? CostFrom { get; set; }
public double? PriceTo { get; set; } public double? CostTo { get; set; }
public PurchaseStatus? Status { get; set; } public PurchaseStatus? Status { get; set; }
public Guid UserId { get; set; }
} }
} }

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.SearchModels
{
public class SaleSearchModel
{
public Guid? Id { get; set; }
public string? Category { get; set; }
public string? Description { get; set; }
}
}

View File

@ -0,0 +1,22 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.StorageContracts
{
public interface ICartItemStorage
{
List<CartItemViewModel> GetFullList();
List<CartItemViewModel> GetFilteredList(CartItemSearchModel model);
CartItemViewModel? GetElement(CartItemSearchModel model);
CartItemViewModel? Insert(CartItemBindingModel model);
CartItemViewModel? Update(CartItemBindingModel model);
CartItemViewModel? Delete(CartItemBindingModel model);
void CloseItem(CartItemViewModel model);
}
}

View File

@ -0,0 +1,21 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.StorageContracts
{
public interface IMediaFileStorage
{
List<MediaFileViewModel> GetFullList();
List<MediaFileViewModel> GetFilteredList(MediaFileSearchModel model);
MediaFileViewModel? GetElement(MediaFileSearchModel model);
MediaFileViewModel? Insert(MediaFileBindingModel model);
MediaFileViewModel? Update(MediaFileBindingModel model);
MediaFileViewModel? Delete(MediaFileBindingModel model);
}
}

View File

@ -1,5 +1,7 @@
using Contracts.BindingModels; using Contracts.BindingModels;
using Contracts.SearchModels; using Contracts.SearchModels;
using Contracts.ViewModels;
using DataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -10,14 +12,17 @@ namespace Contracts.StorageContracts
{ {
public interface IPurchaseStorage public interface IPurchaseStorage
{ {
PurchaseBindingModel? Insert(PurchaseBindingModel model); PurchaseViewModel? Insert(PurchaseBindingModel model);
IEnumerable<PurchaseBindingModel> GetList(PurchaseSearchModel? model); List<PurchaseViewModel> GetFullList(PurchaseSearchModel? model);
List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel? model);
PurchaseBindingModel? GetElement(PurchaseSearchModel model); PurchaseViewModel? GetElement(PurchaseSearchModel model);
PurchaseBindingModel? Update(PurchaseBindingModel model); PurchaseViewModel? Update(PurchaseBindingModel model);
PurchaseBindingModel? Delete(PurchaseSearchModel model); PurchaseViewModel? Delete(PurchaseSearchModel model);
List<CartItemViewModel> GetCartItems(PurchaseSearchModel purchaseModel);
List<ProductViewModel> GetProducts(PurchaseSearchModel model);
} }
} }

View File

@ -0,0 +1,21 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.StorageContracts
{
public interface ISaleStorage
{
List<SaleViewModel> GetFullList();
List<SaleViewModel> GetFilteredList(SaleSearchModel model);
SaleViewModel? GetElement(SaleSearchModel model);
SaleViewModel? Insert(SaleBindingModel model);
SaleViewModel? Update(SaleBindingModel model);
SaleViewModel? Delete(SaleBindingModel model);
}
}

View File

@ -1,5 +1,6 @@
using Contracts.BindingModels; using Contracts.BindingModels;
using Contracts.SearchModels; using Contracts.SearchModels;
using Contracts.ViewModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -10,14 +11,15 @@ namespace Contracts.StorageContracts
{ {
public interface ISellStorage public interface ISellStorage
{ {
SellBindingModel? Insert(SellBindingModel model); SellViewModel? Insert(SellBindingModel model);
IEnumerable<SellBindingModel> GetList(SellSearchModel? model); IEnumerable<SellViewModel> GetFullList(SellSearchModel? model);
IEnumerable<SellViewModel> GetFilteredList(SellSearchModel? model);
SellBindingModel? GetElement(SellSearchModel model); SellViewModel? GetElement(SellSearchModel model);
SellBindingModel? Update(SellBindingModel model); SellViewModel? Update(SellBindingModel model);
SellBindingModel? Delete(SellSearchModel model); SellViewModel? Delete(SellSearchModel model);
} }
} }

View File

@ -14,8 +14,8 @@ namespace Contracts.StorageContracts
List<SupplyViewModel> GetFullList(); List<SupplyViewModel> GetFullList();
List<SupplyViewModel> GetFilteredList(SupplySearchModel model); List<SupplyViewModel> GetFilteredList(SupplySearchModel model);
SupplyViewModel? GetElement(SupplySearchModel model); SupplyViewModel? GetElement(SupplySearchModel model);
SupplyViewModel? Insert(SupplyBindingModel model); bool? Insert(SupplyBindingModel model);
SupplyViewModel? Update(SupplyBindingModel model); bool? Update(SupplyBindingModel model);
SupplyViewModel? Delete(SupplyBindingModel model); SupplyViewModel? Delete(SupplyBindingModel model);
} }
} }

View File

@ -19,5 +19,7 @@ namespace Contracts.StorageContracts
UserBindingModel? Update(UserBindingModel model); UserBindingModel? Update(UserBindingModel model);
UserBindingModel? Delete(UserSearchModel model); UserBindingModel? Delete(UserSearchModel model);
void UpdateBonus(BonusUpdateBindingModel model);
} }
} }

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class BillViewModel
{
public Guid UserId { get; set; }
public Guid PurchaseId { get; set; }
public List<ProductViewModel> Products { get; set; } = new List<ProductViewModel>();
public int Count { get; set; }
public double Cost { get; set; }
public DateTime DateCreated { get; set; }
public string UserFirstName { get; set; } = string.Empty;
public string UserLastName { get; set; } = string.Empty;
public string UserEmail { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,21 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class CartItemViewModel
{
public Guid Id { get; set; }
public Guid UserId { get; set; }
public Guid ProductId { get; set; }
public string ProductName { get; set; } = string.Empty;
public DateTime DateCreated { get; set; }
public int Count { get; set; }
public Guid? PurchaseId { get; set; }
}
}

View File

@ -5,22 +5,22 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace Contracts.ViewModels namespace Contracts.ViewModels
{ {
public class MediaFileViewModel public class MediaFileViewModel
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Location { get; set; } = string.Empty; public required byte[] Image { get; set; }
public string Name { get; set; } = string.Empty;
public Guid ProductId { get; set; } public Guid ProductId { get; set; }
public string ProductName { get; set; } = string.Empty;
public MediaFileBindingModel GetBindingModel() public MediaFileBindingModel GetBindingModel()
{ {
return new MediaFileBindingModel return new MediaFileBindingModel
{ {
Id = Id, Id = Id,
Name = Name, Image = Image,
Location = Location,
ProductId = ProductId ProductId = ProductId
}; };
} }

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class PaymentViewModel
{
public Guid UserId { get; set; }
public string UserFirstName { get; set; } = string.Empty;
public string UserSecondName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public int ProductCount { get; set; }
public double Cost { get; set; }
public int? Bonus { get; set; }
}
}

View File

@ -7,14 +7,18 @@ using System.Threading.Tasks;
namespace Contracts.ViewModels namespace Contracts.ViewModels
{ {
public class ProductViewModel public class ProductViewModel : IProduct
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public double Price { get; set; } public double Price { get; set; }
public double Rating { get; set; } public double ActualPrice { get; set; }
public double Rate { get; set; }
public bool IsBeingSold { get; set; } public bool IsBeingSold { get; set; }
public int Amount { get; set; } public int Amount { get; set; }
public string? Category { get; set; }
public string? Description { get; set; }
public List<MediaFileViewModel> MediaFiles { get; set; } = new(); public List<MediaFileViewModel> MediaFiles { get; set; } = new();
public Guid? SaleId { get; set; }
} }
} }

View File

@ -11,9 +11,12 @@ namespace Contracts.ViewModels
public class PurchaseViewModel public class PurchaseViewModel
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DatePurchase { get; set; } public DateTime DateCreated { get; set; }
public required IUser User { get; set; } public DateTime? DateClosed { get; set; }
public required List<IProduct> Products { get; set; } public required Guid UserId { get; set; }
public PurchaseStatus Status { get; set; } public PurchaseStatus Status { get; set; }
public int ProductCount { get; set; }
public double Cost { get; set; }
public bool IsPaid { get; set; }
} }
} }

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class ReportSupplyProductViewModel
{
public string SupplyName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<Tuple<string, int>> Products { get; set; } = new();
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class ReportSupplyViewModel
{
public int Id { get; set; }
public DateTime Date { get; set; }
public string Name { get; set; } = string.Empty;
public double Price { get; set; }
public String Status { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,21 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class SaleViewModel : ISale
{
public string Category { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string FullDescription { get; set; } = string.Empty;
public DateTime Start { get; set; }
public DateTime End { get; set; }
public string Name { get; set; } = string.Empty;
public int Value { get; set; }
public Guid Id { get; set; }
}
}

View File

@ -11,6 +11,7 @@ namespace Contracts.ViewModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime DateSell { get; set; } public DateTime DateSell { get; set; }
public ISupplyDoc? SupplyDoc { get; set; } public Guid? UserId { get; set; }
public Dictionary<Guid, (IProduct, int)> SellProducts { get; set; } = new();
} }
} }

View File

@ -11,6 +11,7 @@ namespace Contracts.ViewModels
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public int Deals { get; set; }
public Dictionary<Guid, (IProduct, int)> AvailibleProducts = new(); public Dictionary<Guid, (IProduct, int)> AvailibleProducts = new();
} }
} }

View File

@ -18,6 +18,8 @@ namespace Contracts.ViewModels
public double Price { get; set; } public double Price { get; set; }
public Dictionary<Guid, (IProduct, int)> Products { get; set; } = new(); public Dictionary<Guid, (IProduct, int)> Products { get; set; } = new();
public DateTime Date { get; set; } public DateTime Date { get; set; }
public DateTime? DateArriving { get; set; }
public DateTime? DateComplete { get; set; }
public SupplyStatus Status { get; set; } public SupplyStatus Status { get; set; }
} }
} }

View File

@ -10,6 +10,7 @@ namespace Contracts.ViewModels
{ {
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public double Price { get; set; } public double Price { get; set; }
public string Description { get; set; } = string.Empty;
public double Rate { get; set; } public double Rate { get; set; }
} }
} }

View File

@ -15,5 +15,6 @@ namespace Contracts.ViewModels
public DateTime Birthday { get; set; } public DateTime Birthday { get; set; }
public bool OnlyImportantMails { get; set; } public bool OnlyImportantMails { get; set; }
public RoleViewModel Role { get; set; } = null!; public RoleViewModel Role { get; set; } = null!;
public int Bonus { get; set; }
} }
} }

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataModels.Models
{
public interface ICartItem : IId
{
Guid UserId { get; }
int Count { get; }
DateTime DateCreated { get; set; }
Guid ProductId { get; set; }
string ProductName { get; set; }
bool IsClosed { get; set; }
}
}

View File

@ -8,8 +8,7 @@ namespace DataModels.Models
{ {
public interface IMediaFile : IId public interface IMediaFile : IId
{ {
string Name { get; } byte[] Image { get; }
string Location { get; }
Guid ProductId { get; } Guid ProductId { get; }
} }
} }

View File

@ -13,7 +13,7 @@ namespace DataModels.Models
bool IsBeingSold { get; } bool IsBeingSold { get; }
public double Rate { get; } public double Rate { get; }
int Amount { get; } int Amount { get; }
// будут браться через mediafilestorage так что скорее всего это тут не надо string Category { get; }
// List<IMediaFile> MediaFiles { get; } string Description { get; }
} }
} }

View File

@ -9,7 +9,11 @@ namespace DataModels.Models
{ {
public interface IPurchase : IId public interface IPurchase : IId
{ {
DateTime DatePurchase { get; } DateTime DateCreated { get; }
DateTime? DateClosed { get; }
PurchaseStatus Status { get; } PurchaseStatus Status { get; }
int ProductCount { get; }
double Cost { get; }
bool IsPaid { get; }
} }
} }

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataModels.Models
{
public interface ISale : IId
{
public string Category { get; set; }
public string Description { get; set; }
public string FullDescription { get; set; }
public string Name { get; set; }
public int Value { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
}
}

View File

@ -13,6 +13,8 @@ namespace DataModels.Models
double Price { get; } double Price { get; }
Guid SupplierId { get; } Guid SupplierId { get; }
DateTime Date { get; } DateTime Date { get; }
DateTime? DateArriving { get; }
DateTime? DateComplete { get; }
SupplyStatus Status { get; } SupplyStatus Status { get; }
Dictionary<Guid, (IProduct, int)> SupplyProducts { get; } Dictionary<Guid, (IProduct, int)> SupplyProducts { get; }
} }

View File

@ -14,5 +14,6 @@ namespace DataModels.Models
string Email { get; } string Email { get; }
DateTime Birthday { get; } DateTime Birthday { get; }
bool OnlyImportantMails { get; } bool OnlyImportantMails { get; }
int Bonus { get; }
} }
} }

View File

@ -14,6 +14,8 @@ namespace DatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
optionsBuilder.UseNpgsql("Server=192.168.191.42:32768;Database=gun_market;Username=postgres;Password=7355608;"); optionsBuilder.UseNpgsql("Server=192.168.191.42:32768;Database=gun_market;Username=postgres;Password=7355608;");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
@ -28,7 +30,11 @@ namespace DatabaseImplement
public virtual DbSet<SupplyProduct> SupplyProducts { get; set; } = null!; public virtual DbSet<SupplyProduct> SupplyProducts { get; set; } = null!;
public virtual DbSet<Supplier> Suppliers { get; set; } = null!; public virtual DbSet<Supplier> Suppliers { get; set; } = null!;
public virtual DbSet<SupplierProduct> SupplierProducts { get; set; } = null!; public virtual DbSet<SupplierProduct> SupplierProducts { get; set; } = null!;
public virtual DbSet<MediaFile> MediaFiles { get; set; } = null!; public virtual DbSet<MediaFile> MediaFiles { get; set; } = null!;
public virtual DbSet<SellProducts> SellProducts { get; set; } = null!;
public virtual DbSet<SupplyDoc> SupplyDocs { get; set; } = null!;
public virtual DbSet<CartItem> CartItems { get; set; } = null!;
public virtual DbSet<Sale> Sales { get; set; } = null!;
} }
} }

View File

@ -0,0 +1,168 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class CartItemStorage : ICartItemStorage
{
public CartItemViewModel? Delete(CartItemBindingModel model)
{
using var context = new Database();
var element = context.CartItems
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.CartItems.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public CartItemViewModel? GetElement(CartItemSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new Database();
return context.CartItems
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<CartItemViewModel> GetFilteredList(CartItemSearchModel model)
{
if (model.UserId == Guid.Empty && string.IsNullOrEmpty(model.ProductName) && model.isClosed == null)
{
Console.WriteLine();
return new();
}
using var context = new Database();
if (model.UserId != Guid.Empty && model.isClosed != null)
{
return context.CartItems
.Where(x => x.UserId == model.UserId).Where(x => x.IsClosed == model.isClosed)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.UserId != Guid.Empty)
{
return context.CartItems
.Where(x => x.UserId == model.UserId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.isClosed != null)
{
return context.CartItems
.Where(x => x.IsClosed == model.isClosed)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context.CartItems
.Where(x => x.ProductName.Contains(model.ProductName))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<CartItemViewModel> GetFullList()
{
using var context = new Database();
return context.CartItems
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public CartItemViewModel? Insert(CartItemBindingModel model)
{
using var context = new Database();
var newItem = CartItem.Create(context, model);
if (newItem == null)
{
return null;
}
context.CartItems.Add(newItem);
context.SaveChanges();
return newItem.GetViewModel;
}
public CartItemViewModel? Update(CartItemBindingModel model)
{
using var context = new Database();
using var transaction = context.Database.BeginTransaction();
try
{
var item = context.CartItems.FirstOrDefault(rec =>
rec.Id == model.Id);
if (item == null)
{
return null;
}
item.Update(model);
context.SaveChanges();
transaction.Commit();
return new();
}
catch
{
transaction.Rollback();
throw;
}
}
public void CloseItem(CartItemViewModel model)
{
using var context = new Database();
using var transaction = context.Database.BeginTransaction();
try
{
var item = context.CartItems.FirstOrDefault(rec =>
rec.Id == model.Id);
if (item == null)
{
return;
}
var product = context.Products.FirstOrDefault(x => x.Id == model.ProductId);
if (product == null)
{
return;
}
var binding = product.GetBindingModel();
binding.Amount -= item.Count;
product.Update(binding);
item.IsClosed = true;
context.SaveChanges();
transaction.Commit();
return;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -0,0 +1,101 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class MediaFileStorage : IMediaFileStorage
{
public MediaFileViewModel? Delete(MediaFileBindingModel model)
{
using var context = new Database();
var element = context.MediaFiles
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.MediaFiles.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public MediaFileViewModel? GetElement(MediaFileSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new Database();
return context.MediaFiles
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<MediaFileViewModel> GetFilteredList(MediaFileSearchModel model)
{
if (!model.ProductId.HasValue && !model.Id.HasValue)
{
return new();
}
using var context = new Database();
if (model.ProductId.HasValue)
{
return context.MediaFiles.Where(x => x.ProductId == model.ProductId).Select(x => x.GetViewModel).ToList();
}
return context.MediaFiles.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
}
public List<MediaFileViewModel> GetFullList()
{
using var context = new Database();
return context.MediaFiles
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public MediaFileViewModel? Insert(MediaFileBindingModel model)
{
using var context = new Database();
var newProduct = MediaFile.Create(model);
if (newProduct == null)
{
return null;
}
context.MediaFiles.Add(newProduct);
context.SaveChanges();
return newProduct.GetViewModel;
}
public MediaFileViewModel? Update(MediaFileBindingModel model)
{
using var context = new Database();
using var transaction = context.Database.BeginTransaction();
try
{
var product = context.MediaFiles.FirstOrDefault(rec =>
rec.Id == model.Id);
if (product == null)
{
return null;
}
product.Update(model);
context.SaveChanges();
transaction.Commit();
return product.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -18,11 +18,6 @@ namespace DatabaseImplement.Implements
{ {
using var context = new Database(); using var context = new Database();
var element = context.Products var element = context.Products
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
.FirstOrDefault(rec => rec.Id == model.Id); .FirstOrDefault(rec => rec.Id == model.Id);
if (element != null) if (element != null)
{ {
@ -40,43 +35,54 @@ namespace DatabaseImplement.Implements
return null; return null;
} }
using var context = new Database(); using var context = new Database();
return context.Products return context.Products.Include(x => x.Sale)
.Include(x => x.Name) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} }
public List<ProductViewModel> GetFilteredList(ProductSearchModel model) public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
{ {
if (!model.IsBeingSold.HasValue && !model.Price.HasValue && !model.Rate.HasValue && !model.Amount.HasValue && string.IsNullOrEmpty(model.Name)) if (!model.IsBeingSold.HasValue && !model.PriceFrom.HasValue && !model.PriceTo.HasValue && !model.Price.HasValue && !model.Rate.HasValue
&& !model.Amount.HasValue && string.IsNullOrEmpty(model.Name) && string.IsNullOrEmpty(model.Category))
{ {
return new(); return new();
} }
using var context = new Database(); using var context = new Database();
if (model.Price.HasValue) if (model.Price.HasValue)
{ {
return context.Products return context.Products.Include(x => x.Sale)
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
.Where(x => x.Price <= model.Price) .Where(x => x.Price <= model.Price)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
if (model.PriceFrom.HasValue && model.PriceTo.HasValue)
{
return context.Products.Include(x => x.Sale)
.Where(x => x.Price <= model.PriceTo && x.Price >= model.PriceFrom)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.PriceFrom.HasValue)
{
return context.Products.Include(x => x.Sale)
.Where(x => x.Price >= model.PriceFrom)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.PriceTo.HasValue)
{
return context.Products.Include(x => x.Sale)
.Where(x => x.Price <= model.PriceTo)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.Rate.HasValue) if (model.Rate.HasValue)
{ {
return context.Products return context.Products.Include(x => x.Sale)
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
.Where(x => x.Rate <= model.Rate) .Where(x => x.Rate <= model.Rate)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
@ -84,24 +90,22 @@ namespace DatabaseImplement.Implements
} }
if (model.Amount.HasValue && model.IsBeingSold.HasValue) if (model.Amount.HasValue && model.IsBeingSold.HasValue)
{ {
return context.Products return context.Products.Include(x => x.Sale)
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
.Where(x => x.IsBeingSold == model.IsBeingSold && x.Amount >= model.Amount) .Where(x => x.IsBeingSold == model.IsBeingSold && x.Amount >= model.Amount)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
return context.Products if (!string.IsNullOrEmpty(model.Category))
.Include(x => x.Name) {
.Include(x => x.Price) return context.Products.Include(x => x.Sale)
.Include(x => x.IsBeingSold) .Where(x => x.Category == model.Category)
.Include(x => x.Rate) .ToList()
.Include(x => x.Amount) .Select(x => x.GetViewModel)
.Where(x => x.Name == model.Name) .ToList();
}
return context.Products.Include(x => x.Sale)
.Where(x => x.Name.Contains(model.Name))
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -110,12 +114,7 @@ namespace DatabaseImplement.Implements
public List<ProductViewModel> GetFullList() public List<ProductViewModel> GetFullList()
{ {
using var context = new Database(); using var context = new Database();
return context.Products return context.Products.Include(x => x.Sale)
.Include(x => x.Name)
.Include(x => x.Price)
.Include(x => x.IsBeingSold)
.Include(x => x.Rate)
.Include(x => x.Amount)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -125,6 +124,16 @@ namespace DatabaseImplement.Implements
{ {
using var context = new Database(); using var context = new Database();
var newProduct = Product.Create(context, model); var newProduct = Product.Create(context, model);
foreach (var sale in context.Sales)
{
if (sale.Category == newProduct.Category)
{
newProduct.Sale = sale;
newProduct.SaleId = sale.Id;
}
}
if (newProduct == null) if (newProduct == null)
{ {
return null; return null;
@ -140,7 +149,7 @@ namespace DatabaseImplement.Implements
using var transaction = context.Database.BeginTransaction(); using var transaction = context.Database.BeginTransaction();
try try
{ {
var product = context.Products.FirstOrDefault(rec => var product = context.Products.Include(x => x.Sale).FirstOrDefault(rec =>
rec.Id == model.Id); rec.Id == model.Id);
if (product == null) if (product == null)
{ {
@ -149,7 +158,7 @@ namespace DatabaseImplement.Implements
product.Update(model); product.Update(model);
context.SaveChanges(); context.SaveChanges();
transaction.Commit(); transaction.Commit();
return product.GetViewModel; return new();
} }
catch catch
{ {

View File

@ -0,0 +1,241 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Models;
using DataModels.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class PurchaseStorage : IPurchaseStorage
{
public PurchaseViewModel? Delete(PurchaseSearchModel model)
{
using var context = new Database();
var element = context.Purchases.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Purchases.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new Database();
return context.Purchases
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<PurchaseViewModel> GetFullList(PurchaseSearchModel? model)
{
using var context = new Database();
return context.Purchases
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel? model)
{
using var context = new Database();
if (model != null && model.UserId == Guid.Empty && !model.CostFrom.HasValue && !model.CostTo.HasValue && !model.DateTo.HasValue
&& !model.DateFrom.HasValue && !model.Status.HasValue)
{
return new();
}
if (model.CostFrom.HasValue && model.CostTo.HasValue)
{
return context.Purchases
.Where(x => x.Cost <= model.CostTo && x.Cost >= model.CostFrom)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.CostFrom.HasValue)
{
return context.Purchases
.Where(x => x.Cost >= model.CostFrom)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.CostTo.HasValue)
{
return context.Purchases
.Where(x => x.Cost <= model.CostTo)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
return context.Purchases
.Where(x => x.DateCreated <= model.DateTo && x.DateCreated >= model.DateFrom)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.DateFrom.HasValue)
{
return context.Purchases
.Where(x => x.DateCreated >= model.DateFrom)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.DateTo.HasValue)
{
return context.Purchases
.Where(x => x.DateCreated <= model.DateTo)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
if (model.UserId != Guid.Empty)
{
return context.Purchases
.Where(x => x.UserId == model.UserId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context.Purchases
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public PurchaseViewModel? Insert(PurchaseBindingModel model)
{
using var context = new Database();
using var transaction = context.Database.BeginTransaction();
try
{
var purchase = Purchase.Create(context, model);
if (purchase == null)
return null;
var cartItems = context.CartItems
.Where(x => !x.IsClosed).ToList();
var updated = new List<CartItem>();
foreach (var item in cartItems)
{
var bitem = item.GetBindingModel();
bitem.IsClosed = true;
bitem.PurchaseId = purchase.Id;
bitem.Purchase = purchase;
item.Update(bitem);
updated.Add(item);
Console.WriteLine();
}
var products = new List<Product>();
foreach (var item in updated)
{
var product = context.Products
.FirstOrDefault(x => x.Id == item.ProductId);
products.Add(product);
}
purchase.Products = products;
context.Purchases.Add(purchase);
context.SaveChanges();
transaction.Commit();
return purchase.GetViewModel;
}
catch (DbUpdateException ex)
{
transaction.Rollback();
throw new InvalidOperationException("Не удалось сохранить изменения.", ex);
}
finally
{
transaction.Dispose();
}
return null;
}
public PurchaseViewModel? Update(PurchaseBindingModel model)
{
using var context = new Database();
using var transaction = context.Database.BeginTransaction();
try
{
var purchase = context.Purchases.FirstOrDefault(rec =>
rec.Id == model.Id);
if (purchase == null)
{
return null;
}
purchase.Update(model);
context.SaveChanges();
transaction.Commit();
return purchase.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public List<CartItemViewModel> GetCartItems(PurchaseSearchModel model)
{
using var context = new Database();
var cartItems = context.CartItems
.Where(x => x.PurchaseId == model.Id).ToList()
.Select(x => x.GetViewModel).ToList();
if (cartItems == null)
{
return null;
}
return cartItems;
}
public List<ProductViewModel> GetProducts(PurchaseSearchModel model)
{
using var context = new Database();
if (!model.Id.HasValue)
{
return null;
}
var products = new List<ProductViewModel>();
var cartItems = GetCartItems(model);
if (cartItems != null)
{
foreach (var item in cartItems)
{
var product = context.Products
.FirstOrDefault(x => x.Id == item.ProductId)?.GetViewModel;
if (product != null) products.Add(product) ;
}
}
else return null;
return products;
}
}
}

View File

@ -0,0 +1,113 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class SaleStorage : ISaleStorage
{
public SaleViewModel? Delete(SaleBindingModel model)
{
using var context = new Database();
var element = context.Sales
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Sales.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public SaleViewModel? GetElement(SaleSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new Database();
return context.Sales
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<SaleViewModel> GetFilteredList(SaleSearchModel model)
{
if (string.IsNullOrEmpty(model.Category))
{
return new();
}
using var context = new Database();
return context.Sales
.Where(x => x.Category.Contains(model.Category))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<SaleViewModel> GetFullList()
{
using var context = new Database();
return context.Sales
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public SaleViewModel? Insert(SaleBindingModel model)
{
using var context = new Database();
var newSale = Sale.Create(context, model);
if (newSale == null)
{
return null;
}
foreach (var product in context.Products)
{
if (product.Category == newSale.Category)
{
product.Sale = newSale;
product.SaleId = newSale.Id;
}
}
context.Sales.Add(newSale);
context.SaveChanges();
return newSale.GetViewModel;
}
public SaleViewModel? Update(SaleBindingModel model)
{
using var context = new Database();
using var transaction = context.Database.BeginTransaction();
try
{
var sale = context.Sales.FirstOrDefault(rec =>
rec.Id == model.Id);
if (sale == null)
{
return null;
}
sale.Update(model);
context.SaveChanges();
transaction.Commit();
return new();
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -0,0 +1,92 @@
using Contracts.BindingModels;
using Contracts.Converters;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using DatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class SellStorage : ISellStorage
{
public SellViewModel? Delete(SellSearchModel model)
{
using var context = new Database();
var element = context.Sells.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Sells.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public SellViewModel? GetElement(SellSearchModel model)
{
using var context = new Database();
return context.Sells
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public IEnumerable<SellViewModel> GetFilteredList(SellSearchModel? model)
{
throw new NotImplementedException();
}
public IEnumerable<SellViewModel> GetFullList(SellSearchModel? model)
{
using var context = new Database();
return context.Sells
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.ToList()
.Select((Sell sell, int index) => sell.GetViewModel)
.ToList();
}
public SellViewModel? Insert(SellBindingModel model)
{
using var context = new Database();
var sell = Sell.Create(context, model);
if (sell == null)
{
return null;
}
context.Sells.Add(sell);
context.SaveChanges();
return sell.GetViewModel;
}
public SellViewModel? Update(SellBindingModel model)
{
using var context = new Database();
using var transaction = context.Database.BeginTransaction();
try
{
var sell = context.Sells.FirstOrDefault(rec => rec.Id == model.Id);
if (sell == null)
{
return null;
}
sell.Update(model);
context.SaveChanges();
transaction.Commit();
return sell.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -37,7 +37,7 @@ namespace DatabaseImplement.Implements
} }
using var context = new Database(); using var context = new Database();
return context.Suppliers return context.Suppliers
.Include(x => x.Name) //.Include(x => x.Name)
.Include(x => x.Products) .Include(x => x.Products)
.ThenInclude(x => x.Product) .ThenInclude(x => x.Product)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;

View File

@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -106,7 +107,7 @@ namespace DatabaseImplement.Implements
.ToList(); .ToList();
} }
public SupplyViewModel? Insert(SupplyBindingModel model) public bool? Insert(SupplyBindingModel model)
{ {
using var context = new Database(); using var context = new Database();
var newProduct = Supply.Create(context, model); var newProduct = Supply.Create(context, model);
@ -115,11 +116,18 @@ namespace DatabaseImplement.Implements
return null; return null;
} }
context.Supplies.Add(newProduct); context.Supplies.Add(newProduct);
try
{
context.SaveChanges(); context.SaveChanges();
return newProduct.GetViewModel; }
catch (Exception ex)
{
Debug.WriteLine(ex);
}
return true;
} }
public SupplyViewModel? Update(SupplyBindingModel model) public bool? Update(SupplyBindingModel model)
{ {
using var context = new Database(); using var context = new Database();
using var transaction = context.Database.BeginTransaction(); using var transaction = context.Database.BeginTransaction();
@ -129,13 +137,12 @@ namespace DatabaseImplement.Implements
rec.Id == model.Id); rec.Id == model.Id);
if (product == null) if (product == null)
{ {
return null; return false;
} }
product.Update(model); product.Update(model);
context.SaveChanges(); context.SaveChanges();
product.UpdateProducts(context, model);
transaction.Commit(); transaction.Commit();
return product.GetViewModel; return true;
} }
catch catch
{ {

View File

@ -106,5 +106,20 @@ namespace DatabaseImplement.Implements
context.SaveChanges(); context.SaveChanges();
return user.GetBindingModel(); return user.GetBindingModel();
} }
public void UpdateBonus(BonusUpdateBindingModel model)
{
var context = new Database();
var user = context.Users
.FirstOrDefault(u => u.Id == model.UserId);
if (user is null)
return;
user.Bonus += model.BonusPlus;
user.Bonus -= model.BonusMinus;
context.SaveChanges();
}
} }
} }

View File

@ -0,0 +1,395 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240623130351_many-to-many")]
partial class manytomany
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("PurchaseProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Purchase", "Purchase")
.WithMany("Products")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Purchase");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Navigation("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,90 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class manytomany : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "UserId",
table: "Purchases",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
migrationBuilder.CreateTable(
name: "PurchaseProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
PurchaseId = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PurchaseProducts", x => x.Id);
table.ForeignKey(
name: "FK_PurchaseProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PurchaseProducts_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Purchases_UserId",
table: "Purchases",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseProducts_ProductId",
table: "PurchaseProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseProducts_PurchaseId",
table: "PurchaseProducts",
column: "PurchaseId");
migrationBuilder.AddForeignKey(
name: "FK_Purchases_Users_UserId",
table: "Purchases",
column: "UserId",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Purchases_Users_UserId",
table: "Purchases");
migrationBuilder.DropTable(
name: "PurchaseProducts");
migrationBuilder.DropIndex(
name: "IX_Purchases_UserId",
table: "Purchases");
migrationBuilder.DropColumn(
name: "UserId",
table: "Purchases");
}
}
}

View File

@ -0,0 +1,477 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240624105540_sellproducts")]
partial class sellproducts
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("PurchaseProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Purchase", "Purchase")
.WithMany("Products")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Purchase");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("SellProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Sell", "Sell")
.WithMany("Products")
.HasForeignKey("SellId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Sell");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Navigation("PurchaseProducts");
b.Navigation("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,104 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class sellproducts : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "UserId",
table: "Sells",
type: "uuid",
nullable: true);
migrationBuilder.CreateTable(
name: "SellProducts",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
SellId = table.Column<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SellProducts", x => x.Id);
table.ForeignKey(
name: "FK_SellProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SellProducts_Sells_SellId",
column: x => x.SellId,
principalTable: "Sells",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SupplyDocs",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
SupplyId = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SupplyDocs", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Sells_UserId",
table: "Sells",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_SellProducts_ProductId",
table: "SellProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_SellProducts_SellId",
table: "SellProducts",
column: "SellId");
migrationBuilder.AddForeignKey(
name: "FK_Sells_Users_UserId",
table: "Sells",
column: "UserId",
principalTable: "Users",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Sells_Users_UserId",
table: "Sells");
migrationBuilder.DropTable(
name: "SellProducts");
migrationBuilder.DropTable(
name: "SupplyDocs");
migrationBuilder.DropIndex(
name: "IX_Sells_UserId",
table: "Sells");
migrationBuilder.DropColumn(
name: "UserId",
table: "Sells");
}
}
}

View File

@ -0,0 +1,496 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240625085945_dates_migration")]
partial class dates_migration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Location")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("PurchaseProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Purchase", "Purchase")
.WithMany("Products")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Purchase");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("SellProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Sell", "Sell")
.WithMany("Products")
.HasForeignKey("SellId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Sell");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Navigation("PurchaseProducts");
b.Navigation("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,60 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class dates_migration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "DateArriving",
table: "Supplies",
type: "timestamp with time zone",
nullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "DateComplete",
table: "Supplies",
type: "timestamp with time zone",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_MediaFiles_ProductId",
table: "MediaFiles",
column: "ProductId");
migrationBuilder.AddForeignKey(
name: "FK_MediaFiles_Products_ProductId",
table: "MediaFiles",
column: "ProductId",
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_MediaFiles_Products_ProductId",
table: "MediaFiles");
migrationBuilder.DropIndex(
name: "IX_MediaFiles_ProductId",
table: "MediaFiles");
migrationBuilder.DropColumn(
name: "DateArriving",
table: "Supplies");
migrationBuilder.DropColumn(
name: "DateComplete",
table: "Supplies");
}
}
}

View File

@ -0,0 +1,496 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240625124236_image")]
partial class image
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("PurchaseProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Purchase", "Purchase")
.WithMany("Products")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Purchase");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("SellProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Sell", "Sell")
.WithMany("Products")
.HasForeignKey("SellId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Sell");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Navigation("PurchaseProducts");
b.Navigation("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class image : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Location",
table: "MediaFiles");
migrationBuilder.AddColumn<byte[]>(
name: "Image",
table: "MediaFiles",
type: "bytea",
nullable: false,
defaultValue: new byte[0]);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Image",
table: "MediaFiles");
migrationBuilder.AddColumn<string>(
name: "Location",
table: "MediaFiles",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -0,0 +1,492 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240625131604_image2")]
partial class image2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp with time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("PurchaseProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Purchase", "Purchase")
.WithMany("Products")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Purchase");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("SellProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Sell", "Sell")
.WithMany("Products")
.HasForeignKey("SellId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Sell");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Navigation("PurchaseProducts");
b.Navigation("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class image2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Name",
table: "MediaFiles");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Name",
table: "MediaFiles",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@ -0,0 +1,495 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240625215017_purchase")]
partial class purchase
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.HasKey("Id");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<DateTime>("DatePurchase")
.HasColumnType("timestamp without time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp without time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp without time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp without time zone");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("PurchaseProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Purchase", "Purchase")
.WithMany("Products")
.HasForeignKey("PurchaseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Purchase");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.HasOne("DatabaseImplement.Models.User", "User")
.WithMany()
.HasForeignKey("UserId");
b.Navigation("User");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany("SellProducts")
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Sell", "Sell")
.WithMany("Products")
.HasForeignKey("SellId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Sell");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany("Products")
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.HasOne("DatabaseImplement.Models.Supplier", "Supplier")
.WithMany()
.HasForeignKey("SupplierId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Supplier");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.HasOne("DatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("DatabaseImplement.Models.Supply", "Supply")
.WithMany("Products")
.HasForeignKey("SupplyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Product");
b.Navigation("Supply");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.HasOne("DatabaseImplement.Models.Role", "Role")
.WithMany()
.HasForeignKey("RoleId");
b.Navigation("Role");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Navigation("PurchaseProducts");
b.Navigation("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Navigation("Products");
});
#pragma warning restore 612, 618
}
}
}

Some files were not shown because too many files have changed in this diff Show More