diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs index e4868b2..247925f 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs @@ -23,5 +23,6 @@ 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; } + } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/MessageInfoStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/MessageInfoStorage.cs new file mode 100644 index 0000000..3f805bd --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/MessageInfoStorage.cs @@ -0,0 +1,53 @@ +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/Migrations/20240530150159_AddMessages.Designer.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240530150159_AddMessages.Designer.cs new file mode 100644 index 0000000..daf6f22 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240530150159_AddMessages.Designer.cs @@ -0,0 +1,322 @@ +// +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("20240530150159_AddMessages")] + partial class AddMessages + { + /// + 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.Property("_productID") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProductID"); + + 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("OrderID") + .HasColumnType("int"); + + b.Property("PayOption") + .HasColumnType("int"); + + b.Property("PaymentID") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.Property("SumPayment") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("PaymentID"); + + 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("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ElectronicsShopDataBaseImplement.Models.Product", "_product") + .WithMany() + .HasForeignKey("_productID"); + + b.Navigation("_order"); + + 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") + .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("Payments"); + + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240530150159_AddMessages.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240530150159_AddMessages.cs new file mode 100644 index 0000000..8284989 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240530150159_AddMessages.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ElectronicsShopDataBaseImplement.Migrations +{ + /// + public partial class AddMessages : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Messages", + columns: table => new + { + MessageID = table.Column(type: "nvarchar(450)", nullable: false), + ClientID = table.Column(type: "int", nullable: true), + SenderName = table.Column(type: "nvarchar(max)", nullable: false), + DateDelivery = table.Column(type: "datetime2", nullable: false), + Subject = table.Column(type: "nvarchar(max)", nullable: false), + Body = 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"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Messages"); + } + } +} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs index 55e33e5..a578fb3 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/DatabaseModelSnapshot.cs @@ -100,6 +100,36 @@ namespace ElectronicsShopDataBaseImplement.Migrations 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") @@ -219,6 +249,15 @@ 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) diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/MessageInfo.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/MessageInfo.cs new file mode 100644 index 0000000..dda8193 --- /dev/null +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/MessageInfo.cs @@ -0,0 +1,58 @@ +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/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index 37d2866..27b90fd 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -14,6 +14,7 @@ namespace ElectronicsShopRestAPI.Controllers { private readonly ILogger _logger; private readonly IProductLogic _product; private readonly IOrderLogic _order; + private readonly IMessageInfoLogic _message; public MainController(ILogger logger, IProductLogic product, @@ -55,7 +56,7 @@ namespace ElectronicsShopRestAPI.Controllers { { return _order.ReadList(new OrderSearchModel { - ID = _clientID + ClientID = _clientID }); } catch (Exception ex) @@ -98,7 +99,7 @@ namespace ElectronicsShopRestAPI.Controllers { } - [HttpPost] + [HttpGet] public void AddProduct(OrderBindingModel model) { try @@ -116,5 +117,21 @@ namespace ElectronicsShopRestAPI.Controllers { throw; } } + [HttpGet] + public List? GetMessages(int _clientID) + { + try + { + return _message?.ReadList(new MessageInfoSearchModel + { + ClientID = _clientID + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id = {Id} ", _clientID); + throw; + } + } } } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/appsettings.json b/ElectronicsShop/ElectronicsShopRestAPI/appsettings.json index 10f68b8..b54a8bc 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/appsettings.json +++ b/ElectronicsShop/ElectronicsShopRestAPI/appsettings.json @@ -5,5 +5,11 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "SmtpClientHost": "smtp.gmail.com", + "SmtpClientPort": "587", + "PopHost": "pop.gmail.com", + "PopPort": "995", + "MailLogin": "electronicsshop437@gmail.com", + "MailPassword": "ntlt xijz ckup zglg" } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index 49e1181..d68458c 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -12,11 +12,9 @@ using System.Runtime.Serialization; namespace ElectronicsShopUserApp.Controllers { public class HomeController : Controller { private readonly ILogger _logger; - //private readonly IOrderLogic _order; - public HomeController(ILogger logger/*, IOrderLogic orderLogic*/) { + public HomeController(ILogger logger) { _logger = logger; - //_order = orderLogic; } public IActionResult Index() { @@ -151,5 +149,11 @@ namespace ElectronicsShopUserApp.Controllers { Response.Redirect("CreateOrder"); } - } + [HttpGet] + public IActionResult Message() + { + ViewBag.Massages = APIClient.GetRequset>("api/main/getmessages"); + return View(); + } + } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Message.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Message.cshtml new file mode 100644 index 0000000..95e88cc --- /dev/null +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Message.cshtml @@ -0,0 +1,49 @@ +@using ElectronicsShopContracts.ViewModels + +@model List +@{ + ViewData["Title"] = "Message"; +} + +
+

Отчёты

+ Создать товар +
+
+ @{ + + + + + + + + + + @if (Model != null) + { + @foreach (var item in Model) + { + + + + + } + } + +
+ Заголовок + + Тело письма + + Дата письма +
+ + @Html.DisplayFor(modelItem => item.Subject) + + @Html.DisplayFor(modelItem => item.Body) + + @Html.DisplayFor(modelItem => item.DateDelivery) +
+ } +
\ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml index f572c08..aa192c2 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml @@ -37,6 +37,9 @@ +