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 358bb8b..3e30b7e 100644 Binary files a/ElectronicsShop/ElectronicsShopRestAPI/Report and b/ElectronicsShop/ElectronicsShopRestAPI/Report differ 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 @@ -