Курсовая: Война Бесконечности

This commit is contained in:
devil_1nc 2024-07-26 02:46:29 +04:00
parent 4c0b6d983d
commit af14af2496
110 changed files with 10060 additions and 608 deletions

View File

@ -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));
}
}
}

View File

@ -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<CartItemLogic> logger)
{
_cartItemStorage = cartItemStorage;
_logger = logger;
}
public bool Create(CartItemBindingModel model)
{
CheckModel(model);
if (_cartItemStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CartItemBindingModel model)
{
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_cartItemStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public CartItemViewModel ReadElement(CartItemSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _cartItemStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<CartItemViewModel> ReadElements(CartItemSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _cartItemStorage.GetFullList() : _cartItemStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(CartItemBindingModel model)
{
CheckModel(model);
if (_cartItemStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public void CheckModel(CartItemBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ProductName))
{
throw new ArgumentNullException("Нет категории", nameof(model.ProductName));
}
_logger.LogInformation("Cart Item. Id: { Id}", model.Id);
}
}
}

View File

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

View File

@ -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<Guid, int> GetProducts(PurchaseSearchModel model)
public List<CartItemViewModel> 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<ProductViewModel> GetProducts(PurchaseSearchModel model)
{
var products = _purchaseStorage.GetProducts(model);
if (products is null)
{
throw new Exception("Get operation failed.");
}
return products;
}
}
}

View File

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

View File

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

View File

@ -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<Attachment>? Attachments { get; set; } = new List<Attachment>();
}
}

View File

@ -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);
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<Guid, (IProduct, int)>? PurchaseProducts { get; set; } = new();
public int ProductCount { get; set; }
public double Cost { get; set; }
}
public bool IsPaid { get; set; }
}
}

View File

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

View File

@ -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; }
}
}

View File

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

View File

@ -0,0 +1,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<CartItemViewModel> ReadElements(CartItemSearchModel? model);
bool Delete(CartItemBindingModel model);
}
}

View File

@ -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<PurchaseViewModel> ReadElements(PurchaseSearchModel? model);
PurchaseViewModel Delete(PurchaseSearchModel model);
PurchaseViewModel AddProduct(PurchaseSearchModel purchase, ProductSearchModel product, int count);
Dictionary<Guid, int> GetProducts(PurchaseSearchModel model);
List<CartItemViewModel> GetCartItems(PurchaseSearchModel model);
List<ProductViewModel> GetProducts(PurchaseSearchModel model);
}
}

View File

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

View File

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

View File

@ -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
};
}
}

View File

@ -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
};
}
}

View File

@ -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,
};
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

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

View File

@ -0,0 +1,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<CartItemViewModel> GetFullList();
List<CartItemViewModel> GetFilteredList(CartItemSearchModel model);
CartItemViewModel? GetElement(CartItemSearchModel model);
CartItemViewModel? Insert(CartItemBindingModel model);
CartItemViewModel? Update(CartItemBindingModel model);
CartItemViewModel? Delete(CartItemBindingModel model);
}
}

View File

@ -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<Guid, int> GetProducts(PurchaseSearchModel purchaseModel);
List<CartItemViewModel> GetCartItems(PurchaseSearchModel purchaseModel);
List<ProductViewModel> GetProducts(PurchaseSearchModel model);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<MediaFileViewModel> MediaFiles { get; set; } = new();
public Guid? SaleId { get; set; }
}
}

View File

@ -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<Guid, (IProduct, int)>? PurchaseProducts { get; set; } = new();
public int ProductCount { get; set; }
public double Cost { get; set; }
public bool IsPaid { get; set; }
}
}

View File

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

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

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

View File

@ -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; }
}
}

View File

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

View File

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

View File

@ -21,7 +21,7 @@ namespace DatabaseImplement
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Role> Roles { get; set; } = null!;
public virtual DbSet<Role> Roles { get; set; } = null!;
public virtual DbSet<User> Users { get; set; } = null!;
public virtual DbSet<Sell> Sells { get; set; } = null!;
public virtual DbSet<Purchase> Purchases { get; set; } = null!;
@ -31,8 +31,10 @@ namespace DatabaseImplement
public virtual DbSet<Supplier> Suppliers { get; set; } = null!;
public virtual DbSet<SupplierProduct> SupplierProducts { get; set; } = null!;
public virtual DbSet<MediaFile> MediaFiles { get; set; } = null!;
public virtual DbSet<PurchaseProducts> PurchaseProducts { get; set; } = null!;
public virtual DbSet<SellProducts> SellProducts { get; set; } = null!;
public virtual DbSet<SupplyDoc> SupplyDocs { get; set; } = null!;
public virtual DbSet<CartItem> CartItems { get; set; } = null!;
public virtual DbSet<Sale> Sales { get; set; } = null!;
}
}

View File

@ -0,0 +1,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<CartItemViewModel> 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<CartItemViewModel> GetFullList()
{
using var context = new Database();
return context.CartItems
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public CartItemViewModel? Insert(CartItemBindingModel model)
{
using var context = new Database();
var newItem = CartItem.Create(context, model);
if (newItem == null)
{
return null;
}
context.CartItems.Add(newItem);
context.SaveChanges();
return newItem.GetViewModel;
}
public CartItemViewModel? Update(CartItemBindingModel model)
{
using var context = new Database();
using var transaction = context.Database.BeginTransaction();
try
{
var item = context.CartItems.FirstOrDefault(rec =>
rec.Id == model.Id);
if (item == null)
{
return null;
}
item.Update(model);
context.SaveChanges();
transaction.Commit();
return new();
}
catch
{
transaction.Rollback();
throw;
}
}
}
}

