diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs index 2d0b7d5..a2a5524 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/EmployeeLogic.cs @@ -93,7 +93,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic { var element = _storage.GetElement(new EmployeeSearchModel { Login = model.Login }); - if (element != null && element.Login != model.Login) { + if (element != null && element.Login == model.Login) { throw new InvalidOperationException("Сотрудник с таким логином уже есть"); } } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs index d5a8b5d..b04932d 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs @@ -10,7 +10,7 @@ namespace ElectronicsShopDataBaseImplement optionsBuilder) { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase11;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240525133056_InitMigration.Designer.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240525133056_InitMigration.Designer.cs deleted file mode 100644 index 3ba3334..0000000 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240525133056_InitMigration.Designer.cs +++ /dev/null @@ -1,204 +0,0 @@ -// -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("20240525133056_InitMigration")] - partial class InitMigration - { - /// - 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("EmployeeID") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("ID"); - - 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("EmployeeID") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("ID"); - - 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("OrdersID") - .HasColumnType("int"); - - b.Property("ProductID") - .HasColumnType("int"); - - b.Property("_orderID") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ProductID"); - - b.HasIndex("_orderID"); - - b.ToTable("OrderProducts"); - }); - - 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.ToTable("Products"); - }); - - modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b => - { - b.HasOne("ElectronicsShopDataBaseImplement.Models.Product", "_product") - .WithMany() - .HasForeignKey("ProductID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ElectronicsShopDataBaseImplement.Models.Order", "_order") - .WithMany("Products") - .HasForeignKey("_orderID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("_order"); - - b.Navigation("_product"); - }); - - modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => - { - b.Navigation("Products"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240526155227_Migration02.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240526155227_Migration02.cs deleted file mode 100644 index d6a861a..0000000 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240526155227_Migration02.cs +++ /dev/null @@ -1,175 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ElectronicsShopDataBaseImplement.Migrations -{ - /// - public partial class Migration02 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_OrderProducts_Orders__orderID", - table: "OrderProducts"); - - migrationBuilder.DropForeignKey( - name: "FK_OrderProducts_Products_ProductID", - table: "OrderProducts"); - - migrationBuilder.DropIndex( - name: "IX_OrderProducts__orderID", - table: "OrderProducts"); - - migrationBuilder.DropColumn( - name: "EmployeeID", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "OrdersID", - table: "OrderProducts"); - - migrationBuilder.RenameColumn( - name: "_orderID", - table: "OrderProducts", - newName: "OrderID"); - - migrationBuilder.AddColumn( - name: "_productID", - table: "OrderProducts", - type: "int", - nullable: true); - - migrationBuilder.CreateTable( - name: "Paymeants", - columns: table => new - { - ID = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ProductID = table.Column(type: "int", nullable: false), - OrderID = table.Column(type: "int", nullable: false), - SumPayment = table.Column(type: "float", nullable: false), - PayOption = table.Column(type: "int", nullable: false), - PaymentID = table.Column(type: "int", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Paymeants", x => x.ID); - table.ForeignKey( - name: "FK_Paymeants_Orders_PaymentID", - column: x => x.PaymentID, - principalTable: "Orders", - principalColumn: "ID"); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ClientID", - table: "Orders", - column: "ClientID"); - - migrationBuilder.CreateIndex( - name: "IX_OrderProducts__productID", - table: "OrderProducts", - column: "_productID"); - - migrationBuilder.CreateIndex( - name: "IX_Paymeants_PaymentID", - table: "Paymeants", - column: "PaymentID"); - - migrationBuilder.AddForeignKey( - name: "FK_OrderProducts_Orders_ProductID", - table: "OrderProducts", - column: "ProductID", - principalTable: "Orders", - principalColumn: "ID", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_OrderProducts_Products__productID", - table: "OrderProducts", - column: "_productID", - principalTable: "Products", - principalColumn: "ID"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Clients_ClientID", - table: "Orders", - column: "ClientID", - principalTable: "Clients", - principalColumn: "ID", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_OrderProducts_Orders_ProductID", - table: "OrderProducts"); - - migrationBuilder.DropForeignKey( - name: "FK_OrderProducts_Products__productID", - table: "OrderProducts"); - - migrationBuilder.DropForeignKey( - name: "FK_Orders_Clients_ClientID", - table: "Orders"); - - migrationBuilder.DropTable( - name: "Paymeants"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ClientID", - table: "Orders"); - - migrationBuilder.DropIndex( - name: "IX_OrderProducts__productID", - table: "OrderProducts"); - - migrationBuilder.DropColumn( - name: "_productID", - table: "OrderProducts"); - - migrationBuilder.RenameColumn( - name: "OrderID", - table: "OrderProducts", - newName: "_orderID"); - - migrationBuilder.AddColumn( - name: "EmployeeID", - table: "Orders", - type: "int", - nullable: true); - - migrationBuilder.AddColumn( - name: "OrdersID", - table: "OrderProducts", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.CreateIndex( - name: "IX_OrderProducts__orderID", - table: "OrderProducts", - column: "_orderID"); - - migrationBuilder.AddForeignKey( - name: "FK_OrderProducts_Orders__orderID", - table: "OrderProducts", - column: "_orderID", - principalTable: "Orders", - principalColumn: "ID", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_OrderProducts_Products_ProductID", - table: "OrderProducts", - column: "ProductID", - principalTable: "Products", - principalColumn: "ID", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240526155227_Migration02.Designer.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.Designer.cs similarity index 99% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240526155227_Migration02.Designer.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.Designer.cs index 1b7a36c..a6a4844 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240526155227_Migration02.Designer.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ElectronicsShopDataBaseImplement.Migrations { [DbContext(typeof(Database))] - [Migration("20240526155227_Migration02")] - partial class Migration02 + [Migration("20240527144429_test")] + partial class test { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240525133056_InitMigration.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.cs similarity index 71% rename from ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240525133056_InitMigration.cs rename to ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.cs index c2f48b4..161dfc1 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240525133056_InitMigration.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Migrations/20240527144429_test.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace ElectronicsShopDataBaseImplement.Migrations { /// - public partial class InitMigration : Migration + public partial class test : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -56,22 +56,6 @@ namespace ElectronicsShopDataBaseImplement.Migrations table.PrimaryKey("PK_Employees", x => x.ID); }); - migrationBuilder.CreateTable( - name: "Orders", - columns: table => new - { - ID = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Sum = table.Column(type: "float", nullable: false), - ClientID = table.Column(type: "int", nullable: false), - EmployeeID = table.Column(type: "int", nullable: true), - DateCreate = table.Column(type: "datetime2", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Orders", x => x.ID); - }); - migrationBuilder.CreateTable( name: "Products", columns: table => new @@ -87,51 +71,100 @@ namespace ElectronicsShopDataBaseImplement.Migrations table.PrimaryKey("PK_Products", x => x.ID); }); + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Sum = table.Column(type: "float", nullable: false), + ClientID = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.ID); + table.ForeignKey( + name: "FK_Orders_Clients_ClientID", + column: x => x.ClientID, + principalTable: "Clients", + principalColumn: "ID", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "OrderProducts", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - OrdersID = table.Column(type: "int", nullable: false), + OrderID = table.Column(type: "int", nullable: false), ProductID = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), - _orderID = table.Column(type: "int", nullable: false) + _productID = table.Column(type: "int", nullable: true) }, constraints: table => { table.PrimaryKey("PK_OrderProducts", x => x.Id); table.ForeignKey( - name: "FK_OrderProducts_Orders__orderID", - column: x => x._orderID, + name: "FK_OrderProducts_Orders_ProductID", + column: x => x.ProductID, principalTable: "Orders", principalColumn: "ID", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_OrderProducts_Products_ProductID", - column: x => x.ProductID, + name: "FK_OrderProducts_Products__productID", + column: x => x._productID, principalTable: "Products", - principalColumn: "ID", - onDelete: ReferentialAction.Cascade); + principalColumn: "ID"); + }); + + migrationBuilder.CreateTable( + name: "Paymeants", + columns: table => new + { + ID = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProductID = table.Column(type: "int", nullable: false), + OrderID = table.Column(type: "int", nullable: false), + SumPayment = table.Column(type: "float", nullable: false), + PayOption = table.Column(type: "int", nullable: false), + PaymentID = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Paymeants", x => x.ID); + table.ForeignKey( + name: "FK_Paymeants_Orders_PaymentID", + column: x => x.PaymentID, + principalTable: "Orders", + principalColumn: "ID"); }); migrationBuilder.CreateIndex( - name: "IX_OrderProducts__orderID", + name: "IX_OrderProducts__productID", table: "OrderProducts", - column: "_orderID"); + column: "_productID"); migrationBuilder.CreateIndex( name: "IX_OrderProducts_ProductID", table: "OrderProducts", column: "ProductID"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientID", + table: "Orders", + column: "ClientID"); + + migrationBuilder.CreateIndex( + name: "IX_Paymeants_PaymentID", + table: "Paymeants", + column: "PaymentID"); } /// protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropTable( - name: "Clients"); - migrationBuilder.DropTable( name: "CostItems"); @@ -142,10 +175,16 @@ namespace ElectronicsShopDataBaseImplement.Migrations name: "OrderProducts"); migrationBuilder.DropTable( - name: "Orders"); + name: "Paymeants"); migrationBuilder.DropTable( name: "Products"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Clients"); } } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index 23bc9e2..dc484fe 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -64,7 +64,7 @@ namespace ElectronicsShopUserApp.Controllers { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { throw new Exception(" "); } - APIClient.Client = APIClient.GetRequset($"api/client/email?email={email}&password={password}"); + APIClient.Client = APIClient.GetRequset($"api/Client/Login?email={email}&password={password}"); if (APIClient.Client == null) { throw new Exception(" /"); }