diff --git a/BeautySalon/FormClients.cs b/BeautySalon/FormClients.cs index 233ef4b..549cbbd 100644 --- a/BeautySalon/FormClients.cs +++ b/BeautySalon/FormClients.cs @@ -25,6 +25,7 @@ namespace BeautySalon dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PhoneNumber"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка клиентов"); } diff --git a/BeautySalon/FormCreateVisit.cs b/BeautySalon/FormCreateVisit.cs index eef55a9..6754f2d 100644 --- a/BeautySalon/FormCreateVisit.cs +++ b/BeautySalon/FormCreateVisit.cs @@ -9,13 +9,17 @@ 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) + public FormCreateVisit(ILogger logger, IVisitLogic logicV, IServiceLogic logicS, IClientLogic logicC, IMasterLogic logicM) { InitializeComponent(); _logger = logger; _logicS = logicS; _logicV = logicV; + _logicC = logicC; + _logicM = logicM; LoadData(); } @@ -27,7 +31,41 @@ namespace BeautySalon var list = _logicS.ReadList(null); if (list != null) { - comboBoxMaster.DisplayMember = "ServiceName"; + 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); + } + _logger.LogInformation("Загрузка клиентов для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + } + catch (Exception ex) + { + _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; @@ -35,7 +73,7 @@ namespace BeautySalon } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки списка услуг"); + _logger.LogError(ex, "Ошибка загрузки списка мастеров"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -70,12 +108,10 @@ namespace BeautySalon private void ComboBoxClient_SelectedIndexChanged(object sender, EventArgs e) { - CalcSum(); } private void ComboBoxMaster_SelectedIndexChanged(object sender, EventArgs e) { - CalcSum(); } private void ComboBoxService_SelectedIndexChanged(object sender, EventArgs e) diff --git a/BeautySalon/FormMaster.Designer.cs b/BeautySalon/FormMaster.Designer.cs index 2325e28..cfb2b28 100644 --- a/BeautySalon/FormMaster.Designer.cs +++ b/BeautySalon/FormMaster.Designer.cs @@ -35,14 +35,14 @@ this.buttonDel = new System.Windows.Forms.Button(); this.buttonUpd = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonAdd = new System.Windows.Forms.Button(); - this.labelWorkingHours = new System.Windows.Forms.Label(); - this.buttonSave = new System.Windows.Forms.Button(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.textBoxWorkingHours = new System.Windows.Forms.TextBox(); this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.NameService = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Time = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.labelWage = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.textBoxWage = new System.Windows.Forms.TextBox(); this.groupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -58,7 +58,7 @@ // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(123, 24); + this.textBoxName.Location = new System.Drawing.Point(138, 24); this.textBoxName.Name = "textBoxName"; this.textBoxName.Size = new System.Drawing.Size(301, 23); this.textBoxName.TabIndex = 1; @@ -122,6 +122,24 @@ this.dataGridView.Size = new System.Drawing.Size(398, 270); this.dataGridView.TabIndex = 1; // + // ID + // + this.ID.HeaderText = "ID"; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // NameService + // + this.NameService.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.NameService.HeaderText = "Услуга"; + this.NameService.Name = "NameService"; + // + // Time + // + this.Time.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Time.HeaderText = "Время на услугу, час(ов)"; + this.Time.Name = "Time"; + // // buttonAdd // this.buttonAdd.Location = new System.Drawing.Point(438, 36); @@ -132,14 +150,14 @@ this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); // - // labelWorkingHours + // labelWage // - this.labelWorkingHours.AutoSize = true; - this.labelWorkingHours.Location = new System.Drawing.Point(24, 59); - this.labelWorkingHours.Name = "labelWorkingHours"; - this.labelWorkingHours.Size = new System.Drawing.Size(93, 15); - this.labelWorkingHours.TabIndex = 3; - this.labelWorkingHours.Text = "Рабочее время:"; + this.labelWage.AutoSize = true; + this.labelWage.Location = new System.Drawing.Point(24, 59); + this.labelWage.Name = "labelWage"; + this.labelWage.Size = new System.Drawing.Size(108, 15); + this.labelWage.TabIndex = 3; + this.labelWage.Text = "Заработная плата:"; // // buttonSave // @@ -161,41 +179,23 @@ this.buttonCancel.UseVisualStyleBackColor = true; this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // - // textBoxWorkingHours + // textBoxWage // - this.textBoxWorkingHours.Location = new System.Drawing.Point(123, 53); - this.textBoxWorkingHours.Name = "textBoxWorkingHours"; - this.textBoxWorkingHours.ReadOnly = true; - this.textBoxWorkingHours.Size = new System.Drawing.Size(152, 23); - this.textBoxWorkingHours.TabIndex = 7; - // - // ID - // - this.ID.HeaderText = "ID"; - this.ID.Name = "ID"; - this.ID.Visible = false; - // - // NameService - // - this.NameService.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.NameService.HeaderText = "Услуга"; - this.NameService.Name = "NameService"; - // - // Time - // - this.Time.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Time.HeaderText = "Время на услугу, час(ов)"; - this.Time.Name = "Time"; + this.textBoxWage.Location = new System.Drawing.Point(138, 56); + this.textBoxWage.Name = "textBoxWage"; + this.textBoxWage.ReadOnly = true; + this.textBoxWage.Size = new System.Drawing.Size(152, 23); + this.textBoxWage.TabIndex = 7; // // FormMaster // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(575, 444); - this.Controls.Add(this.textBoxWorkingHours); + this.Controls.Add(this.textBoxWage); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.labelWorkingHours); + this.Controls.Add(this.labelWage); this.Controls.Add(this.groupBox); this.Controls.Add(this.textBoxName); this.Controls.Add(this.labelName); @@ -218,12 +218,12 @@ private Button buttonUpd; private DataGridView dataGridView; private Button buttonAdd; - private Label labelWorkingHours; + private Label labelWage; private Button buttonSave; private Button buttonCancel; private DataGridViewTextBoxColumn ID; private DataGridViewTextBoxColumn NameService; private DataGridViewTextBoxColumn Time; - private TextBox textBoxWorkingHours; + private TextBox textBoxWage; } } \ No newline at end of file diff --git a/BeautySalon/FormMaster.cs b/BeautySalon/FormMaster.cs index 5b20cef..0bf87ff 100644 --- a/BeautySalon/FormMaster.cs +++ b/BeautySalon/FormMaster.cs @@ -11,14 +11,14 @@ namespace BeautySalon private readonly ILogger _logger; private readonly IMasterLogic _logic; private int? _id; - private Dictionary _masterServices; + private Dictionary _masterServices; public int Id { set { _id = value; } } public FormMaster(ILogger logger, IMasterLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; - _masterServices = new Dictionary(); + _masterServices = new Dictionary(); } private void LoadData() @@ -33,7 +33,7 @@ namespace BeautySalon { dataGridView.Rows.Add(new object[] { ec.Key, ec.Value.Item1.ServiceName, ec.Value.Item2 }); } - textBoxWorkingHours.Text = CalcWorkingHours().ToString(); + textBoxWage.Text = CalcWage().ToString(); } } catch (Exception ex) @@ -129,7 +129,7 @@ namespace BeautySalon MessageBox.Show("Заполните услуги", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (string.IsNullOrEmpty(textBoxWorkingHours.Text)) + if (string.IsNullOrEmpty(textBoxWage.Text)) { MessageBox.Show("Заполните рабочее время", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -141,7 +141,7 @@ namespace BeautySalon { Id = _id ?? 0, MasterFIO = textBoxName.Text, - WorkingHours = Convert.ToDouble(textBoxWorkingHours.Text), + Wage = Convert.ToDouble(textBoxWage.Text), MasterServices = _masterServices }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); @@ -177,8 +177,8 @@ namespace BeautySalon if (view != null) { textBoxName.Text = view.MasterFIO; - textBoxWorkingHours.Text = view.WorkingHours.ToString(); - _masterServices = view.MasterServices ?? new Dictionary(); + textBoxWage.Text = view.Wage.ToString(); + _masterServices = view.MasterServices ?? new Dictionary(); LoadData(); } } @@ -189,14 +189,14 @@ namespace BeautySalon } } } - private double CalcWorkingHours() + private double CalcWage() { - double workingHours = 0; + double price = 0; foreach (var elem in _masterServices) { - workingHours += elem.Value.Item1?.Cost ?? 0; + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); } - return Math.Round(workingHours, 2); + return Math.Round(price * 1.1, 2); } } } diff --git a/BeautySalon/FormMasterService.Designer.cs b/BeautySalon/FormMasterService.Designer.cs index 5664950..785e982 100644 --- a/BeautySalon/FormMasterService.Designer.cs +++ b/BeautySalon/FormMasterService.Designer.cs @@ -48,7 +48,7 @@ // labelTime // this.labelTime.AutoSize = true; - this.labelTime.Location = new System.Drawing.Point(23, 60); + this.labelTime.Location = new System.Drawing.Point(23, 51); this.labelTime.Name = "labelTime"; this.labelTime.Size = new System.Drawing.Size(45, 15); this.labelTime.TabIndex = 1; @@ -58,21 +58,21 @@ // this.comboBoxService.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxService.FormattingEnabled = true; - this.comboBoxService.Location = new System.Drawing.Point(119, 19); + this.comboBoxService.Location = new System.Drawing.Point(76, 19); this.comboBoxService.Name = "comboBoxService"; this.comboBoxService.Size = new System.Drawing.Size(248, 23); this.comboBoxService.TabIndex = 2; // // textBoxTime // - this.textBoxTime.Location = new System.Drawing.Point(119, 57); + this.textBoxTime.Location = new System.Drawing.Point(76, 48); this.textBoxTime.Name = "textBoxTime"; this.textBoxTime.Size = new System.Drawing.Size(248, 23); this.textBoxTime.TabIndex = 3; // // buttonSave // - this.buttonSave.Location = new System.Drawing.Point(198, 97); + this.buttonSave.Location = new System.Drawing.Point(168, 82); this.buttonSave.Name = "buttonSave"; this.buttonSave.Size = new System.Drawing.Size(75, 23); this.buttonSave.TabIndex = 4; @@ -82,7 +82,7 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(279, 97); + this.buttonCancel.Location = new System.Drawing.Point(249, 82); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 5; @@ -94,7 +94,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(379, 132); + this.ClientSize = new System.Drawing.Size(347, 117); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.textBoxTime); diff --git a/BeautySalon/FormMasterService.cs b/BeautySalon/FormMasterService.cs index 3b43ad1..dbe1e51 100644 --- a/BeautySalon/FormMasterService.cs +++ b/BeautySalon/FormMasterService.cs @@ -36,9 +36,9 @@ namespace BeautySalon return null; } } - public int Time + public double Time { - get { return Convert.ToInt32(textBoxTime.Text); } + get { return Convert.ToDouble(textBoxTime.Text); } set { textBoxTime.Text = value.ToString(); } } diff --git a/BeautySalon/FormServices.cs b/BeautySalon/FormServices.cs index 3712c8e..bc67518 100644 --- a/BeautySalon/FormServices.cs +++ b/BeautySalon/FormServices.cs @@ -30,6 +30,7 @@ namespace BeautySalon dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["ServiceName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Cost"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка услуг"); } diff --git a/BeautySalonBusinessLogic/BusinessLogics/MasterLogic.cs b/BeautySalonBusinessLogic/BusinessLogics/MasterLogic.cs index 4396541..4b1d9c5 100644 --- a/BeautySalonBusinessLogic/BusinessLogics/MasterLogic.cs +++ b/BeautySalonBusinessLogic/BusinessLogics/MasterLogic.cs @@ -89,11 +89,11 @@ namespace BeautySalonBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет ФИО мастера", nameof(model.MasterFIO)); } - if (string.IsNullOrEmpty(model.Specialization)) + if (model.Wage <= 0) { - throw new ArgumentNullException("Нет специализации мастера", nameof(model.MasterFIO)); + throw new ArgumentNullException("Зарплата должна быть больше 0", nameof(model.Wage)); } - _logger.LogInformation("Master. MasterFIO:{MasterFIO}. Specialization:{ Specialization}. Id: { Id} ", model.MasterFIO, model.Specialization, model.Id); + _logger.LogInformation("Master. MasterFIO:{MasterFIO}. Wage:{ Wage}. Id: { Id} ", model.MasterFIO, model.Wage, model.Id); var element = _masterStorage.GetElement(new MasterSearchModel { MasterFIO = model.MasterFIO diff --git a/BeautySalonDataModels/Models/IMasterModel.cs b/BeautySalonDataModels/Models/IMasterModel.cs index a586d45..659b229 100644 --- a/BeautySalonDataModels/Models/IMasterModel.cs +++ b/BeautySalonDataModels/Models/IMasterModel.cs @@ -3,7 +3,7 @@ public interface IMasterModel : IId { string MasterFIO { get; } - double WorkingHours { get; } - public Dictionary MasterServices { get; } + double Wage { get; } + public Dictionary MasterServices { get; } } } diff --git a/BeautySalonDatabaseImplement/Implements/VisitStorage.cs b/BeautySalonDatabaseImplement/Implements/VisitStorage.cs index bd1641b..6bfcca5 100644 --- a/BeautySalonDatabaseImplement/Implements/VisitStorage.cs +++ b/BeautySalonDatabaseImplement/Implements/VisitStorage.cs @@ -12,7 +12,11 @@ namespace BeautySalonDatabaseImplement.Implements public VisitViewModel? Delete(VisitBindingModel model) { using var context = new BeautySalonDatabase(); - var element = context.Visits.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Visits + .Include(x => x.Master) + .Include(x => x.Client) + .Include(x => x.Service) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Visits.Remove(element); @@ -39,13 +43,21 @@ namespace BeautySalonDatabaseImplement.Implements return new(); } using var context = new BeautySalonDatabase(); - return context.Visits.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Visits + .Where(x => x.ClientId == model.ClientId) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { using var context = new BeautySalonDatabase(); - return context.Visits.Select(x => x.GetViewModel).ToList(); + return context.Visits + .Include(x => x.Service) + .Include(x => x.Master) + .Include(x => x.Client) + .Select(x => x.GetViewModel).ToList(); } public VisitViewModel? Insert(VisitBindingModel model) @@ -58,7 +70,12 @@ namespace BeautySalonDatabaseImplement.Implements using var context = new BeautySalonDatabase(); context.Visits.Add(newVisit); context.SaveChanges(); - return newVisit.GetViewModel; + return context.Visits + .Include(x => x.Service) + .Include(x => x.Master) + .Include(x => x.Client) + .FirstOrDefault(x => x.Id == newVisit.Id) + ?.GetViewModel; } public VisitViewModel? Update(VisitBindingModel model) diff --git a/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.Designer.cs b/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.Designer.cs new file mode 100644 index 0000000..b479bc5 --- /dev/null +++ b/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.Designer.cs @@ -0,0 +1,224 @@ +// +using System; +using BeautySalonDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BeautySalonDatabaseImplement.Migrations +{ + [DbContext(typeof(BeautySalonDatabase))] + [Migration("20230513191649_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MasterFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Wage") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Masters"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MasterId") + .HasColumnType("int"); + + b.Property("ServiceId") + .HasColumnType("int"); + + b.Property("Wage") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("MasterId"); + + b.HasIndex("ServiceId"); + + b.ToTable("MasterServices"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("ServiceName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Time") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Services"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateOfVisit") + .HasColumnType("datetime2"); + + b.Property("MasterFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MasterId") + .HasColumnType("int"); + + b.Property("ServiceId") + .HasColumnType("int"); + + b.Property("ServiceName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("MasterId"); + + b.HasIndex("ServiceId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b => + { + b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master") + .WithMany("Services") + .HasForeignKey("MasterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service") + .WithMany("MasterServices") + .HasForeignKey("ServiceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Master"); + + b.Navigation("Service"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b => + { + b.HasOne("BeautySalonDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master") + .WithMany("Visits") + .HasForeignKey("MasterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service") + .WithMany() + .HasForeignKey("ServiceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Master"); + + b.Navigation("Service"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b => + { + b.Navigation("Services"); + + b.Navigation("Visits"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b => + { + b.Navigation("MasterServices"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.cs b/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.cs new file mode 100644 index 0000000..bc66a5c --- /dev/null +++ b/BeautySalonDatabaseImplement/Migrations/20230513191649_InitialCreate.cs @@ -0,0 +1,167 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BeautySalonDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : 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), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_Masters", x => x.Id); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_Services", x => x.Id); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_MasterServices", x => x.Id); + table.ForeignKey( + name: "FK_MasterServices_Masters_MasterId", + column: x => x.MasterId, + principalTable: "Masters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_MasterServices_Services_ServiceId", + column: x => x.ServiceId, + principalTable: "Services", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_Visits", x => x.Id); + table.ForeignKey( + name: "FK_Visits_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Visits_Masters_MasterId", + column: x => x.MasterId, + principalTable: "Masters", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Visits_Services_ServiceId", + column: x => x.ServiceId, + principalTable: "Services", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_MasterServices_MasterId", + table: "MasterServices", + column: "MasterId"); + + migrationBuilder.CreateIndex( + name: "IX_MasterServices_ServiceId", + table: "MasterServices", + column: "ServiceId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_ClientId", + table: "Visits", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_MasterId", + table: "Visits", + column: "MasterId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_ServiceId", + table: "Visits", + column: "ServiceId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "MasterServices"); + + migrationBuilder.DropTable( + name: "Visits"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Masters"); + + migrationBuilder.DropTable( + name: "Services"); + } + } +} diff --git a/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs b/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs new file mode 100644 index 0000000..5757101 --- /dev/null +++ b/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs @@ -0,0 +1,221 @@ +// +using System; +using BeautySalonDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BeautySalonDatabaseImplement.Migrations +{ + [DbContext(typeof(BeautySalonDatabase))] + partial class BeautySalonDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MasterFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Wage") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Masters"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MasterId") + .HasColumnType("int"); + + b.Property("ServiceId") + .HasColumnType("int"); + + b.Property("Wage") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("MasterId"); + + b.HasIndex("ServiceId"); + + b.ToTable("MasterServices"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("ServiceName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Time") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Services"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateOfVisit") + .HasColumnType("datetime2"); + + b.Property("MasterFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MasterId") + .HasColumnType("int"); + + b.Property("ServiceId") + .HasColumnType("int"); + + b.Property("ServiceName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("MasterId"); + + b.HasIndex("ServiceId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b => + { + b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master") + .WithMany("Services") + .HasForeignKey("MasterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service") + .WithMany("MasterServices") + .HasForeignKey("ServiceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Master"); + + b.Navigation("Service"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b => + { + b.HasOne("BeautySalonDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master") + .WithMany("Visits") + .HasForeignKey("MasterId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service") + .WithMany() + .HasForeignKey("ServiceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Master"); + + b.Navigation("Service"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b => + { + b.Navigation("Services"); + + b.Navigation("Visits"); + }); + + modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b => + { + b.Navigation("MasterServices"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BeautySalonDatabaseImplement/Models/Master.cs b/BeautySalonDatabaseImplement/Models/Master.cs index 97e986d..ac17e78 100644 --- a/BeautySalonDatabaseImplement/Models/Master.cs +++ b/BeautySalonDatabaseImplement/Models/Master.cs @@ -12,18 +12,18 @@ namespace BeautySalonDatabaseImplement.Models [Required] public string MasterFIO { get; set; } = string.Empty; [Required] - public double WorkingHours { get; set; } - private Dictionary? _masterServices = null; + public double Wage { get; set; } + private Dictionary? _masterServices = null; [NotMapped] - public Dictionary MasterServices + public Dictionary MasterServices { get { if (_masterServices == null) { _masterServices = Services - .ToDictionary(recPC => recPC.MasterId, recPC => - (recPC.Service as IServiceModel, recPC.Count)); + .ToDictionary(recPC => recPC.ServiceId, recPC => + (recPC.Service as IServiceModel, recPC.Wage)); } return _masterServices; } @@ -38,26 +38,33 @@ namespace BeautySalonDatabaseImplement.Models { Id = model.Id, MasterFIO = model.MasterFIO, - WorkingHours = model.WorkingHours, + Wage = model.Wage, Services = model.MasterServices.Select(x => new MasterService { Service = context.Services.First(y => y.Id == x.Key), - Count = x.Value.Item2 + Wage = x.Value.Item2 }).ToList() }; } public void Update(MasterBindingModel model) { MasterFIO = model.MasterFIO; - WorkingHours = model.WorkingHours; + Wage = model.Wage; } - public MasterViewModel GetViewModel => new() + public MasterViewModel GetViewModel { - Id = Id, - MasterFIO = MasterFIO, - WorkingHours = WorkingHours, - MasterServices = MasterServices - }; + get + { + using var context = new BeautySalonDatabase(); + return new MasterViewModel + { + Id = Id, + MasterFIO = MasterFIO, + Wage = Wage, + MasterServices = MasterServices + }; + } + } public void UpdateServices(BeautySalonDatabase context, MasterBindingModel model) { var masterServices = context.MasterServices.Where(rec => rec.MasterId == model.Id).ToList(); @@ -69,8 +76,7 @@ namespace BeautySalonDatabaseImplement.Models // обновили количество у существующих записей foreach (var updateService in masterServices) { - updateService.Count = - model.MasterServices[updateService.ServiceId].Item2; + updateService.Wage = model.MasterServices[updateService.ServiceId].Item2; model.MasterServices.Remove(updateService.ServiceId); } context.SaveChanges(); @@ -82,7 +88,7 @@ namespace BeautySalonDatabaseImplement.Models { Master = master, Service = context.Services.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 + Wage = pc.Value.Item2 }); context.SaveChanges(); } diff --git a/BeautySalonDatabaseImplement/Models/MasterService.cs b/BeautySalonDatabaseImplement/Models/MasterService.cs index db8bdaf..3ab4dd0 100644 --- a/BeautySalonDatabaseImplement/Models/MasterService.cs +++ b/BeautySalonDatabaseImplement/Models/MasterService.cs @@ -10,7 +10,7 @@ namespace BeautySalonDatabaseImplement.Models [Required] public int ServiceId { get; set; } [Required] - public int Count { get; set; } + public double Wage { get; set; } public virtual Service Service { get; set; } = new(); public virtual Master Master { get; set; } = new(); } diff --git a/BeautySalonDatabaseImplement/Models/Service.cs b/BeautySalonDatabaseImplement/Models/Service.cs index 282281a..4eea991 100644 --- a/BeautySalonDatabaseImplement/Models/Service.cs +++ b/BeautySalonDatabaseImplement/Models/Service.cs @@ -13,6 +13,8 @@ namespace BeautySalonDatabaseImplement.Models public string ServiceName { get; private set; } = string.Empty; [Required] public double Cost { get; set; } + [Required] + public double Time { get; set; } [ForeignKey("ServiceId")] public virtual List MasterServices { get; set; } = new(); public static Service? Create(ServiceBindingModel model) diff --git a/BeautySalonDatabaseImplement/Models/Visit.cs b/BeautySalonDatabaseImplement/Models/Visit.cs index ea6c452..9ec2119 100644 --- a/BeautySalonDatabaseImplement/Models/Visit.cs +++ b/BeautySalonDatabaseImplement/Models/Visit.cs @@ -10,7 +10,6 @@ namespace BeautySalonDatabaseImplement.Models public int Id { get; private set; } [Required] public DateTime DateOfVisit { get; private set; } - [Required] public int ClientId { get; private set; } public int MasterId { get; private set; } public int ServiceId { get; private set; } @@ -19,7 +18,7 @@ namespace BeautySalonDatabaseImplement.Models public string ServiceName { get; set; } = string.Empty; [Required] public double Sum { get; private set; } - public virtual Client Client { get; set; } + public Client Client { get; set; } public virtual Master Master { get; set; } public virtual Service Service { get; set; } @@ -50,28 +49,29 @@ namespace BeautySalonDatabaseImplement.Models { return; } - - ClientId = model.ClientId; - ClientFIO = model.ClientFIO; - MasterId = model.MasterId; - MasterFIO = model.MasterFIO; - ServiceId = model.ServiceId; - ServiceName = model.ServiceName; + Sum = model.Sum; DateOfVisit = model.DateOfVisit; } - public VisitViewModel GetViewModel => new() + public VisitViewModel GetViewModel { - Id = Id, - ClientId = ClientId, - ClientFIO = ClientFIO, - MasterId = MasterId, - MasterFIO = MasterFIO, - ServiceId = ServiceId, - ServiceName = ServiceName, - Sum = Sum, - DateOfVisit = DateOfVisit - }; + get + { + using var context = new BeautySalonDatabase(); + return new VisitViewModel + { + 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, + DateOfVisit = DateOfVisit + }; + } + } } } diff --git a/BeauySalonContracts/BindingModels/MasterBindingModel.cs b/BeauySalonContracts/BindingModels/MasterBindingModel.cs index d48839a..4f2931b 100644 --- a/BeauySalonContracts/BindingModels/MasterBindingModel.cs +++ b/BeauySalonContracts/BindingModels/MasterBindingModel.cs @@ -6,7 +6,7 @@ namespace BeautySalonContracts.BindingModels { public int Id { get; set; } public string MasterFIO { get; set; } = string.Empty; - public double WorkingHours { get; set; } - public Dictionary MasterServices { get; set; } = new(); + public double Wage { get; set; } + public Dictionary MasterServices { get; set; } = new(); } } diff --git a/BeauySalonContracts/BindingModels/ServiceBindingModel.cs b/BeauySalonContracts/BindingModels/ServiceBindingModel.cs index 4bf5afa..b835350 100644 --- a/BeauySalonContracts/BindingModels/ServiceBindingModel.cs +++ b/BeauySalonContracts/BindingModels/ServiceBindingModel.cs @@ -6,6 +6,6 @@ namespace BeautySalonContracts.BindingModels { public int Id { get; set; } public string ServiceName { get; set; } = string.Empty; - public double Cost { get; set; } + public double Cost { get; set; } } } diff --git a/BeauySalonContracts/SearchModels/VisitSearchModel.cs b/BeauySalonContracts/SearchModels/VisitSearchModel.cs index c7f1a35..720a301 100644 --- a/BeauySalonContracts/SearchModels/VisitSearchModel.cs +++ b/BeauySalonContracts/SearchModels/VisitSearchModel.cs @@ -3,5 +3,6 @@ public class VisitSearchModel { public int? Id { get; set; } + public int? ClientId { get; set; } } } diff --git a/BeauySalonContracts/ViewModels/MasterViewModel.cs b/BeauySalonContracts/ViewModels/MasterViewModel.cs index 27610ac..446e9ac 100644 --- a/BeauySalonContracts/ViewModels/MasterViewModel.cs +++ b/BeauySalonContracts/ViewModels/MasterViewModel.cs @@ -8,8 +8,8 @@ namespace BeautySalonContracts.ViewModels public int Id { get; set; } [DisplayName("ФИО мастера")] public string MasterFIO { get; set; } = string.Empty; - [DisplayName("Рабочее время")] - public double WorkingHours { get; set; } - public Dictionary MasterServices { get; set; } = new(); + [DisplayName("Зарплата")] + public double Wage { get; set; } + public Dictionary MasterServices { get; set; } = new(); } }