View File

@ -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<ProductViewModel> 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<ProductViewModel> 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)
{

View File

@ -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<PurchaseViewModel> 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<Product>();
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<Guid, int> GetProducts(PurchaseSearchModel model)
public List<CartItemViewModel> GetCartItems(PurchaseSearchModel model)
{
Dictionary<Guid, int> 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<ProductViewModel> 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<ProductViewModel>();
if (purchase.Products == null)
return null;
foreach (var product in purchase.Products)
products.Add(product.GetViewModel);
return products;
}
}
}

View File

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

View File

@ -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();
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,101 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class sale : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "Products",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Category",
table: "Products",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AddColumn<Guid>(
name: "SaleId",
table: "Products",
type: "uuid",
nullable: true);
migrationBuilder.CreateTable(
name: "Sales",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Category = table.Column<string>(type: "text", nullable: true),
Description = table.Column<string>(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");
}
/// <inheritdoc />
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<string>(
name: "Description",
table: "Products",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Category",
table: "Products",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
}
}
}

View File

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

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class sale2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

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

View File

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

View File

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

View File

@ -0,0 +1,52 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class sale3 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
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<string>(
name: "FullDescription",
table: "Sales",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<DateTime>(
name: "Start",
table: "Sales",
type: "timestamp without time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "End",
table: "Sales");
migrationBuilder.DropColumn(
name: "FullDescription",
table: "Sales");
migrationBuilder.DropColumn(
name: "Start",
table: "Sales");
}
}
}

View File

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

View File

@ -0,0 +1,68 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class cartitem : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
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<Guid>(type: "uuid", nullable: false),
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false),
Cost = table.Column<double>(type: "double precision", nullable: false),
DateCreated = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
ProductName = table.Column<string>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CartItems");
migrationBuilder.AlterColumn<DateTime>(
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);
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,559 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240718212855_purchaseitems")]
partial class purchaseitems
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.CartItem", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("PurchaseId")
.HasColumnType("uuid");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("CartItems");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.Property<Guid?>("SaleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SaleId");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<DateTime?>("DatePurchase")
.HasColumnType("timestamp without time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sale", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("End")
.HasColumnType("timestamp without time zone");
b.Property<string>("FullDescription")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("Start")
.HasColumnType("timestamp without time zone");
b.Property<int>("Value")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Sales");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp without time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp without time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp without time zone");
b.Property<int>("Bonus")
.HasColumnType("integer");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.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
}
}
}

View File

@ -0,0 +1,88 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class purchaseitems : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PurchaseProducts");
migrationBuilder.AddColumn<Guid>(
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");
}
/// <inheritdoc />
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<Guid>(type: "uuid", nullable: false),
ProductId = table.Column<Guid>(type: "uuid", nullable: false),
PurchaseId = table.Column<Guid>(type: "uuid", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PurchaseProducts", x => x.Id);
table.ForeignKey(
name: "FK_PurchaseProducts_Products_ProductId",
column: x => x.ProductId,
principalTable: "Products",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PurchaseProducts_Purchases_PurchaseId",
column: x => x.PurchaseId,
principalTable: "Purchases",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_PurchaseProducts_ProductId",
table: "PurchaseProducts",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_PurchaseProducts_PurchaseId",
table: "PurchaseProducts",
column: "PurchaseId");
}
}
}

View File

@ -0,0 +1,562 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240718214141_purchasepatch")]
partial class purchasepatch
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.CartItem", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("PurchaseId")
.HasColumnType("uuid");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("CartItems");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.Property<Guid?>("SaleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SaleId");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<DateTime?>("DateClosed")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sale", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("End")
.HasColumnType("timestamp without time zone");
b.Property<string>("FullDescription")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("Start")
.HasColumnType("timestamp without time zone");
b.Property<int>("Value")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Sales");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp without time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp without time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp without time zone");
b.Property<int>("Bonus")
.HasColumnType("integer");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.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
}
}
}

View File

@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class purchasepatch : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "DatePurchase",
table: "Purchases",
newName: "DateClosed");
migrationBuilder.AddColumn<DateTime>(
name: "DateCreated",
table: "Purchases",
type: "timestamp without time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "DateCreated",
table: "Purchases");
migrationBuilder.RenameColumn(
name: "DateClosed",
table: "Purchases",
newName: "DatePurchase");
}
}
}

View File

@ -0,0 +1,565 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240720140718_purchase2")]
partial class purchase2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.CartItem", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("PurchaseId")
.HasColumnType("uuid");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("CartItems");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.Property<Guid?>("SaleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SaleId");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<DateTime?>("DateClosed")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<int>("ProductCount")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sale", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("End")
.HasColumnType("timestamp without time zone");
b.Property<string>("FullDescription")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("Start")
.HasColumnType("timestamp without time zone");
b.Property<int>("Value")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Sales");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp without time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp without time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp without time zone");
b.Property<int>("Bonus")
.HasColumnType("integer");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.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
}
}
}

View File

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

View File

