diff --git a/VetClinic/EmployeeView/EmployeeView.csproj b/VetClinic/EmployeeView/EmployeeView.csproj
new file mode 100644
index 0000000..172e0e1
--- /dev/null
+++ b/VetClinic/EmployeeView/EmployeeView.csproj
@@ -0,0 +1,25 @@
+
+
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+ enable
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
\ No newline at end of file
diff --git a/VetClinic/EmployeeView/Form1.Designer.cs b/VetClinic/EmployeeView/Form1.Designer.cs
new file mode 100644
index 0000000..9135698
--- /dev/null
+++ b/VetClinic/EmployeeView/Form1.Designer.cs
@@ -0,0 +1,39 @@
+namespace EmployeeView
+{
+ partial class Form1
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Text = "Form1";
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/VetClinic/EmployeeView/Form1.cs b/VetClinic/EmployeeView/Form1.cs
new file mode 100644
index 0000000..5a149ff
--- /dev/null
+++ b/VetClinic/EmployeeView/Form1.cs
@@ -0,0 +1,10 @@
+namespace EmployeeView
+{
+ public partial class Form1 : Form
+ {
+ public Form1()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/VetClinic/EmployeeView/Form1.resx b/VetClinic/EmployeeView/Form1.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/VetClinic/EmployeeView/Form1.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/VetClinic/EmployeeView/Program.cs b/VetClinic/EmployeeView/Program.cs
new file mode 100644
index 0000000..3265677
--- /dev/null
+++ b/VetClinic/EmployeeView/Program.cs
@@ -0,0 +1,17 @@
+namespace EmployeeView
+{
+ internal static class Program
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
+ {
+ // To customize application configuration such as set high DPI settings or default font,
+ // see https://aka.ms/applicationconfiguration.
+ ApplicationConfiguration.Initialize();
+ Application.Run(new Form1());
+ }
+ }
+}
\ No newline at end of file
diff --git a/VetClinic/VetClinic.sln b/VetClinic/VetClinic.sln
index a6f1dc9..fd42e70 100644
--- a/VetClinic/VetClinic.sln
+++ b/VetClinic/VetClinic.sln
@@ -3,10 +3,25 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VetClinicView", "VetClinicView\VetClinicView.csproj", "{278BCF5A-EAE2-41FF-A5FC-5376AB7FE6E2}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientView", "VetClinicView\ClientView.csproj", "{278BCF5A-EAE2-41FF-A5FC-5376AB7FE6E2}"
+ ProjectSection(ProjectDependencies) = postProject
+ {E3827255-F30E-4DD8-A18E-A542280F631F} = {E3827255-F30E-4DD8-A18E-A542280F631F}
+ {F5FF371F-B183-4C35-9840-2DDA4F28135E} = {F5FF371F-B183-4C35-9840-2DDA4F28135E}
+ EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VetClinicBusinessLogic", "VetClinicBusinessLogic\VetClinicBusinessLogic.csproj", "{E3827255-F30E-4DD8-A18E-A542280F631F}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeView", "EmployeeView\EmployeeView.csproj", "{B7AE7431-8989-43E3-A72E-AFFDF0861364}"
+ ProjectSection(ProjectDependencies) = postProject
+ {E3827255-F30E-4DD8-A18E-A542280F631F} = {E3827255-F30E-4DD8-A18E-A542280F631F}
+ {F5FF371F-B183-4C35-9840-2DDA4F28135E} = {F5FF371F-B183-4C35-9840-2DDA4F28135E}
+ EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VetClinicDatabaseImplement", "VetClinicDatabaseImplement\VetClinicDatabaseImplement.csproj", "{F5FF371F-B183-4C35-9840-2DDA4F28135E}"
+ ProjectSection(ProjectDependencies) = postProject
+ {E3827255-F30E-4DD8-A18E-A542280F631F} = {E3827255-F30E-4DD8-A18E-A542280F631F}
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +36,14 @@ Global
{E3827255-F30E-4DD8-A18E-A542280F631F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3827255-F30E-4DD8-A18E-A542280F631F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3827255-F30E-4DD8-A18E-A542280F631F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B7AE7431-8989-43E3-A72E-AFFDF0861364}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B7AE7431-8989-43E3-A72E-AFFDF0861364}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B7AE7431-8989-43E3-A72E-AFFDF0861364}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B7AE7431-8989-43E3-A72E-AFFDF0861364}.Release|Any CPU.Build.0 = Release|Any CPU
+ {F5FF371F-B183-4C35-9840-2DDA4F28135E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {F5FF371F-B183-4C35-9840-2DDA4F28135E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {F5FF371F-B183-4C35-9840-2DDA4F28135E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {F5FF371F-B183-4C35-9840-2DDA4F28135E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/VetClinic/VetClinicBusinessLogic/Interfaces/IClientStorage.cs b/VetClinic/VetClinicBusinessLogic/Interfaces/IClientStorage.cs
index 763df97..086ff3c 100644
--- a/VetClinic/VetClinicBusinessLogic/Interfaces/IClientStorage.cs
+++ b/VetClinic/VetClinicBusinessLogic/Interfaces/IClientStorage.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Text;
using System.Linq;
using System.Threading.Tasks;
using VetClinicBusinessLogic.BindingModels;
diff --git a/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj b/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj
index 132c02c..f90a805 100644
--- a/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj
+++ b/VetClinic/VetClinicBusinessLogic/VetClinicBusinessLogic.csproj
@@ -6,4 +6,13 @@
enable
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
diff --git a/VetClinic/VetClinicDatabaseImplement/Implement/ClientStorage.cs b/VetClinic/VetClinicDatabaseImplement/Implement/ClientStorage.cs
new file mode 100644
index 0000000..c574df4
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Implement/ClientStorage.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VetClinicBusinessLogic.BindingModels;
+using VetClinicBusinessLogic.Interfaces;
+using VetClinicBusinessLogic.ViewModels;
+using VetClinicDatabaseImplement.Models;
+
+namespace VetClinicDatabaseImplement.Implement
+{
+ public class ClientStorage: IClientStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new VetClinicDatabase();
+ return context.Clients
+ .Select(CreateModel)
+ .ToList();
+ }
+ public List GetFilteredList(ClientBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ return context.Clients
+ .Where(rec => rec.Name.Contains(model.Name))
+ .Select(CreateModel)
+ .ToList();
+ }
+ public ClientViewModel GetElement(ClientBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ var client = context.Clients
+ .FirstOrDefault(rec => rec.Phone == model.Phone);
+ if (client == null)
+ {
+ return null;
+ }
+ return client.Password == model.Password ? CreateModel(client) : null;
+ }
+ public void Insert(ClientBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ Client element = context.Clients.FirstOrDefault(rec => rec.Phone ==
+ model.Phone);
+ if (element != null)
+ {
+ throw new Exception("Телефон уже зарегистрирован");
+ }
+ context.Clients.Add(CreateModel(model, new Client()));
+ context.SaveChanges();
+ }
+ public void Update(ClientBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element == null)
+ {
+ throw new Exception("Элемент не найден");
+ }
+ CreateModel(model, element);
+ context.SaveChanges();
+ }
+ public void Delete(ClientBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ Client element = context.Clients.FirstOrDefault(rec => rec.Id ==
+ model.Id);
+ if (element != null)
+ {
+ context.Clients.Remove(element);
+ context.SaveChanges();
+ }
+ else
+ {
+ throw new Exception("Элемент не найден");
+ }
+ }
+ private static Client CreateModel(ClientBindingModel model, Client
+ client)
+ {
+ client.Password = model.Password;
+ client.Mail = model.Email;
+ client.Name = model.Name;
+ client.Pet = model.Pet;
+ client.Phone = model.Phone;
+ client.PetName = model.PetName;
+ return client;
+ }
+ private static ClientViewModel CreateModel(Client client)
+ {
+ return new ClientViewModel
+ {
+ Id = client.Id,
+ Name = client.Name,
+ Email = client.Mail,
+ Pet = client.Pet,
+ PetName = client.PetName,
+ Phone = client.Phone
+ };
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Implement/EmployeeStorage.cs b/VetClinic/VetClinicDatabaseImplement/Implement/EmployeeStorage.cs
new file mode 100644
index 0000000..d1b135c
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Implement/EmployeeStorage.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VetClinicBusinessLogic.BindingModels;
+using VetClinicBusinessLogic.Interfaces;
+using VetClinicBusinessLogic.ViewModels;
+using VetClinicDatabaseImplement.Models;
+
+
+namespace VetClinicDatabaseImplement.Implement
+{
+ public class EmployeeStorage : IEmployeeStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new VetClinicDatabase();
+ return context.Employees
+ .Select(CreateModel)
+ .ToList();
+ }
+ public List GetFilteredList(EmployeeBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ return context.Employees
+ .Where(rec => rec.Name.Contains(model.Name))
+ .Select(CreateModel)
+ .ToList();
+ }
+ public EmployeeViewModel GetElement(EmployeeBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ var employee = context.Employees
+ .FirstOrDefault(rec => rec.Phone == model.Phone);
+ if (employee == null)
+ {
+ return null;
+ }
+ return employee.Password == model.Password ? CreateModel(employee) : null;
+ }
+ public void Insert(EmployeeBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ Employee element = context.Employees.FirstOrDefault(rec => rec.Phone ==
+ model.Phone);
+ if (element != null)
+ {
+ throw new Exception("Телефон уже зарегистрирован");
+ }
+ context.Employees.Add(CreateModel(model, new Employee()));
+ context.SaveChanges();
+ }
+ public void Update(EmployeeBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ var element = context.Employees.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element == null)
+ {
+ throw new Exception("Элемент не найден");
+ }
+ CreateModel(model, element);
+ context.SaveChanges();
+ }
+ public void Delete(EmployeeBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ Employee element = context.Employees.FirstOrDefault(rec => rec.Id ==
+ model.Id);
+ if (element != null)
+ {
+ context.Employees.Remove(element);
+ context.SaveChanges();
+ }
+ else
+ {
+ throw new Exception("Элемент не найден");
+ }
+ }
+ private static Employee CreateModel(EmployeeBindingModel model, Employee
+ employee)
+ {
+ employee.Password = model.Password;
+ employee.Name = model.Name;
+ employee.Mail = model.Email;
+ employee.Specialization = model.Specialization;
+ employee.Phone = model.Phone;
+ return employee;
+ }
+ private static EmployeeViewModel CreateModel(Employee employee)
+ {
+ return new EmployeeViewModel
+ {
+ Id = employee.Id,
+ Email = employee.Mail,
+ Name = employee.Name,
+ Specialization = employee.Specialization,
+ Phone = employee.Phone
+ };
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Implement/PaymentStorage.cs b/VetClinic/VetClinicDatabaseImplement/Implement/PaymentStorage.cs
new file mode 100644
index 0000000..993ed2b
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Implement/PaymentStorage.cs
@@ -0,0 +1,145 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VetClinicBusinessLogic.BindingModels;
+using VetClinicBusinessLogic.Interfaces;
+using VetClinicBusinessLogic.ViewModels;
+using VetClinicDatabaseImplement.Models;
+
+namespace VetClinicDatabaseImplement.Implement
+{
+ public class PaymentStorage : IPaymentStorage
+ {
+ public List GetFullList()
+ {
+ var context = new VetClinicDatabase();
+ return context.Payments.Include(rec => rec.Visit)
+ .Select(CreateViewModel)
+ .OrderBy(x => x.DateOfPayment)
+ .ToList();
+ }
+
+ public List GetFilteredList(PaymentBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ var context = new VetClinicDatabase();
+ var list = context.Payments.Where(rec => rec.VisitsId == model.VisitId)
+ .OrderBy(x => x.DateOfPayment)
+ .Include(rec => rec.Visit);
+ return list
+ .Select(rec => new PaymentViewModel
+ {
+ DateOfPayment = rec.DateOfPayment,
+ Id = rec.Id,
+ Remains = rec.Remains,
+ Sum = rec.Sum,
+ VisitId = rec.VisitsId
+
+ })
+ .ToList();
+ }
+
+
+ public PaymentViewModel GetElement(PaymentBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ var context = new VetClinicDatabase();
+ {
+ var payment = context.Payments.Include(rec => rec.Visit)
+ .FirstOrDefault(rec => rec.VisitsId == model.VisitId);
+ return payment != null ?
+ new PaymentViewModel
+ {
+ DateOfPayment = payment.DateOfPayment,
+ Id = payment.Id,
+ Remains = payment.Visit.Sum,
+ Sum = payment.Sum,
+ VisitId = payment.VisitsId
+ } :
+ null;
+ }
+ }
+ public PaymentViewModel GetElementFirstLast(PaymentDateBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ var context = new VetClinicDatabase();
+ {
+ return new PaymentViewModel()
+ {
+ Remains = context.Payments.Include(rec => rec.Visit)
+ .Where(x => x.DateOfPayment > model.DateFrom || x.DateOfPayment < model.DateTo).Sum(x => x.Sum)
+ };
+
+ }
+ }
+
+ public void Insert(PaymentBindingModel model)
+ {
+ var context = new VetClinicDatabase();
+ context.Payments.Add(CreateModel(model, new Payment()));
+ context.SaveChanges();
+ }
+
+ public void Update(PaymentBindingModel model)
+ {
+ var context = new VetClinicDatabase();
+ var element = context.Payments.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element == null)
+ {
+ throw new Exception("Оплата не найдена");
+ }
+ CreateModel(model, element);
+ context.SaveChanges();
+ }
+
+
+ public void Delete(PaymentBindingModel model)
+ {
+ var context = new VetClinicDatabase();
+
+ Payment element = context.Payments.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Payments.Remove(element);
+ context.SaveChanges();
+ }
+ else
+ {
+ throw new Exception("Оплата не найдена");
+ }
+ }
+
+ private PaymentViewModel CreateViewModel(Payment payment)
+ {
+ return new PaymentViewModel
+ {
+ DateOfPayment = payment.DateOfPayment,
+ Id = payment.Id,
+ Remains = payment.Visit.Sum,
+ Sum = payment.Sum,
+ VisitId = payment.VisitsId
+ };
+ }
+
+ private Payment CreateModel(PaymentBindingModel model, Payment payment)
+ {
+ payment.DateOfPayment = model.DateOfPayment;
+ payment.Id = model.Id;
+ payment.Remains = model.Remains;
+ payment.Sum = model.Sum;
+ payment.VisitsId = model.VisitId;
+ return payment;
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Implement/ServiceStorage.cs b/VetClinic/VetClinicDatabaseImplement/Implement/ServiceStorage.cs
new file mode 100644
index 0000000..189ecc8
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Implement/ServiceStorage.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VetClinicBusinessLogic.BindingModels;
+using VetClinicBusinessLogic.Interfaces;
+using VetClinicBusinessLogic.ViewModels;
+using VetClinicDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace VetClinicDatabaseImplement.Implement
+{
+ public class ServiceStorage : IServiceStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new VetClinicDatabase();
+ return context.Services
+ .Include(rec => rec.VisitServices)
+ .ThenInclude(rec => rec.Visit)
+ .Select(CreateModel)
+ .ToList();
+ }
+ public List GetFilteredList(ServiceBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ return context.Services
+ .Where(rec => rec.Name.Contains(model.Name))
+ .Include(rec => rec.VisitServices)
+ .ThenInclude(rec => rec.Visit)
+ .Select(CreateModel)
+ .ToList();
+ }
+ public ServiceViewModel GetElement(ServiceBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ var service = context.Services
+ .FirstOrDefault(rec => rec.Id == model.Id);
+ if (service == null)
+ {
+ return null;
+ }
+ return CreateModel(service);
+ }
+ public void Insert(ServiceBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+
+ context.Services.Add(CreateModel(model, new Service()));
+ context.SaveChanges();
+ }
+ public void Update(ServiceBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ var element = context.Services.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element == null)
+ {
+ throw new Exception("Элемент не найден");
+ }
+ CreateModel(model, element);
+ context.SaveChanges();
+ }
+ public void Delete(ServiceBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ Service element = context.Services.FirstOrDefault(rec => rec.Id ==
+ model.Id);
+ if (element != null)
+ {
+ context.Services.Remove(element);
+ context.SaveChanges();
+ }
+ else
+ {
+ throw new Exception("Элемент не найден");
+ }
+ }
+ private static Service CreateModel(ServiceBindingModel model, Service
+ service)
+ {
+ service.Cost = model.Cost;
+ service.Name = model.Name;
+ return service;
+ }
+ private static ServiceViewModel CreateModel(Service service)
+ {
+ return new ServiceViewModel
+ {
+ Id = service.Id,
+ Cost = service.Cost,
+ Name = service.Name,
+ VisitServices = service.VisitServices
+ .ToDictionary(recPC => recPC.VisitId,
+ recPC => recPC.Visit.DateVisit)
+ };
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Implement/VisitStorage.cs b/VetClinic/VetClinicDatabaseImplement/Implement/VisitStorage.cs
new file mode 100644
index 0000000..fd9fc34
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Implement/VisitStorage.cs
@@ -0,0 +1,200 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VetClinicBusinessLogic.BindingModels;
+using VetClinicBusinessLogic.Interfaces;
+using VetClinicBusinessLogic.ViewModels;
+using VetClinicDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+
+namespace VetClinicDatabaseImplement.Implement
+{
+ public class VisitStorage : IVisitStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new VetClinicDatabase();
+ return context.Visits
+ .Include(rec => rec.VisitServices)
+ .ThenInclude(rec => rec.Service)
+ .Include(x => x.Client)
+ .Include(x => x.Employee)
+ .Select(CreateModel)
+ .ToList();
+ }
+ public List GetFilteredList(VisitBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ return context.Visits.Include(rec => rec.VisitServices)
+ .ThenInclude(rec => rec.Service)
+ .Include(x => x.Client)
+ .Include(x => x.Employee).Where(rec => rec.ClientId == model.ClientId)
+ .Select(CreateModel)
+
+ .ToList();
+ }
+ public List GetFilteredListEmployee(VisitBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ return context.Visits.Include(rec => rec.VisitServices)
+ .ThenInclude(rec => rec.Service)
+ .Include(x => x.Client)
+ .Include(x => x.Employee).Where(rec => rec.EmployeeId == model.EmployeeId)
+ .Select(CreateModel)
+
+ .ToList();
+ }
+ public List GetFilteredListDate(VisitBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ return context.Visits.Include(rec => rec.VisitServices)
+ .ThenInclude(rec => rec.Service)
+ .Include(x => x.Client)
+ .Include(x => x.Employee).Where(rec => rec.Id.Equals(model.Id) || rec.DateVisit >= model.DateFrom && rec.DateVisit <= model.DateTo)
+ .Select(CreateModel)
+
+ .ToList();
+ }
+ public VisitViewModel GetElement(VisitBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ using var context = new VetClinicDatabase();
+ var visit = context.Visits
+ .Include(rec => rec.VisitServices)
+ .ThenInclude(rec => rec.Service)
+ .Include(x => x.Client)
+ .Include(x => x.Employee)
+ .FirstOrDefault(rec => rec.Id == model.Id)
+ ;
+ if (visit == null)
+ {
+ return null;
+ }
+ return CreateModel(visit);
+ }
+ public void Insert(VisitBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ using var transaction = context.Database.BeginTransaction();
+ try
+ {
+ CreateModel(model, new Visit(), context);
+ context.SaveChanges();
+ transaction.Commit();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.ToString());
+ transaction.Rollback();
+ throw;
+ }
+ }
+ public void Update(VisitBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ using var transaction = context.Database.BeginTransaction();
+ try
+ {
+ var element = context.Visits.FirstOrDefault(rec => rec.Id ==
+ model.Id);
+ if (element == null)
+ {
+ throw new Exception("Элемент не найден");
+ }
+ CreateModel(model, element, context);
+ context.SaveChanges();
+ transaction.Commit();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.ToString());
+ transaction.Rollback();
+ throw;
+ }
+ }
+ public void Delete(VisitBindingModel model)
+ {
+ using var context = new VetClinicDatabase();
+ Visit element = context.Visits.FirstOrDefault(rec => rec.Id ==
+ model.Id);
+ if (element != null)
+ {
+ context.Visits.Remove(element);
+ context.SaveChanges();
+ }
+ else
+ {
+ throw new Exception("Элемент не найден");
+ }
+ }
+ private static Visit CreateModel(VisitBindingModel model, Visit visit,
+ VetClinicDatabase context)
+ {
+ visit.DateVisit = model.VisitsDate;
+ visit.ClientId = model.ClientId;
+ visit.EmployeeId = model.EmployeeId;
+ visit.Sum = model.Sum;
+ if (visit.Id == 0)
+ {
+ context.Visits.Add(visit);
+ context.SaveChanges();
+ }
+ if (model.Id != 0)
+ {
+ var visitServices = context.VisitServices.Where(rec =>
+ rec.VisitId == model.Id).ToList();
+ // удалили те, которых нет в модели
+ context.VisitServices.RemoveRange(visitServices.Where(rec =>
+ !model.VisitServices.ContainsKey(rec.VisitId)).ToList());
+ context.SaveChanges();
+ context.SaveChanges();
+ }
+ // добавили новые
+ foreach (var pc in model.VisitServices)
+ {
+ context.VisitServices.Add(new VisitService
+ {
+ VisitId = visit.Id,
+ ServiceId = pc.Key,
+ });
+ var temp = context.VisitServices;
+ context.SaveChanges();
+ }
+ return visit;
+ }
+ private static VisitViewModel CreateModel(Visit visit)
+ {
+ return new VisitViewModel
+ {
+ Id = visit.Id,
+ ClientName = visit.Client.Name,
+ EmployeeName = visit?.Employee?.Name,
+ ClientId = visit.ClientId,
+ EmployeeId = visit?.EmployeeId,
+ Sum = visit.Sum,
+ VisitsDate = visit.DateVisit,
+ VisitServices = visit.VisitServices
+ .ToDictionary(recPC => recPC.ServiceId,
+ recPC => recPC.Service?.Name)
+ };
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Migrations/VetClinicDatabaseModelSnapshot.cs b/VetClinic/VetClinicDatabaseImplement/Migrations/VetClinicDatabaseModelSnapshot.cs
new file mode 100644
index 0000000..f74dfc5
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Migrations/VetClinicDatabaseModelSnapshot.cs
@@ -0,0 +1,310 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using VetClinicDatabaseImplement;
+
+namespace VetClinicDatabaseImplement.Migrations
+{
+ [DbContext(typeof(VetClinicDatabase))]
+ partial class VetClinicDatabaseModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("Relational:MaxIdentifierLength", 128)
+ .HasAnnotation("ProductVersion", "5.0.15")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Mail")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Name")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Pet")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("PetName")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Phone")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Employee", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Mail")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Name")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Password")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Phone")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Specialization")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Employees");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Expense", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Name")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Sum")
+ .HasColumnType("decimal(18,2)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Expenses");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Payment", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("DateOfPayment")
+ .HasColumnType("datetime2");
+
+ b.Property("Remains")
+ .HasColumnType("decimal(18,2)");
+
+ b.Property("Sum")
+ .HasColumnType("decimal(18,2)");
+
+ b.Property("VisitId")
+ .HasColumnType("int");
+
+ b.Property("VisitsId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("VisitId");
+
+ b.ToTable("Payments");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Service", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("Cost")
+ .HasColumnType("decimal(18,2)");
+
+ b.Property("Name")
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Services");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.ServiceExpense", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ExpenseId")
+ .HasColumnType("int");
+
+ b.Property("ServiceId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ExpenseId");
+
+ b.HasIndex("ServiceId");
+
+ b.ToTable("ServiceExpense");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Visit", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ClientId")
+ .HasColumnType("int");
+
+ b.Property("DateVisit")
+ .HasColumnType("datetime2");
+
+ b.Property("EmployeeId")
+ .HasColumnType("int");
+
+ b.Property("ServiceId")
+ .HasColumnType("int");
+
+ b.Property("Sum")
+ .HasColumnType("decimal(18,2)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("EmployeeId");
+
+ b.ToTable("Visits");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.VisitService", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int")
+ .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
+
+ b.Property("ServiceId")
+ .HasColumnType("int");
+
+ b.Property("VisitId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ServiceId");
+
+ b.HasIndex("VisitId");
+
+ b.ToTable("VisitServices");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Payment", b =>
+ {
+ b.HasOne("VetClinicDatabaseImplement.Models.Visit", "Visit")
+ .WithMany("Payment")
+ .HasForeignKey("VisitId");
+
+ b.Navigation("Visit");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.ServiceExpense", b =>
+ {
+ b.HasOne("VetClinicDatabaseImplement.Models.Expense", "Expense")
+ .WithMany("ServiceExpenses")
+ .HasForeignKey("ExpenseId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("VetClinicDatabaseImplement.Models.Service", "Service")
+ .WithMany()
+ .HasForeignKey("ServiceId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Expense");
+
+ b.Navigation("Service");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Visit", b =>
+ {
+ b.HasOne("VetClinicDatabaseImplement.Models.Client", "Client")
+ .WithMany("Visits")
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("VetClinicDatabaseImplement.Models.Employee", "Employee")
+ .WithMany()
+ .HasForeignKey("EmployeeId");
+
+ b.Navigation("Client");
+
+ b.Navigation("Employee");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.VisitService", b =>
+ {
+ b.HasOne("VetClinicDatabaseImplement.Models.Service", "Service")
+ .WithMany("VisitServices")
+ .HasForeignKey("ServiceId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("VetClinicDatabaseImplement.Models.Visit", "Visit")
+ .WithMany("VisitServices")
+ .HasForeignKey("VisitId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Service");
+
+ b.Navigation("Visit");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Client", b =>
+ {
+ b.Navigation("Visits");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Expense", b =>
+ {
+ b.Navigation("ServiceExpenses");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Service", b =>
+ {
+ b.Navigation("VisitServices");
+ });
+
+ modelBuilder.Entity("VetClinicDatabaseImplement.Models.Visit", b =>
+ {
+ b.Navigation("Payment");
+
+ b.Navigation("VisitServices");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Migrations/init2.cs b/VetClinic/VetClinicDatabaseImplement/Migrations/init2.cs
new file mode 100644
index 0000000..1861ddb
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Migrations/init2.cs
@@ -0,0 +1,186 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+
+namespace VetClinicDatabaseImplement.Migrations
+{
+ public partial class init2 : 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"),
+ Name = table.Column(type: "nvarchar(max)", nullable: true),
+ Phone = table.Column(type: "nvarchar(max)", nullable: true),
+ Password = table.Column(type: "nvarchar(max)", nullable: true),
+ Pet = table.Column(type: "nvarchar(max)", nullable: true),
+ PetName = table.Column(type: "nvarchar(max)", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Clients", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Employees",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Phone = table.Column(type: "nvarchar(max)", nullable: true),
+ Password = table.Column(type: "nvarchar(max)", nullable: true),
+ Name = table.Column(type: "nvarchar(max)", nullable: true),
+ Specialization = table.Column(type: "nvarchar(max)", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Employees", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Services",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Name = table.Column(type: "nvarchar(max)", nullable: true),
+ Cost = table.Column(type: "decimal(18,2)", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Services", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Expenses",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Sum = table.Column(type: "decimal(18,2)", nullable: false),
+ ServiceId = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Expenses", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Expenses_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"),
+ DateVisit = table.Column(type: "datetime2", nullable: false),
+ Remains = table.Column(type: "decimal(18,2)", nullable: false),
+ EmployeeId = table.Column(type: "int", nullable: true),
+ ServiceId = table.Column(type: "int", nullable: false),
+ ClientId = table.Column(type: "int", 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_Employees_EmployeeId",
+ column: x => x.EmployeeId,
+ principalTable: "Employees",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+ table.ForeignKey(
+ name: "FK_Visits_Services_ServiceId",
+ column: x => x.ServiceId,
+ principalTable: "Services",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Payments",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ VisitsId = table.Column(type: "int", nullable: false),
+ Sum = table.Column(type: "decimal(18,2)", nullable: false),
+ DateOfPayment = table.Column(type: "datetime2", nullable: false),
+ VisitId = table.Column(type: "int", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Payments", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Payments_Visits_VisitId",
+ column: x => x.VisitId,
+ principalTable: "Visits",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Expenses_ServiceId",
+ table: "Expenses",
+ column: "ServiceId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Payments_VisitId",
+ table: "Payments",
+ column: "VisitId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Visits_ClientId",
+ table: "Visits",
+ column: "ClientId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Visits_EmployeeId",
+ table: "Visits",
+ column: "EmployeeId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Visits_ServiceId",
+ table: "Visits",
+ column: "ServiceId");
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Expenses");
+
+ migrationBuilder.DropTable(
+ name: "Payments");
+
+ migrationBuilder.DropTable(
+ name: "Visits");
+
+ migrationBuilder.DropTable(
+ name: "Clients");
+
+ migrationBuilder.DropTable(
+ name: "Employees");
+
+ migrationBuilder.DropTable(
+ name: "Services");
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Migrations/mail.cs b/VetClinic/VetClinicDatabaseImplement/Migrations/mail.cs
new file mode 100644
index 0000000..c77fff8
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Migrations/mail.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+
+namespace VetClinicDatabaseImplement.Migrations
+{
+ public partial class mail : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Expenses_Services_ServiceId",
+ table: "Expenses");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Expenses_ServiceId",
+ table: "Expenses");
+
+ migrationBuilder.DropColumn(
+ name: "ServiceId",
+ table: "Expenses");
+
+ migrationBuilder.AddColumn(
+ name: "Name",
+ table: "Expenses",
+ type: "nvarchar(max)",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ name: "Mail",
+ table: "Employees",
+ type: "nvarchar(max)",
+ nullable: true);
+
+ migrationBuilder.AddColumn(
+ name: "Mail",
+ table: "Clients",
+ type: "nvarchar(max)",
+ nullable: true);
+
+ migrationBuilder.CreateTable(
+ name: "ServiceExpense",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ExpenseId = table.Column(type: "int", nullable: false),
+ ServiceId = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_ServiceExpense", x => x.Id);
+ table.ForeignKey(
+ name: "FK_ServiceExpense_Expenses_ExpenseId",
+ column: x => x.ExpenseId,
+ principalTable: "Expenses",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_ServiceExpense_Services_ServiceId",
+ column: x => x.ServiceId,
+ principalTable: "Services",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_ServiceExpense_ExpenseId",
+ table: "ServiceExpense",
+ column: "ExpenseId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_ServiceExpense_ServiceId",
+ table: "ServiceExpense",
+ column: "ServiceId");
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "ServiceExpense");
+
+ migrationBuilder.DropColumn(
+ name: "Name",
+ table: "Expenses");
+
+ migrationBuilder.DropColumn(
+ name: "Mail",
+ table: "Employees");
+
+ migrationBuilder.DropColumn(
+ name: "Mail",
+ table: "Clients");
+
+ migrationBuilder.AddColumn(
+ name: "ServiceId",
+ table: "Expenses",
+ type: "int",
+ nullable: false,
+ defaultValue: 0);
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Expenses_ServiceId",
+ table: "Expenses",
+ column: "ServiceId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Expenses_Services_ServiceId",
+ table: "Expenses",
+ column: "ServiceId",
+ principalTable: "Services",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Migrations/manyToMany.cs b/VetClinic/VetClinicDatabaseImplement/Migrations/manyToMany.cs
new file mode 100644
index 0000000..ad285e5
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Migrations/manyToMany.cs
@@ -0,0 +1,78 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace VetClinicDatabaseImplement.Migrations
+{
+ public partial class manyToMany : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Visits_Services_ServiceId",
+ table: "Visits");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Visits_ServiceId",
+ table: "Visits");
+
+ migrationBuilder.CreateTable(
+ name: "VisitServices",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ VisitId = table.Column(type: "int", nullable: false),
+ ServiceId = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_VisitServices", x => x.Id);
+ table.ForeignKey(
+ name: "FK_VisitServices_Services_ServiceId",
+ column: x => x.ServiceId,
+ principalTable: "Services",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_VisitServices_Visits_VisitId",
+ column: x => x.VisitId,
+ principalTable: "Visits",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_VisitServices_ServiceId",
+ table: "VisitServices",
+ column: "ServiceId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_VisitServices_VisitId",
+ table: "VisitServices",
+ column: "VisitId");
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "VisitServices");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Visits_ServiceId",
+ table: "Visits",
+ column: "ServiceId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Visits_Services_ServiceId",
+ table: "Visits",
+ column: "ServiceId",
+ principalTable: "Services",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Migrations/payment.cs b/VetClinic/VetClinicDatabaseImplement/Migrations/payment.cs
new file mode 100644
index 0000000..e44a773
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Migrations/payment.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+
+namespace VetClinicDatabaseImplement.Migrations
+{
+ public partial class payment : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.RenameColumn(
+ name: "Remains",
+ table: "Visits",
+ newName: "Sum");
+
+ migrationBuilder.AddColumn(
+ name: "Remains",
+ table: "Payments",
+ type: "decimal(18,2)",
+ nullable: false,
+ defaultValue: 0m);
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "Remains",
+ table: "Payments");
+
+ migrationBuilder.RenameColumn(
+ name: "Sum",
+ table: "Visits",
+ newName: "Remains");
+ }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Models/Client.cs b/VetClinic/VetClinicDatabaseImplement/Models/Client.cs
new file mode 100644
index 0000000..8c981b1
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Models/Client.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using VetClinicBusinessLogic.Enums;
+using VetClinicDatabaseImplement.Models;
+
+namespace VetClinicDatabaseImplement.Models
+{
+ public class Client
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string Phone { get; set; }
+ public string Password { get; set; }
+ public string Mail { get; set; }
+ public string Pet { get; set; }
+ public string PetName { get; set; }
+ public List Visits { get; set; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Models/Employee.cs b/VetClinic/VetClinicDatabaseImplement/Models/Employee.cs
new file mode 100644
index 0000000..a75c928
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Models/Employee.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace VetClinicDatabaseImplement.Models
+{
+ public class Employee
+ {
+ public int Id { get; set; }
+ public string Phone { get; set; }
+ public string Mail { get; set; }
+ public string Password { get; set; }
+ public string Name { get; set; }
+ public string Specialization { get; set; }
+ List Visits { get; set; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Models/Expense.cs b/VetClinic/VetClinicDatabaseImplement/Models/Expense.cs
new file mode 100644
index 0000000..4dc9db6
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Models/Expense.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace VetClinicDatabaseImplement.Models
+{
+ public class Expense
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public decimal Sum { get; set; }
+ public List ServiceExpenses { get; set; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Models/Payment.cs b/VetClinic/VetClinicDatabaseImplement/Models/Payment.cs
new file mode 100644
index 0000000..5006abc
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Models/Payment.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace VetClinicDatabaseImplement.Models
+{
+ public class Payment
+ {
+ public int Id { get; set; }
+ public int VisitsId { get; set; }
+ public decimal Sum { get; set; }
+ public decimal Remains { get; set; }
+ public DateTime DateOfPayment { get; set; }
+ public Visit Visit { get; set; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Models/Service.cs b/VetClinic/VetClinicDatabaseImplement/Models/Service.cs
new file mode 100644
index 0000000..34a381c
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Models/Service.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+
+namespace VetClinicDatabaseImplement.Models
+{
+ public class Service
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public decimal Cost { get; set; }
+ public List VisitServices { get; set; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Models/ServiceExpense.cs b/VetClinic/VetClinicDatabaseImplement/Models/ServiceExpense.cs
new file mode 100644
index 0000000..52cc249
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Models/ServiceExpense.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace VetClinicDatabaseImplement.Models
+{
+ public class ServiceExpense
+ {
+ public int Id { get; set; }
+ public int ExpenseId { get; set; }
+ public int ServiceId { get; set; }
+ public Expense Expense { get; set; }
+ public Service Service { get; set; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Models/Visit.cs b/VetClinic/VetClinicDatabaseImplement/Models/Visit.cs
new file mode 100644
index 0000000..931da5a
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Models/Visit.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace VetClinicDatabaseImplement.Models
+{
+ public class Visit
+ {
+ public int Id { get; set; }
+ public DateTime DateVisit { get; set; }
+ public decimal Sum { get; set; }
+ public int? EmployeeId { get; set; }
+ public int ServiceId { get; set; }
+ public int ClientId { get; set; }
+ public Employee Employee { get; set; }
+ public List VisitServices { get; set; }
+ public Client Client { get; set; }
+ public virtual List Payment { get; set; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/Models/VisitService.cs b/VetClinic/VetClinicDatabaseImplement/Models/VisitService.cs
new file mode 100644
index 0000000..77922c1
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/Models/VisitService.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace VetClinicDatabaseImplement.Models
+{
+ public class VisitService
+ {
+ public int Id { get; set; }
+ public int VisitId { get; set; }
+ public int ServiceId { get; set; }
+ public Service Service { get; set; }
+ public Visit Visit { get; set; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/VetClinicDatabase.cs b/VetClinic/VetClinicDatabaseImplement/VetClinicDatabase.cs
new file mode 100644
index 0000000..76a3d43
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/VetClinicDatabase.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VetClinicDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace VetClinicDatabaseImplement
+{
+ public class VetClinicDatabase : DbContext
+ {
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ {
+ if (optionsBuilder.IsConfigured == false)
+ {
+ optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-KG5V1L9\SQLEXPRESS;Initial Catalog=VetClinicDB;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
+ }
+ base.OnConfiguring(optionsBuilder);
+
+ }
+ public virtual DbSet Clients { set; get; }
+ public virtual DbSet VisitServices { set; get; }
+ public virtual DbSet Employees { set; get; }
+ public virtual DbSet Payments { set; get; }
+ public virtual DbSet Expenses { set; get; }
+ public virtual DbSet Visits { set; get; }
+ public virtual DbSet Services { set; get; }
+ }
+}
diff --git a/VetClinic/VetClinicDatabaseImplement/VetClinicDatabaseImplement.csproj b/VetClinic/VetClinicDatabaseImplement/VetClinicDatabaseImplement.csproj
new file mode 100644
index 0000000..fdce674
--- /dev/null
+++ b/VetClinic/VetClinicDatabaseImplement/VetClinicDatabaseImplement.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
diff --git a/VetClinic/VetClinicView/ClientView.csproj b/VetClinic/VetClinicView/ClientView.csproj
new file mode 100644
index 0000000..796f053
--- /dev/null
+++ b/VetClinic/VetClinicView/ClientView.csproj
@@ -0,0 +1,20 @@
+
+
+
+ WinExe
+ net6.0-windows
+ enable
+ true
+ enable
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
\ No newline at end of file
diff --git a/VetClinic/VetClinicView/VetClinicView.csproj b/VetClinic/VetClinicView/VetClinicView.csproj
deleted file mode 100644
index b57c89e..0000000
--- a/VetClinic/VetClinicView/VetClinicView.csproj
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- WinExe
- net6.0-windows
- enable
- true
- enable
-
-
-
\ No newline at end of file