diff --git a/BusinessLogic/BusinessLogic/BillLogic.cs b/BusinessLogic/BusinessLogic/BillLogic.cs new file mode 100644 index 0000000..674c943 --- /dev/null +++ b/BusinessLogic/BusinessLogic/BillLogic.cs @@ -0,0 +1,122 @@ +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); // Текст заголовка + + 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(1)); + columnProduct.Format.Alignment = ParagraphAlignment.Left; + + Column columnPrice = table.AddColumn(Unit.FromCentimeter(1)); + columnPrice.Format.Alignment = ParagraphAlignment.Right; + + // Добавление строк с товарами + foreach (var product in model.Products) + { + Row row = table.AddRow(); + row.Cells[0].AddParagraph(product.Name); + row.Cells[1].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)); + } + } +} diff --git a/BusinessLogic/BusinessLogic/CartItemLogic.cs b/BusinessLogic/BusinessLogic/CartItemLogic.cs new file mode 100644 index 0000000..546e327 --- /dev/null +++ b/BusinessLogic/BusinessLogic/CartItemLogic.cs @@ -0,0 +1,105 @@ +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 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 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); + } + } +} diff --git a/BusinessLogic/BusinessLogic/ProductLogic.cs b/BusinessLogic/BusinessLogic/ProductLogic.cs index e10985d..64e594d 100644 --- a/BusinessLogic/BusinessLogic/ProductLogic.cs +++ b/BusinessLogic/BusinessLogic/ProductLogic.cs @@ -23,6 +23,7 @@ namespace BusinessLogic.BusinessLogic } public bool Create(ProductBindingModel model) { + CheckModel(model); if (_productStorage.Insert(model) == null) { diff --git a/BusinessLogic/BusinessLogic/PurchaseLogic.cs b/BusinessLogic/BusinessLogic/PurchaseLogic.cs index d9acc2b..4ea4fd8 100644 --- a/BusinessLogic/BusinessLogic/PurchaseLogic.cs +++ b/BusinessLogic/BusinessLogic/PurchaseLogic.cs @@ -103,14 +103,25 @@ namespace BusinessLogic.BusinessLogic } return purchase; } - public PurchaseViewModel AddProduct(PurchaseSearchModel purchase_model, ProductSearchModel product_model, int count) - { - _purchaseStorage.AddProducts(purchase_model, product_model, count); - return _purchaseStorage.GetElement(purchase_model); - } - public Dictionary GetProducts(PurchaseSearchModel model) + public List GetCartItems(PurchaseSearchModel model) { - return _purchaseStorage.GetProducts(model); + var items = _purchaseStorage.GetCartItems(model); + if (items is null) + { + throw new Exception("Get operation failed."); + } + return items; } - } + + public List GetProducts(PurchaseSearchModel model) + { + var products = _purchaseStorage.GetProducts(model); + if (products is null) + { + throw new Exception("Get operation failed."); + } + return products; + } + + } } diff --git a/BusinessLogic/BusinessLogic/SaleLogic.cs b/BusinessLogic/BusinessLogic/SaleLogic.cs new file mode 100644 index 0000000..b4c6cee --- /dev/null +++ b/BusinessLogic/BusinessLogic/SaleLogic.cs @@ -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 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 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("Акция с таким описанием уже есть"); + } + } + } +} diff --git a/BusinessLogic/BusinessLogic/UserLogic.cs b/BusinessLogic/BusinessLogic/UserLogic.cs index 0ccec27..163d1c2 100644 --- a/BusinessLogic/BusinessLogic/UserLogic.cs +++ b/BusinessLogic/BusinessLogic/UserLogic.cs @@ -181,5 +181,10 @@ namespace BusinessLogic.BusinessLogic { return _twoFactorAuthService.Verify(code); } + + public void UpdateBonus(BonusUpdateBindingModel model) + { + _userStorage.UpdateBonus(model); + } } } \ No newline at end of file diff --git a/BusinessLogic/Tools/Mail/Mail.cs b/BusinessLogic/Tools/Mail/Mail.cs index 44cc1a8..1b677a9 100644 --- a/BusinessLogic/Tools/Mail/Mail.cs +++ b/BusinessLogic/Tools/Mail/Mail.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Mail; using System.Text; using System.Threading.Tasks; @@ -12,5 +13,6 @@ namespace BusinessLogic.Tools.Mail public string Title { get; set; } = null!; public string Body { get; set; } = null!; public bool IsSendable { get; set; } = true; + public List? Attachments { get; set; } = new List(); } } \ No newline at end of file diff --git a/BusinessLogic/Tools/Mail/MailSender.cs b/BusinessLogic/Tools/Mail/MailSender.cs index 3df9c48..bb1c93a 100644 --- a/BusinessLogic/Tools/Mail/MailSender.cs +++ b/BusinessLogic/Tools/Mail/MailSender.cs @@ -42,6 +42,11 @@ namespace BusinessLogic.Tools.Mail message.Subject = mail.Title; message.Body = mail.Body; + foreach (var attachment in mail.Attachments) + { + message.Attachments.Add(attachment); + } + client.Send(message); } } diff --git a/BusinessLogic/Tools/Mail/MailTemplates/MailBillSender.cs b/BusinessLogic/Tools/Mail/MailTemplates/MailBillSender.cs new file mode 100644 index 0000000..c4cbaf3 --- /dev/null +++ b/BusinessLogic/Tools/Mail/MailTemplates/MailBillSender.cs @@ -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); + } + } +} diff --git a/BusinessLogic/Tools/Mail/MailTemplates/MailTwoFactorCode.cs b/BusinessLogic/Tools/Mail/MailTemplates/MailTwoFactorCode.cs index 6c5e4d4..ae72567 100644 --- a/BusinessLogic/Tools/Mail/MailTemplates/MailTwoFactorCode.cs +++ b/BusinessLogic/Tools/Mail/MailTemplates/MailTwoFactorCode.cs @@ -15,7 +15,7 @@ namespace BusinessLogic.Tools.Mail.MailTemplates Title = "Ваш код для подтверждения"; Body = $"Здравствуйте, {user.SecondName} {user.FirstName}! Вот Ваш код для подтверждения:\n" + $"{code}\n" + - $"Если это не Вы, игноритруйте это сообщение."; + $"Если это не Вы, игнорируйте это сообщение."; } } } \ No newline at end of file diff --git a/Contracts/BindingModels/BonusUpdateBindingModel.cs b/Contracts/BindingModels/BonusUpdateBindingModel.cs new file mode 100644 index 0000000..d2bb6bf --- /dev/null +++ b/Contracts/BindingModels/BonusUpdateBindingModel.cs @@ -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; } + } +} diff --git a/Contracts/BindingModels/CartItemBindingModel.cs b/Contracts/BindingModels/CartItemBindingModel.cs new file mode 100644 index 0000000..fc042d1 --- /dev/null +++ b/Contracts/BindingModels/CartItemBindingModel.cs @@ -0,0 +1,20 @@ +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; } + } +} diff --git a/Contracts/BindingModels/ProductBindingModel.cs b/Contracts/BindingModels/ProductBindingModel.cs index 8f44dbd..4a86885 100644 --- a/Contracts/BindingModels/ProductBindingModel.cs +++ b/Contracts/BindingModels/ProductBindingModel.cs @@ -15,5 +15,8 @@ namespace Contracts.BindingModels public int Amount { get; set; } public bool IsBeingSold { get; set; } public double Rate { get; set; } - } + public string? Description { get; set; } + public string? Category { get; set; } + public Guid? SaleId { get; set; } + } } diff --git a/Contracts/BindingModels/PurchaseBindingModel.cs b/Contracts/BindingModels/PurchaseBindingModel.cs index 67268dd..1c0a66c 100644 --- a/Contracts/BindingModels/PurchaseBindingModel.cs +++ b/Contracts/BindingModels/PurchaseBindingModel.cs @@ -11,10 +11,12 @@ namespace Contracts.BindingModels public class PurchaseBindingModel { public Guid Id { get; set; } - public DateTime DatePurchase { get; set; } - public Guid UserId { get; set; } + public DateTime DateCreated { get; set; } + public DateTime? DateClosed { get; set; } + public Guid UserId { get; set; } public PurchaseStatus Status { get; set; } - public Dictionary? PurchaseProducts { get; set; } = new(); + public int ProductCount { get; set; } public double Cost { get; set; } - } + public bool IsPaid { get; set; } + } } diff --git a/Contracts/BindingModels/SaleBindingModel.cs b/Contracts/BindingModels/SaleBindingModel.cs new file mode 100644 index 0000000..0cb5f95 --- /dev/null +++ b/Contracts/BindingModels/SaleBindingModel.cs @@ -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; } + } +} diff --git a/Contracts/BindingModels/UserBindingModel.cs b/Contracts/BindingModels/UserBindingModel.cs index 6c192d6..7b131d9 100644 --- a/Contracts/BindingModels/UserBindingModel.cs +++ b/Contracts/BindingModels/UserBindingModel.cs @@ -17,5 +17,6 @@ namespace Contracts.BindingModels public DateTime Birthday { get; set; } public bool OnlyImportantMails { get; set; } public RoleBindingModel Role { get; set; } = null!; + public int Bonus { get; set; } } } \ No newline at end of file diff --git a/Contracts/BusinessLogicContracts/IBillLogic.cs b/Contracts/BusinessLogicContracts/IBillLogic.cs new file mode 100644 index 0000000..753abd3 --- /dev/null +++ b/Contracts/BusinessLogicContracts/IBillLogic.cs @@ -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); + } +} diff --git a/Contracts/BusinessLogicContracts/ICartItemLogic.cs b/Contracts/BusinessLogicContracts/ICartItemLogic.cs new file mode 100644 index 0000000..ad1a4aa --- /dev/null +++ b/Contracts/BusinessLogicContracts/ICartItemLogic.cs @@ -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 ICartItemLogic + { + bool Create(CartItemBindingModel model); + + bool Update(CartItemBindingModel model); + + CartItemViewModel ReadElement(CartItemSearchModel model); + + List ReadElements(CartItemSearchModel? model); + + bool Delete(CartItemBindingModel model); + } +} diff --git a/Contracts/BusinessLogicContracts/IPurchaseLogic.cs b/Contracts/BusinessLogicContracts/IPurchaseLogic.cs index 8fa80fa..353df3b 100644 --- a/Contracts/BusinessLogicContracts/IPurchaseLogic.cs +++ b/Contracts/BusinessLogicContracts/IPurchaseLogic.cs @@ -1,6 +1,7 @@ using Contracts.BindingModels; using Contracts.SearchModels; using Contracts.ViewModels; +using DataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -20,7 +21,7 @@ namespace Contracts.BusinessLogicContracts List ReadElements(PurchaseSearchModel? model); PurchaseViewModel Delete(PurchaseSearchModel model); - PurchaseViewModel AddProduct(PurchaseSearchModel purchase, ProductSearchModel product, int count); - Dictionary GetProducts(PurchaseSearchModel model); + List GetCartItems(PurchaseSearchModel model); + List GetProducts(PurchaseSearchModel model); } } diff --git a/Contracts/BusinessLogicContracts/ISaleLogic.cs b/Contracts/BusinessLogicContracts/ISaleLogic.cs new file mode 100644 index 0000000..aec7741 --- /dev/null +++ b/Contracts/BusinessLogicContracts/ISaleLogic.cs @@ -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 ReadElements(SaleSearchModel? model); + + bool Delete(SaleBindingModel model); + } +} diff --git a/Contracts/BusinessLogicContracts/IUserLogic.cs b/Contracts/BusinessLogicContracts/IUserLogic.cs index 802f723..a801e75 100644 --- a/Contracts/BusinessLogicContracts/IUserLogic.cs +++ b/Contracts/BusinessLogicContracts/IUserLogic.cs @@ -25,5 +25,6 @@ namespace Contracts.BusinessLogicContracts IEnumerable ReadElements(UserSearchModel? model); UserViewModel Delete(UserSearchModel model); + void UpdateBonus(BonusUpdateBindingModel model); } } \ No newline at end of file diff --git a/Contracts/Converters/PurchaseConverter.cs b/Contracts/Converters/PurchaseConverter.cs index c2139b8..53bd3d7 100644 --- a/Contracts/Converters/PurchaseConverter.cs +++ b/Contracts/Converters/PurchaseConverter.cs @@ -8,22 +8,26 @@ using System.Threading.Tasks; namespace Contracts.Converters { - public class PurchaseConverter - { - public static PurchaseViewModel ToView(PurchaseBindingModel model) => new() - { - Id = model.Id, - DatePurchase = model.DatePurchase, - UserId = model.UserId, - PurchaseProducts = model.PurchaseProducts, - }; + 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, - DatePurchase = model.DatePurchase, - UserId = model.UserId, - PurchaseProducts = model.PurchaseProducts, - }; - } + 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 + }; + } } diff --git a/Contracts/Converters/SellConverter.cs b/Contracts/Converters/SellConverter.cs deleted file mode 100644 index e24a426..0000000 --- a/Contracts/Converters/SellConverter.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Contracts.BindingModels; -using Contracts.ViewModels; -using DataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Contracts.Converters -{ - public class SellConverter - { - public static SellViewModel ToView(SellBindingModel model) => new() - { - Id = model.Id, - DateSell = model.DateSell, - UserId = model.UserId - }; - - public static SellBindingModel ToBinding(SellViewModel model) => new() - { - Id = model.Id, - DateSell = model.DateSell, - UserId = model.UserId - }; - } -} diff --git a/Contracts/Converters/UserConverter.cs b/Contracts/Converters/UserConverter.cs index ae6fd8a..9a24b7a 100644 --- a/Contracts/Converters/UserConverter.cs +++ b/Contracts/Converters/UserConverter.cs @@ -19,6 +19,7 @@ namespace Contracts.Converters Birthday = model.Birthday, OnlyImportantMails = model.OnlyImportantMails, Role = RoleConverter.ToView(model.Role), + Bonus = model.Bonus, }; public static UserBindingModel ToBinding(UserViewModel model) => new() @@ -30,6 +31,7 @@ namespace Contracts.Converters Birthday = model.Birthday, OnlyImportantMails = model.OnlyImportantMails, Role = RoleConverter.ToBinding(model.Role), + Bonus = model.Bonus, }; } } \ No newline at end of file diff --git a/Contracts/SearchModels/CartItemSearchModel.cs b/Contracts/SearchModels/CartItemSearchModel.cs new file mode 100644 index 0000000..27dd057 --- /dev/null +++ b/Contracts/SearchModels/CartItemSearchModel.cs @@ -0,0 +1,16 @@ +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; } + } +} diff --git a/Contracts/SearchModels/ProductSearchModel.cs b/Contracts/SearchModels/ProductSearchModel.cs index dac5012..0241aec 100644 --- a/Contracts/SearchModels/ProductSearchModel.cs +++ b/Contracts/SearchModels/ProductSearchModel.cs @@ -16,5 +16,6 @@ namespace Contracts.SearchModels public double? Rate { get; set; } public int? Amount { get; set; } public bool? IsBeingSold { get; set; } + public string? Category { get; set; } } } diff --git a/Contracts/SearchModels/PurchaseSearchModel.cs b/Contracts/SearchModels/PurchaseSearchModel.cs index 2738bf0..853c9d7 100644 --- a/Contracts/SearchModels/PurchaseSearchModel.cs +++ b/Contracts/SearchModels/PurchaseSearchModel.cs @@ -16,5 +16,6 @@ namespace Contracts.SearchModels public double? CostFrom { get; set; } public double? CostTo { get; set; } public PurchaseStatus? Status { get; set; } + public Guid UserId { get; set; } } } diff --git a/Contracts/SearchModels/SaleSearchModel.cs b/Contracts/SearchModels/SaleSearchModel.cs new file mode 100644 index 0000000..023817a --- /dev/null +++ b/Contracts/SearchModels/SaleSearchModel.cs @@ -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; } + } +} diff --git a/Contracts/StorageContracts/ICartItemStorage.cs b/Contracts/StorageContracts/ICartItemStorage.cs new file mode 100644 index 0000000..e7a35d4 --- /dev/null +++ b/Contracts/StorageContracts/ICartItemStorage.cs @@ -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 ICartItemStorage + { + List GetFullList(); + List GetFilteredList(CartItemSearchModel model); + CartItemViewModel? GetElement(CartItemSearchModel model); + CartItemViewModel? Insert(CartItemBindingModel model); + CartItemViewModel? Update(CartItemBindingModel model); + CartItemViewModel? Delete(CartItemBindingModel model); + } +} diff --git a/Contracts/StorageContracts/IPurchaseStorage.cs b/Contracts/StorageContracts/IPurchaseStorage.cs index 8944c44..2a29c45 100644 --- a/Contracts/StorageContracts/IPurchaseStorage.cs +++ b/Contracts/StorageContracts/IPurchaseStorage.cs @@ -1,6 +1,7 @@ using Contracts.BindingModels; using Contracts.SearchModels; using Contracts.ViewModels; +using DataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -21,7 +22,7 @@ namespace Contracts.StorageContracts PurchaseViewModel? Update(PurchaseBindingModel model); PurchaseViewModel? Delete(PurchaseSearchModel model); - PurchaseViewModel? AddProducts(PurchaseSearchModel purchaseModel, ProductSearchModel productModel, int count); - Dictionary GetProducts(PurchaseSearchModel purchaseModel); + List GetCartItems(PurchaseSearchModel purchaseModel); + List GetProducts(PurchaseSearchModel model); } } diff --git a/Contracts/StorageContracts/ISaleStorage.cs b/Contracts/StorageContracts/ISaleStorage.cs new file mode 100644 index 0000000..1acc043 --- /dev/null +++ b/Contracts/StorageContracts/ISaleStorage.cs @@ -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 GetFullList(); + List GetFilteredList(SaleSearchModel model); + SaleViewModel? GetElement(SaleSearchModel model); + SaleViewModel? Insert(SaleBindingModel model); + SaleViewModel? Update(SaleBindingModel model); + SaleViewModel? Delete(SaleBindingModel model); + } +} \ No newline at end of file diff --git a/Contracts/StorageContracts/IUserStorage.cs b/Contracts/StorageContracts/IUserStorage.cs index 3a38799..6483843 100644 --- a/Contracts/StorageContracts/IUserStorage.cs +++ b/Contracts/StorageContracts/IUserStorage.cs @@ -19,5 +19,7 @@ namespace Contracts.StorageContracts UserBindingModel? Update(UserBindingModel model); UserBindingModel? Delete(UserSearchModel model); - } + void UpdateBonus(BonusUpdateBindingModel model); + + } } \ No newline at end of file diff --git a/Contracts/ViewModels/BillViewModel.cs b/Contracts/ViewModels/BillViewModel.cs new file mode 100644 index 0000000..01a5307 --- /dev/null +++ b/Contracts/ViewModels/BillViewModel.cs @@ -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 Products { get; set; } = new List(); + 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; + + } +} diff --git a/Contracts/ViewModels/CartItemViewModel.cs b/Contracts/ViewModels/CartItemViewModel.cs new file mode 100644 index 0000000..50344d1 --- /dev/null +++ b/Contracts/ViewModels/CartItemViewModel.cs @@ -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; } + } +} diff --git a/Contracts/ViewModels/PaymentViewModel.cs b/Contracts/ViewModels/PaymentViewModel.cs new file mode 100644 index 0000000..d7ff482 --- /dev/null +++ b/Contracts/ViewModels/PaymentViewModel.cs @@ -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; } + } +} diff --git a/Contracts/ViewModels/ProductViewModel.cs b/Contracts/ViewModels/ProductViewModel.cs index 14b7df3..933212a 100644 --- a/Contracts/ViewModels/ProductViewModel.cs +++ b/Contracts/ViewModels/ProductViewModel.cs @@ -12,9 +12,13 @@ namespace Contracts.ViewModels public Guid Id { get; set; } public string Name { get; set; } = string.Empty; public double Price { get; set; } + public double ActualPrice { get; set; } public double Rate { get; set; } public bool IsBeingSold { get; set; } public int Amount { get; set; } + public string? Category { get; set; } + public string? Description { get; set; } public List MediaFiles { get; set; } = new(); + public Guid? SaleId { get; set; } } } diff --git a/Contracts/ViewModels/PurchaseViewModel.cs b/Contracts/ViewModels/PurchaseViewModel.cs index bd2eede..1eba591 100644 --- a/Contracts/ViewModels/PurchaseViewModel.cs +++ b/Contracts/ViewModels/PurchaseViewModel.cs @@ -11,10 +11,12 @@ namespace Contracts.ViewModels public class PurchaseViewModel { public Guid Id { get; set; } - public DateTime DatePurchase { get; set; } - public required Guid UserId { get; set; } + public DateTime DateCreated { get; set; } + public DateTime? DateClosed { get; set; } + public required Guid UserId { get; set; } public PurchaseStatus Status { get; set; } - public Dictionary? PurchaseProducts { get; set; } = new(); + public int ProductCount { get; set; } public double Cost { get; set; } + public bool IsPaid { get; set; } } } diff --git a/Contracts/ViewModels/SaleViewModel.cs b/Contracts/ViewModels/SaleViewModel.cs new file mode 100644 index 0000000..9c48256 --- /dev/null +++ b/Contracts/ViewModels/SaleViewModel.cs @@ -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; } + } +} diff --git a/Contracts/ViewModels/UserProductViewModel.cs b/Contracts/ViewModels/UserProductViewModel.cs index 2da47eb..ed882ac 100644 --- a/Contracts/ViewModels/UserProductViewModel.cs +++ b/Contracts/ViewModels/UserProductViewModel.cs @@ -10,6 +10,7 @@ namespace Contracts.ViewModels { public string Name { get; set; } = string.Empty; public double Price { get; set; } - public double Rate { get; set; } + public string Description { get; set; } = string.Empty; + public double Rate { get; set; } } } diff --git a/Contracts/ViewModels/UserViewModel.cs b/Contracts/ViewModels/UserViewModel.cs index 6b3ccd4..71d805f 100644 --- a/Contracts/ViewModels/UserViewModel.cs +++ b/Contracts/ViewModels/UserViewModel.cs @@ -15,5 +15,6 @@ namespace Contracts.ViewModels public DateTime Birthday { get; set; } public bool OnlyImportantMails { get; set; } public RoleViewModel Role { get; set; } = null!; + public int Bonus { get; set; } } } \ No newline at end of file diff --git a/DataModels/Models/ICartItem.cs b/DataModels/Models/ICartItem.cs new file mode 100644 index 0000000..4dba12d --- /dev/null +++ b/DataModels/Models/ICartItem.cs @@ -0,0 +1,17 @@ +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; } + } +} diff --git a/DataModels/Models/IProduct.cs b/DataModels/Models/IProduct.cs index bfb12c0..c6e1652 100644 --- a/DataModels/Models/IProduct.cs +++ b/DataModels/Models/IProduct.cs @@ -13,7 +13,7 @@ namespace DataModels.Models bool IsBeingSold { get; } public double Rate { get; } int Amount { get; } - // будут браться через mediafilestorage так что скорее всего это тут не надо - // List MediaFiles { get; } + string Category { get; } + string Description { get; } } } diff --git a/DataModels/Models/IPurchase.cs b/DataModels/Models/IPurchase.cs index d862ed1..46645c6 100644 --- a/DataModels/Models/IPurchase.cs +++ b/DataModels/Models/IPurchase.cs @@ -9,8 +9,11 @@ namespace DataModels.Models { public interface IPurchase : IId { - DateTime DatePurchase { get; } - PurchaseStatus Status { get; } + DateTime DateCreated { get; } + DateTime? DateClosed { get; } + PurchaseStatus Status { get; } + int ProductCount { get; } double Cost { get; } + bool IsPaid { get; } } } diff --git a/DataModels/Models/ISale.cs b/DataModels/Models/ISale.cs new file mode 100644 index 0000000..d736e3b --- /dev/null +++ b/DataModels/Models/ISale.cs @@ -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; } + } +} diff --git a/DataModels/Models/IUser.cs b/DataModels/Models/IUser.cs index fb5020d..98be4d5 100644 --- a/DataModels/Models/IUser.cs +++ b/DataModels/Models/IUser.cs @@ -14,5 +14,6 @@ namespace DataModels.Models string Email { get; } DateTime Birthday { get; } bool OnlyImportantMails { get; } + int Bonus { get; } } } \ No newline at end of file diff --git a/DatabaseImplement/Database.cs b/DatabaseImplement/Database.cs index dbb6a25..4bb249e 100644 --- a/DatabaseImplement/Database.cs +++ b/DatabaseImplement/Database.cs @@ -21,7 +21,7 @@ namespace DatabaseImplement base.OnConfiguring(optionsBuilder); } - public virtual DbSet Roles { get; set; } = null!; + public virtual DbSet Roles { get; set; } = null!; public virtual DbSet Users { get; set; } = null!; public virtual DbSet Sells { get; set; } = null!; public virtual DbSet Purchases { get; set; } = null!; @@ -31,8 +31,10 @@ namespace DatabaseImplement public virtual DbSet Suppliers { get; set; } = null!; public virtual DbSet SupplierProducts { get; set; } = null!; public virtual DbSet MediaFiles { get; set; } = null!; - public virtual DbSet PurchaseProducts { get; set; } = null!; public virtual DbSet SellProducts { get; set; } = null!; public virtual DbSet SupplyDocs { get; set; } = null!; + public virtual DbSet CartItems { get; set; } = null!; + public virtual DbSet Sales { get; set; } = null!; + } } \ No newline at end of file diff --git a/DatabaseImplement/Implements/CartItemStorage.cs b/DatabaseImplement/Implements/CartItemStorage.cs new file mode 100644 index 0000000..8dadcc7 --- /dev/null +++ b/DatabaseImplement/Implements/CartItemStorage.cs @@ -0,0 +1,112 @@ +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 GetFilteredList(CartItemSearchModel model) + { + if (model.UserId == Guid.Empty && string.IsNullOrEmpty(model.ProductName)) + { + return new(); + } + using var context = new Database(); + if (model.UserId != Guid.Empty) + { + return context.CartItems + .Where(x => x.UserId == model.UserId) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + return context.CartItems + .Where(x => x.ProductName.Contains(model.ProductName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List 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; + } + } + } +} diff --git a/DatabaseImplement/Implements/ProductStorage.cs b/DatabaseImplement/Implements/ProductStorage.cs index 2fc3c0c..7c3706f 100644 --- a/DatabaseImplement/Implements/ProductStorage.cs +++ b/DatabaseImplement/Implements/ProductStorage.cs @@ -35,20 +35,22 @@ namespace DatabaseImplement.Implements return null; } using var context = new Database(); - return context.Products - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Products.Include(x => x.Sale) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; } public List GetFilteredList(ProductSearchModel model) { - if (!model.IsBeingSold.HasValue && !model.PriceFrom.HasValue && !model.PriceTo.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(); } using var context = new Database(); + if (model.Price.HasValue) { - return context.Products + return context.Products.Include(x => x.Sale) .Where(x => x.Price <= model.Price) .ToList() .Select(x => x.GetViewModel) @@ -56,7 +58,7 @@ namespace DatabaseImplement.Implements } if (model.PriceFrom.HasValue && model.PriceTo.HasValue) { - return context.Products + return context.Products.Include(x => x.Sale) .Where(x => x.Price <= model.PriceTo && x.Price >= model.PriceFrom) .ToList() .Select(x => x.GetViewModel) @@ -64,7 +66,7 @@ namespace DatabaseImplement.Implements } if (model.PriceFrom.HasValue) { - return context.Products + return context.Products.Include(x => x.Sale) .Where(x => x.Price >= model.PriceFrom) .ToList() .Select(x => x.GetViewModel) @@ -72,7 +74,7 @@ namespace DatabaseImplement.Implements } if (model.PriceTo.HasValue) { - return context.Products + return context.Products.Include(x => x.Sale) .Where(x => x.Price <= model.PriceTo) .ToList() .Select(x => x.GetViewModel) @@ -80,7 +82,7 @@ namespace DatabaseImplement.Implements } if (model.Rate.HasValue) { - return context.Products + return context.Products.Include(x => x.Sale) .Where(x => x.Rate <= model.Rate) .ToList() .Select(x => x.GetViewModel) @@ -88,13 +90,21 @@ namespace DatabaseImplement.Implements } if (model.Amount.HasValue && model.IsBeingSold.HasValue) { - return context.Products + return context.Products.Include(x => x.Sale) .Where(x => x.IsBeingSold == model.IsBeingSold && x.Amount >= model.Amount) .ToList() .Select(x => x.GetViewModel) .ToList(); } - return context.Products + if (!string.IsNullOrEmpty(model.Category)) + { + return context.Products.Include(x => x.Sale) + .Where(x => x.Category == model.Category) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + return context.Products.Include(x => x.Sale) .Where(x => x.Name.Contains(model.Name)) .ToList() .Select(x => x.GetViewModel) @@ -104,7 +114,7 @@ namespace DatabaseImplement.Implements public List GetFullList() { using var context = new Database(); - return context.Products + return context.Products.Include(x => x.Sale) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -114,6 +124,16 @@ namespace DatabaseImplement.Implements { using var context = new Database(); 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) { return null; @@ -129,7 +149,7 @@ namespace DatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var product = context.Products.FirstOrDefault(rec => + var product = context.Products.Include(x => x.Sale).FirstOrDefault(rec => rec.Id == model.Id); if (product == null) { diff --git a/DatabaseImplement/Implements/PurchaseStorage.cs b/DatabaseImplement/Implements/PurchaseStorage.cs index 2239727..ae2e23c 100644 --- a/DatabaseImplement/Implements/PurchaseStorage.cs +++ b/DatabaseImplement/Implements/PurchaseStorage.cs @@ -3,6 +3,7 @@ using Contracts.SearchModels; using Contracts.StorageContracts; using Contracts.ViewModels; using DatabaseImplement.Models; +using DataModels.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -35,8 +36,6 @@ namespace DatabaseImplement.Implements } using var context = new Database(); return context.Purchases - .Include(x => x.Products) - .ThenInclude(x => x.Product) .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } @@ -44,8 +43,6 @@ namespace DatabaseImplement.Implements { using var context = new Database(); return context.Purchases - .Include(x => x.Products) - .ThenInclude(x => x.Product) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -53,7 +50,8 @@ namespace DatabaseImplement.Implements public List GetFilteredList(PurchaseSearchModel? model) { using var context = new Database(); - if (!model.CostFrom.HasValue && !model.CostTo.HasValue && !model.DateTo.HasValue && !model.DateFrom.HasValue && !model.Status.HasValue) + if (model.UserId == Guid.Empty && !model.CostFrom.HasValue && !model.CostTo.HasValue && !model.DateTo.HasValue + && !model.DateFrom.HasValue && !model.Status.HasValue) { return new(); } @@ -85,7 +83,7 @@ namespace DatabaseImplement.Implements if (model.DateFrom.HasValue && model.DateTo.HasValue) { return context.Purchases - .Where(x => x.DatePurchase <= model.DateTo && x.DatePurchase >= model.DateFrom) + .Where(x => x.DateCreated <= model.DateTo && x.DateCreated >= model.DateFrom) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -93,7 +91,7 @@ namespace DatabaseImplement.Implements if (model.DateFrom.HasValue) { return context.Purchases - .Where(x => x.DatePurchase >= model.DateFrom) + .Where(x => x.DateCreated >= model.DateFrom) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -101,14 +99,20 @@ namespace DatabaseImplement.Implements if (model.DateTo.HasValue) { return context.Purchases - .Where(x => x.DatePurchase <= model.DateTo) + .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 - .Include(x => x.Products) - .ThenInclude(x => x.Product) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -120,13 +124,31 @@ namespace DatabaseImplement.Implements var purchase = Purchase.Create(context, model); if (purchase == null) return null; + + + var cartItems = context.CartItems + .Where(x => x.PurchaseId == model.Id).ToList() + .Select(x => x.GetViewModel).ToList(); + + var products = new List(); + + foreach (var item in cartItems) + { + var product = context.Products + .Where(x => x.Id == item.ProductId) + .FirstOrDefault(); + + products.Add(product); + } + + purchase.Products = products; context.Purchases.Add(purchase); context.SaveChanges(); return purchase.GetViewModel; } - public PurchaseViewModel? Update(PurchaseBindingModel model) - { + public PurchaseViewModel? Update(PurchaseBindingModel model) + { using var context = new Database(); using var transaction = context.Database.BeginTransaction(); try @@ -139,7 +161,6 @@ namespace DatabaseImplement.Implements } purchase.Update(model); context.SaveChanges(); - purchase.UpdateProducts(context, model); transaction.Commit(); return purchase.GetViewModel; } @@ -149,64 +170,44 @@ namespace DatabaseImplement.Implements throw; } } - public PurchaseViewModel? AddProducts(PurchaseSearchModel purchaseModel, ProductSearchModel productModel, int count) - { - using var context = new Database(); - using var transaction = context.Database.BeginTransaction(); - try - { - var purchase = context.Purchases.FirstOrDefault(rec => - rec.Id == purchaseModel.Id); - var product = context.Products.FirstOrDefault(rec => - rec.Id == productModel.Id); - - if (purchase == null) - return null; - - if (product == null) - return null; - - if (count <= 0) - return null; - - context.PurchaseProducts.Add(new PurchaseProducts - { - Purchase = purchase, - Product = product, - Count = count - }); - context.SaveChanges(); - return purchase.GetViewModel; - } - catch { transaction.Rollback(); throw; } - - } - - public Dictionary GetProducts(PurchaseSearchModel model) + public List GetCartItems(PurchaseSearchModel model) { - Dictionary productsDict = new(); using var context = new Database(); - var purchase = context.Purchases.FirstOrDefault(rec => - rec.Id == model.Id); + var cartItems = context.CartItems + .Where(x => x.PurchaseId == model.Id).ToList() + .Select(x => x.GetViewModel).ToList(); - if (purchase == null) + if (cartItems == null) { return null; } - var purchaseProducts = context.PurchaseProducts - .Where(x => x.PurchaseId == model.Id) - .ToList(); - - foreach (var purchaseProduct in purchaseProducts) - { - productsDict.Add(purchaseProduct.ProductId, purchaseProduct.Count); - } - - return productsDict; + return cartItems; } + public List GetProducts(PurchaseSearchModel model) + { + using var context = new Database(); + + if (!model.Id.HasValue) + { + return null; + } + + var purchase = context.Purchases + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)); + + var products = new List(); + + if (purchase.Products == null) + return null; + + foreach (var product in purchase.Products) + products.Add(product.GetViewModel); + + return products; + } } } diff --git a/DatabaseImplement/Implements/SaleStorage.cs b/DatabaseImplement/Implements/SaleStorage.cs new file mode 100644 index 0000000..fc8047f --- /dev/null +++ b/DatabaseImplement/Implements/SaleStorage.cs @@ -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 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 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; + } + } + } +} diff --git a/DatabaseImplement/Implements/UserStorage.cs b/DatabaseImplement/Implements/UserStorage.cs index 2755bbf..b5f3ac6 100644 --- a/DatabaseImplement/Implements/UserStorage.cs +++ b/DatabaseImplement/Implements/UserStorage.cs @@ -106,5 +106,20 @@ namespace DatabaseImplement.Implements context.SaveChanges(); 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(); + } } } \ No newline at end of file diff --git a/DatabaseImplement/Migrations/20240702133630_prod.Designer.cs b/DatabaseImplement/Migrations/20240702133630_prod.Designer.cs new file mode 100644 index 0000000..a7d5b8c --- /dev/null +++ b/DatabaseImplement/Migrations/20240702133630_prod.Designer.cs @@ -0,0 +1,503 @@ +// +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("20240702133630_prod")] + partial class prod + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .IsRequired() + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240702133630_prod.cs b/DatabaseImplement/Migrations/20240702133630_prod.cs new file mode 100644 index 0000000..c4865c9 --- /dev/null +++ b/DatabaseImplement/Migrations/20240702133630_prod.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class prod : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Category", + table: "Products", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Description", + table: "Products", + type: "text", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Category", + table: "Products"); + + migrationBuilder.DropColumn( + name: "Description", + table: "Products"); + } + } +} diff --git a/DatabaseImplement/Migrations/20240714172818_bonus.Designer.cs b/DatabaseImplement/Migrations/20240714172818_bonus.Designer.cs new file mode 100644 index 0000000..ad29b16 --- /dev/null +++ b/DatabaseImplement/Migrations/20240714172818_bonus.Designer.cs @@ -0,0 +1,506 @@ +// +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("20240714172818_bonus")] + partial class bonus + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .IsRequired() + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240714172818_bonus.cs b/DatabaseImplement/Migrations/20240714172818_bonus.cs new file mode 100644 index 0000000..849ac16 --- /dev/null +++ b/DatabaseImplement/Migrations/20240714172818_bonus.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class bonus : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Bonus", + table: "Users", + type: "integer", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Bonus", + table: "Users"); + } + } +} diff --git a/DatabaseImplement/Migrations/20240714214732_sale.Designer.cs b/DatabaseImplement/Migrations/20240714214732_sale.Designer.cs new file mode 100644 index 0000000..7f4ce35 --- /dev/null +++ b/DatabaseImplement/Migrations/20240714214732_sale.Designer.cs @@ -0,0 +1,536 @@ +// +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("20240714214732_sale")] + partial class sale + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany() + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240714214732_sale.cs b/DatabaseImplement/Migrations/20240714214732_sale.cs new file mode 100644 index 0000000..065ced3 --- /dev/null +++ b/DatabaseImplement/Migrations/20240714214732_sale.cs @@ -0,0 +1,101 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class sale : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Description", + table: "Products", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AlterColumn( + name: "Category", + table: "Products", + type: "text", + nullable: true, + oldClrType: typeof(string), + oldType: "text"); + + migrationBuilder.AddColumn( + name: "SaleId", + table: "Products", + type: "uuid", + nullable: true); + + migrationBuilder.CreateTable( + name: "Sales", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Category = table.Column(type: "text", nullable: true), + Description = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Sales", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Products_SaleId", + table: "Products", + column: "SaleId"); + + migrationBuilder.AddForeignKey( + name: "FK_Products_Sales_SaleId", + table: "Products", + column: "SaleId", + principalTable: "Sales", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Products_Sales_SaleId", + table: "Products"); + + migrationBuilder.DropTable( + name: "Sales"); + + migrationBuilder.DropIndex( + name: "IX_Products_SaleId", + table: "Products"); + + migrationBuilder.DropColumn( + name: "SaleId", + table: "Products"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Products", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Category", + table: "Products", + type: "text", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "text", + oldNullable: true); + } + } +} diff --git a/DatabaseImplement/Migrations/20240715001559_sale2.Designer.cs b/DatabaseImplement/Migrations/20240715001559_sale2.Designer.cs new file mode 100644 index 0000000..527d50b --- /dev/null +++ b/DatabaseImplement/Migrations/20240715001559_sale2.Designer.cs @@ -0,0 +1,541 @@ +// +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("20240715001559_sale2")] + partial class sale2 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240715001559_sale2.cs b/DatabaseImplement/Migrations/20240715001559_sale2.cs new file mode 100644 index 0000000..8218095 --- /dev/null +++ b/DatabaseImplement/Migrations/20240715001559_sale2.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class sale2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/DatabaseImplement/Migrations/20240715122630_sale-update.Designer.cs b/DatabaseImplement/Migrations/20240715122630_sale-update.Designer.cs new file mode 100644 index 0000000..998f1c3 --- /dev/null +++ b/DatabaseImplement/Migrations/20240715122630_sale-update.Designer.cs @@ -0,0 +1,548 @@ +// +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("20240715122630_sale-update")] + partial class saleupdate + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240715122630_sale-update.cs b/DatabaseImplement/Migrations/20240715122630_sale-update.cs new file mode 100644 index 0000000..109d05b --- /dev/null +++ b/DatabaseImplement/Migrations/20240715122630_sale-update.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class saleupdate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Name", + table: "Sales", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Value", + table: "Sales", + type: "integer", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Name", + table: "Sales"); + + migrationBuilder.DropColumn( + name: "Value", + table: "Sales"); + } + } +} diff --git a/DatabaseImplement/Migrations/20240715233951_sale3.Designer.cs b/DatabaseImplement/Migrations/20240715233951_sale3.Designer.cs new file mode 100644 index 0000000..0b0ffc5 --- /dev/null +++ b/DatabaseImplement/Migrations/20240715233951_sale3.Designer.cs @@ -0,0 +1,558 @@ +// +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("20240715233951_sale3")] + partial class sale3 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("End") + .HasColumnType("timestamp without time zone"); + + b.Property("FullDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Start") + .HasColumnType("timestamp without time zone"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240715233951_sale3.cs b/DatabaseImplement/Migrations/20240715233951_sale3.cs new file mode 100644 index 0000000..eee91f7 --- /dev/null +++ b/DatabaseImplement/Migrations/20240715233951_sale3.cs @@ -0,0 +1,52 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class sale3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "End", + table: "Sales", + type: "timestamp without time zone", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + + migrationBuilder.AddColumn( + name: "FullDescription", + table: "Sales", + type: "text", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Start", + table: "Sales", + type: "timestamp without time zone", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "End", + table: "Sales"); + + migrationBuilder.DropColumn( + name: "FullDescription", + table: "Sales"); + + migrationBuilder.DropColumn( + name: "Start", + table: "Sales"); + } + } +} diff --git a/DatabaseImplement/Migrations/20240716134506_cartitem.Designer.cs b/DatabaseImplement/Migrations/20240716134506_cartitem.Designer.cs new file mode 100644 index 0000000..8f18b85 --- /dev/null +++ b/DatabaseImplement/Migrations/20240716134506_cartitem.Designer.cs @@ -0,0 +1,601 @@ +// +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("20240716134506_cartitem")] + partial class cartitem + { + /// + 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.CartItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("CartItems"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("End") + .HasColumnType("timestamp without time zone"); + + b.Property("FullDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Start") + .HasColumnType("timestamp without time zone"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.CartItem", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + 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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240716134506_cartitem.cs b/DatabaseImplement/Migrations/20240716134506_cartitem.cs new file mode 100644 index 0000000..a1e7bb4 --- /dev/null +++ b/DatabaseImplement/Migrations/20240716134506_cartitem.cs @@ -0,0 +1,68 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class cartitem : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "DatePurchase", + table: "Purchases", + type: "timestamp without time zone", + nullable: true, + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone"); + + migrationBuilder.CreateTable( + name: "CartItems", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UserId = table.Column(type: "uuid", nullable: false), + Count = table.Column(type: "integer", nullable: false), + Cost = table.Column(type: "double precision", nullable: false), + DateCreated = table.Column(type: "timestamp without time zone", nullable: false), + ProductId = table.Column(type: "uuid", nullable: false), + ProductName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CartItems", x => x.Id); + table.ForeignKey( + name: "FK_CartItems_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_CartItems_ProductId", + table: "CartItems", + column: "ProductId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CartItems"); + + migrationBuilder.AlterColumn( + name: "DatePurchase", + table: "Purchases", + type: "timestamp without time zone", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), + oldClrType: typeof(DateTime), + oldType: "timestamp without time zone", + oldNullable: true); + } + } +} diff --git a/DatabaseImplement/Migrations/20240717230804_cartitem2.Designer.cs b/DatabaseImplement/Migrations/20240717230804_cartitem2.Designer.cs new file mode 100644 index 0000000..bb8aa46 --- /dev/null +++ b/DatabaseImplement/Migrations/20240717230804_cartitem2.Designer.cs @@ -0,0 +1,598 @@ +// +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("20240717230804_cartitem2")] + partial class cartitem2 + { + /// + 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.CartItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("CartItems"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("End") + .HasColumnType("timestamp without time zone"); + + b.Property("FullDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Start") + .HasColumnType("timestamp without time zone"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.CartItem", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + 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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240717230804_cartitem2.cs b/DatabaseImplement/Migrations/20240717230804_cartitem2.cs new file mode 100644 index 0000000..31b72bb --- /dev/null +++ b/DatabaseImplement/Migrations/20240717230804_cartitem2.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class cartitem2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Cost", + table: "CartItems"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "Cost", + table: "CartItems", + type: "double precision", + nullable: false, + defaultValue: 0.0); + } + } +} diff --git a/DatabaseImplement/Migrations/20240718212855_purchaseitems.Designer.cs b/DatabaseImplement/Migrations/20240718212855_purchaseitems.Designer.cs new file mode 100644 index 0000000..4827142 --- /dev/null +++ b/DatabaseImplement/Migrations/20240718212855_purchaseitems.Designer.cs @@ -0,0 +1,559 @@ +// +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("20240718212855_purchaseitems")] + partial class purchaseitems + { + /// + 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.CartItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("CartItems"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DatePurchase") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("End") + .HasColumnType("timestamp without time zone"); + + b.Property("FullDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Start") + .HasColumnType("timestamp without time zone"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.CartItem", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Purchase", "Purchase") + .WithMany() + .HasForeignKey("PurchaseId"); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + + 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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.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("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240718212855_purchaseitems.cs b/DatabaseImplement/Migrations/20240718212855_purchaseitems.cs new file mode 100644 index 0000000..97f0c8a --- /dev/null +++ b/DatabaseImplement/Migrations/20240718212855_purchaseitems.cs @@ -0,0 +1,88 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class purchaseitems : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "PurchaseProducts"); + + migrationBuilder.AddColumn( + name: "PurchaseId", + table: "CartItems", + type: "uuid", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_CartItems_PurchaseId", + table: "CartItems", + column: "PurchaseId"); + + migrationBuilder.AddForeignKey( + name: "FK_CartItems_Purchases_PurchaseId", + table: "CartItems", + column: "PurchaseId", + principalTable: "Purchases", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_CartItems_Purchases_PurchaseId", + table: "CartItems"); + + migrationBuilder.DropIndex( + name: "IX_CartItems_PurchaseId", + table: "CartItems"); + + migrationBuilder.DropColumn( + name: "PurchaseId", + table: "CartItems"); + + migrationBuilder.CreateTable( + name: "PurchaseProducts", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + ProductId = table.Column(type: "uuid", nullable: false), + PurchaseId = table.Column(type: "uuid", nullable: false), + Count = table.Column(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_PurchaseProducts_ProductId", + table: "PurchaseProducts", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_PurchaseProducts_PurchaseId", + table: "PurchaseProducts", + column: "PurchaseId"); + } + } +} diff --git a/DatabaseImplement/Migrations/20240718214141_purchasepatch.Designer.cs b/DatabaseImplement/Migrations/20240718214141_purchasepatch.Designer.cs new file mode 100644 index 0000000..1ca65fe --- /dev/null +++ b/DatabaseImplement/Migrations/20240718214141_purchasepatch.Designer.cs @@ -0,0 +1,562 @@ +// +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("20240718214141_purchasepatch")] + partial class purchasepatch + { + /// + 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.CartItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("CartItems"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DateClosed") + .HasColumnType("timestamp without time zone"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("End") + .HasColumnType("timestamp without time zone"); + + b.Property("FullDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Start") + .HasColumnType("timestamp without time zone"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.CartItem", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Purchase", "Purchase") + .WithMany() + .HasForeignKey("PurchaseId"); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + + 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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.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("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240718214141_purchasepatch.cs b/DatabaseImplement/Migrations/20240718214141_purchasepatch.cs new file mode 100644 index 0000000..0a7f621 --- /dev/null +++ b/DatabaseImplement/Migrations/20240718214141_purchasepatch.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class purchasepatch : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "DatePurchase", + table: "Purchases", + newName: "DateClosed"); + + migrationBuilder.AddColumn( + name: "DateCreated", + table: "Purchases", + type: "timestamp without time zone", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "DateCreated", + table: "Purchases"); + + migrationBuilder.RenameColumn( + name: "DateClosed", + table: "Purchases", + newName: "DatePurchase"); + } + } +} diff --git a/DatabaseImplement/Migrations/20240720140718_purchase2.Designer.cs b/DatabaseImplement/Migrations/20240720140718_purchase2.Designer.cs new file mode 100644 index 0000000..f435080 --- /dev/null +++ b/DatabaseImplement/Migrations/20240720140718_purchase2.Designer.cs @@ -0,0 +1,565 @@ +// +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("20240720140718_purchase2")] + partial class purchase2 + { + /// + 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.CartItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("CartItems"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DateClosed") + .HasColumnType("timestamp without time zone"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("ProductCount") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("End") + .HasColumnType("timestamp without time zone"); + + b.Property("FullDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Start") + .HasColumnType("timestamp without time zone"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.CartItem", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Purchase", "Purchase") + .WithMany() + .HasForeignKey("PurchaseId"); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + + 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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.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("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240720140718_purchase2.cs b/DatabaseImplement/Migrations/20240720140718_purchase2.cs new file mode 100644 index 0000000..f2df882 --- /dev/null +++ b/DatabaseImplement/Migrations/20240720140718_purchase2.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class purchase2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ProductCount", + table: "Purchases", + type: "integer", + nullable: false, + defaultValue: 0); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ProductCount", + table: "Purchases"); + } + } +} diff --git a/DatabaseImplement/Migrations/20240722134201_purchase3.Designer.cs b/DatabaseImplement/Migrations/20240722134201_purchase3.Designer.cs new file mode 100644 index 0000000..297db26 --- /dev/null +++ b/DatabaseImplement/Migrations/20240722134201_purchase3.Designer.cs @@ -0,0 +1,568 @@ +// +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("20240722134201_purchase3")] + partial class purchase3 + { + /// + 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.CartItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("CartItems"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Image") + .IsRequired() + .HasColumnType("bytea"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Amount") + .HasColumnType("integer"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("IsBeingSold") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Rate") + .HasColumnType("double precision"); + + b.Property("SaleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SaleId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DateClosed") + .HasColumnType("timestamp without time zone"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("IsPaid") + .HasColumnType("boolean"); + + b.Property("ProductCount") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("End") + .HasColumnType("timestamp without time zone"); + + b.Property("FullDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Start") + .HasColumnType("timestamp without time zone"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DateSell") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Sells"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SellId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SellId"); + + b.ToTable("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Deals") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplierId"); + + b.ToTable("SupplierProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("DateArriving") + .HasColumnType("timestamp without time zone"); + + b.Property("DateComplete") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("SupplierId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SupplierId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("SupplyDocs"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("SupplyId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthday") + .HasColumnType("timestamp without time zone"); + + b.Property("Bonus") + .HasColumnType("integer"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("OnlyImportantMails") + .HasColumnType("boolean"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.Property("SecondName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.CartItem", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Purchase", "Purchase") + .WithMany() + .HasForeignKey("PurchaseId"); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + + 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.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + + 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.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("SellProducts"); + }); + + modelBuilder.Entity("DatabaseImplement.Models.Sale", 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 + } + } +} diff --git a/DatabaseImplement/Migrations/20240722134201_purchase3.cs b/DatabaseImplement/Migrations/20240722134201_purchase3.cs new file mode 100644 index 0000000..d7d899c --- /dev/null +++ b/DatabaseImplement/Migrations/20240722134201_purchase3.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplement.Migrations +{ + /// + public partial class purchase3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "IsPaid", + table: "Purchases", + type: "boolean", + nullable: false, + defaultValue: false); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "IsPaid", + table: "Purchases"); + } + } +} diff --git a/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs b/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs index db099bf..953543e 100644 --- a/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -22,6 +22,40 @@ namespace DatabaseImplement.Migrations NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + modelBuilder.Entity("DatabaseImplement.Models.CartItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("ProductId") + .HasColumnType("uuid"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PurchaseId") + .HasColumnType("uuid"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("CartItems"); + }); + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => { b.Property("Id") @@ -51,6 +85,12 @@ namespace DatabaseImplement.Migrations b.Property("Amount") .HasColumnType("integer"); + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .HasColumnType("text"); + b.Property("IsBeingSold") .HasColumnType("boolean"); @@ -64,8 +104,13 @@ namespace DatabaseImplement.Migrations b.Property("Rate") .HasColumnType("double precision"); + b.Property("SaleId") + .HasColumnType("uuid"); + b.HasKey("Id"); + b.HasIndex("SaleId"); + b.ToTable("Products"); }); @@ -78,9 +123,18 @@ namespace DatabaseImplement.Migrations b.Property("Cost") .HasColumnType("double precision"); - b.Property("DatePurchase") + b.Property("DateClosed") .HasColumnType("timestamp without time zone"); + b.Property("DateCreated") + .HasColumnType("timestamp without time zone"); + + b.Property("IsPaid") + .HasColumnType("boolean"); + + b.Property("ProductCount") + .HasColumnType("integer"); + b.Property("Status") .HasColumnType("integer"); @@ -94,30 +148,6 @@ namespace DatabaseImplement.Migrations b.ToTable("Purchases"); }); - modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("ProductId") - .HasColumnType("uuid"); - - b.Property("PurchaseId") - .HasColumnType("uuid"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.HasIndex("PurchaseId"); - - b.ToTable("PurchaseProducts"); - }); - modelBuilder.Entity("DatabaseImplement.Models.Role", b => { b.Property("Id") @@ -133,6 +163,41 @@ namespace DatabaseImplement.Migrations b.ToTable("Roles"); }); + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Category") + .HasColumnType("text"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("End") + .HasColumnType("timestamp without time zone"); + + b.Property("FullDescription") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Start") + .HasColumnType("timestamp without time zone"); + + b.Property("Value") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Sales"); + }); + modelBuilder.Entity("DatabaseImplement.Models.Sell", b => { b.Property("Id") @@ -304,6 +369,9 @@ namespace DatabaseImplement.Migrations b.Property("Birthday") .HasColumnType("timestamp without time zone"); + b.Property("Bonus") + .HasColumnType("integer"); + b.Property("Email") .IsRequired() .HasColumnType("text"); @@ -333,6 +401,23 @@ namespace DatabaseImplement.Migrations b.ToTable("Users"); }); + modelBuilder.Entity("DatabaseImplement.Models.CartItem", b => + { + b.HasOne("DatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseImplement.Models.Purchase", "Purchase") + .WithMany() + .HasForeignKey("PurchaseId"); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b => { b.HasOne("DatabaseImplement.Models.Product", "Product") @@ -344,6 +429,15 @@ namespace DatabaseImplement.Migrations b.Navigation("Product"); }); + modelBuilder.Entity("DatabaseImplement.Models.Product", b => + { + b.HasOne("DatabaseImplement.Models.Sale", "Sale") + .WithMany("Products") + .HasForeignKey("SaleId"); + + b.Navigation("Sale"); + }); + modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => { b.HasOne("DatabaseImplement.Models.User", "User") @@ -355,25 +449,6 @@ namespace DatabaseImplement.Migrations 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") @@ -462,12 +537,10 @@ namespace DatabaseImplement.Migrations modelBuilder.Entity("DatabaseImplement.Models.Product", b => { - b.Navigation("PurchaseProducts"); - b.Navigation("SellProducts"); }); - modelBuilder.Entity("DatabaseImplement.Models.Purchase", b => + modelBuilder.Entity("DatabaseImplement.Models.Sale", b => { b.Navigation("Products"); }); diff --git a/DatabaseImplement/Models/CartItem.cs b/DatabaseImplement/Models/CartItem.cs new file mode 100644 index 0000000..7db0737 --- /dev/null +++ b/DatabaseImplement/Models/CartItem.cs @@ -0,0 +1,83 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; +using System.Xml.Linq; +using System.ComponentModel.DataAnnotations.Schema; + +namespace DatabaseImplement.Models +{ + public class CartItem : ICartItem + { + public Guid Id { get; set; } + [Required] + public Guid UserId { get; set; } + [Required] + public int Count { get; set; } + public Guid? PurchaseId { get; set; } + [Required] + public DateTime DateCreated { get; set; } + [Required] + public Guid ProductId { get; set; } + [Required] + public string ProductName { get; set; } = string.Empty; + public virtual Product? Product { get; set; } + public virtual Purchase? Purchase { get; set; } + public static CartItem Create(Database context, CartItemBindingModel model) + { + return new CartItem() + { + Id = model.Id, + UserId = model.UserId, + Count = model.Count, + DateCreated = model.DateCreated, + ProductId = model.ProductId, + ProductName = model.ProductName, + PurchaseId = model.PurchaseId, + }; + } + public void Update(CartItemBindingModel model) + { + if (model is null) + { + throw new ArgumentNullException("Update CartItem: binding model is null"); + } + Count = model.Count; + PurchaseId = model.PurchaseId; + } + public CartItemViewModel GetViewModel + { + get + { + var context = new Database(); + return new() + { + Id = Id, + UserId = UserId, + DateCreated = DateCreated, + ProductId = ProductId, + ProductName = ProductName, + Count = Count, + PurchaseId = PurchaseId, + }; + } + } + public CartItemBindingModel GetBindingModel() => new() + { + Id = Id, + UserId = UserId, + DateCreated = DateCreated, + ProductId = ProductId, + ProductName = ProductName, + Count = Count, + PurchaseId = PurchaseId, + }; + } +} diff --git a/DatabaseImplement/Models/Product.cs b/DatabaseImplement/Models/Product.cs index 552b6cd..84dd390 100644 --- a/DatabaseImplement/Models/Product.cs +++ b/DatabaseImplement/Models/Product.cs @@ -15,19 +15,21 @@ namespace DatabaseImplement.Models public class Product : IProduct { [Required] - public Guid Id { get; set; } + public Guid Id { get; set; } + public Guid? SaleId { get; set; } [Required] public string Name { get; set; } = string.Empty; [Required] - public double Price { get; set; } + public double Price { get; set; } [Required] public double Rate { get; set; } [Required] public bool IsBeingSold { get; set; } - [Required] + public string? Category { get; set; } + public string? Description { get; set; } + public virtual Sale? Sale { get; set; } + [Required] public int Amount { get; set; } - [ForeignKey("ProductId")] - public virtual List PurchaseProducts { get; set; } = new(); [ForeignKey("ProductId")] public virtual List SellProducts { get; set; } = new(); public ProductBindingModel GetBindingModel() => new() @@ -37,8 +39,11 @@ namespace DatabaseImplement.Models Price = Price, Rate = Rate, IsBeingSold = IsBeingSold, - Amount = Amount - }; + Amount = Amount, + Category = Category, + Description = Description, + SaleId = SaleId + }; public static Product ToProductFromView(ProductViewModel model, Product product) => new() { @@ -47,8 +52,10 @@ namespace DatabaseImplement.Models Price = model.Price, Rate = model.Rate, IsBeingSold = model.IsBeingSold, - Amount = model.Amount - }; + Amount = model.Amount, + Category = model.Category, + SaleId = model.SaleId + }; public static Product ToProductFromBinding(ProductBindingModel model, Product product) => new() { @@ -57,8 +64,11 @@ namespace DatabaseImplement.Models Price = model.Price, Rate = model.Rate, IsBeingSold = model.IsBeingSold, - Amount = model.Amount - }; + Amount = model.Amount, + Description = model.Description, + Category = model.Category, + SaleId = model.SaleId + }; public static Product Create(Database context, ProductBindingModel model) { @@ -69,7 +79,10 @@ namespace DatabaseImplement.Models Price = model.Price, Rate = model.Rate, IsBeingSold = model.IsBeingSold, - Amount = model.Amount + Amount = model.Amount, + Description = model.Description, + Category = model.Category, + SaleId = model.SaleId }; } @@ -86,21 +99,30 @@ namespace DatabaseImplement.Models Rate = model.Rate; IsBeingSold = model.IsBeingSold; Amount = model.Amount; - } + Description = model.Description; + Category = model.Category; + SaleId = model.SaleId; + } public ProductViewModel GetViewModel { get { - var context = new Database(); - return new() - { - Id = Id, - Name = Name, - Price = Price, - IsBeingSold = IsBeingSold, - Rate = Rate, - Amount = Amount - }; + double saleValue = 0; + if (Sale is not null) + saleValue = Sale.Value; + return new() + { + Id = Id, + Name = Name, + Price = Price, + IsBeingSold = IsBeingSold, + Rate = Rate, + Amount = Amount, + Description = Description, + Category = Category, + SaleId = SaleId, + ActualPrice = Price / 100 * (100 - saleValue) + }; } } } diff --git a/DatabaseImplement/Models/Purchase.cs b/DatabaseImplement/Models/Purchase.cs index e02aec8..721d4ef 100644 --- a/DatabaseImplement/Models/Purchase.cs +++ b/DatabaseImplement/Models/Purchase.cs @@ -19,79 +19,77 @@ namespace DatabaseImplement.Models public class Purchase : IPurchase { public Guid Id { get; set; } - [Required] - public DateTime DatePurchase { get; set; } + [Required] + public DateTime DateCreated { get; set; } + public DateTime? DateClosed { get; set; } [Required] public Guid UserId { get; set; } public double Cost { get; set; } + public int ProductCount { get; set; } [Required] public PurchaseStatus Status { get; private set; } = PurchaseStatus.Unknown; - private Dictionary? _purchaseProducts = null; + [Required] + public bool IsPaid { get; set; } public virtual User? User { get; set; } - [DataMember] [NotMapped] - public Dictionary PurchaseProducts - { - get - { - if (_purchaseProducts == null) - { - _purchaseProducts = Products.ToDictionary(e => e.ProductId, e => (e.Product as IProduct, e.Count)); - } - return _purchaseProducts; - } - set { } - } - [ForeignKey("PurchaseId")] - public virtual List Products { get; set; } = new(); + public List Products { get; set; } public static Purchase Create(Database context, PurchaseBindingModel model) { return new Purchase() { - DatePurchase = DateTime.Now, - UserId = Guid.NewGuid(), - Status = PurchaseStatus.Unknown, - + DateCreated = model.DateCreated, + UserId = model.UserId, + Status = model.Status, + Cost = model.Cost, + ProductCount = model.ProductCount, + IsPaid = model.IsPaid, }; } public PurchaseBindingModel GetBindingModel => new() { Id = Id, - DatePurchase = DatePurchase, + DateCreated = DateCreated, UserId = UserId, - PurchaseProducts = PurchaseProducts, Status = Status, - Cost = Cost - }; + Cost = Cost, + ProductCount = ProductCount, + IsPaid = IsPaid, + }; public PurchaseViewModel GetViewModel => new() { Id = Id, - DatePurchase = DatePurchase, + DateCreated = DateCreated, + DateClosed = DateClosed, UserId = UserId, - PurchaseProducts = PurchaseProducts, Status = Status, - Cost = Cost + ProductCount = ProductCount, + Cost = Cost, + IsPaid = IsPaid, }; public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new() { Id = model.Id, - DatePurchase = model.DatePurchase, + DateCreated = model.DateCreated, + DateClosed = model.DateClosed, UserId = model.UserId, - PurchaseProducts = model.PurchaseProducts, Status = model.Status, - Cost = model.Cost + ProductCount = model.ProductCount, + Cost = model.Cost, + IsPaid = model.IsPaid, }; public static Purchase ToPurchaseFromBinding(PurchaseBindingModel model, Purchase purchase) => new() { Id = model.Id, - DatePurchase = model.DatePurchase, + DateCreated = model.DateCreated, + DateClosed = model.DateClosed, UserId = model.UserId, - PurchaseProducts = model.PurchaseProducts, Status = model.Status, - Cost = model.Cost + ProductCount = model.ProductCount, + Cost = model.Cost, + IsPaid = model.IsPaid, }; public void Update(PurchaseBindingModel model) @@ -101,43 +99,11 @@ namespace DatabaseImplement.Models throw new ArgumentNullException("Update purchase: binding model is null"); } - DatePurchase = model.DatePurchase; - UserId = model.UserId; - PurchaseProducts = model.PurchaseProducts; + DateClosed = model.DateClosed; Status = model.Status; + ProductCount = model.ProductCount; Cost = model.Cost; - + IsPaid = model.IsPaid; } - public void UpdateProducts(Database context, PurchaseBindingModel model) - { - var purchaseProducts = context.PurchaseProducts.Where(rec => - rec.Id == model.Id).ToList(); - if (purchaseProducts != null && purchaseProducts.Count > 0) - { // удалили те, которых нет в модели - context.PurchaseProducts.RemoveRange(purchaseProducts.Where(rec - => !model.PurchaseProducts.ContainsKey(rec.ProductId))); - context.SaveChanges(); - // обновили количество у существующих записей - foreach (var updateProduct in purchaseProducts) - { - updateProduct.Count = model.PurchaseProducts[updateProduct.ProductId].Item2; - model.PurchaseProducts.Remove(updateProduct.ProductId); - } - context.SaveChanges(); - } - var purchase = context.Purchases.First(x => x.Id == Id); - foreach (var pc in model.PurchaseProducts) - { - context.PurchaseProducts.Add(new PurchaseProducts - { - Purchase = purchase, - Product = context.Products.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 - }); - context.SaveChanges(); - } - _purchaseProducts = null; - } - } } diff --git a/DatabaseImplement/Models/PurchaseProducts.cs b/DatabaseImplement/Models/PurchaseProducts.cs deleted file mode 100644 index 58049cb..0000000 --- a/DatabaseImplement/Models/PurchaseProducts.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DatabaseImplement.Models -{ - public class PurchaseProducts - { - public Guid Id { get; set; } - [Required] - public Guid PurchaseId { get; set; } - [Required] - public Guid ProductId { get; set; } - [Required] - public int Count { get; set; } - public virtual Product Product { get; set; } = new(); - public virtual Purchase Purchase { get; set; } = new(); - - } -} diff --git a/DatabaseImplement/Models/Sale.cs b/DatabaseImplement/Models/Sale.cs new file mode 100644 index 0000000..7f6b2c9 --- /dev/null +++ b/DatabaseImplement/Models/Sale.cs @@ -0,0 +1,123 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; +using System.Xml.Linq; + +namespace DatabaseImplement.Models +{ + public class Sale : ISale + { + [Required] + public Guid Id { get; set; } + [Required] + public string Name { get; set; } + public string? Category { get; set; } + [Required] + public string Description { get; set; } = string.Empty; + [Required] + public string FullDescription { get; set; } = string.Empty; + [Required] + public int Value { get; set; } + [Required] + public DateTime Start { get; set; } + [Required] + public DateTime End { get; set; } + + [ForeignKey("SaleId")] + public ICollection Products { get; set; } = new List(); + public SaleBindingModel GetBindingModel() => new() + { + Id = Id, + Category = Category, + Description = Description, + FullDescription = FullDescription, + Name = Name, + Value = Value, + Start = Start, + End = End + }; + + public static Sale ToSaleFromView(SaleBindingModel model, Sale sale) => new() + { + Id = model.Id, + Category = model.Category, + Description = model.Description, + FullDescription = model.FullDescription, + Name = model.Name, + Value = model.Value, + Start = model.Start, + End = model.End + }; + + public static Sale ToProductFromBinding(SaleBindingModel model, Sale sale) => new() + { + Id = model.Id, + Category = model.Category, + Description = model.Description, + FullDescription = model.FullDescription, + Name = model.Name, + Value = model.Value, + Start = model.Start, + End = model.End + }; + + public static Sale Create(Database context, SaleBindingModel model) + { + return new Sale() + { + Id = model.Id, + Category = model.Category, + Description = model.Description, + FullDescription = model.FullDescription, + Name = model.Name, + Value = model.Value, + Start = model.Start, + End = model.End + }; + } + + + public void Update(SaleBindingModel model) + { + if (model is null) + { + throw new ArgumentNullException("Update product: binding model is null"); + } + + Category = model.Category; + Description = model.Description; + FullDescription = model.FullDescription; + Name = model.Name; + Value = model.Value; + Start = model.Start; + End = model.End; + } + public SaleViewModel GetViewModel + { + get + { + var context = new Database(); + return new() + { + Id = Id, + Category = Category, + Description = Description, + FullDescription = FullDescription, + Name = Name, + Value = Value, + Start = Start, + End = End + }; + } + } + } +} diff --git a/DatabaseImplement/Models/SupplierProduct.cs b/DatabaseImplement/Models/SupplierProduct.cs index 95ce3af..14bccd8 100644 --- a/DatabaseImplement/Models/SupplierProduct.cs +++ b/DatabaseImplement/Models/SupplierProduct.cs @@ -19,4 +19,4 @@ namespace DatabaseImplement.Models public virtual Supplier Supplier { get; set; } = new(); public virtual Product Product { get; set; } = new(); } -} +} \ No newline at end of file diff --git a/DatabaseImplement/Models/User.cs b/DatabaseImplement/Models/User.cs index 4de0fd1..174be99 100644 --- a/DatabaseImplement/Models/User.cs +++ b/DatabaseImplement/Models/User.cs @@ -28,6 +28,9 @@ namespace DatabaseImplement.Models [Required] public string Email { get; set; } = string.Empty; + [Required] + public int Bonus { get; set; } + [Required] public DateTime Birthday { get; set; } @@ -44,7 +47,8 @@ namespace DatabaseImplement.Models PasswordHash = PasswordHash, Birthday = Birthday, OnlyImportantMails = OnlyImportantMails, - Role = Role?.GetBindingModel() ?? new() + Role = Role?.GetBindingModel() ?? new(), + Bonus = Bonus, }; public static User ToUserFromView(UserViewModel model, Role role) => new() @@ -54,7 +58,8 @@ namespace DatabaseImplement.Models SecondName = model.SecondName, Email = model.Email, Birthday = model.Birthday, - Role = role + Role = role, + Bonus = model.Bonus }; public static User ToUserFromBinding(UserBindingModel model, Role role) => new() @@ -66,7 +71,8 @@ namespace DatabaseImplement.Models PasswordHash = model.PasswordHash, Birthday = model.Birthday, OnlyImportantMails = model.OnlyImportantMails, - Role = role + Role = role, + Bonus = model.Bonus }; public void Update(UserBindingModel model, Role role) @@ -83,6 +89,7 @@ namespace DatabaseImplement.Models Birthday = model.Birthday; OnlyImportantMails = model.OnlyImportantMails; Role = role ?? Role; - } + Bonus = model.Bonus; + } } } \ No newline at end of file diff --git a/RestAPI/Controllers/CartItemController.cs b/RestAPI/Controllers/CartItemController.cs new file mode 100644 index 0000000..313a926 --- /dev/null +++ b/RestAPI/Controllers/CartItemController.cs @@ -0,0 +1,147 @@ +using BusinessLogic.BusinessLogic; +using Contracts.BindingModels; +using Contracts.BusinessLogicContracts; +using Contracts.Exceptions; +using Contracts.SearchModels; +using Contracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace RestAPI.Controllers +{ + [Route("[controller]/[action]")] + [ApiController] + public class CartItemController : Controller + { + private readonly ICartItemLogic _cartItemLogic; + private readonly IProductLogic _productLogic; + private readonly ILogger _logger; + public CartItemController(ILogger logger, ICartItemLogic cartItemLogic, IProductLogic productLogic) + { + _logger = logger; + _cartItemLogic = cartItemLogic; + _productLogic = productLogic; + } + [HttpGet] + public List GetFullList(Guid userId) + { + try + { + return _cartItemLogic.ReadElements(new CartItemSearchModel(){ UserId = userId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка"); + throw; + } + } + [HttpGet] + public CartItemViewModel GetElement(Guid id) + { + try + { + return _cartItemLogic.ReadElement(new CartItemSearchModel() { Id = id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения элемента корзины"); + throw; + } + } + [HttpGet] + public ProductViewModel GetProduct(Guid cartItemId) + { + try + { + var item = _cartItemLogic.ReadElement(new CartItemSearchModel() { Id = cartItemId }); + return _productLogic.ReadElement(new ProductSearchModel() { Id = item.ProductId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта"); + throw; + } + } + [HttpPost] + public IResult Create([FromBody] CartItemBindingModel model) + { + try + { + var res = _cartItemLogic.Create(model); + return Results.Ok(res); + } + catch (AccountException ex) + { + _logger.LogWarning(ex, "Wrong data"); + return Results.BadRequest(ex.Message); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error create item"); + return Results.Problem(ex.Message); + } + } + [HttpPatch] + public IResult Update([FromBody] CartItemBindingModel model) + { + try + { + var res = _cartItemLogic.Update(model); + return Results.Ok(res); + } + catch (AccountException ex) + { + _logger.LogWarning(ex, "Wrong update data"); + return Results.BadRequest(ex.Message); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error update cart item"); + return Results.Problem(ex.Message); + } + } + [HttpDelete] + public IResult Delete(Guid id) + { + try + { + var res = _cartItemLogic.Delete(new() { Id = id }); + return Results.Ok(res); + } + catch (ElementNotFoundException ex) + { + _logger.LogInformation(ex, "Item not found"); + return Results.NoContent(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error delete item"); + return Results.Problem(ex.Message); + } + } + [HttpDelete] + public IResult DeleteAll() + { + try + { + var list = _cartItemLogic.ReadElements(null); + var res = new List(); + + foreach (var element in list) + { + _cartItemLogic.Delete(new() { Id = element.Id }); + } + return Results.Ok(res); + } + catch (ElementNotFoundException ex) + { + _logger.LogInformation(ex, "Item not found"); + return Results.NoContent(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error delete item"); + return Results.Problem(ex.Message); + } + } + } +} diff --git a/RestAPI/Controllers/MediaFileController.cs b/RestAPI/Controllers/MediaFileController.cs index d6f1445..61cc0eb 100644 --- a/RestAPI/Controllers/MediaFileController.cs +++ b/RestAPI/Controllers/MediaFileController.cs @@ -30,7 +30,7 @@ namespace RestAPI.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка продуктов"); + _logger.LogError(ex, "Ошибка получения списка"); throw; } } diff --git a/RestAPI/Controllers/ProductController.cs b/RestAPI/Controllers/ProductController.cs index e9feeb3..d1dd71a 100644 --- a/RestAPI/Controllers/ProductController.cs +++ b/RestAPI/Controllers/ProductController.cs @@ -22,17 +22,18 @@ namespace RestAPI.Controllers _product = productLogic; } [HttpGet] - public List? GetList(string? search, double? pricefrom, double? priceto) + public List? GetList(string? search, string? category, double? pricefrom, double? priceto) { try { - if (search == null && pricefrom == null && priceto == null) + if (string.IsNullOrEmpty(search) && string.IsNullOrEmpty(category) && pricefrom == null && priceto == null) return _product.ReadList(null); else return _product.ReadList(new ProductSearchModel() { Name = search, + Category = category, PriceFrom = pricefrom, PriceTo = priceto }); diff --git a/RestAPI/Controllers/PurchaseController.cs b/RestAPI/Controllers/PurchaseController.cs index 3be2e5c..81bf079 100644 --- a/RestAPI/Controllers/PurchaseController.cs +++ b/RestAPI/Controllers/PurchaseController.cs @@ -5,6 +5,7 @@ using Contracts.Exceptions; using Contracts.SearchModels; using Contracts.ViewModels; using DatabaseImplement.Models; +using DataModels.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -17,23 +18,27 @@ namespace RestAPI.Controllers { private readonly ILogger _logger; private readonly IPurchaseLogic _purchaseLogic; + private readonly IBillLogic _billLogic; - public PurchaseController(ILogger logger, IPurchaseLogic purchaseLogic) + public PurchaseController(ILogger logger, IPurchaseLogic purchaseLogic, IBillLogic billLogic) { _logger = logger; _purchaseLogic = purchaseLogic; + _billLogic = billLogic; } [HttpGet] - public List? GetList(double? costfrom, double? costto, DateTime? datefrom, DateTime? dateto) + public List? GetList(Guid id, Guid userId, double? costfrom, double? costto, DateTime? datefrom, DateTime? dateto) { try { - if (costfrom == null && costto == null && datefrom == null && dateto == null) + if (id == Guid.Empty && userId == Guid.Empty && costfrom == null && costto == null && datefrom == null && dateto == null) return _purchaseLogic.ReadElements(null); else return _purchaseLogic.ReadElements(new PurchaseSearchModel() { + Id = id, + UserId = userId, CostFrom = costfrom, CostTo = costto, DateFrom = datefrom, @@ -42,7 +47,7 @@ namespace RestAPI.Controllers } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка продуктов"); + _logger.LogError(ex, "Ошибка получения списка покупок"); throw; } } @@ -55,37 +60,57 @@ namespace RestAPI.Controllers return _purchaseLogic.ReadElement(new PurchaseSearchModel() { Id = id }); } catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения покупки"); + throw; + } + } + + [HttpGet] + public List GetProducts(Guid purchaseid) + { + try + { + return _purchaseLogic.GetProducts(new PurchaseSearchModel() { Id = purchaseid }); + } + catch (Exception ex) { _logger.LogError(ex, "Ошибка получения продукта"); throw; } } [HttpPost] - public PurchaseViewModel Create(Guid UserId) + public IResult Create([FromBody] PurchaseBindingModel model) { try { - var purchase = _purchaseLogic.Create(new PurchaseBindingModel() - { - Cost = 0, - DatePurchase = DateTime.Now, - UserId = UserId - }); + var purchase = _purchaseLogic.Create(model); - return new PurchaseViewModel() - { - DatePurchase = purchase.DatePurchase, - UserId = purchase.UserId, - Cost = purchase.Cost, - }; + return Results.Ok(purchase); } catch (Exception ex) { - _logger.LogError(ex, "Error update purchase"); - return null; + _logger.LogError(ex, "Error create purchase"); + return Results.Problem(ex.Message); } } - + + [HttpPost] + public IResult CreateBill([FromBody] BillViewModel model) + { + try + { + _billLogic.CreateBill(model); + + return Results.Ok(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error create bill"); + throw; + } + } + [HttpPatch] public PurchaseViewModel Update([FromBody] PurchaseBindingModel model) { @@ -96,8 +121,7 @@ namespace RestAPI.Controllers { Id = res.Id, Cost = res.Cost, - DatePurchase = res.DatePurchase, - PurchaseProducts = res.PurchaseProducts, + DateClosed = res.DateClosed, UserId = res.UserId, }; } @@ -108,45 +132,5 @@ namespace RestAPI.Controllers return null; } } - [HttpPatch] - public PurchaseViewModel AddProducts(Guid purchaseId, Guid productId, int count) - { - try - { - var purchase = _purchaseLogic.AddProduct( - new PurchaseSearchModel() - { - Id = purchaseId - }, - new ProductSearchModel() - { - Id = productId - }, - count); - - return new PurchaseViewModel() - { - Id = purchase.Id, - Cost = purchase.Cost, - DatePurchase = purchase.DatePurchase, - PurchaseProducts = purchase.PurchaseProducts, - UserId = purchase.UserId, - }; - } - - catch (Exception ex) - { - _logger.LogError(ex, "Error update purchase"); - return null; - } - } - [HttpGet] - public Dictionary GetProducts(Guid productId) - { - return _purchaseLogic.GetProducts(new PurchaseSearchModel - { - Id = productId, - }); - } } } diff --git a/RestAPI/Controllers/SaleController.cs b/RestAPI/Controllers/SaleController.cs new file mode 100644 index 0000000..1be0e9b --- /dev/null +++ b/RestAPI/Controllers/SaleController.cs @@ -0,0 +1,100 @@ +using BusinessLogic.BusinessLogic; +using Contracts.BindingModels; +using Contracts.BusinessLogicContracts; +using Contracts.Exceptions; +using Contracts.SearchModels; +using Contracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace RestAPI.Controllers +{ + [Route("[controller]/[action]")] + [ApiController] + public class SaleController : Controller + { + private readonly ILogger _logger; + private readonly ISaleLogic _saleLogic; + private readonly IProductLogic _productLogic; + + public SaleController(ILogger logger, ISaleLogic saleLogic, IProductLogic productLogic) + { + _logger = logger; + _saleLogic = saleLogic; + _productLogic = productLogic; + } + + [HttpGet] + public List? GetList(string? category) + { + try + { + if (string.IsNullOrEmpty(category)) + return _saleLogic.ReadElements(null); + + else + return _saleLogic.ReadElements(new SaleSearchModel() + { + Category = category + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка акций"); + throw; + } + } + + [HttpGet] + public SaleViewModel GetSale(Guid id) + { + try + { + return _saleLogic.ReadElement(new SaleSearchModel() { Id = id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения акции"); + throw; + } + } + + [HttpGet] + public SaleViewModel GetSaleByProduct(Guid id) + { + try + { + var product = _productLogic.ReadElement(new ProductSearchModel() { Id = id }); + if (product.SaleId == null) + { + return null; + } + return _saleLogic.ReadElement(new SaleSearchModel() { Id = product.SaleId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения акции"); + throw; + } + } + + [HttpPost] + public IResult CreateSale([FromBody] SaleBindingModel model) + { + try + { + var res = _saleLogic.Create(model); + return Results.Ok(res); + } + catch (AccountException ex) + { + _logger.LogWarning(ex, "Wrong data"); + return Results.BadRequest(ex.Message); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error create sale"); + return Results.Problem(ex.Message); + } + } + } +} diff --git a/RestAPI/Controllers/UserController.cs b/RestAPI/Controllers/UserController.cs index 0047df3..f10e082 100644 --- a/RestAPI/Controllers/UserController.cs +++ b/RestAPI/Controllers/UserController.cs @@ -4,6 +4,7 @@ using Contracts.BindingModels; using Contracts.BusinessLogicContracts; using Contracts.Exceptions; using Contracts.SearchModels; +using Contracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace RestAPI.Controllers @@ -140,7 +141,22 @@ namespace RestAPI.Controllers return Results.Problem(ex.Message); } } - } + + [HttpPatch] + public void UpdateBonus([FromBody] BonusUpdateBindingModel model) + { + try + { + _userLogic.UpdateBonus(model); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error update purchase"); + return; + } + } + } public record class UserData(string email, string password); public record class VerifyCodeData(string code); diff --git a/RestAPI/Program.cs b/RestAPI/Program.cs index 19c5492..a1747ab 100644 --- a/RestAPI/Program.cs +++ b/RestAPI/Program.cs @@ -19,20 +19,25 @@ builder.Logging.AddLog4Net("log4net.config"); #region DI builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddSingleton(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -69,6 +74,8 @@ mailSender?.SetupMailOptions(new() #endregion Setup config + +System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/WebApp/Pages/Cart.cshtml b/WebApp/Pages/Cart.cshtml index 93f400c..fdb5ebb 100644 --- a/WebApp/Pages/Cart.cshtml +++ b/WebApp/Pages/Cart.cshtml @@ -6,10 +6,10 @@