@ -0,0 +1,568 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240722134201_purchase3")]
partial class purchase3
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.CartItem", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("PurchaseId")
.HasColumnType("uuid");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("CartItems");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<byte[]>("Image")
.IsRequired()
.HasColumnType("bytea");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.ToTable("MediaFiles");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<double>("Rate")
.HasColumnType("double precision");
b.Property<Guid?>("SaleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SaleId");
b.ToTable("Products");
});
modelBuilder.Entity("DatabaseImplement.Models.Purchase", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<DateTime?>("DateClosed")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<bool>("IsPaid")
.HasColumnType("boolean");
b.Property<int>("ProductCount")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sale", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("End")
.HasColumnType("timestamp without time zone");
b.Property<string>("FullDescription")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("Start")
.HasColumnType("timestamp without time zone");
b.Property<int>("Value")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Sales");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("DateSell")
.HasColumnType("timestamp without time zone");
b.Property<Guid?>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Sells");
});
modelBuilder.Entity("DatabaseImplement.Models.SellProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SellId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SellId");
b.ToTable("SellProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supplier", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Deals")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Suppliers");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplierProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplierId");
b.ToTable("SupplierProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Supply", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Date")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateArriving")
.HasColumnType("timestamp without time zone");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp without time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<Guid>("SupplierId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SupplierId");
b.ToTable("Supplies");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyDoc", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.ToTable("SupplyDocs");
});
modelBuilder.Entity("DatabaseImplement.Models.SupplyProduct", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("SupplyId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("SupplyId");
b.ToTable("SupplyProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.User", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp without time zone");
b.Property<int>("Bonus")
.HasColumnType("integer");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("OnlyImportantMails")
.HasColumnType("boolean");
b.Property<string>("PasswordHash")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("RoleId")
.HasColumnType("uuid");
b.Property<string>("SecondName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("Users");
});
modelBuilder.Entity("DatabaseImplement.Models.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
}
}
}

View File

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

View File

@ -22,6 +22,40 @@ namespace DatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.CartItem", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<string>("ProductName")
.IsRequired()
.HasColumnType("text");
b.Property<Guid?>("PurchaseId")
.HasColumnType("uuid");
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("CartItems");
});
modelBuilder.Entity("DatabaseImplement.Models.MediaFile", b =>
{
b.Property<Guid>("Id")
@ -51,6 +85,12 @@ namespace DatabaseImplement.Migrations
b.Property<int>("Amount")
.HasColumnType("integer");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsBeingSold")
.HasColumnType("boolean");
@ -64,8 +104,13 @@ namespace DatabaseImplement.Migrations
b.Property<double>("Rate")
.HasColumnType("double precision");
b.Property<Guid?>("SaleId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("SaleId");
b.ToTable("Products");
});
@ -78,9 +123,18 @@ namespace DatabaseImplement.Migrations
b.Property<double>("Cost")
.HasColumnType("double precision");
b.Property<DateTime>("DatePurchase")
b.Property<DateTime?>("DateClosed")
.HasColumnType("timestamp without time zone");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone");
b.Property<bool>("IsPaid")
.HasColumnType("boolean");
b.Property<int>("ProductCount")
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
@ -94,30 +148,6 @@ namespace DatabaseImplement.Migrations
b.ToTable("Purchases");
});
modelBuilder.Entity("DatabaseImplement.Models.PurchaseProducts", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<Guid>("ProductId")
.HasColumnType("uuid");
b.Property<Guid>("PurchaseId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ProductId");
b.HasIndex("PurchaseId");
b.ToTable("PurchaseProducts");
});
modelBuilder.Entity("DatabaseImplement.Models.Role", b =>
{
b.Property<Guid>("Id")
@ -133,6 +163,41 @@ namespace DatabaseImplement.Migrations
b.ToTable("Roles");
});
modelBuilder.Entity("DatabaseImplement.Models.Sale", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("End")
.HasColumnType("timestamp without time zone");
b.Property<string>("FullDescription")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("Start")
.HasColumnType("timestamp without time zone");
b.Property<int>("Value")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Sales");
});
modelBuilder.Entity("DatabaseImplement.Models.Sell", b =>
{
b.Property<Guid>("Id")
@ -304,6 +369,9 @@ namespace DatabaseImplement.Migrations
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp without time zone");
b.Property<int>("Bonus")
.HasColumnType("integer");
b.Property<string>("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");
});

View File

@ -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,
};
}
}

View File

@ -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> PurchaseProducts { get; set; } = new();
[ForeignKey("ProductId")]
public virtual List<SellProducts> 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)
};
}
}
}

View File

@ -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<Guid, (IProduct, int)>? _purchaseProducts = null;
[Required]
public bool IsPaid { get; set; }
public virtual User? User { get; set; }
[DataMember]
[NotMapped]
public Dictionary<Guid, (IProduct, int)> 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<PurchaseProducts> Products { get; set; } = new();
public List<Product> 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;
}
}
}

View File

@ -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();
}
}

View File

@ -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<Product> Products { get; set; } = new List<Product>();
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
};
}
}
}
}

View File

@ -19,4 +19,4 @@ namespace DatabaseImplement.Models
public virtual Supplier Supplier { get; set; } = new();
public virtual Product Product { get; set; } = new();
}
}
}

View File

@ -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;
}
}
}

View File

