From d9463e4f4c01e7bdd8cf0d5e8b872ab6aef0c925 Mon Sep 17 00:00:00 2001 From: Allllen4a Date: Sun, 7 Apr 2024 19:43:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Pizzeria/Pizzeria.sln | 20 ++-- Pizzeria/PizzeriaClientApp/APIClient.cs | 72 ++++++------ .../Controllers/HomeController.cs | 4 +- .../Models/ErrorViewModel.cs | 10 +- .../PizzeriaClientApp.csproj | 6 +- Pizzeria/PizzeriaClientApp/Program.cs | 10 +- .../Properties/launchSettings.json | 6 +- Pizzeria/PizzeriaClientApp/appsettings.json | 2 +- .../Migrations/20240403141650_InitClient.cs | 68 ----------- ... 20240407121638_InitMigration.Designer.cs} | 4 +- ...ion.cs => 20240407121638_InitMigration.cs} | 33 ++++++ ...0240407121716_ClientMigration.Designer.cs} | 60 ++++++++-- .../20240407121716_ClientMigration.cs | 22 ++++ .../Controllers/ClientController.cs | 110 +++++++++--------- Pizzeria/PizzeriaRestApi/Program.cs | 6 +- .../Properties/launchSettings.json | 6 +- Pizzeria/PizzeriaView/FormMain.cs | 1 - 17 files changed, 233 insertions(+), 207 deletions(-) delete mode 100644 Pizzeria/PizzeriaDatabaseImplement/Migrations/20240403141650_InitClient.cs rename Pizzeria/PizzeriaDatabaseImplement/Migrations/{20240403141650_InitClient.Designer.cs => 20240407121638_InitMigration.Designer.cs} (98%) rename Pizzeria/PizzeriaDatabaseImplement/Migrations/{20240309113549_InitMigration.cs => 20240407121638_InitMigration.cs} (78%) rename Pizzeria/PizzeriaDatabaseImplement/Migrations/{20240309113549_InitMigration.Designer.cs => 20240407121716_ClientMigration.Designer.cs} (75%) create mode 100644 Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121716_ClientMigration.cs diff --git a/Pizzeria/Pizzeria.sln b/Pizzeria/Pizzeria.sln index dc6b188..7acc099 100644 --- a/Pizzeria/Pizzeria.sln +++ b/Pizzeria/Pizzeria.sln @@ -17,9 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "Pi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{AA78A273-0E83-4B45-A155-F9CAFD64E895}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaRestApi", "PizzeriaRestApi\PizzeriaRestApi.csproj", "{86BFFB1F-C08C-4939-91F3-7A582996065B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaRestApi", "PizzeriaRestApi\PizzeriaRestApi.csproj", "{6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaClientApp", "PizzeriaClientApp\PizzeriaClientApp.csproj", "{11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaClientApp", "PizzeriaClientApp\PizzeriaClientApp.csproj", "{8E483155-EC2D-460A-9B65-1B6831C5E441}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -55,14 +55,14 @@ Global {AA78A273-0E83-4B45-A155-F9CAFD64E895}.Debug|Any CPU.Build.0 = Debug|Any CPU {AA78A273-0E83-4B45-A155-F9CAFD64E895}.Release|Any CPU.ActiveCfg = Release|Any CPU {AA78A273-0E83-4B45-A155-F9CAFD64E895}.Release|Any CPU.Build.0 = Release|Any CPU - {86BFFB1F-C08C-4939-91F3-7A582996065B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {86BFFB1F-C08C-4939-91F3-7A582996065B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {86BFFB1F-C08C-4939-91F3-7A582996065B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {86BFFB1F-C08C-4939-91F3-7A582996065B}.Release|Any CPU.Build.0 = Release|Any CPU - {11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}.Debug|Any CPU.Build.0 = Debug|Any CPU - {11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}.Release|Any CPU.ActiveCfg = Release|Any CPU - {11B12B10-0ADF-4FBA-9DFC-5DF8E5ACD888}.Release|Any CPU.Build.0 = Release|Any CPU + {6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D8E3DBB-9AB7-4C2B-9F26-3FCBEE3362D8}.Release|Any CPU.Build.0 = Release|Any CPU + {8E483155-EC2D-460A-9B65-1B6831C5E441}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E483155-EC2D-460A-9B65-1B6831C5E441}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E483155-EC2D-460A-9B65-1B6831C5E441}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E483155-EC2D-460A-9B65-1B6831C5E441}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Pizzeria/PizzeriaClientApp/APIClient.cs b/Pizzeria/PizzeriaClientApp/APIClient.cs index 60d09af..a929777 100644 --- a/Pizzeria/PizzeriaClientApp/APIClient.cs +++ b/Pizzeria/PizzeriaClientApp/APIClient.cs @@ -5,45 +5,45 @@ using System.Text; namespace PizzeriaClientApp { - public class APIClient - { - private static readonly HttpClient _client = new(); + public class APIClient + { + private static readonly HttpClient _client = new(); - public static ClientViewModel? Client { get; set; } = null; + public static ClientViewModel? Client { get; set; } = null; - public static void Connect(IConfiguration configuration) - { - _client.BaseAddress = new Uri(configuration["IPAddress"]); - _client.DefaultRequestHeaders.Accept.Clear(); - _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - } + public static void Connect(IConfiguration configuration) + { + _client.BaseAddress = new Uri(configuration["IPAddress"]); + _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + } - public static T? GetRequest(string requestUrl) - { - var response = _client.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject(result); - } - else - { - throw new Exception(result); - } - } + public static T? GetRequest(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } - public static void PostRequest(string requestUrl, T model) - { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); + public static void PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); - var response = _client.PostAsync(requestUrl, data); + var response = _client.PostAsync(requestUrl, data); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - } -} \ No newline at end of file + var result = response.Result.Content.ReadAsStringAsync().Result; + if (!response.Result.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } +} diff --git a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs index 60ff0d6..7c5c08b 100644 --- a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs +++ b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs @@ -39,7 +39,7 @@ namespace PizzeriaClientApp.Controllers { if (APIClient.Client == null) { - throw new Exception("Вы не авторизованы"); + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { @@ -121,7 +121,7 @@ namespace PizzeriaClientApp.Controllers { if (APIClient.Client == null) { - throw new Exception("Вы не авторизованы"); + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } if (count <= 0) { diff --git a/Pizzeria/PizzeriaClientApp/Models/ErrorViewModel.cs b/Pizzeria/PizzeriaClientApp/Models/ErrorViewModel.cs index 5fcce25..4d61c8f 100644 --- a/Pizzeria/PizzeriaClientApp/Models/ErrorViewModel.cs +++ b/Pizzeria/PizzeriaClientApp/Models/ErrorViewModel.cs @@ -1,9 +1,9 @@ namespace PizzeriaClientApp.Models { - public class ErrorViewModel - { - public string? RequestId { get; set; } + public class ErrorViewModel + { + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - } + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } } diff --git a/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj b/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj index e756033..534d27b 100644 --- a/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj +++ b/Pizzeria/PizzeriaClientApp/PizzeriaClientApp.csproj @@ -6,16 +6,12 @@ enable - - - - - + diff --git a/Pizzeria/PizzeriaClientApp/Program.cs b/Pizzeria/PizzeriaClientApp/Program.cs index 0727468..559dd3a 100644 --- a/Pizzeria/PizzeriaClientApp/Program.cs +++ b/Pizzeria/PizzeriaClientApp/Program.cs @@ -8,9 +8,9 @@ var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { - app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); + app.UseExceptionHandler("/Home/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } app.UseHttpsRedirection(); @@ -21,7 +21,7 @@ app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( - name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); diff --git a/Pizzeria/PizzeriaClientApp/Properties/launchSettings.json b/Pizzeria/PizzeriaClientApp/Properties/launchSettings.json index c862244..6339452 100644 --- a/Pizzeria/PizzeriaClientApp/Properties/launchSettings.json +++ b/Pizzeria/PizzeriaClientApp/Properties/launchSettings.json @@ -3,8 +3,8 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:28755", - "sslPort": 44389 + "applicationUrl": "http://localhost:59663", + "sslPort": 44301 } }, "profiles": { @@ -12,7 +12,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:7056;http://localhost:5138", + "applicationUrl": "https://localhost:7132;http://localhost:5220", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Pizzeria/PizzeriaClientApp/appsettings.json b/Pizzeria/PizzeriaClientApp/appsettings.json index f8a6772..51c9463 100644 --- a/Pizzeria/PizzeriaClientApp/appsettings.json +++ b/Pizzeria/PizzeriaClientApp/appsettings.json @@ -6,5 +6,5 @@ } }, "AllowedHosts": "*", - "IPAddress": "http://localhost:5104/" + "IPAddress": "http://localhost:5129/" } diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240403141650_InitClient.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240403141650_InitClient.cs deleted file mode 100644 index 648a0a9..0000000 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240403141650_InitClient.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace PizzeriaDatabaseImplement.Migrations -{ - /// - public partial class InitClient : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "ClientId", - table: "Orders", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.CreateTable( - name: "Clients", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Clients", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ClientId", - table: "Orders", - column: "ClientId"); - - 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_Orders_Clients_ClientId", - table: "Orders"); - - migrationBuilder.DropTable( - name: "Clients"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ClientId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ClientId", - table: "Orders"); - } - } -} diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240403141650_InitClient.Designer.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121638_InitMigration.Designer.cs similarity index 98% rename from Pizzeria/PizzeriaDatabaseImplement/Migrations/20240403141650_InitClient.Designer.cs rename to Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121638_InitMigration.Designer.cs index 93d6bc6..d04beac 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240403141650_InitClient.Designer.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121638_InitMigration.Designer.cs @@ -12,8 +12,8 @@ using PizzeriaDatabaseImplement; namespace PizzeriaDatabaseImplement.Migrations { [DbContext(typeof(PizzeriaDatabase))] - [Migration("20240403141650_InitClient")] - partial class InitClient + [Migration("20240407121638_InitMigration")] + partial class InitMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240309113549_InitMigration.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121638_InitMigration.cs similarity index 78% rename from Pizzeria/PizzeriaDatabaseImplement/Migrations/20240309113549_InitMigration.cs rename to Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121638_InitMigration.cs index f598a51..2ca426a 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240309113549_InitMigration.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121638_InitMigration.cs @@ -5,10 +5,27 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace PizzeriaDatabaseImplement.Migrations { + /// public partial class InitMigration : Migration { + /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Components", columns: table => new @@ -43,6 +60,7 @@ namespace PizzeriaDatabaseImplement.Migrations { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), + ClientId = table.Column(type: "int", nullable: false), PizzaId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), @@ -53,6 +71,12 @@ namespace PizzeriaDatabaseImplement.Migrations 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); table.ForeignKey( name: "FK_Orders_Pizzas_PizzaId", column: x => x.PizzaId, @@ -88,6 +112,11 @@ namespace PizzeriaDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_PizzaId", table: "Orders", @@ -104,6 +133,7 @@ namespace PizzeriaDatabaseImplement.Migrations column: "PizzaId"); } + /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( @@ -112,6 +142,9 @@ namespace PizzeriaDatabaseImplement.Migrations migrationBuilder.DropTable( name: "PizzaComponents"); + migrationBuilder.DropTable( + name: "Clients"); + migrationBuilder.DropTable( name: "Components"); diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240309113549_InitMigration.Designer.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121716_ClientMigration.Designer.cs similarity index 75% rename from Pizzeria/PizzeriaDatabaseImplement/Migrations/20240309113549_InitMigration.Designer.cs rename to Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121716_ClientMigration.Designer.cs index 49d4313..ac4cc59 100644 --- a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240309113549_InitMigration.Designer.cs +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121716_ClientMigration.Designer.cs @@ -12,17 +12,43 @@ using PizzeriaDatabaseImplement; namespace PizzeriaDatabaseImplement.Migrations { [DbContext(typeof(PizzeriaDatabase))] - [Migration("20240309113549_InitMigration")] - partial class InitMigration + [Migration("20240407121716_ClientMigration")] + partial class ClientMigration { + /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "6.0.27") + .HasAnnotation("ProductVersion", "7.0.3") .HasAnnotation("Relational:MaxIdentifierLength", 128); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PizzeriaDatabaseImplement.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("PizzeriaDatabaseImplement.Models.Component", b => { @@ -30,7 +56,7 @@ namespace PizzeriaDatabaseImplement.Migrations .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("ComponentName") .IsRequired() @@ -50,7 +76,10 @@ namespace PizzeriaDatabaseImplement.Migrations .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); b.Property("Count") .HasColumnType("int"); @@ -72,6 +101,8 @@ namespace PizzeriaDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("ClientId"); + b.HasIndex("PizzaId"); b.ToTable("Orders"); @@ -83,7 +114,7 @@ namespace PizzeriaDatabaseImplement.Migrations .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("PizzaName") .IsRequired() @@ -103,7 +134,7 @@ namespace PizzeriaDatabaseImplement.Migrations .ValueGeneratedOnAdd() .HasColumnType("int"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("ComponentId") .HasColumnType("int"); @@ -125,12 +156,20 @@ namespace PizzeriaDatabaseImplement.Migrations modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b => { + b.HasOne("PizzeriaDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza") .WithMany("Orders") .HasForeignKey("PizzaId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + b.Navigation("Pizza"); }); @@ -153,6 +192,11 @@ namespace PizzeriaDatabaseImplement.Migrations b.Navigation("Pizza"); }); + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b => { b.Navigation("PizzaComponents"); diff --git a/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121716_ClientMigration.cs b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121716_ClientMigration.cs new file mode 100644 index 0000000..e22ff07 --- /dev/null +++ b/Pizzeria/PizzeriaDatabaseImplement/Migrations/20240407121716_ClientMigration.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PizzeriaDatabaseImplement.Migrations +{ + /// + public partial class ClientMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs b/Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs index 95d1348..51fdd6a 100644 --- a/Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs +++ b/Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs @@ -6,64 +6,64 @@ using PizzeriaContracts.ViewModels; namespace PizzeriaRestApi.Controllers { - [Route("api/[controller]/[action]")] - [ApiController] - public class ClientController : Controller - { - private readonly ILogger _logger; + [Route("api/[controller]/[action]")] + [ApiController] + public class ClientController : Controller + { + private readonly ILogger _logger; - private readonly IClientLogic _logic; + private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) - { - _logger = logger; - _logic = logic; - } + public ClientController(IClientLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } - [HttpGet] - public ClientViewModel? Login(string login, string password) - { - try - { - return _logic.ReadElement(new ClientSearchModel - { - Email = login, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } + [HttpGet] + public ClientViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ClientSearchModel + { + Email = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } - [HttpPost] - public void Register(ClientBindingModel model) - { - try - { - _logic.Create(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка регистрации"); - throw; - } - } + [HttpPost] + public void Register(ClientBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } - [HttpPost] - public void UpdateData(ClientBindingModel model) - { - try - { - _logic.Update(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка обновления данных"); - throw; - } - } - } + [HttpPost] + public void UpdateData(ClientBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } } diff --git a/Pizzeria/PizzeriaRestApi/Program.cs b/Pizzeria/PizzeriaRestApi/Program.cs index 25b07ec..9a12dc7 100644 --- a/Pizzeria/PizzeriaRestApi/Program.cs +++ b/Pizzeria/PizzeriaRestApi/Program.cs @@ -23,7 +23,7 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "PizzeriaRestApi", Version = "v1" }); + c.SwaggerDoc("v1", new OpenApiInfo { Title = "PizzeriaRestApi", Version = "v1" }); }); var app = builder.Build(); @@ -31,8 +31,8 @@ var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PizzeriaRestApi v1")); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PizzeriaRestApi v1")); } app.UseHttpsRedirection(); diff --git a/Pizzeria/PizzeriaRestApi/Properties/launchSettings.json b/Pizzeria/PizzeriaRestApi/Properties/launchSettings.json index 2352a59..86d099b 100644 --- a/Pizzeria/PizzeriaRestApi/Properties/launchSettings.json +++ b/Pizzeria/PizzeriaRestApi/Properties/launchSettings.json @@ -4,8 +4,8 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:47639", - "sslPort": 44347 + "applicationUrl": "http://localhost:10859", + "sslPort": 44324 } }, "profiles": { @@ -14,7 +14,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:7075;http://localhost:5104", + "applicationUrl": "https://localhost:7043;http://localhost:5129", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/Pizzeria/PizzeriaView/FormMain.cs b/Pizzeria/PizzeriaView/FormMain.cs index caa88c9..a5737a5 100644 --- a/Pizzeria/PizzeriaView/FormMain.cs +++ b/Pizzeria/PizzeriaView/FormMain.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using Pizzeria; using PizzeriaContracts.BindingModels; using PizzeriaContracts.BusinessLogicsContracts;