Корзина

- @* @if (Model.Amount == 0) + @if (Model.cartItemsView == null! || Model.cartItemsView.Count == 0) {

Ваша корзина пуста.

- } *@ + } else { @@ -23,34 +23,102 @@ - @* @foreach (var item in Model.CartItems) + + @foreach (var item in Model.cartItemsView) { + - + + - + + + + + + + - } *@ + }
@item.Product.Price.ToString("C")@Model.GetProduct(item.Id).ActualPrice - + @item.Count @((item.Product.Price * item.Quantity).ToString("C"))@(item.Count * @Model.GetProduct(item.Id).ActualPrice) - +
+ + +
- @*

Итого: @Model.TotalPrice.ToString("C")

*@ +

Сумма заказа: руб.

- Оформить заказ +
+ + + + +
} -
\ No newline at end of file + + + + \ No newline at end of file diff --git a/WebApp/Pages/Cart.cshtml.cs b/WebApp/Pages/Cart.cshtml.cs index 72928b1..89f8711 100644 --- a/WebApp/Pages/Cart.cshtml.cs +++ b/WebApp/Pages/Cart.cshtml.cs @@ -1,7 +1,10 @@ +using Contracts.BindingModels; using Contracts.ViewModels; +using DataModels.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Routing.Constraints; using System.Diagnostics.Eventing.Reader; using WebApp.Helpers; @@ -10,26 +13,49 @@ namespace WebApp.Pages [Authorize(Roles = Roles.User)] public class CartModel : PageModel { - public PurchaseViewModel purchaseModel = null; - public Dictionary Products { get; set; } - public void OnGet(Guid id, int count) + [BindProperty] + public List cartItems { get; set; } + public List cartItemsView { get; set; } + public PaymentViewModel paymentViewModel { get; set; } + public void OnGet() { - if (purchaseModel == null) + var id = this.GetUserId(); + if (id is null) { - purchaseModel = APIClient.GetRequest($"Purchase/Create/{this.GetUserId()}"); - - APIClient.GetRequest($"Purchase/AddProducts?purchaseId={purchaseModel.Id}?productId={id}?count={count}"); + return; } - purchaseModel = APIClient.GetRequest($"Purchase/Get/"); - Products = APIClient.GetRequest>($"Purchase/GetProducts?id={purchaseModel.Id}"); + cartItemsView = APIClient.GetRequest>($"cartitem/GetFullList?userId={id}"); } - public IActionResult OnPostAsync() + public ProductViewModel GetProduct(Guid cartItemId) { + return APIClient.GetRequest($"CartItem/GetProduct?cartItemId={cartItemId}"); + } + public void OnPostDeleteCartItem(Guid Id) + { + var response = APIClient.DeleteRequest($"CartItem/Delete?id={Id}"); + if (response is null) + { + throw new Exception("Something wrong LOL!"); + } + OnGet(); - - - return RedirectToAction(""); + } + public IActionResult OnPostGoToPayment(int ProductCount, Guid UserId, double Cost) + { + paymentViewModel = new PaymentViewModel() + { + UserId = UserId, + Cost = Cost, + ProductCount = ProductCount, + UserFirstName = string.Empty, + UserSecondName = string.Empty, + }; + if (ProductCount <= 0 || UserId == Guid.Empty || Cost <= 0) + { + throw new Exception("Something wrong LOL!"); + } + return RedirectToPage("Purchase", paymentViewModel); } } } \ No newline at end of file diff --git a/WebApp/Pages/Index.cshtml b/WebApp/Pages/Index.cshtml index c8411ec..ac51bb5 100644 --- a/WebApp/Pages/Index.cshtml +++ b/WebApp/Pages/Index.cshtml @@ -12,34 +12,80 @@ @@ -53,7 +99,21 @@ @weapon.Name
@weapon.Name
-