@ -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<CartItemController> logger, ICartItemLogic cartItemLogic, IProductLogic productLogic)
{
_logger = logger;
_cartItemLogic = cartItemLogic;
_productLogic = productLogic;
}
[HttpGet]
public List<CartItemViewModel> 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<IResult>();
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);
}
}
}
}

View File

@ -30,7 +30,7 @@ namespace RestAPI.Controllers
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка продуктов");
_logger.LogError(ex, "Ошибка получения списка");
throw;
}
}

View File

@ -22,17 +22,18 @@ namespace RestAPI.Controllers
_product = productLogic;
}
[HttpGet]
public List<ProductViewModel>? GetList(string? search, double? pricefrom, double? priceto)
public List<ProductViewModel>? 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
});

View File

@ -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<PurchaseController> logger, IPurchaseLogic purchaseLogic)
public PurchaseController(ILogger<PurchaseController> logger, IPurchaseLogic purchaseLogic, IBillLogic billLogic)
{
_logger = logger;
_purchaseLogic = purchaseLogic;
_billLogic = billLogic;
}
[HttpGet]
public List<PurchaseViewModel>? GetList(double? costfrom, double? costto, DateTime? datefrom, DateTime? dateto)
public List<PurchaseViewModel>? 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<ProductViewModel> 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<Guid, int> GetProducts(Guid productId)
{
return _purchaseLogic.GetProducts(new PurchaseSearchModel
{
Id = productId,
});
}
}
}

View File

@ -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<SaleController> logger, ISaleLogic saleLogic, IProductLogic productLogic)
{
_logger = logger;
_saleLogic = saleLogic;
_productLogic = productLogic;
}
[HttpGet]
public List<SaleViewModel>? 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);
}
}
}
}

View File

@ -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);

View File

@ -19,20 +19,25 @@ builder.Logging.AddLog4Net("log4net.config");
#region DI
builder.Services.AddTransient<IRoleLogic, RoleLogic>();
builder.Services.AddTransient<ISaleLogic, SaleLogic>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<ISellLogic, SellLogic>();
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
builder.Services.AddTransient<IMediaFileLogic, MediaFileLogic>();
builder.Services.AddTransient<ICartItemLogic, CartItemLogic>();
builder.Services.AddTransient<IBillLogic, BillLogic>();
builder.Services.AddSingleton<ITwoFactorAuthService, TwoFactorAuthService>();
builder.Services.AddTransient<IRoleStorage, RoleStorage>();
builder.Services.AddTransient<ISaleStorage, SaleStorage>();
builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<ISellStorage, SellStorage>();
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
builder.Services.AddTransient<IMediaFileStorage, MediaFileStorage>();
builder.Services.AddTransient<ICartItemStorage, CartItemStorage>();
builder.Services.AddSingleton<JwtProvider>();
builder.Services.AddSingleton<MailSender>();
@ -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())
{

View File

@ -6,10 +6,10 @@
<div class="container my-5">
<h1>Корзина</h1>
@* @if (Model.Amount == 0)
@if (Model.cartItemsView == null! || Model.cartItemsView.Count == 0)
{
<p>Ваша корзина пуста.</p>
} *@
}
else
{
<table class="table">
@ -23,34 +23,102 @@
</tr>
</thead>
<tbody>
@* @foreach (var item in Model.CartItems)
@foreach (var item in Model.cartItemsView)
{
<tr>
<td>
<div class="d-flex align-items-center">
<img src="data:image/png;base64,@Convert.ToBase64String(Model.GetMediaByProduct(item.Product))" class="img-fluid me-3" style="max-height: 50px;" alt="@item.Product.Name">
<a asp-page="ProductDetails" asp-route-id="@item.Product.Id">@item.Product.Name</a>
<a asp-page="ProductPage" asp-route-id="@item.ProductId">@Model.GetProduct(item.Id).Name</a>
</div>
</td>
<td>@item.Product.Price.ToString("C")</td>
<td>@Model.GetProduct(item.Id).ActualPrice</td>
<td>
<input type="number" class="form-control" value="@item.Quantity" min="1" max="100" onchange="updateCartItem('@item.Product.Id', this.value)">
<span>@item.Count</span>
</td>
<td>@((item.Product.Price * item.Quantity).ToString("C"))</td>
<td>@(item.Count * @Model.GetProduct(item.Id).ActualPrice)</td>
<td>
<button class="btn btn-danger" onclick="removeFromCart('@item.Product.Id')">Удалить</button>
<form asp-page-handler="DeleteCartItem" method="post">
<input type="hidden" name="Id" value="@item.Id">
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</td>
</tr>
} *@
}
</tbody>
</table>
<div class="d-flex justify-content-end">
@* <h3>Итого: @Model.TotalPrice.ToString("C")</h3> *@
<h3>Сумма заказа: <span id="totalCost"></span> руб.</h3>
</div>
<div class="d-flex justify-content-end">
<a asp-page="Checkout" class="btn btn-primary">Оформить заказ</a>
<form asp-page-handler="GoToPayment">
<input type="hidden" id="ProductCount" name="ProductCount" value="0" />
<input type="hidden" id="Cost" name="Cost" value="0.00" />
<input type="hidden" id="UserId" name="UserId" value="@Model.GetUserId()" />
<button type="submit" class="btn btn-primary">Перейти к оформлению</button>
</form>
</div>
}
</div>
</div>
<script>
window.onload = function () {
calculateTotalCost();
calculateCount();
};
function calculateTotalCost() {
var totalCost = 0;
var totalCells = document.querySelectorAll('tbody td:nth-child(4)');
totalCells.forEach(function (cell) {
var costText = cell.innerText.trim(); // Убираем пробелы вокруг текста
var cost = parseFloat(costText);
// Проверяем, является ли cost числом
if (!isNaN(cost)) {
totalCost += cost;
} else {
console.warn(`Не удалось преобразовать значение "${costText}" в число.`);
}
});
// Обновляем элемент totalCost
var totalCostElement = document.getElementById('totalCost');
var Cost = document.getElementById('Cost');
totalCostElement.textContent = Number(totalCost.toFixed(2)); // Преобразуем обратно в число перед отображением
Cost.value = Number(totalCost.toFixed(2));
}
function calculateCount() {
var totalCount = 0;
var totalCells = document.querySelectorAll('tbody td:nth-child(3)');
totalCells.forEach(function (cell) {
var countText = cell.innerText.trim(); // Убираем пробелы вокруг текста
var count = parseInt(countText);
// Проверяем, является ли count числом
if (!isNaN(count)) {
totalCount += count;
} else {
console.warn(`Не удалось преобразовать значение "${countText}" в число.`);
}
});
// Обновляем элемент totalCount
var ProductCount = document.getElementById('ProductCount');
ProductCount.value = Number(totalCount); // Преобразуем обратно в число перед отображением
}
</script>

