This commit is contained in:
Илья Федотов 2024-07-24 09:53:21 +04:00
parent 93e0fe9524
commit 83a2cfe0d7
31 changed files with 730 additions and 377 deletions

View File

@ -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("Такая статья затрат уде есть");
}

View File

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

View File

@ -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<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
{
throw new NotImplementedException();
}
}
}

View File

@ -47,7 +47,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return element;
}
public List<PaymeantViewModel> ReadList(PaymeantSearchModel? model)
public List<PaymeantViewModel>? ReadList(PaymeantSearchModel? model)
{
_logger.LogInformation($"ReadList. ClientID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ;

View File

@ -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("Продукт с таким названием уже есть");
}
}

View File

@ -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
?? "Отсутствует"
});
}
}

View File

@ -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<AbstractMailWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic)
public AbstractMailWorker(ILogger<AbstractMailWorker> 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<List<MessageInfoBindingModel>> ReceiveMailAsync();
}
}

View File

@ -16,8 +16,8 @@ namespace ElectronicsShopBusinessLogic.MailWorker
{
public class MailKitWorker : AbstractMailWorker
{
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic,
IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { }
public MailKitWorker(ILogger<MailKitWorker> 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<List<MessageInfoBindingModel>> ReceiveMailAsync()
{
var list = new List<MessageInfoBindingModel>();
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;
}
}
}

View File

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

View File

@ -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<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
bool Create(MessageInfoBindingModel model);
}
}

View File

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

View File

@ -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<MessageInfoViewModel> GetFullList();
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
}
}

View File

@ -23,6 +23,5 @@ namespace ElectronicsShopDataBaseImplement
public virtual DbSet<Employee> Employees { set; get; }
public virtual DbSet<CostItem> CostItems { set; get; }
public virtual DbSet<Paymeant> Paymeants { get; set; }
public virtual DbSet<MessageInfo> Messages { set; get; }
}
}

View File

@ -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<ClientViewModel> GetFullList()

View File

@ -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<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
{
using var context = new Database();
return context.Messages
.Where(x => x.MessageID == model.MessageID).Select(x => x.GetViewModel).ToList();
}
public List<MessageInfoViewModel> 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;
}
}
}

View File

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

View File

@ -0,0 +1,310 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ID");
b.ToTable("Clients");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("CostNum")
.HasColumnType("int");
b.Property<int>("EmployeeID")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("ID");
b.HasIndex("EmployeeID");
b.ToTable("CostItems");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("EmployeeFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ID");
b.ToTable("Employees");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b =>
{
b.Property<string>("MessageID")
.HasColumnType("nvarchar(450)");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("ClientID")
.HasColumnType("int");
b.Property<DateTime>("DateDelivery")
.HasColumnType("datetime2");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("MessageID");
b.HasIndex("ClientID");
b.ToTable("Messages");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ClientID")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("ID");
b.HasIndex("ClientID");
b.ToTable("Orders");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<int>("ProductID")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("OrderID");
b.HasIndex("ProductID");
b.ToTable("OrderProducts");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ClientID")
.HasColumnType("int");
b.Property<DateTime>("DatePaymeant")
.HasColumnType("datetime2");
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<int>("PayOption")
.HasColumnType("int");
b.Property<double>("SumPayment")
.HasColumnType("float");
b.HasKey("ID");
b.ToTable("Paymeants");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("CostItemID")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,48 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ElectronicsShopDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class Migration02 : Migration
{
/// <inheritdoc />
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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
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");
}
}
}

View File

