From 83a2cfe0d77112634a15089bb8db206d0a532710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Wed, 24 Jul 2024 09:53:21 +0400 Subject: [PATCH] fix bugs --- .../BusinessLogic/CostItemLogic.cs | 2 +- .../BusinessLogic/EmployeeLogic.cs | 2 +- .../BusinessLogic/MessageInfoLogic.cs | 25 -- .../BusinessLogic/PaymeantLogic.cs | 2 +- .../BusinessLogic/ProductLogic.cs | 2 +- .../BusinessLogic/ReportClientLogic.cs | 3 +- .../MailWorker/AbstractMailWorker.cs | 31 +- .../MailWorker/MailKitWorker.cs | 42 +-- .../BindingModels/MessageInfoBindingModel.cs | 19 -- .../IMessageInfoLogic.cs | 17 - .../SearchModels/MessageInfoSearchModel.cs | 14 - .../StorageContracts/IMessageInfoStorage.cs | 19 -- .../DataBase.cs | 1 - .../Implements/ClientStorage.cs | 3 +- .../Implements/MessageInfoStorage.cs | 53 --- .../Implements/OrderStorage.cs | 2 - .../20240724032333_Migration02.Designer.cs | 310 ++++++++++++++++++ .../Migrations/20240724032333_Migration02.cs | 48 +++ .../20240724033824_Migration03.Designer.cs | 271 +++++++++++++++ .../Migrations/20240724033824_Migration03.cs | 48 +++ .../Migrations/DatabaseModelSnapshot.cs | 67 +--- .../Models/CostItem.cs | 2 +- .../Models/MessageInfo.cs | 58 ---- .../Models/Order.cs | 9 +- .../Models/Product.cs | 4 +- .../Controllers/ClientController.cs | 4 +- .../Controllers/MainController.cs | 20 +- .../ElectronicsShopRestAPI/Program.cs | 1 - ElectronicsShop/ElectronicsShopRestAPI/Report | Bin 37522 -> 37629 bytes .../Controllers/HomeController.cs | 25 +- .../Views/Shared/_Layout.cshtml | 3 - 31 files changed, 730 insertions(+), 377 deletions(-) delete mode 100644 ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/MessageInfoLogic.cs delete mode 100644 ElectronicsShop/ElectronicsShopContracts/BindingModels/MessageInfoBindingModel.cs delete mode 100644 ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IMessageInfoLogic.cs delete mode 100644 ElectronicsShop/ElectronicsShopContracts/SearchModels/MessageInfoSearchModel.cs delete mode 100644 ElectronicsShop/ElectronicsShopContracts/StorageContracts/IMessageInfoStorage.cs delete mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/MessageInfoStorage.cs create mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724032333_Migration02.Designer.cs create mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724032333_Migration02.cs create mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724033824_Migration03.Designer.cs create mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724033824_Migration03.cs delete mode 100644 ElectronicsShop/ElectronicsShopDataBaseImplement/Models/MessageInfo.cs diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs index 942d003..0435ff5 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/CostItemLogic.cs @@ -101,7 +101,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic _logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}" + $"CostNum:{model.CostNum}"); var element = _storage.GetElement(new CostItemSearchModel { Name = model.Name }); - if (element != null && element.Name == model.Name && element.ID != model.ID) + if (element != null && element.Name == model.Name) { throw new InvalidOperationException("Такая статья затрат уде есть"); } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs index a2a5524..aa7cc50 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs @@ -83,7 +83,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic { throw new ArgumentNullException("Нет логина сотрудника", nameof(model.Login)); } if (string.IsNullOrEmpty(model.EmployeeFIO)) { - throw new ArgumentNullException("Нет имени сотрудника", nameof(model.EmployeeFIO)); + throw new ArgumentNullException("Нет ФИО сотрудника", nameof(model.EmployeeFIO)); } if (string.IsNullOrEmpty(model.Password)) { throw new ArgumentNullException("Нет пароля сотрудника", nameof(model.Password)); diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/MessageInfoLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/MessageInfoLogic.cs deleted file mode 100644 index 2ed4022..0000000 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/MessageInfoLogic.cs +++ /dev/null @@ -1,25 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.BusinessLogicContracts; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopBusinessLogic.BusinessLogic -{ - public class MessageInfoLogic : IMessageInfoLogic - { - public bool Create(MessageInfoBindingModel model) - { - throw new NotImplementedException(); - } - - public List? ReadList(MessageInfoSearchModel? model) - { - throw new NotImplementedException(); - } - } -} diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PaymeantLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PaymeantLogic.cs index 06b3806..189f26f 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PaymeantLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PaymeantLogic.cs @@ -47,7 +47,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic return element; } - public List ReadList(PaymeantSearchModel? model) + public List? ReadList(PaymeantSearchModel? model) { _logger.LogInformation($"ReadList. ClientID:{model?.ID}"); var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ; diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs index cb0987a..ccd4bd2 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ProductLogic.cs @@ -95,7 +95,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic } _logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.CostItemID:{model.CostItemID}"); var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName }); - if (element != null && element.ProductName != model.ProductName) { + if (element != null && element.ProductName == model.ProductName) { throw new InvalidOperationException("Продукт с таким названием уже есть"); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs index 655e733..921b703 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/ReportClientLogic.cs @@ -50,7 +50,8 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic ID = product.Value.Item1.ID, ProductName = product.Value.Item1.ProductName, Price = product.Value.Item1.Price, - CostItemName = _costItemStorage.GetElement(new CostItemSearchModel { ID = product.Value.Item1.CostItemID }).Name + CostItemName = _costItemStorage.GetElement(new CostItemSearchModel { ID = product.Value.Item1.CostItemID })?.Name + ?? "Отсутствует" }); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/MailWorker/AbstractMailWorker.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/MailWorker/AbstractMailWorker.cs index 277c91d..535990b 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/MailWorker/AbstractMailWorker.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/MailWorker/AbstractMailWorker.cs @@ -23,15 +23,13 @@ namespace ElectronicsShopBusinessLogic.MailWorker protected int _popPort; - private readonly IMessageInfoLogic _messageInfoLogic; private readonly IClientLogic _clientLogic; private readonly ILogger _logger; - public AbstractMailWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) + public AbstractMailWorker(ILogger logger, IClientLogic clientLogic) { _logger = logger; - _messageInfoLogic = messageInfoLogic; _clientLogic = clientLogic; } @@ -67,34 +65,7 @@ namespace ElectronicsShopBusinessLogic.MailWorker await SendMailAsync(info); } - public async void MailCheck() - { - if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword)) - { - return; - } - - if (string.IsNullOrEmpty(_popHost) || _popPort == 0) - { - return; - } - - if (_messageInfoLogic == null) - { - return; - } - - var list = await ReceiveMailAsync(); - _logger.LogDebug("Check Mail: {Count} new mails", list.Count); - foreach (var mail in list) - { - mail.ClientID = _clientLogic.ReadElemet(new() { Email = mail.SenderName })?.ID; - _messageInfoLogic.Create(mail); - } - } protected abstract Task SendMailAsync(MailSendInfoBindingModel info); - - protected abstract Task> ReceiveMailAsync(); } } diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/MailWorker/MailKitWorker.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/MailWorker/MailKitWorker.cs index 9df1536..f3a5701 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/MailWorker/MailKitWorker.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/MailWorker/MailKitWorker.cs @@ -16,8 +16,8 @@ namespace ElectronicsShopBusinessLogic.MailWorker { public class MailKitWorker : AbstractMailWorker { - public MailKitWorker(ILogger logger, IMessageInfoLogic messageInfoLogic, - IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { } + public MailKitWorker(ILogger logger, + IClientLogic clientLogic) : base(logger, clientLogic) { } protected override async Task SendMailAsync(MailSendInfoBindingModel info) { @@ -50,43 +50,5 @@ namespace ElectronicsShopBusinessLogic.MailWorker throw; } } - - protected override async Task> ReceiveMailAsync() - { - var list = new List(); - using var client = new Pop3Client(); - await Task.Run(() => - { - try - { - client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect); - client.Authenticate(_mailLogin, _mailPassword); - for (int i = 0; i < client.Count; i++) - { - var message = client.GetMessage(i); - foreach (var mail in message.From.Mailboxes) - { - list.Add(new MessageInfoBindingModel - { - DateDelivery = message.Date.DateTime, - MessageID = message.MessageId, - SenderName = mail.Address, - Subject = message.Subject, - Body = message.TextBody - }); - } - } - } - catch (MailKit.Security.AuthenticationException) - { } - finally - { - client.Disconnect(true); - } - }); - return list; - } - - } } diff --git a/ElectronicsShop/ElectronicsShopContracts/BindingModels/MessageInfoBindingModel.cs b/ElectronicsShop/ElectronicsShopContracts/BindingModels/MessageInfoBindingModel.cs deleted file mode 100644 index 473aa4c..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/BindingModels/MessageInfoBindingModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using ElectronicsShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.BindingModels -{ - public class MessageInfoBindingModel : IMessageInfoModel - { - public string MessageID { get; set; } = string.Empty; - public int? ClientID { get; set; } - public string SenderName { get; set; } = string.Empty; - public string Subject { get; set; } = string.Empty; - public string Body { get; set; } = string.Empty; - public DateTime DateDelivery { get; set; } - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IMessageInfoLogic.cs b/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IMessageInfoLogic.cs deleted file mode 100644 index 4e1c2c6..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/BusinessLogicContracts/IMessageInfoLogic.cs +++ /dev/null @@ -1,17 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.BusinessLogicContracts -{ - public interface IMessageInfoLogic - { - List? ReadList(MessageInfoSearchModel? model); - bool Create(MessageInfoBindingModel model); - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/MessageInfoSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/MessageInfoSearchModel.cs deleted file mode 100644 index fe50a21..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/MessageInfoSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.SearchModels -{ - public class MessageInfoSearchModel - { - public int? ClientID { get; set; } - public string? MessageID { get; set; } - } -} diff --git a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IMessageInfoStorage.cs b/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IMessageInfoStorage.cs deleted file mode 100644 index 3e0169f..0000000 --- a/ElectronicsShop/ElectronicsShopContracts/StorageContracts/IMessageInfoStorage.cs +++ /dev/null @@ -1,19 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopContracts.StorageContracts -{ - public interface IMessageInfoStorage - { - List GetFullList(); - List GetFilteredList(MessageInfoSearchModel model); - MessageInfoViewModel? GetElement(MessageInfoSearchModel model); - MessageInfoViewModel? Insert(MessageInfoBindingModel model); - } -} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs index b327360..b4f0cb5 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs @@ -23,6 +23,5 @@ namespace ElectronicsShopDataBaseImplement public virtual DbSet Employees { set; get; } public virtual DbSet CostItems { set; get; } public virtual DbSet Paymeants { get; set; } - public virtual DbSet Messages { set; get; } } } \ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ClientStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ClientStorage.cs index f2569f0..3b5d457 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ClientStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ClientStorage.cs @@ -76,7 +76,8 @@ namespace ElectronicsShopDataBaseImplement.Implements return new(); } using var context = new Database(); - return context.Clients.Where(x=> x.ClientFIO.Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList(); + return context.Clients.Where(x => !string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO + .Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList(); } public List GetFullList() diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/MessageInfoStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/MessageInfoStorage.cs deleted file mode 100644 index 3f805bd..0000000 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/MessageInfoStorage.cs +++ /dev/null @@ -1,53 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.SearchModels; -using ElectronicsShopContracts.StorageContracts; -using ElectronicsShopContracts.ViewModels; -using ElectronicsShopDataBaseImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopDataBaseImplement.Implements -{ - public class MessageInfoStorage : IMessageInfoStorage - { - - public MessageInfoViewModel? GetElement(MessageInfoSearchModel model) - { - using var context = new Database(); - if (model.MessageID != null) - { - return context.Messages.FirstOrDefault(x => x.MessageID == model.MessageID)?.GetViewModel; - } - return null; - } - - public List GetFilteredList(MessageInfoSearchModel model) - { - using var context = new Database(); - return context.Messages - .Where(x => x.MessageID == model.MessageID).Select(x => x.GetViewModel).ToList(); - } - - public List GetFullList() - { - using var context = new Database(); - return context.Messages.Select(x => x.GetViewModel).ToList(); - } - - public MessageInfoViewModel? Insert(MessageInfoBindingModel model) - { - using var context = new Database(); - var newMessage = MessageInfo.Create(model); - if (newMessage == null || context.Messages.Any(x => x.MessageID.Equals(model.MessageID))) - { - return null; - } - context.Messages.Add(newMessage); - context.SaveChanges(); - return newMessage.GetViewModel; - } - } -} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs index db2be2e..9737bba 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs @@ -67,7 +67,6 @@ namespace ElectronicsShopDataBaseImplement.Implements using var context = new Database(); if (model.ClientID.HasValue) { return context.Orders - .Include(x => x.Payments) .Include(x => x.Products) .ThenInclude(x => x._product) .OrderBy(x => x.ID) @@ -76,7 +75,6 @@ namespace ElectronicsShopDataBaseImplement.Implements if (model.ID.HasValue) { return context.Orders - .Include(x => x.Payments) .Include(x => x.Products) .ThenInclude(x => x._product) .FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724032333_Migration02.Designer.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724032333_Migration02.Designer.cs new file mode 100644 index 0000000..b702db8 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724032333_Migration02.Designer.cs @@ -0,0 +1,310 @@ +// +using System; +using ElectronicsShopDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ElectronicsShopDataBaseImplement.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20240724032333_Migration02")] + partial class Migration02 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("CostNum") + .HasColumnType("int"); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("CostItems"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b => + { + b.Property("MessageID") + .HasColumnType("nvarchar(450)"); + + b.Property("Body") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientID") + .HasColumnType("int"); + + b.Property("DateDelivery") + .HasColumnType("datetime2"); + + b.Property("SenderName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("MessageID"); + + b.HasIndex("ClientID"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ClientID") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("ClientID"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderID"); + + b.HasIndex("ProductID"); + + b.ToTable("OrderProducts"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ClientID") + .HasColumnType("int"); + + b.Property("DatePaymeant") + .HasColumnType("datetime2"); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("PayOption") + .HasColumnType("int"); + + b.Property("SumPayment") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.ToTable("Paymeants"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("CostItemID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.HasIndex("CostItemID"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientID"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null) + .WithMany("Orders") + .HasForeignKey("ClientID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Order", "_order") + .WithMany("Products") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ElectronicsShopDataBaseImplement.Models.Product", "_product") + .WithMany() + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("_order"); + + b.Navigation("_product"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem") + .WithMany() + .HasForeignKey("CostItemID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CostItem"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724032333_Migration02.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724032333_Migration02.cs new file mode 100644 index 0000000..d332ab6 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724032333_Migration02.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ElectronicsShopDataBaseImplement.Migrations +{ + /// + public partial class Migration02 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Paymeants_Orders_PaymentID", + table: "Paymeants"); + + migrationBuilder.DropIndex( + name: "IX_Paymeants_PaymentID", + table: "Paymeants"); + + migrationBuilder.DropColumn( + name: "PaymentID", + table: "Paymeants"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "PaymentID", + table: "Paymeants", + type: "int", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Paymeants_PaymentID", + table: "Paymeants", + column: "PaymentID"); + + migrationBuilder.AddForeignKey( + name: "FK_Paymeants_Orders_PaymentID", + table: "Paymeants", + column: "PaymentID", + principalTable: "Orders", + principalColumn: "ID"); + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724033824_Migration03.Designer.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724033824_Migration03.Designer.cs new file mode 100644 index 0000000..361dcc0 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724033824_Migration03.Designer.cs @@ -0,0 +1,271 @@ +// +using System; +using ElectronicsShopDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ElectronicsShopDataBaseImplement.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20240724033824_Migration03")] + partial class Migration03 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("CostNum") + .HasColumnType("int"); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("CostItems"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ClientID") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("ClientID"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderID"); + + b.HasIndex("ProductID"); + + b.ToTable("OrderProducts"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ClientID") + .HasColumnType("int"); + + b.Property("DatePaymeant") + .HasColumnType("datetime2"); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("PayOption") + .HasColumnType("int"); + + b.Property("SumPayment") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.ToTable("Paymeants"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("CostItemID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.HasIndex("CostItemID"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null) + .WithMany("Orders") + .HasForeignKey("ClientID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.Order", "_order") + .WithMany("Products") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ElectronicsShopDataBaseImplement.Models.Product", "_product") + .WithMany() + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("_order"); + + b.Navigation("_product"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => + { + b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem") + .WithMany() + .HasForeignKey("CostItemID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CostItem"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724033824_Migration03.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724033824_Migration03.cs new file mode 100644 index 0000000..08a73a8 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240724033824_Migration03.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ElectronicsShopDataBaseImplement.Migrations +{ + /// + public partial class Migration03 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Messages"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageID = table.Column(type: "nvarchar(450)", nullable: false), + ClientID = table.Column(type: "int", nullable: true), + Body = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Messages", x => x.MessageID); + table.ForeignKey( + name: "FK_Messages_Clients_ClientID", + column: x => x.ClientID, + principalTable: "Clients", + principalColumn: "ID"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Messages_ClientID", + table: "Messages", + column: "ClientID"); + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs index 634e552..c26ec3b 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -44,7 +44,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasKey("ID"); - b.ToTable("Clients"); + b.ToTable("Clients", (string)null); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => @@ -72,7 +72,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("EmployeeID"); - b.ToTable("CostItems"); + b.ToTable("CostItems", (string)null); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b => @@ -97,37 +97,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasKey("ID"); - b.ToTable("Employees"); - }); - - modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b => - { - b.Property("MessageID") - .HasColumnType("nvarchar(450)"); - - b.Property("Body") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("ClientID") - .HasColumnType("int"); - - b.Property("DateDelivery") - .HasColumnType("datetime2"); - - b.Property("SenderName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Subject") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("MessageID"); - - b.HasIndex("ClientID"); - - b.ToTable("Messages"); + b.ToTable("Employees", (string)null); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => @@ -151,7 +121,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("ClientID"); - b.ToTable("Orders"); + b.ToTable("Orders", (string)null); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b => @@ -177,7 +147,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("ProductID"); - b.ToTable("OrderProducts"); + b.ToTable("OrderProducts", (string)null); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b => @@ -200,17 +170,12 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.Property("PayOption") .HasColumnType("int"); - b.Property("PaymentID") - .HasColumnType("int"); - b.Property("SumPayment") .HasColumnType("float"); b.HasKey("ID"); - b.HasIndex("PaymentID"); - - b.ToTable("Paymeants"); + b.ToTable("Paymeants", (string)null); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => @@ -235,7 +200,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.HasIndex("CostItemID"); - b.ToTable("Products"); + b.ToTable("Products", (string)null); }); modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => @@ -249,15 +214,6 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.Navigation("Employee"); }); - modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b => - { - b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", "Client") - .WithMany() - .HasForeignKey("ClientID"); - - b.Navigation("Client"); - }); - modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => { b.HasOne("ElectronicsShopDataBaseImplement.Models.Client", null) @@ -286,13 +242,6 @@ namespace ElectronicsShopDataBaseImplement.Migrations b.Navigation("_product"); }); - modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b => - { - b.HasOne("ElectronicsShopDataBaseImplement.Models.Order", null) - .WithMany("Payments") - .HasForeignKey("PaymentID"); - }); - modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => { b.HasOne("ElectronicsShopDataBaseImplement.Models.CostItem", "CostItem") @@ -311,8 +260,6 @@ namespace ElectronicsShopDataBaseImplement.Migrations modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => { - b.Navigation("Payments"); - b.Navigation("Products"); }); #pragma warning restore 612, 618 diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs index b31c66a..cd0960a 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/CostItem.cs @@ -27,7 +27,7 @@ namespace ElectronicsShopDataBaseImplement.Models [Required] public int CostNum { get; set; } - public virtual Employee Employee { get; set; } + public virtual Employee Employee { get; set; } public static CostItem? Create(CostItemBindingModel? model) { diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/MessageInfo.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/MessageInfo.cs deleted file mode 100644 index dda8193..0000000 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/MessageInfo.cs +++ /dev/null @@ -1,58 +0,0 @@ -using ElectronicsShopContracts.BindingModels; -using ElectronicsShopContracts.ViewModels; -using ElectronicsShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ElectronicsShopDataBaseImplement.Models -{ - public class MessageInfo : IMessageInfoModel - { - [Key] - public string MessageID { get; private set; } = string.Empty; - - public int? ClientID { get; private set; } - - public string SenderName { get; private set; } = string.Empty; - - public DateTime DateDelivery { get; private set; } = DateTime.Now; - - public string Subject { get; private set; } = string.Empty; - - public string Body { get; private set; } = string.Empty; - - public Client? Client { get; private set; } - - public static MessageInfo? Create(MessageInfoBindingModel model) - { - if (model == null) - { - return null; - } - return new() - { - Body = model.Body, - Subject = model.Subject, - ClientID = model.ClientID, - MessageID = model.MessageID, - SenderName = model.SenderName, - DateDelivery = model.DateDelivery, - }; - } - - public MessageInfoViewModel GetViewModel => new() - { - Body = Body, - Subject = Subject, - ClientID = ClientID, - MessageID = MessageID, - SenderName = SenderName, - DateDelivery = DateDelivery, - }; - - } -} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs index 8404e5e..5322763 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs @@ -43,9 +43,6 @@ namespace ElectronicsShopDataBaseImplement.Models [ForeignKey("OrderID")] public virtual List Products { get; set; } = new(); - [ForeignKey("PaymentID")] - public virtual List Payments { get; set; } = new(); - public static Order? Create(Database context ,OrderBindingModel? model) { if (model == null) @@ -87,6 +84,12 @@ namespace ElectronicsShopDataBaseImplement.Models context.SaveChanges(); } var order = context.Orders.FirstOrDefault(x => x.ID == model.ID); + + if (order == null) { + + throw new Exception("Ошибка получения заказа"); + } + order.Sum = model.Sum; foreach (var op in model.ProductList) { context.OrderProducts.Add(new OrderProduct { diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs index 2f940f5..e3f8815 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs @@ -24,7 +24,7 @@ namespace ElectronicsShopDataBaseImplement.Models [ForeignKey("CostItemID")] public int CostItemID { get; set; } - public virtual CostItem CostItem {get; set;} + public virtual CostItem CostItem { get; set; } public static Product? Create(ProductBindingModel? model) { @@ -56,7 +56,7 @@ namespace ElectronicsShopDataBaseImplement.Models ProductName = ProductName, Price = Price, CostItemID = CostItemID, - CostItemName = CostItem?.Name + CostItemName = CostItem?.Name ?? string.Empty, }; } } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs index 34349e0..94da2b5 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs @@ -103,7 +103,7 @@ namespace ElectronicsShopRestAPI.Controllers { } [HttpGet] - public byte[] CreateXlsxReport (int _clientID) { + public byte[]? CreateXlsxReport (int _clientID) { try { var document = _reportLogic.SavePaymeantToExcelFile (_clientID); return document; @@ -115,7 +115,7 @@ namespace ElectronicsShopRestAPI.Controllers { } [HttpGet] - public byte[] CreateDocxReport (int _clientID) { + public byte[]? CreateDocxReport (int _clientID) { try { var document = _reportLogic.SavePaymeantToWordFile (_clientID); return document; diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index 8e81b73..1405d1d 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -122,6 +122,10 @@ namespace ElectronicsShopRestAPI.Controllers { try { var products = _order.ReadElement(new OrderSearchModel { ID = _orderid}); + if (products == null) { + return list; + } + foreach (var pr in products.ProductList) { var sentence = new List { JsonConvert.SerializeObject(pr.Value.Item1), @@ -138,18 +142,20 @@ namespace ElectronicsShopRestAPI.Controllers { } } - [HttpPost] - public void AddProduct(List jslist) - { - var product = JsonConvert.DeserializeObject(jslist[0]); + [HttpPost] + public void AddProduct(List jslist) { + var product = JsonConvert.DeserializeObject(jslist[0]) ?? throw new Exception("Ошибка десериализации"); int count = JsonConvert.DeserializeObject(jslist[1]); int orderid = JsonConvert.DeserializeObject(jslist[2]); var view = _order.ReadElement(new OrderSearchModel { ID = orderid }); + if (view != null) { _productlist = view.ProductList; } - + else { + throw new Exception("Такого заказа нет"); + } _logger.LogInformation($"Добавление нового товара: {product.ProductName} - {count}"); if (_productlist.ContainsKey(product.ID)) { @@ -169,8 +175,8 @@ namespace ElectronicsShopRestAPI.Controllers { ID = orderid, ClientID = view.ClientID, DateCreate = view.DateCreate, - ProductList = _productlist, - Sum = Calc(_productlist) + ProductList = _productlist ?? new Dictionary(), + Sum = Calc(_productlist ?? new Dictionary()) }; var operationResult = _order.Update(model); if (!operationResult) { diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Program.cs b/ElectronicsShop/ElectronicsShopRestAPI/Program.cs index f62b45e..5dc0f7c 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Program.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Program.cs @@ -39,7 +39,6 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddSingleton(); diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Report b/ElectronicsShop/ElectronicsShopRestAPI/Report index 358bb8b55ce340172f70ad792bb3dbd239ee33a7..3e30b7e35d34be36eb44467875826f8567e5d8f8 100644 GIT binary patch delta 2115 zcmaiydpy$%AICSA%jTLSPG{(p+}8m@!?j;Y*fhP1M(IK z91^g=*W#cu5CDNj6q022FpCE`!w9u!l9clgK+oWLn}-#u7V4bF)E?@)>*XJrr~LM4 z4wbY!Z$I1ZwEyku^5KDT>9fUz*913@VX37UzqzprJWSs_JYbvdan!za({o)m_ndf9 z%ZAw-U$SoSTy*ThwQJE*j9qwg$wO*N!4fgU-;v+kZtioC+`Z&u-kX>laD8=nwY7`Ujo+_y z`0624JCXcrzsVwcRd6jU=ftg;Fq)pSkHlkn{G~{$)8i^BnmS&W?LWyrUjRDQZM_eE z^h;4Lhd$!Tbu$fk#Pp1viA{4SZE}*h+;1rDyGG)PNC|If=kWSyr@(7`h_F#ga3dHZ zW>YD!WlP!0oLk1kpsbL6$39%j-!Zhbi*|Z{(7^zw6H#2R393L-Kp%e+6F=Jf622Fy zZnGq%yBeHnfaH5-+>SjG8z5!{SB1w{j}>2=DOzb>cD(9N{b-E-l{v4? zlva6)5iAp7lr^8t`pIJ?!>Bo$t!!luy3{9#<+mx(>`Px~#5@h(bt%H}^4dKWGYHFF zIIb&f{DVU_8Bl4h@rM<#j-eJz0^mZ5NzB&kv&=MDW^^F&bE$r}`Mv5WLu9%l!r z?qsMpokV2nYW>#pQl~Y0L`e@a6Qq;#h!lG$N`2v0l3iy1{vZwta$z4iXCbMX-o%dE696*GePGR>Pn!2roDBhMTbU_^ ziTvK;4`cU*XzST_Vr_qS18f;4O zG!yQr;rsb@_o-?LBnXso{c@;jv9;M%DSo>*0=_%<}ejZTC%Ty}FzNSkCW|x39lvp{{%Y6NQ5k2+)K? zdIaSJ^i*l^#on7!2qpFkYf&YntRDANtCPl8IL$J9|3v&;wmdsfW_WM8SP*YpWs(xQ zbA!)ZdQ%r}{05#Ztl^QrCd|+I6pvIalmKIELVtONil{Mg*R7JqvTwSzZN43o5d<5F zPxH_BUG5w)E=udul?*e#ktK82ZO`S+3rDkR7ivCktbAQ6;K4gS?;j;C&soV?;E zJ)->XR-mVL3L&p=y@glyulgy?tA>-J1ce@M$5YpjZHg;bZ+7@IM4ub|X(yCw8cdzf z1ZLGpZS|t2q}<&*F@})Xe2ZfOwXqEJ1>#AUS6wa;HOY3?#Mf#j82b2jK(CiVoW{K~ zxx|x}F(m7Pt2R)M6<;l=e@@d7(iCRCU=NwFu};YbO}-VVJ^BJKSASgl{($WsyXPL6 zLI;T;a<{=3d;{1uQEroQfwoe88yM8Ao+<8XiS`K<$iBK%Y{&rLgsCfuI#YN2;|+Z` z@3O*?7`~Uns{}V@w+kdR-b)8WiDpvG!m>I=k-Ii>bEn%=LGLs8-e&l&!%=YMlnsGHnc2 zl|`(ef^|-!drcSdwEGoOD|gLN!c|}|_HL!`O6gP4I3QN;U)1l*5LFk;mpB(zrsqsq zXGMP;TuSNVHNt2Jl?{HRXl_M|u%nQ#*#5ub?5t0PPJdUVty?LPxtEGZ187_XV2Z>b z08@)FD$hG{3=knj+`Z`Xt3=@L`^bmiJ zUYs8EzY7AuA}xMo80-%Wk3;^IA<_6B{7?W6_g5VXg~I&FnBP4{q0!%mNu*O~$0O)a zYip?aVTV9#5(2O%q8*4xEP!($SzvHj1QLnGkt_gFO25uK><7lx^ExJ!x8!)r(Ty^ delta 1984 zcmaiyc{H1e8pb8H#Ak2O)>69~5tA=pB8jaC!IV5>%tq(pD(l zl#+H(s*9E}rii7swo?;Z=}qUhC1V?N=AL`cnR7em%=_1Se&_j}=bvY*4t}8yejb#A zFldm7MmG}x_zof#)9kIo2e6i9gc!sZ#H1l{F zO42FXZ|S+3ZjPLs92BRC)>3#2?^3KoOzjpPQ4Z9%>h1fyDUw{%c($hU{J?N>l|5Vd zsdclikMcBa?Y@~M<$9|m)rvsr@~Y+yhrQMb_U;P+Sd~9B9`j_`SEHl~()1W_H`YE9 zs6GZ9=WS+jX;aH6BOb4n$zQfRtK5%Jmq_R*zB4apEv1x;2l{>40+wY$NWy?T$!Agc z(@9m08mK?5pli|0fHr+=%3sT^dvv2R^~2Iani9QU^5ZG1NoR{wq~~r@oe@`lQ9-Ts zkX?x<%=+p}EyCD0?ti>*k9T3a+PJ%KmMi*SOpF&u4l(i>tfg?F*-6G#)*%(13ZS?i zI^pziK+0USl&89z@7FipZeq;A+L0^X$d7w#`b?KcsJC5;;@qfey*s77ns8t4oQJc@ z*)AQPydDZ>>>IXRF&20%mFj0csg1wz1Y1}9i#evpxb=vDEo@o z@zRe^^|^onGkm6J*O_X-vVz)uNFkjrSk$`lH7QW_dQ!C(xHpGhE}UcC$x?9Sk2Fhq zo9{d_(&!gtH6mX+Mes8`b^U+fL_PJ?%{(S#n(r8^O-ypp_S1XC*rPG;WB+id81A5{ z?D0*b+ag zky;iC8{Ik8UVAlkkq9$Wkc%|=R`m#!CPaZvQqQZE0cDE@`Kf7eEYoW z6WseTP@`=SQ`%Enq9`8y?#YSy^4kMjr+j77EA4E@%PQDACWduWy+5{!9vvPF27NEz z?k)j-%f5MgCc3=H7FZ2!lHN6@V^wXP1?I}5WR2|3k04F#YLFtDzupX=ncIc(i;XLz zs2}V-PhOMFUqK~J%zAy6?C#{c8wl942$-zrkwYFw19(G#Ca+eG#KwYvy*+R`F@a8v z1(K^mN?zO&p%pn2&W3X6n~t_;2l7Uo)b249LVi+dg;a)2?`il)V&qeeXmd7$b66;G-Am;dge&MCb>bpzyd41ntJz$ zdsnA!t_0F4BfY(BLg(m4z1VWbXagLjMom?wZiig4Zy6DM*v@7~xz?#2)omQ1bY0%~ zu)y@*n_^$I^0|F4=&k9hp&sTLAP*^EIw5SAy8#dIG9=T|!aPyt!uB{6q3)A%-(Z20& zgDY7krt1?wx67ToD{8wWBRp-H6I`6uc#m&kIQPnH;UFT1sXRLAHn=6T&d=d zTcyiRjc#48*8BY;4D7DQ7`@KhAWJSFaz6Ecb-<87wBXrzT(cp($i>Rd2Y^c0i>8NH zbaEI7;b`qUXz+5q5(B*&(quZmxhZ3Po~Hmj`tN=OL%{m~wj>x*%wroz(uiO<4WywU z907yEVsThhI28?|Fjx!$Zxv3X(+D7s#l;yz^vDPr1|*`WP=pl<3xVM%0tQD%Sz&QR zLS!Tz145C4ajrdVC*+GkTZ2SvG};o4$AVU9Ja2!Y&EMg~!m_`?0^OoEI2(rt_0fNx zew;q=p9c+Ef!Hq@4*vxs;4%NtFj&GDE`%n0(E(vF#6R7bzZ63_EdDQYVgi*BLr(x~ zZGo@dor7$NE|3$6gh%6@oL$HmERhH~x)7Z~41^_;@Sqje{vQ*(#}^;~O&|g$CN5rN F;17sfQ3L=0 diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index b5b6fd7..78b0466 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -143,7 +143,7 @@ namespace ElectronicsShopUserApp.Controllers { } var products = APIClient.GetRequset>>($"api/main/getorderproducts?_orderid={id}"); - foreach (var pr in products) { + foreach (var pr in products ?? new List>()) { var product = JsonConvert.DeserializeObject(pr[0]); int count = JsonConvert.DeserializeObject(pr[1]); _productList.Add(product.ID, (product, count)); @@ -194,7 +194,8 @@ namespace ElectronicsShopUserApp.Controllers { [HttpGet] public IActionResult DeleteProductOrder(int id) { - var view = APIClient.GetRequset($"api/main/getorder?_clientid={APIClient.Client?.ID}"); + var view = APIClient.GetRequset($"api/main/getorder?_clientid={APIClient.Client?.ID}") + ?? throw new Exception(" "); APIClient.PostRequestStr($"api/main/deleteproductorder", view.ID, id); return RedirectToAction("OrderView"); @@ -208,19 +209,15 @@ namespace ElectronicsShopUserApp.Controllers { [HttpPost] public void AddProduct(int product, int count) { - var _product = APIClient.GetRequset($"api/main/getproduct?_productid={product}"); - var _order = APIClient.GetRequset($"api/main/getorder?_clientid={APIClient.Client?.ID}"); + var _product = APIClient.GetRequset($"api/main/getproduct?_productid={product}") + ?? throw new Exception(" "); + var _order = APIClient.GetRequset($"api/main/getorder?_clientid={APIClient.Client?.ID}") + ?? throw new Exception(" "); APIClient.ListPostRequest($"api/main/addproduct", _product, count, _order.ID); Response.Redirect("OrderView"); } - [HttpGet] - public IActionResult Message() { - //ViewBag.Reports = APIClient.GetRequset>($"api/main/getproducts"); - return View(); - } - [HttpGet] public IActionResult Payment(int id) { if (APIClient.Client == null) { @@ -295,7 +292,7 @@ namespace ElectronicsShopUserApp.Controllers { if (DateTo == DateTime.MinValue || DateFrom > DateTo) { throw new Exception(" "); } - Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateto={DateTo}"); + Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateto={DateTo + DateTime.Now.TimeOfDay}"); } [HttpGet] @@ -309,7 +306,7 @@ namespace ElectronicsShopUserApp.Controllers { [HttpGet] public IActionResult CreateExcelReport() { - var fileMemStream = APIClient.GetRequset($"api/Client/CreateXlsxReport?_clientID={APIClient.Client.ID}"); + var fileMemStream = APIClient.GetRequset($"api/Client/CreateXlsxReport?_clientID={APIClient.Client?.ID}"); if (fileMemStream == null) { throw new Exception(" "); @@ -320,7 +317,7 @@ namespace ElectronicsShopUserApp.Controllers { [HttpGet] public IActionResult CreateWordReport() { - var fileMemStream = APIClient.GetRequset($"api/client/CreateDocxReport?_clientID={APIClient.Client.ID}"); + var fileMemStream = APIClient.GetRequset($"api/client/CreateDocxReport?_clientID={APIClient.Client?.ID}"); if (fileMemStream == null) { throw new Exception(" "); @@ -332,7 +329,7 @@ namespace ElectronicsShopUserApp.Controllers { [HttpGet] public IActionResult CreatePdfReport(string DateFrom, string DateTo) { APIClient.PostRequest("api/client/SendReportMail", new ReportBindingModel { - ClientEmail = APIClient.Client.Email, + ClientEmail = APIClient.Client?.Email ?? throw new Exception(" "), DateFrom = DateTime.Parse(DateFrom), DateTo = DateTime.Parse(DateTo) }); diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml index 23f23eb..e7aeb1b 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml @@ -37,9 +37,6 @@ -