View File

@ -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<Guid, int> Products { get; set; }
public void OnGet(Guid id, int count)
[BindProperty]
public List<CartItemBindingModel> cartItems { get; set; }
public List<CartItemViewModel> 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<PurchaseViewModel>($"Purchase/Create/{this.GetUserId()}");
APIClient.GetRequest<PurchaseViewModel>($"Purchase/AddProducts?purchaseId={purchaseModel.Id}?productId={id}?count={count}");
return;
}
purchaseModel = APIClient.GetRequest<PurchaseViewModel>($"Purchase/Get/");
Products = APIClient.GetRequest<Dictionary<Guid, int>>($"Purchase/GetProducts?id={purchaseModel.Id}");
cartItemsView = APIClient.GetRequest<List<CartItemViewModel>>($"cartitem/GetFullList?userId={id}");
}
public IActionResult OnPostAsync()
public ProductViewModel GetProduct(Guid cartItemId)
{
return APIClient.GetRequest<ProductViewModel>($"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);
}
}
}

View File

@ -12,34 +12,80 @@
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Category
</a>
@* МОЖНО РЕАЛИЗОВАТЬ ПОЗЖЕ *@
<ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<li><a class="dropdown-item" href="#">Pistols</a></li>
<li><a class="dropdown-item" href="#">Rifles</a></li>
<li><a class="dropdown-item" href="#">Hard Weapons</a></li>
</ul>
</li>
</ul>
<form class="d-flex" method="get">
<input asp-for="ProductsModel" type="search" placeholder="Поиск" name="search" value="">
<input asp-for="ProductsModel" type="search" placeholder="Поиск" name="search" value="" id="search">
<button class="btn btn-outline-success" type="submit"><i class="fas fa-search"></i></button>
</form>
<div class="form-group ms-3">
<div class="d-flex align-items-center">
<input type="range" step="1" min="0" max="100" value="" class="custom-range me-2" id="priceFrom">
<label asp-for="ProductsModel" s for="pricefrom">От: <span id="priceLabelFrom"></span> руб.</label>
</div>
<div class="d-flex align-items-center">
<input type="range" step="1" min="0" max="100" value="" class="custom-range me-2" id="priceTo">
<label asp-for="ProductsModel" for="priceto">До: <span id="priceLabelTo"></span> руб.</label>
</div>
<div class="dropdown">
<form class="form-group" method="get">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Фильтр
</a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuLink">
<input type="hidden" name="search" id="search_hidden">
<div class="d-flex align-items-center">
<input type="range" step="1" min="0" max="100" value="0" class="custom-range me-2" id="priceFrom">
От: <input type="number" name="pricefrom" step="0.01" id="priceLabelFrom"> руб.
</div>
<div class="d-flex align-items-center">
<input type="range" step="1" min="0" max="100" value="100" class="custom-range me-2" id="priceTo">
До: <input type="number" name="priceto" step="0.01" id="priceLabelTo"> руб.
</div>
<li><input type="radio" name="category" value="Pistol" class="dropdown-item">Pistol</li>
<li><input type="radio" name="category" value="Rifle" class="dropdown-item">Rifle</li>
<li><input type="radio" name="category" value="Revolver" class="dropdown-item">Revolver</li>
<button class="btn btn-outline-success" type="submit">Применить</i></button>
</ul>
</form>
</div>
</div>
@* АКЦИИ *@
<div class="container mt-4">
<div class="row">
@foreach (var sale in Model.SalesModel)
{
<div class="col-12 col-md-6 mb-4">
<div class="card h-100 border-0 shadow-sm rounded-lg overflow-hidden">
<div class="row g-0">
<div class="col-md-4">
<img src="~/big-sale.png" class="card-img" alt="@sale.Name">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">@sale.Name</h5>
<p class="card-text small text-muted">@sale.Description</p>
<a asp-page="Details" asp-route-id="@sale.Id" class="btn btn-primary stretched-link" data-toggle="modal" data-target="#saleDetailModal">Подробнее</a>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="saleDetailModal" tabindex="-1" role="dialog" aria-labelledby="saleDetailModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="saleDetailModalLabel">Подробная информация об акции</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
@sale.FullDescription
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
}
</div>
</div>
</div>
</nav>
@ -53,7 +99,21 @@
<img src="data:image/png;base64,@Convert.ToBase64String(Model.GetMediaByProduct(weapon))" class="card-img-top" alt="@weapon.Name">
<div class="card-body">
<h5 class="card-title">@weapon.Name</h5>
<p class="card-text">Цена: @weapon.Price руб.</p>
<p class="card-text">
@foreach (var sale in Model.SalesModel)
if (sale.Category == weapon.Category)
{
<span>Цена: <del>@weapon.Price руб.</del> </span>
<span style="color:red;">@(weapon.Price / 100 * (100 - sale.Value)) руб.</span>
break;
}
else
{
<span>Цена: @weapon.Price руб.</span>
}
</p>
<div class="star-rating">
@for (int i = 0; i < (int)Math.Round(@weapon.Rate); i++)
@ -67,18 +127,8 @@
(@weapon.Rate)
</div>
@if (User.Identity.IsAuthenticated)
{
<a asp-page="Cart" asp-route-id="@weapon.Id" asp-route-count=1 class="btn btn-primary">To cart</a>
}
else
{
<a asp-page="Login" asp-route-count=1 class="btn btn-primary">To cart</a>
}
<a asp-page="ProductPage" asp-route-id="@weapon.Id" class="btn btn-secondary">View Product</a>
<a asp-page="ProductPage" asp-route-id="@weapon.Id" class="btn btn-success">Подробнее</a>
</div>
</div>
</div>
@ -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);
}
});
});
</script>
}