@ -0,0 +1,271 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ID");
b.ToTable("Clients");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("CostNum")
.HasColumnType("int");
b.Property<int>("EmployeeID")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("ID");
b.HasIndex("EmployeeID");
b.ToTable("CostItems");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("EmployeeFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Login")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ID");
b.ToTable("Employees");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ClientID")
.HasColumnType("int");
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<double>("Sum")
.HasColumnType("float");
b.HasKey("ID");
b.HasIndex("ClientID");
b.ToTable("Orders");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<int>("ProductID")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("OrderID");
b.HasIndex("ProductID");
b.ToTable("OrderProducts");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ClientID")
.HasColumnType("int");
b.Property<DateTime>("DatePaymeant")
.HasColumnType("datetime2");
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<int>("PayOption")
.HasColumnType("int");
b.Property<double>("SumPayment")
.HasColumnType("float");
b.HasKey("ID");
b.ToTable("Paymeants");
});
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("CostItemID")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("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
}
}
}

View File

@ -0,0 +1,48 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ElectronicsShopDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class Migration03 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Messages");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Messages",
columns: table => new
{
MessageID = table.Column<string>(type: "nvarchar(450)", nullable: false),
ClientID = table.Column<int>(type: "int", nullable: true),
Body = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Subject = table.Column<string>(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");
}
}
}

View File

@ -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<string>("MessageID")
.HasColumnType("nvarchar(450)");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int?>("ClientID")
.HasColumnType("int");
b.Property<DateTime>("DateDelivery")
.HasColumnType("datetime2");
b.Property<string>("SenderName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("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<int>("PayOption")
.HasColumnType("int");
b.Property<int?>("PaymentID")
.HasColumnType("int");
b.Property<double>("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

View File

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

View File

@ -43,9 +43,6 @@ namespace ElectronicsShopDataBaseImplement.Models
[ForeignKey("OrderID")]
public virtual List<OrderProduct> Products { get; set; } = new();
[ForeignKey("PaymentID")]
public virtual List<Paymeant> 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 {

View File

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

View File

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

View File

@ -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<string> {
JsonConvert.SerializeObject(pr.Value.Item1),
@ -139,17 +143,19 @@ namespace ElectronicsShopRestAPI.Controllers {
}
[HttpPost]
public void AddProduct(List<string> jslist)
{
var product = JsonConvert.DeserializeObject<ProductViewModel>(jslist[0]);
public void AddProduct(List<string> jslist) {
var product = JsonConvert.DeserializeObject<ProductViewModel>(jslist[0]) ?? throw new Exception("Ошибка десериализации");
int count = JsonConvert.DeserializeObject<int>(jslist[1]);
int orderid = JsonConvert.DeserializeObject<int>(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<int, (IProductModel, int)>(),
Sum = Calc(_productlist ?? new Dictionary<int, (IProductModel, int)>())
};
var operationResult = _order.Update(model);
if (!operationResult) {

View File

@ -39,7 +39,6 @@ builder.Services.AddTransient<ICostItemLogic, CostItemLogic>();
builder.Services.AddTransient<IReportClientLogic, ReportClientLogic>();
builder.Services.AddTransient<IReportEmployeeLogic, ReportEmployeeLogic>();
builder.Services.AddTransient<IPaymeantLogic, PaymeantLogic>();
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();

View File

@ -143,7 +143,7 @@ namespace ElectronicsShopUserApp.Controllers {
}
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
foreach (var pr in products) {
foreach (var pr in products ?? new List<List<string>>()) {
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
int count = JsonConvert.DeserializeObject<int>(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<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}");
var view = APIClient.GetRequset<OrderViewModel>($"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<ProductViewModel>($"api/main/getproduct?_productid={product}");
var _order = APIClient.GetRequset<OrderViewModel>($"api/main/getorder?_clientid={APIClient.Client?.ID}");
var _product = APIClient.GetRequset<ProductViewModel>($"api/main/getproduct?_productid={product}")
?? throw new Exception("Îøèáêà ïîëó÷åíèÿ òîâàðà");
var _order = APIClient.GetRequset<OrderViewModel>($"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<List<ProductViewModel>>($"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<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client.ID}");
var fileMemStream = APIClient.GetRequset<byte[]>($"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<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client.ID}");
var fileMemStream = APIClient.GetRequset<byte[]>($"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)
});

View File

@ -37,9 +37,6 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Report">Отчёты</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Message">Письма</a>
</li>
</ul>
</div>
</div>