Цена: @weapon.Price руб.

+

+ + @foreach (var sale in Model.SalesModel) + if (sale.Category == weapon.Category) + { + Цена: @weapon.Price руб. + @(weapon.Price / 100 * (100 - sale.Value)) руб. + break; + } + else + { + Цена: @weapon.Price руб. + } +

+
@for (int i = 0; i < (int)Math.Round(@weapon.Rate); i++) @@ -67,18 +127,8 @@ (@weapon.Rate)
- @if (User.Identity.IsAuthenticated) - { - To cart - } - else - { - To cart - } - View Product - + Подробнее -
@@ -91,12 +141,33 @@ // СЛАЙДЕРЫ document.getElementById("priceFrom").addEventListener("input", function () { var price = this.value; - document.getElementById("priceLabelFrom").textContent = price + " р."; + document.getElementById("priceLabelFrom").value = price + " р."; }); document.getElementById("priceTo").addEventListener("input", function () { var price = this.value; - document.getElementById("priceLabelTo").textContent = price + " р."; + document.getElementById("priceLabelTo").value = price + " р."; + }); + + document.getElementById("search").addEventListener("input", function () { + var text = this.value; + document.getElementById("search_hidden").value = text; + }); + + $('#saleDetailModal').on('show.bs.modal', function (event) { + var button = $(event.relatedTarget); // Кнопка, которая активировала модальное окно + var saleId = button.data('sale-id'); // Экземпляр saleId из атрибута data-sale-id кнопки + + // Загрузка данных о продаже с сервера (пример с использованием AJAX) + $.ajax({ + url: '/api/sales/' + saleId, // URL API для получения данных о продаже + type: 'GET', + success: function (data) { + var modal = $(this); + modal.find('.modal-title').text('Дата проведения акции: ' + data.date); + modal.find('.modal-body').text('Описание акции: ' + data.description); + } + }); }); } \ No newline at end of file diff --git a/WebApp/Pages/Index.cshtml.cs b/WebApp/Pages/Index.cshtml.cs index fe78f42..6c983bf 100644 --- a/WebApp/Pages/Index.cshtml.cs +++ b/WebApp/Pages/Index.cshtml.cs @@ -10,22 +10,28 @@ namespace WebApp.Pages public class IndexModel : PageModel { public List ProductsModel { get; set; } + public List SalesModel { get; set; } public Dictionary> MediaByProductsModel { get; set; } - public void OnGet(double? pricefrom, double? priceto, string? search) + public void OnGet(double? pricefrom, double? priceto, string? search, string? category) { string request = "Product/GetList"; if (!string.IsNullOrEmpty(search)) - request += $"?search={search}"; + request += $"?search={search}&"; + + if (!string.IsNullOrEmpty(category)) + request += $"?category={category}&"; if (pricefrom != null) - request += $"?pricefrom={pricefrom}"; + request += $"?pricefrom={pricefrom}&"; if (priceto != null) request += $"?priceto={priceto}"; ProductsModel = APIClient.GetRequest>(request); MediaByProductsModel = APIClient.GetRequest>>($"MediaFile/GetByProducts"); + + SalesModel = APIClient.GetRequest>($"Sale/GetList"); } public byte[] GetMediaByProduct(ProductViewModel productModel) { diff --git a/WebApp/Pages/Login.cshtml.cs b/WebApp/Pages/Login.cshtml.cs index 46144ad..4e565e1 100644 --- a/WebApp/Pages/Login.cshtml.cs +++ b/WebApp/Pages/Login.cshtml.cs @@ -22,7 +22,9 @@ namespace WebApp.Pages TempData["jwt"] = (string)response; - return RedirectToPage("TwoFactor"); + //return RedirectToPage("TwoFactor"); + this.SetJWT((string)TempData["jwt"]); + return RedirectToPage("Index"); } } } \ No newline at end of file diff --git a/WebApp/Pages/ProductPage.cshtml b/WebApp/Pages/ProductPage.cshtml index c4e93b8..cb06adc 100644 --- a/WebApp/Pages/ProductPage.cshtml +++ b/WebApp/Pages/ProductPage.cshtml @@ -15,24 +15,12 @@
- @*
- @Model.productModel.Name -
*@ -
-
- -
- PREV - NEXT -
-
-