View File

@ -10,22 +10,28 @@ namespace WebApp.Pages
public class IndexModel : PageModel
{
public List<ProductViewModel> ProductsModel { get; set; }
public List<SaleViewModel> SalesModel { get; set; }
public Dictionary<Guid, List<MediaFileViewModel>> 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<List<ProductViewModel>>(request);
MediaByProductsModel = APIClient.GetRequest<Dictionary<Guid, List<MediaFileViewModel>>>($"MediaFile/GetByProducts");
SalesModel = APIClient.GetRequest<List<SaleViewModel>>($"Sale/GetList");
}
public byte[] GetMediaByProduct(ProductViewModel productModel)
{

View File

@ -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");
}
}
}

View File

@ -15,24 +15,12 @@
<div class="container my-5">
<div class="row">
@* <div class="col-md-6">
<img src="data:image/png;base64,@Convert.ToBase64String(Model.GetMediaByProduct(Model.productModel))" class="img-fluid" alt="@Model.productModel.Name">
</div> *@
<div class="wrap">
<div class="window">
<div id="carousel">
@for (int i = 0; i < Model.GetAllMediaFilesByProduct(Model.productModel).Count; i++)
{
<span class="slide" id=@{"b"+i;}><img src="data:image/png;base64,@Convert.ToBase64String(Model.GetAllMediaFilesByProduct(Model.productModel)[i].Image)" class="img-fluid" alt="@Model.productModel.Name"></span>
}
</div>
</div>
<span id="prev">PREV</span>
<span id="next">NEXT</span>
</div>
<div class="col-md-6">
<h1>@Model.productModel.Name</h1>
<img src="data:image/png;base64,@Convert.ToBase64String(Model.GetMediaByProduct(Model.productModel))" class="img-fluid" alt="@Model.productModel.Name">
</div>
<div class="col-md-6">
<h1 id="ProductName">@Model.productModel.Name</h1>
<div class="star-rating">
@for (int i = 0; i < (int)Math.Round(@Model.productModel.Rate); i++)
{
@ -44,19 +32,36 @@
}
(@Model.productModel.Rate)
</div>
<p class="lead">Цена: @Model.productModel.Price руб.</p>
<p class="lead">
@if (Model.saleModel != null)
{
<span>Цена: <del>@Model.productModel.Price руб.</del> </span>
<span style="color:red;">@(Model.productModel.Price / 100 * (100 - @Model.saleModel.Value)) руб.</span>
}
else
{
<span>Цена: @Model.productModel.Price руб.</span>
}
</p>
<p>Количество товара на складе: @Model.productModel.Amount</p>
<div class="hero-unit">
<div class="container">
<div id="YMapsID"></div>
</div>
</div>
@if (User.Identity.IsAuthenticated)
{
<form method="post">
<div class="d-flex align-items-center mb-3">
<input type="hidden" name="id" value="@Model.productModel.Id" />
<input type="number" name="count" min="1" max="@Model.productModel.Amount" value="1" class="form-control w-auto" />
<button type="submit" class="btn btn-primary me-2">В корзину</button>
<input type="hidden" name="productId" value="@Model.productModel.Id"></input>
<input type="hidden" name="productName" value="@Model.productModel.Name"></input>
<input type="number" name="count" name="count" min="1" max="@Model.productModel.Amount" value="1" class="form-control w-auto" />
<input type="hidden" name="price" value="@Model.productModel.ActualPrice"></input>
</div>
<button type="submit" class="btn btn-primary">В корзину</button>
</form>
}
else
{
@ -64,66 +69,133 @@
<label for="quantity" class="me-2">Количество:</label>
<input type="number" id="quantity" name="quantity" min="1" max="@Model.productModel.Amount" value="1" class="form-control w-auto">
</div>
<a asp-page="Login" class="btn btn-primary me-2">
В корзину
</a>
<a asp-page="Login" asp-route-count=1 class="btn btn-primary" data-toggle="modal" data-target="#loginPromptModal">В корзину</a>
}
<button class="btn btn-secondary">Купить сейчас</button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#shareModal">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-share" viewBox="0 0 16 16">
<path d="M13.5 1a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3M11 2.5a2.5 2.5 0 1 1 .603 1.628l-6.718 3.12a2.5 2.5 0 0 1 0 1.504l6.718 3.12a2.5 2.5 0 1 1-.488.876l-6.718-3.12a2.5 2.5 0 1 1 0-3.256l6.718-3.12A2.5 2.5 0 0 1 11 2.5m-8.5 4a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3m11 5.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3"></path>
</svg>
Поделиться
</button>
<div class="modal fade" id="shareModal" tabindex="-1" aria-labelledby="shareModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="shareModalLabel">Поделиться товаром</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Ссылка на товар:</p>
<input type="text" class="form-control" id="shareLink" value="https://localhost:7122/ProductPage?id=@Model.productModel.Id" readonly>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
<button type="button" class="btn btn-primary" onclick="copyLink()">Копировать ссылку <span class="button-share__icon"></span></button>
<button type="button" class="btn btn-primary" onclick="shareOnTelegram()">Поделиться в Telegram</button>
<button type="button" class="btn btn-primary" onclick="shareOnVK()">Поделиться в VK</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row mt-5">
<div class="col">
<h2>Описание</h2>
<p>@Model.productModel.Amount</p>
<p>@Model.productModel.Description</p>
</div>
</div>
</div>
<script>
var carousel = $('#carousel'),
threshold = 150,
slideWidth = 500,
dragStart,
dragEnd;
@* СПЕРВА ВОЙДИТЕ В СИСТЕМУ ОКНО *@
<div class="modal fade" id="loginPromptModal" tabindex="-1" role="dialog" aria-labelledby="loginPromptModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="loginPromptModalLabel">Предупреждение</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
Сперва войдите в систему.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
$('#next').click(function () { shiftSlide(-1) })
$('#prev').click(function () { shiftSlide(1) })
carousel.on('mousedown', function () {
if (carousel.hasClass('transition')) return;
dragStart = event.pageX;
$(this).on('mousemove', function () {
dragEnd = event.pageX;
$(this).css('transform', 'translateX(' + dragPos() + 'px)')
})
$(document).on('mouseup', function () {
if (dragPos() > threshold) { return shiftSlide(1) }
if (dragPos() < -threshold) { return shiftSlide(-1) }
shiftSlide(0);
})
<script type="text/javascript">
function copyLink() {
const shareLink = document.getElementById("shareLink");
shareLink.select();
shareLink.setSelectionRange(0, 99999);
document.execCommand("copy");
alert("Ссылка скопирована: " + shareLink.value);
}
function shareOnFacebook() {
const shareUrl = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(window.location.href)}`;
window.open(shareUrl, '_blank');
}
function shareOnTwitter() {
const shareText = "Посмотрите этот товар:";
const shareUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(shareText)}&url=${encodeURIComponent(window.location.href)}`;
window.open(shareUrl, '_blank');
}
function shareOnTelegram() {
const name = document.getElementById("ProductName").innerText
const shareText = 'Посмотрите этот товар: ' + name;
const shareUrl = `https://t.me/share/url?url=${encodeURIComponent(window.location.href)}&text=${encodeURIComponent(shareText)}`;
window.open(shareUrl, '_blank');
}
function shareOnVK() {
const shareUrl = `https://vk.com/share.php?url=${encodeURIComponent(window.location.href)}`;
window.open(shareUrl, '_blank');
}
$(document).ready(function () {
if ($('#loginPromptModal').hasClass('show')) {
$('.btn-primary[data-toggle="modal"][data-target="#loginPromptModal"]').remove();
$('<a>', {
class: 'btn btn-primary',
href: '@Url.Page("Cart")',
text: 'В корзину'
}).appendTo('#cartButtonContainer');
}
});
function dragPos() {
return dragEnd - dragStart;
}
ymaps.ready(function () {
var myMap = new ymaps.Map('YMapsID', {
center: [54.352498, 48.387667],
zoom: 16,
// Обратите внимание, что в API 2.1 по умолчанию карта создается с элементами управления.
// Если вам не нужно их добавлять на карту, в ее параметрах передайте пустой массив в поле controls.
controls: []
});
function shiftSlide(direction) {
if (carousel.hasClass('transition')) return;
dragEnd = dragStart;
$(document).off('mouseup')
carousel.off('mousemove')
.addClass('transition')
.css('transform', 'translateX(' + (direction * slideWidth) + 'px)');
setTimeout(function () {
if (direction === 1) {
$('.slide:first').before($('.slide:last'));
} else if (direction === -1) {
$('.slide:last').after($('.slide:first'));
}
carousel.removeClass('transition')
carousel.css('transform', 'translateX(0px)');
}, 700)
}
var myPlacemark = new ymaps.Placemark(myMap.getCenter(), {
balloonContentBody: [
'<address>',
'<strong>Товары на складе в нашем офисе</strong>',
'<br/>',
'Адрес: 119021, Ульяновск, ул. Северный Венец, 32',
'<br/>',
'</address>'
].join('')
}, {
preset: 'islands#redDotIcon'
});
myMap.geoObjects.add(myPlacemark);
});
</script>

View File

@ -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<Guid, List<MediaFileViewModel>> MediaByProductsModel { get; set; }
public int Amount { get; set; } // Ñâîéñòâî äëÿ õðàíåíèÿ êîëè÷åñòâà òîâàðà
public void OnGet(Guid id)
{
productModel = APIClient.GetRequest<ProductViewModel>($"Product/GetProduct?id={id}");
saleModel = APIClient.GetRequest<SaleViewModel>($"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<PurchaseBindingModel>($"Purchase/Create", model);
}
APIClient.GetRequest<PurchaseViewModel>($"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");
}
}

