From c983d6aa31ffaf68a5d3cad1a20acb261b91ee9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B0=D1=82=D1=8C=D1=8F=D0=BD=D0=B0=20=D0=90=D1=80?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=D0=BE=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Wed, 17 May 2023 02:04:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=BE=D1=80=D0=BC=20=D0=B2=D1=8B=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BeautySalon/FormCreateVisit.Designer.cs | 45 +++-------- BeautySalon/FormCreateVisit.cs | 53 ++++++------- BeautySalon/FormMain.cs | 2 - BeautySalonDataModels/Models/IVisitModel.cs | 1 - .../BeautySalonDatabase.cs | 2 +- .../BeautySalonDatabaseImplement.csproj | 1 + .../Implements/MasterStorage.cs | 11 +-- .../Implements/ServiceStorage.cs | 3 +- .../Implements/VisitStorage.cs | 3 - ... 20230516215849_InitialCreate.Designer.cs} | 76 +++++++++---------- ...ate.cs => 20230516215849_InitialCreate.cs} | 59 +++++++------- .../BeautySalonDatabaseModelSnapshot.cs | 74 ++++++++---------- BeautySalonDatabaseImplement/Models/Visit.cs | 7 -- .../BindingModels/VisitBindingModel.cs | 2 - .../ViewModels/VisitViewModel.cs | 3 - 15 files changed, 137 insertions(+), 205 deletions(-) rename BeautySalonDatabaseImplement/Migrations/{20230513191649_InitialCreate.Designer.cs => 20230516215849_InitialCreate.Designer.cs} (71%) rename BeautySalonDatabaseImplement/Migrations/{20230513191649_InitialCreate.cs => 20230516215849_InitialCreate.cs} (64%) diff --git a/BeautySalon/FormCreateVisit.Designer.cs b/BeautySalon/FormCreateVisit.Designer.cs index c7d23af..341c8f7 100644 --- a/BeautySalon/FormCreateVisit.Designer.cs +++ b/BeautySalon/FormCreateVisit.Designer.cs @@ -28,9 +28,7 @@ /// private void InitializeComponent() { - this.labelMaster = new System.Windows.Forms.Label(); this.labelSum = new System.Windows.Forms.Label(); - this.comboBoxMaster = new System.Windows.Forms.ComboBox(); this.textBoxSum = new System.Windows.Forms.TextBox(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); @@ -42,38 +40,18 @@ this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); this.SuspendLayout(); // - // labelMaster - // - this.labelMaster.AutoSize = true; - this.labelMaster.Location = new System.Drawing.Point(12, 44); - this.labelMaster.Name = "labelMaster"; - this.labelMaster.Size = new System.Drawing.Size(51, 15); - this.labelMaster.TabIndex = 0; - this.labelMaster.Text = "Мастер:"; - // // labelSum // this.labelSum.AutoSize = true; - this.labelSum.Location = new System.Drawing.Point(11, 102); + this.labelSum.Location = new System.Drawing.Point(11, 73); this.labelSum.Name = "labelSum"; this.labelSum.Size = new System.Drawing.Size(48, 15); this.labelSum.TabIndex = 2; this.labelSum.Text = "Сумма:"; // - // comboBoxMaster - // - this.comboBoxMaster.BackColor = System.Drawing.SystemColors.Window; - this.comboBoxMaster.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxMaster.FormattingEnabled = true; - this.comboBoxMaster.Location = new System.Drawing.Point(93, 41); - this.comboBoxMaster.Name = "comboBoxMaster"; - this.comboBoxMaster.Size = new System.Drawing.Size(238, 23); - this.comboBoxMaster.TabIndex = 3; - this.comboBoxMaster.SelectedIndexChanged += new System.EventHandler(this.ComboBoxMaster_SelectedIndexChanged); - // // textBoxSum // - this.textBoxSum.Location = new System.Drawing.Point(93, 99); + this.textBoxSum.Location = new System.Drawing.Point(93, 70); this.textBoxSum.Name = "textBoxSum"; this.textBoxSum.ReadOnly = true; this.textBoxSum.Size = new System.Drawing.Size(238, 23); @@ -81,7 +59,7 @@ // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(175, 170); + this.buttonSave.Location = new System.Drawing.Point(175, 141); this.buttonSave.Name = "buttonSave"; this.buttonSave.Size = new System.Drawing.Size(75, 23); this.buttonSave.TabIndex = 6; @@ -91,7 +69,7 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(256, 170); + this.buttonCancel.Location = new System.Drawing.Point(256, 141); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 7; @@ -124,7 +102,7 @@ this.comboBoxService.BackColor = System.Drawing.SystemColors.Window; this.comboBoxService.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxService.FormattingEnabled = true; - this.comboBoxService.Location = new System.Drawing.Point(93, 70); + this.comboBoxService.Location = new System.Drawing.Point(93, 41); this.comboBoxService.Name = "comboBoxService"; this.comboBoxService.Size = new System.Drawing.Size(238, 23); this.comboBoxService.TabIndex = 11; @@ -133,7 +111,7 @@ // labelService // this.labelService.AutoSize = true; - this.labelService.Location = new System.Drawing.Point(11, 73); + this.labelService.Location = new System.Drawing.Point(11, 44); this.labelService.Name = "labelService"; this.labelService.Size = new System.Drawing.Size(47, 15); this.labelService.TabIndex = 10; @@ -142,7 +120,7 @@ // labelDate // this.labelDate.AutoSize = true; - this.labelDate.Location = new System.Drawing.Point(12, 134); + this.labelDate.Location = new System.Drawing.Point(12, 105); this.labelDate.Name = "labelDate"; this.labelDate.Size = new System.Drawing.Size(35, 15); this.labelDate.TabIndex = 12; @@ -150,7 +128,7 @@ // // dateTimePicker // - this.dateTimePicker.Location = new System.Drawing.Point(93, 128); + this.dateTimePicker.Location = new System.Drawing.Point(93, 99); this.dateTimePicker.Name = "dateTimePicker"; this.dateTimePicker.Size = new System.Drawing.Size(238, 23); this.dateTimePicker.TabIndex = 13; @@ -159,7 +137,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(346, 206); + this.ClientSize = new System.Drawing.Size(346, 177); this.Controls.Add(this.dateTimePicker); this.Controls.Add(this.labelDate); this.Controls.Add(this.comboBoxService); @@ -169,9 +147,7 @@ this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.textBoxSum); - this.Controls.Add(this.comboBoxMaster); this.Controls.Add(this.labelSum); - this.Controls.Add(this.labelMaster); this.Name = "FormCreateVisit"; this.Text = "Посещение"; this.Load += new System.EventHandler(this.FormCreateVisit_Load); @@ -181,10 +157,7 @@ } #endregion - - private Label labelMaster; private Label labelSum; - private ComboBox comboBoxMaster; private TextBox textBoxSum; private Button buttonSave; private Button buttonCancel; diff --git a/BeautySalon/FormCreateVisit.cs b/BeautySalon/FormCreateVisit.cs index 6754f2d..d8d35b4 100644 --- a/BeautySalon/FormCreateVisit.cs +++ b/BeautySalon/FormCreateVisit.cs @@ -10,16 +10,14 @@ namespace BeautySalon private readonly ILogger _logger; private readonly IServiceLogic _logicS; private readonly IClientLogic _logicC; - private readonly IMasterLogic _logicM; private readonly IVisitLogic _logicV; - public FormCreateVisit(ILogger logger, IVisitLogic logicV, IServiceLogic logicS, IClientLogic logicC, IMasterLogic logicM) + public FormCreateVisit(ILogger logger, IVisitLogic logicV, IServiceLogic logicS, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicS = logicS; _logicV = logicV; _logicC = logicC; - _logicM = logicM; LoadData(); } @@ -58,24 +56,7 @@ namespace BeautySalon { _logger.LogError(ex, "Ошибка загрузки списка клиентов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - _logger.LogInformation("Загрузка мастеров для заказа"); - try - { - var list = _logicM.ReadList(null); - if (list != null) - { - comboBoxMaster.DisplayMember = "MasterFIO"; - comboBoxMaster.ValueMember = "Id"; - comboBoxMaster.DataSource = list; - comboBoxMaster.SelectedItem = null; - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки списка мастеров"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + } } private void FormCreateVisit_Load(object sender, EventArgs e) @@ -86,7 +67,7 @@ namespace BeautySalon private void CalcSum() { - if (comboBoxService.SelectedValue != null) + if (comboBoxService.SelectedValue != null && comboBoxClient.SelectedValue != null) { try { @@ -112,6 +93,23 @@ namespace BeautySalon private void ComboBoxMaster_SelectedIndexChanged(object sender, EventArgs e) { + _logger.LogInformation("Загрузка услуг для мастера"); + try + { + var list = _logicS.ReadList(null); + if (list != null) + { + comboBoxService.DisplayMember = "ServiceName"; + comboBoxService.ValueMember = "Id"; + comboBoxService.DataSource = list; + comboBoxService.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка мастеров"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void ComboBoxService_SelectedIndexChanged(object sender, EventArgs e) @@ -130,24 +128,17 @@ namespace BeautySalon { MessageBox.Show("Выберите услугу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; - } - if (comboBoxMaster.SelectedValue == null) - { - MessageBox.Show("Выберите мастера", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + } _logger.LogInformation("Создание посещения"); try { var operationResult = _logicV.Create(new VisitBindingModel { - MasterId = Convert.ToInt32(comboBoxMaster.SelectedValue), - MasterFIO = comboBoxMaster.Text, ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), ClientFIO = comboBoxClient.Text, ServiceId = Convert.ToInt32(comboBoxService.SelectedValue), ServiceName = comboBoxService.Text, - DateOfVisit = dateTimePicker.Value, + DateOfVisit = dateTimePicker.Value.ToUniversalTime(), Sum = Convert.ToDouble(textBoxSum.Text) }); if (!operationResult) diff --git a/BeautySalon/FormMain.cs b/BeautySalon/FormMain.cs index 8cf9beb..a00c8e3 100644 --- a/BeautySalon/FormMain.cs +++ b/BeautySalon/FormMain.cs @@ -72,8 +72,6 @@ namespace BeautySalon dataGridView.DataSource = list; dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["MasterId"].Visible = false; - dataGridView.Columns["MasterFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ServiceId"].Visible = false; dataGridView.Columns["ServiceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["DateOfVisit"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; diff --git a/BeautySalonDataModels/Models/IVisitModel.cs b/BeautySalonDataModels/Models/IVisitModel.cs index e3c01b6..4ca0e15 100644 --- a/BeautySalonDataModels/Models/IVisitModel.cs +++ b/BeautySalonDataModels/Models/IVisitModel.cs @@ -4,7 +4,6 @@ { DateTime DateOfVisit { get; } int ClientId { get; } - int MasterId { get; } int ServiceId { get; } double Sum { get; } } diff --git a/BeautySalonDatabaseImplement/BeautySalonDatabase.cs b/BeautySalonDatabaseImplement/BeautySalonDatabase.cs index bd8188f..34adb1e 100644 --- a/BeautySalonDatabaseImplement/BeautySalonDatabase.cs +++ b/BeautySalonDatabaseImplement/BeautySalonDatabase.cs @@ -9,7 +9,7 @@ namespace BeautySalonDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-IHH1ICP\SQLEXPRESS;Initial Catalog=BeautySalonDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseNpgsql("Host=192.168.56.102;Port=5432;Database=BeautySalonDatabase;Username=postgres;Password=12345"); } base.OnConfiguring(optionsBuilder); } diff --git a/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj b/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj index 4caae15..f097722 100644 --- a/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj +++ b/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj @@ -13,6 +13,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/BeautySalonDatabaseImplement/Implements/MasterStorage.cs b/BeautySalonDatabaseImplement/Implements/MasterStorage.cs index 0d57c0a..0c3ed96 100644 --- a/BeautySalonDatabaseImplement/Implements/MasterStorage.cs +++ b/BeautySalonDatabaseImplement/Implements/MasterStorage.cs @@ -2,6 +2,7 @@ using BeautySalonContracts.SearchModels; using BeautySalonContracts.StoragesContracts; using BeautySalonContracts.ViewModels; +using BeautySalonDatabaseImplement; using BeautySalonDatabaseImplement.Models; using Microsoft.EntityFrameworkCore; @@ -68,17 +69,17 @@ namespace BeautySalonDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var engine = context.Masters.FirstOrDefault(rec => + var master = context.Masters.FirstOrDefault(rec => rec.Id == model.Id); - if (engine == null) + if (master == null) { return null; } - engine.Update(model); + master.Update(model); context.SaveChanges(); - engine.UpdateServices(context, model); + master.UpdateServices(context, model); transaction.Commit(); - return engine.GetViewModel; + return master.GetViewModel; } catch { diff --git a/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs b/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs index a3967df..8f7c594 100644 --- a/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs +++ b/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs @@ -2,6 +2,7 @@ using BeautySalonContracts.SearchModels; using BeautySalonContracts.StoragesContracts; using BeautySalonContracts.ViewModels; +using BeautySalonDatabaseImplement; using BeautySalonDatabaseImplement.Models; using System.ServiceModel; @@ -79,4 +80,4 @@ namespace BeautySalonDatabaseImplement.Implements return null; } } -} +} \ No newline at end of file diff --git a/BeautySalonDatabaseImplement/Implements/VisitStorage.cs b/BeautySalonDatabaseImplement/Implements/VisitStorage.cs index 6bfcca5..34e53bf 100644 --- a/BeautySalonDatabaseImplement/Implements/VisitStorage.cs +++ b/BeautySalonDatabaseImplement/Implements/VisitStorage.cs @@ -13,7 +13,6 @@ namespace BeautySalonDatabaseImplement.Implements { using var context = new BeautySalonDatabase(); var element = context.Visits - .Include(x => x.Master) .Include(x => x.Client) .Include(x => x.Service) .FirstOrDefault(rec => rec.Id == model.Id); @@ -55,7 +54,6 @@ namespace BeautySalonDatabaseImplement.Implements using var context = new BeautySalonDatabase(); return context.Visits .Include(x => x.Service) - .Include(x => x.Master) .Include(x => x.Client) .Select(x => x.GetViewModel).ToList(); } @@ -72,7 +70,6 @@ namespace BeautySalonDatabaseImplement.Implements context.SaveChanges(); return context.Visits .Include(x => x.Service) - .Include(x => x.Master) .Include(x => x.Client) .FirstOrDefault(x => x.Id == newVisit.Id) ?.GetViewModel; diff --git a/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.Designer.cs b/BeautySalonDatabaseImplement/Migrations/20230516215849_InitialCreate.Designer.cs similarity index 71% rename from BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.Designer.cs rename to BeautySalonDatabaseImplement/Migrations/20230516215849_InitialCreate.Designer.cs index b479bc5..390df22 100644 --- a/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.Designer.cs +++ b/BeautySalonDatabaseImplement/Migrations/20230516215849_InitialCreate.Designer.cs @@ -3,16 +3,16 @@ using System; using BeautySalonDatabaseImplement; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace BeautySalonDatabaseImplement.Migrations { [DbContext(typeof(BeautySalonDatabase))] - [Migration("20230513191649_InitialCreate")] + [Migration("20230516215849_InitialCreate")] partial class InitialCreate { /// @@ -21,25 +21,25 @@ namespace BeautySalonDatabaseImplement.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Client", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClientFIO") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("PhoneNumber") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -50,16 +50,16 @@ namespace BeautySalonDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("MasterFIO") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Wage") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -70,18 +70,18 @@ namespace BeautySalonDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("MasterId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("ServiceId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Wage") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -96,19 +96,19 @@ namespace BeautySalonDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Cost") - .HasColumnType("float"); + .HasColumnType("double precision"); b.Property("ServiceName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Time") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -119,36 +119,32 @@ namespace BeautySalonDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClientFIO") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("ClientId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("DateOfVisit") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); - b.Property("MasterFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("MasterId") - .HasColumnType("int"); + b.Property("MasterId") + .HasColumnType("integer"); b.Property("ServiceId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("ServiceName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Sum") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -188,11 +184,9 @@ namespace BeautySalonDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master") + b.HasOne("BeautySalonDatabaseImplement.Models.Master", null) .WithMany("Visits") - .HasForeignKey("MasterId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("MasterId"); b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service") .WithMany() @@ -202,8 +196,6 @@ namespace BeautySalonDatabaseImplement.Migrations b.Navigation("Client"); - b.Navigation("Master"); - b.Navigation("Service"); }); diff --git a/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.cs b/BeautySalonDatabaseImplement/Migrations/20230516215849_InitialCreate.cs similarity index 64% rename from BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.cs rename to BeautySalonDatabaseImplement/Migrations/20230516215849_InitialCreate.cs index bc66a5c..e50ada1 100644 --- a/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.cs +++ b/BeautySalonDatabaseImplement/Migrations/20230516215849_InitialCreate.cs @@ -1,5 +1,6 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -15,10 +16,10 @@ namespace BeautySalonDatabaseImplement.Migrations 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), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ClientFIO = table.Column(type: "text", nullable: false), + PhoneNumber = table.Column(type: "text", nullable: false) }, constraints: table => { @@ -29,10 +30,10 @@ namespace BeautySalonDatabaseImplement.Migrations name: "Masters", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - MasterFIO = table.Column(type: "nvarchar(max)", nullable: false), - Wage = table.Column(type: "float", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + MasterFIO = table.Column(type: "text", nullable: false), + Wage = table.Column(type: "double precision", nullable: false) }, constraints: table => { @@ -43,11 +44,11 @@ namespace BeautySalonDatabaseImplement.Migrations name: "Services", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ServiceName = table.Column(type: "nvarchar(max)", nullable: false), - Cost = table.Column(type: "float", nullable: false), - Time = table.Column(type: "float", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ServiceName = table.Column(type: "text", nullable: false), + Cost = table.Column(type: "double precision", nullable: false), + Time = table.Column(type: "double precision", nullable: false) }, constraints: table => { @@ -58,11 +59,11 @@ namespace BeautySalonDatabaseImplement.Migrations name: "MasterServices", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - MasterId = table.Column(type: "int", nullable: false), - ServiceId = table.Column(type: "int", nullable: false), - Wage = table.Column(type: "float", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + MasterId = table.Column(type: "integer", nullable: false), + ServiceId = table.Column(type: "integer", nullable: false), + Wage = table.Column(type: "double precision", nullable: false) }, constraints: table => { @@ -85,16 +86,15 @@ namespace BeautySalonDatabaseImplement.Migrations name: "Visits", columns: table => new { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - DateOfVisit = table.Column(type: "datetime2", nullable: false), - ClientId = table.Column(type: "int", nullable: false), - MasterId = table.Column(type: "int", nullable: false), - ServiceId = table.Column(type: "int", nullable: false), - ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), - MasterFIO = table.Column(type: "nvarchar(max)", nullable: false), - ServiceName = table.Column(type: "nvarchar(max)", nullable: false), - Sum = table.Column(type: "float", nullable: false) + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + DateOfVisit = table.Column(type: "timestamp with time zone", nullable: false), + ClientId = table.Column(type: "integer", nullable: false), + ServiceId = table.Column(type: "integer", nullable: false), + ClientFIO = table.Column(type: "text", nullable: false), + ServiceName = table.Column(type: "text", nullable: false), + Sum = table.Column(type: "double precision", nullable: false), + MasterId = table.Column(type: "integer", nullable: true) }, constraints: table => { @@ -109,8 +109,7 @@ namespace BeautySalonDatabaseImplement.Migrations name: "FK_Visits_Masters_MasterId", column: x => x.MasterId, principalTable: "Masters", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); table.ForeignKey( name: "FK_Visits_Services_ServiceId", column: x => x.ServiceId, diff --git a/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs b/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs index 5757101..4762521 100644 --- a/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs +++ b/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs @@ -3,8 +3,8 @@ using System; using BeautySalonDatabaseImplement; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -18,25 +18,25 @@ namespace BeautySalonDatabaseImplement.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Client", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClientFIO") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("PhoneNumber") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.HasKey("Id"); @@ -47,16 +47,16 @@ namespace BeautySalonDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("MasterFIO") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Wage") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -67,18 +67,18 @@ namespace BeautySalonDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("MasterId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("ServiceId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("Wage") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -93,19 +93,19 @@ namespace BeautySalonDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("Cost") - .HasColumnType("float"); + .HasColumnType("double precision"); b.Property("ServiceName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Time") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -116,36 +116,32 @@ namespace BeautySalonDatabaseImplement.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClientFIO") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("ClientId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("DateOfVisit") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone"); - b.Property("MasterFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("MasterId") - .HasColumnType("int"); + b.Property("MasterId") + .HasColumnType("integer"); b.Property("ServiceId") - .HasColumnType("int"); + .HasColumnType("integer"); b.Property("ServiceName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text"); b.Property("Sum") - .HasColumnType("float"); + .HasColumnType("double precision"); b.HasKey("Id"); @@ -185,11 +181,9 @@ namespace BeautySalonDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master") + b.HasOne("BeautySalonDatabaseImplement.Models.Master", null) .WithMany("Visits") - .HasForeignKey("MasterId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("MasterId"); b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service") .WithMany() @@ -199,8 +193,6 @@ namespace BeautySalonDatabaseImplement.Migrations b.Navigation("Client"); - b.Navigation("Master"); - b.Navigation("Service"); }); diff --git a/BeautySalonDatabaseImplement/Models/Visit.cs b/BeautySalonDatabaseImplement/Models/Visit.cs index 9ec2119..3f124ab 100644 --- a/BeautySalonDatabaseImplement/Models/Visit.cs +++ b/BeautySalonDatabaseImplement/Models/Visit.cs @@ -11,15 +11,12 @@ namespace BeautySalonDatabaseImplement.Models [Required] public DateTime DateOfVisit { get; private set; } public int ClientId { get; private set; } - public int MasterId { get; private set; } public int ServiceId { get; private set; } public string ClientFIO { get; set; } = string.Empty; - public string MasterFIO { get; set; } = string.Empty; public string ServiceName { get; set; } = string.Empty; [Required] public double Sum { get; private set; } public Client Client { get; set; } - public virtual Master Master { get; set; } public virtual Service Service { get; set; } public static Visit? Create(VisitBindingModel? model) @@ -34,8 +31,6 @@ namespace BeautySalonDatabaseImplement.Models Id = model.Id, ClientId = model.ClientId, ClientFIO = model.ClientFIO, - MasterId = model.MasterId, - MasterFIO = model.MasterFIO, ServiceId = model.ServiceId, ServiceName = model.ServiceName, Sum = model.Sum, @@ -64,8 +59,6 @@ namespace BeautySalonDatabaseImplement.Models Id = Id, ClientId = ClientId, ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, - MasterId = MasterId, - MasterFIO = context.Masters.FirstOrDefault(x => x.Id == MasterId)?.MasterFIO ?? string.Empty, ServiceId = ServiceId, ServiceName = context.Services.FirstOrDefault(x => x.Id == ServiceId)?.ServiceName ?? string.Empty, Sum = Sum, diff --git a/BeauySalonContracts/BindingModels/VisitBindingModel.cs b/BeauySalonContracts/BindingModels/VisitBindingModel.cs index 10e26a2..abfa391 100644 --- a/BeauySalonContracts/BindingModels/VisitBindingModel.cs +++ b/BeauySalonContracts/BindingModels/VisitBindingModel.cs @@ -7,10 +7,8 @@ namespace BeautySalonContracts.BindingModels public int Id { get; set; } public DateTime DateOfVisit { get; set; } public int ClientId { get; set; } - public int MasterId { get; set; } public int ServiceId { get; set; } public string ClientFIO { get; set; } = string.Empty; - public string MasterFIO { get; set; } = string.Empty; public string ServiceName { get; set; } = string.Empty; public double Sum { get; set; } } diff --git a/BeauySalonContracts/ViewModels/VisitViewModel.cs b/BeauySalonContracts/ViewModels/VisitViewModel.cs index 6b886af..07b5d37 100644 --- a/BeauySalonContracts/ViewModels/VisitViewModel.cs +++ b/BeauySalonContracts/ViewModels/VisitViewModel.cs @@ -11,9 +11,6 @@ namespace BeautySalonContracts.ViewModels public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; - public int MasterId { get; set; } - [DisplayName("Мастер")] - public string MasterFIO { get; set; } = string.Empty; public int ServiceId { get; set; } [DisplayName("Услуга")] public string ServiceName { get; set; } = string.Empty;