@Model.productModel.Name

+ @Model.productModel.Name +
+ +
+

@Model.productModel.Name

@for (int i = 0; i < (int)Math.Round(@Model.productModel.Rate); i++) { @@ -44,19 +32,36 @@ } (@Model.productModel.Rate)
-

Цена: @Model.productModel.Price руб.

+

+ @if (Model.saleModel != null) + { + Цена: @Model.productModel.Price руб. + @(Model.productModel.Price / 100 * (100 - @Model.saleModel.Value)) руб. + } + else + { + Цена: @Model.productModel.Price руб. + } +

Количество товара на складе: @Model.productModel.Amount

- + +
+
+
+
+
+ @if (User.Identity.IsAuthenticated) {
- - - + + + +
+
- } else { @@ -64,66 +69,133 @@
- - В корзину - - + В корзину } - + + + +

Описание

-

@Model.productModel.Amount

+

@Model.productModel.Description

- diff --git a/WebApp/Pages/ProductPage.cshtml.cs b/WebApp/Pages/ProductPage.cshtml.cs index 1096357..b82ce24 100644 --- a/WebApp/Pages/ProductPage.cshtml.cs +++ b/WebApp/Pages/ProductPage.cshtml.cs @@ -7,14 +7,16 @@ namespace WebApp.Pages { public class ProductPageModel : PageModel { - public PurchaseViewModel purchaseModel { get; set; } public ProductViewModel productModel { get; set; } + public SaleViewModel saleModel { get; set; } public MediaFileViewModel mediaFileModel { get; set; } public Dictionary> MediaByProductsModel { get; set; } - public int Amount { get; set; } // public void OnGet(Guid id) { productModel = APIClient.GetRequest($"Product/GetProduct?id={id}"); + + saleModel = APIClient.GetRequest($"Sale/GetSaleByProduct?id={id}"); + } public byte[] GetMediaByProduct(ProductViewModel productModel) @@ -31,21 +33,18 @@ namespace WebApp.Pages return models; } - public IActionResult OnPostAsync(Guid id, int count) + public IActionResult OnPostAsync(int count, double price, Guid productId, string productName) { - Amount = count; - if (purchaseModel == null) + var model = new CartItemBindingModel() { - var model = new PurchaseBindingModel() - { - Cost = 0, - DatePurchase = DateTime.Now, - Status = 0, - UserId = new Guid(this.GetUserId()) - }; - //purchaseModel = APIClient.PostRequest($"Purchase/Create", model); - } - APIClient.GetRequest($"Purchase/AddProducts?purchaseId={purchaseModel.Id}?productId={id}?count={count}"); + Id = new Guid(), + DateCreated = DateTime.Now, + ProductId = productId, + ProductName = productName, + Count = count, + UserId = new Guid(this.GetUserId()) + }; + APIClient.PostRequest($"CartItem/Create/", model); return RedirectToPage("Cart"); } } diff --git a/WebApp/Pages/Purchase.cshtml b/WebApp/Pages/Purchase.cshtml new file mode 100644 index 0000000..ebfa379 --- /dev/null +++ b/WebApp/Pages/Purchase.cshtml @@ -0,0 +1,63 @@ +@page +@model WebApp.Pages.PurchaseModel +@{ + ViewData["Title"] = "Оплата заказа"; +} +

Оплата заказа

+ +
+
+
+
+
+ + + + + +
+ +
+
+ + +
+ +
+ + + + +
+
+
+
+ + + +
+
+ + \ No newline at end of file diff --git a/WebApp/Pages/Purchase.cshtml.cs b/WebApp/Pages/Purchase.cshtml.cs new file mode 100644 index 0000000..3bdc050 --- /dev/null +++ b/WebApp/Pages/Purchase.cshtml.cs @@ -0,0 +1,98 @@ +using Contracts.BindingModels; +using Contracts.Converters; +using Contracts.ViewModels; +using DataModels.Enums; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using WebApp.Helpers; +using WebApp.Pages.User; + +namespace WebApp.Pages +{ + [Authorize(Roles = Roles.User)] + public class PurchaseModel : PageModel + { + [BindProperty] + public PurchaseBindingModel purchaseModel { get; set; } + public PaymentViewModel paymentViewModel { get; set; } + public UserViewModel userModel { get; set; } + [BindProperty] + public bool bonus { get; set; } + public void OnGet(PaymentViewModel model) + { + var id = this.GetUserId(); + if (id is null) + { + return; + } + + userModel = APIClient.GetRequest($"user/get?id={id}"); + if (userModel is null) + { + throw new Exception("User is not found."); + } + + paymentViewModel = model; + paymentViewModel.Bonus = userModel.Bonus; + paymentViewModel.UserFirstName = userModel.FirstName; + paymentViewModel.UserSecondName = userModel.SecondName; + paymentViewModel.Email = userModel.Email; + } + + public IActionResult OnPostAsync(Guid userId, double cost, string PaymentMethod) + { + purchaseModel.Cost = cost; + if (PaymentMethod == "Online") + purchaseModel.IsPaid = true; + else + purchaseModel.IsPaid = false; + + userModel = APIClient.GetRequest($"user/get?id={userId}"); + UserBindingModel userBinding = UserConverter.ToBinding(userModel); + + var bonusModel = new BonusUpdateBindingModel(); + bonusModel.UserId = userId; + bonusModel.BonusPlus = Convert.ToInt32(purchaseModel.Cost) / 100; + + if (bonus) + { + bonusModel.BonusMinus = userModel.Bonus; + purchaseModel.Cost -= userModel.Bonus; + + var response_update1 = APIClient.PatchRequest($"user/updatebonus", bonusModel); + + if (response_update1 is null || response_update1 is not string) + { + throw new Exception("Something wrong LOL!"); + } + } + var response_update = APIClient.PatchRequest($"user/updatebonus", bonusModel); + + if (response_update is null || response_update is not string) + { + throw new Exception("Something wrong LOL!"); + } + + purchaseModel.Id = new Guid(); + purchaseModel.Status = PurchaseStatus.Processing; + purchaseModel.DateCreated = DateTime.Now; + + var response_create = APIClient.PostRequest($"Purchase/Create/", purchaseModel); + + if (response_create is null || response_create is not string) + { + throw new Exception("Something wrong LOL!"); + } + + var response_delete = APIClient.DeleteRequest($"CartItem/DeleteAll/"); + + if (response_delete is null || response_delete is not string) + { + throw new Exception("Something wrong LOL!"); + } + + return RedirectToPage("/User/Purchases"); + } + } +} diff --git a/WebApp/Pages/Shared/_Layout.cshtml b/WebApp/Pages/Shared/_Layout.cshtml index 420ed43..c970b86 100644 --- a/WebApp/Pages/Shared/_Layout.cshtml +++ b/WebApp/Pages/Shared/_Layout.cshtml @@ -8,9 +8,29 @@ - + + + + + + + + + + + + + + + + + + + + +
@@ -24,7 +44,7 @@ - \ No newline at end of file + + + diff --git a/WebApp/Pages/User/Index.cshtml b/WebApp/Pages/User/Index.cshtml index 5f119a4..29b619f 100644 --- a/WebApp/Pages/User/Index.cshtml +++ b/WebApp/Pages/User/Index.cshtml @@ -9,15 +9,23 @@

@Model.UserModel.FirstName @Model.UserModel.SecondName

@Model.UserModel.Email

+

Бонусы за покупки: @Model.UserModel.Bonus шт.


-
- Settings -
- -
- +
+
+ + + +
+ +
+
- +
diff --git a/WebApp/Pages/User/Purchases.cshtml b/WebApp/Pages/User/Purchases.cshtml new file mode 100644 index 0000000..884784c --- /dev/null +++ b/WebApp/Pages/User/Purchases.cshtml @@ -0,0 +1,172 @@ +@page +@model WebApp.Pages.User.PurchasesModel +@{ + ViewData["Title"] = "Покупки"; +} + + + +
+

Покупки

+ @if (Model.purchaseViewModels == null! || Model.purchaseViewModels.Count == 0) + { +

Вы ещё не совершали покупок.

+ } + else + { +
+ + + +
+ + + + + + + + + + + + + + @foreach (var item in Model.purchaseViewModels) + { + + + + + + + + + + + + + + } + +
Дата покупкиДата полученияКоличество товаровТовары на суммуОплачено
+
+ @item.DateCreated +
+
+
+ @if (item.DateClosed != null) + { + @item.DateClosed + } + else + { + @item.Status + } +
+
+
+ @item.ProductCount +
+
+
+ @item.Cost +
+
+
+ @if (@item.IsPaid) + { + Оплачено + } + else + { + Ждёт оплаты + } +
+
+
+
+ +
+
+
+ } +
+ + + + + \ No newline at end of file diff --git a/WebApp/Pages/User/Purchases.cshtml.cs b/WebApp/Pages/User/Purchases.cshtml.cs new file mode 100644 index 0000000..83f9a76 --- /dev/null +++ b/WebApp/Pages/User/Purchases.cshtml.cs @@ -0,0 +1,82 @@ +using BusinessLogic.BusinessLogic; +using Contracts.BusinessLogicContracts; +using Contracts.SearchModels; +using Contracts.ViewModels; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using System.Reflection; +using WebApp.Helpers; + +namespace WebApp.Pages.User +{ + [Authorize(Roles = Roles.User)] + public class PurchasesModel : PageModel + { + public List purchaseViewModels { get; set; } + public UserViewModel userViewModel { get; set; } + public BillViewModel billViewModel { get; set; } + [BindProperty] + public PurchaseSearchModel purchaseSearchModel { get; set; } + public void OnGet(DateTime? datefrom, DateTime? dateto) + { + var UserId = this.GetUserId(); + if (UserId is null) + { + return; + } + + userViewModel = APIClient.GetRequest($"user/get?id={UserId}"); + + string request = "Purchase/GetList"; + + request += $"?userid={UserId}&"; + + if (datefrom != null) + request += $"?datefrom={datefrom}&"; + + if (dateto != null) + request += $"?datefrom={dateto}&"; + + purchaseViewModels = APIClient.GetRequest>(request); + } + + public void OnGetStatistics() + { + + } + + public void SendBill() + { + + } + + public void OnPostSendBill(Guid id) + { + var UserId = this.GetUserId(); + if (UserId is null) + { + OnGet(null, null); + } + userViewModel = APIClient.GetRequest($"user/get?id={UserId}"); + + var purchase = APIClient.GetRequest($"purchase/get?id={id}"); + var products = APIClient.GetRequest>($"purchase/getproducts?purchaseid={id}"); + + billViewModel = new BillViewModel(); + billViewModel.UserId = new Guid(this.GetUserId()); + billViewModel.PurchaseId = id; + billViewModel.Products = products; + billViewModel.Count = purchase.ProductCount; + billViewModel.Cost = purchase.Cost; + billViewModel.DateCreated = purchase.DateCreated; + billViewModel.UserFirstName = userViewModel.FirstName; + billViewModel.UserLastName = userViewModel.SecondName; + billViewModel.UserEmail = userViewModel.Email; + + APIClient.PostRequest($"purchase/createbill", billViewModel); + + OnGet(null, null); + } + } +} diff --git a/WebApp/Pages/_Header.cshtml b/WebApp/Pages/_Header.cshtml new file mode 100644 index 0000000..0c773e5 --- /dev/null +++ b/WebApp/Pages/_Header.cshtml @@ -0,0 +1,5 @@ +@page +@model WebApp.Pages._HeaderModel +@{ + +} diff --git a/WebApp/Pages/_Header.cshtml.cs b/WebApp/Pages/_Header.cshtml.cs new file mode 100644 index 0000000..64dc485 --- /dev/null +++ b/WebApp/Pages/_Header.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WebApp.Pages +{ + public class _HeaderModel : PageModel + { + public void OnGet() + { + } + } +} diff --git a/WebApp/WebApp.csproj b/WebApp/WebApp.csproj index 8cc73e5..cd4cbec 100644 --- a/WebApp/WebApp.csproj +++ b/WebApp/WebApp.csproj @@ -6,12 +6,17 @@ enable + + + + + @@ -22,4 +27,16 @@ + + + + + + <_ContentIncludedByDefault Remove="Pages\_Header.cshtml" /> + + + + + + diff --git a/WebApp/wwwroot/big-sale.png b/WebApp/wwwroot/big-sale.png new file mode 100644 index 0000000..3ed2d33 Binary files /dev/null and b/WebApp/wwwroot/big-sale.png differ diff --git a/WebApp/wwwroot/css/site.css b/WebApp/wwwroot/css/site.css index 10bda70..eaaeb12 100644 --- a/WebApp/wwwroot/css/site.css +++ b/WebApp/wwwroot/css/site.css @@ -38,4 +38,18 @@ body { .empty-star { color: gray; +} + +.card-text del { + text-decoration: line-through; + color: #ccc; /* Серый цвет зачеркнутого текста */ +} + +.card-text span { + font-weight: bold; /* Жирный шрифт для новой цены */ +} + +#YMapsID { + width: 350px; + height: 300px; } \ No newline at end of file