View File

@ -0,0 +1,63 @@
@page
@model WebApp.Pages.PurchaseModel
@{
ViewData["Title"] = "Оплата заказа";
}
<h2>Оплата заказа</h2>
<div class="row gx-lg-5 align-items-center mb-5">
<form method="post" class="form-section">
<div class="container mt-5">
<div class="row">
<div class="col-md-6">
<label for="userFirstName" class="form-label">Имя</label>
<input type="text" class="form-control form-input" id="customerName" name="CustomerName" value="@Model.paymentViewModel.UserFirstName" readonly>
<label for="userSecondName" class="form-label">Фамилия</label>
<input type="text" class="form-control form-input" id="customerName" name="CustomerName" value="@Model.paymentViewModel.UserSecondName" readonly>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="Cost" class="form-label">Сумма заказа</label>
<input type="number" class="form-control form-input" id="cost" name="cost" value="@Model.paymentViewModel.Cost" readonly>
</div>
<div class="form-group">
<label for="paymentMethod" class="form-label">Способ оплаты</label>
<select class="form-control form-select" id="paymentMethod" name="PaymentMethod">
<option selected>Выберите способ оплаты</option>
<option value="Online">Картой онлайн</option>
<option value="Offline">Картой при получении</option>
</select>
<label class="form-label">Списать бонусы (@Model.paymentViewModel.Bonus шт.)</label>
<input asp-for="bonus" type="checkbox" id="useBonus" name="bonus" class="form-checkbox"></input>
</div>
</div>
</div>
</div>
<input asp-for="purchaseModel.UserId" type="hidden" name="userId" value="@Model.userModel.Id"></input>
<input asp-for="purchaseModel.ProductCount" type="hidden" name="ProductCount" value="@Model.paymentViewModel.ProductCount"></input>
<button type="submit" class="btn btn-primary">Оплатить</button>
</form>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
var useBonusCheckbox = document.getElementById('useBonus');
var costInput = document.getElementById('Cost');
var originalCost = parseFloat('@Model.paymentViewModel.Cost'); // Инициализация исходной стоимости
useBonusCheckbox.addEventListener('change', function () {
if (this.checked) {
var bonusPoints = @Model.paymentViewModel.Bonus; // Убедитесь, что это значение доступно здесь
var currentCost = originalCost; // Используем исходную стоимость
var reducedCost = currentCost - (bonusPoints); // Предполагаем, что баллы равны X% стоимости
costInput.value = reducedCost.toFixed(2); // Округляем до двух десятичных знаков
originalCost = reducedCost; // Обновляем исходную стоимость
} else {
costInput.value = originalCost.toFixed(2); // Восстанавливаем исходную стоимость
}
});
});
</script>

View File

@ -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<UserViewModel>($"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<UserViewModel>($"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");
}
}
}

View File

@ -8,9 +8,29 @@
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/WebApp.styles.css" asp-append-version="true" />
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[emailprotected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<script src="https://api-maps.yandex.ru/2.0-stable/?apikey=69ff7f14-0c56-41b5-814c-ce13b64021f5&load=package.standard&lang=ru-RU" type="text/javascript"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-5/3.0.0-alpha14/css/tempus-dominus.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-5/3.0.0-alpha14/js/tempus-dominus.min.js"></script>
<!-- Bootstrap CSS -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css" rel="stylesheet">
<!-- Tempus Dominus CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-5/3.0.0-alpha14/css/tempus-dominus.css" rel="stylesheet" />
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.bundle.min.js"></script>
<!-- Tempus Dominus JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tempusdominus-bootstrap-5/3.0.0-alpha14/js/tempus-dominus.min.js"></script>
</head>
<body>
<header>
@ -24,7 +44,7 @@
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Catalog</a>
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Каталог</a>
</li>
@* <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
@ -32,16 +52,16 @@
@if (User.Identity.IsAuthenticated)
{
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Cart">Cart</a>
<a class="nav-link text-dark" asp-area="" asp-page="/Cart">Корзина</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/User/Index">Profile</a>
<a class="nav-link text-dark" asp-area="" asp-page="/User/Index">Профиль</a>
</li>
}
else
{
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Login">Login</a>
<a class="nav-link text-dark" asp-area="" asp-page="/Login">Вход</a>
</li>
}
</ul>

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