Реализация хранилищ
This commit is contained in:
parent
4db0c02206
commit
a355deeb56
@ -5,12 +5,12 @@ namespace BeautySaloonContracts.BindingModels
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public double Sum { get; set; }
|
||||
public DateOnly Date { get; set; } = DateOnly.FromDateTime(DateTime.Now);
|
||||
public decimal Sum { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
public Dictionary<int, (DateTime, IServiceModel, IEmployeeModel)> OrderServices
|
||||
public Dictionary<int, (TimeOnly, IServiceModel, IEmployeeModel)> OrderServices
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -6,6 +6,6 @@ namespace BeautySaloonContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public DateTime? Date { get; set; }
|
||||
public DateOnly? Date { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public int? EmployeeId { get; set; }
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace BeautySaloonContracts.StoragesContracts
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -8,15 +8,19 @@ namespace BeautySaloonContracts.ViewModels
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Дата заказа")]
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public DateOnly Date { get; set; } = DateOnly.FromDateTime(DateTime.Now);
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
public decimal Sum { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientName { get; set; } = string.Empty;
|
||||
[DisplayName("Номер клиента")]
|
||||
public string ClientPhone { get; set; } = string.Empty;
|
||||
public int EmployeeId { get; set; }
|
||||
[DisplayName("Продавец")]
|
||||
public string EmployeeName { get; set; } = string.Empty;
|
||||
[DisplayName("Номер продавца")]
|
||||
public string EmployeePhone { get; set; } = string.Empty;
|
||||
public Dictionary<int, (DateTime, IServiceModel, IEmployeeModel)> OrderServices
|
||||
{
|
||||
get;
|
||||
|
@ -3,10 +3,10 @@
|
||||
public interface IOrderModel
|
||||
{
|
||||
int Id { get; }
|
||||
DateTime Date { get; }
|
||||
double Sum { get; }
|
||||
DateOnly Date { get; }
|
||||
decimal Sum { get; }
|
||||
int ClientId { get; }
|
||||
int EmployeeId { get; }
|
||||
Dictionary<int, (DateTime, IServiceModel, IEmployeeModel)> OrderServices { get; }
|
||||
Dictionary<int, (TimeOnly, IServiceModel, IEmployeeModel)> OrderServices { get; }
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,6 @@
|
||||
{
|
||||
int Id { get; }
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
decimal Price { get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
using BeautySaloonDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement
|
||||
{
|
||||
public class BeautySaloonDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D8KMQQU\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Employee> Employees { set; get; }
|
||||
|
||||
public virtual DbSet<Position> Positions { set; get; }
|
||||
|
||||
public virtual DbSet<Service> Services { set; get; }
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
|
||||
public virtual DbSet<ServiceOrder> OrderServices { set; get; }
|
||||
}
|
||||
}
|
@ -6,10 +6,6 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Implements\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||
@ -17,6 +13,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
67
BeautySaloon/BeautySaloonDatabaseImplement/Client.cs
Normal file
67
BeautySaloon/BeautySaloonDatabaseImplement/Client.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность клиенты
|
||||
/// </summary>
|
||||
public partial class Client : IClientModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Уникальный идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Имя
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Фамилия
|
||||
/// </summary>
|
||||
public string Surname { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Отчество
|
||||
/// </summary>
|
||||
public string? Patronymic { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Номер телефона
|
||||
/// </summary>
|
||||
public string Phone { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<Order> Orders { get; } = new List<Order>();
|
||||
|
||||
public static Client Create(ClientBindingModel model)
|
||||
{
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Surname = model.Surname,
|
||||
Patronymic = model.Patronymic,
|
||||
Phone = model.Phone
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Surname = model.Surname;
|
||||
Patronymic = model.Patronymic;
|
||||
Phone = model.Phone;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Surname = Surname,
|
||||
Patronymic = Patronymic,
|
||||
Phone = Phone
|
||||
};
|
||||
}
|
88
BeautySaloon/BeautySaloonDatabaseImplement/Employee.cs
Normal file
88
BeautySaloon/BeautySaloonDatabaseImplement/Employee.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность сотрудники
|
||||
/// </summary>
|
||||
public partial class Employee : IEmployeeModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Уникальный идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Имя
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Фамилия
|
||||
/// </summary>
|
||||
public string Surname { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Отчество
|
||||
/// </summary>
|
||||
public string? Patronymic { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Номер телефона
|
||||
/// </summary>
|
||||
public string Phone { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор позиции
|
||||
/// </summary>
|
||||
public int PositionId { get; set; }
|
||||
|
||||
public virtual ICollection<Order> Orders { get; } = new List<Order>();
|
||||
|
||||
public virtual Position Position { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<ServiceOrder> ServiceOrders { get; } = new List<ServiceOrder>();
|
||||
|
||||
public static Employee? Create(EmployeeBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Employee()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Surname = model.Surname,
|
||||
Patronymic = model.Patronymic,
|
||||
Phone = model.Phone,
|
||||
PositionId = model.PositionId
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(EmployeeBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Surname = model.Surname;
|
||||
Patronymic = model.Patronymic;
|
||||
Phone = model.Phone;
|
||||
PositionId = model.PositionId;
|
||||
}
|
||||
|
||||
public EmployeeViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Surname = Surname,
|
||||
Patronymic = Patronymic,
|
||||
Phone = Phone,
|
||||
PositionId = PositionId,
|
||||
PositionName = Position.Name,
|
||||
};
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.SearchModels;
|
||||
using BeautySaloonContracts.StoragesContracts;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var element = context.Clients
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Clients.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
if (model.Id.HasValue)
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
if (!string.IsNullOrEmpty(model.Phone))
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Phone.Equals(model.Phone))?
|
||||
.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Surname))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
return context.Clients
|
||||
.Where(x => x.Surname.Contains(model.Surname))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
return context.Clients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
var newClient = Client.Create(model);
|
||||
if (newClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var client = context.Clients
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
client.Update(model);
|
||||
context.SaveChanges();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.SearchModels;
|
||||
using BeautySaloonContracts.StoragesContracts;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
public class EmployeeStorage : IEmployeeStorage
|
||||
{
|
||||
public EmployeeViewModel? Delete(EmployeeBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var element = context.Employees
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Employees.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public EmployeeViewModel? GetElement(EmployeeSearchModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
if (model.Id.HasValue)
|
||||
return context.Employees
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
if (!string.IsNullOrEmpty(model.Phone))
|
||||
return context.Employees
|
||||
.FirstOrDefault(x => x.Phone.Equals(model.Phone))?
|
||||
.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Surname))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
return context.Employees
|
||||
.Where(x => x.Surname.Contains(model.Surname))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetFullList()
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
return context.Employees
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public EmployeeViewModel? Insert(EmployeeBindingModel model)
|
||||
{
|
||||
var newEmployee = Employee.Create(model);
|
||||
if (newEmployee == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
context.Employees.Add(newEmployee);
|
||||
context.SaveChanges();
|
||||
return newEmployee.GetViewModel;
|
||||
}
|
||||
|
||||
public EmployeeViewModel? Update(EmployeeBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var client = context.Employees
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
client.Update(model);
|
||||
context.SaveChanges();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.SearchModels;
|
||||
using BeautySaloonContracts.StoragesContracts;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var element = context.Orders
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
if (model.Id.HasValue)
|
||||
return context.Orders
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
if (model.ClientId.HasValue)
|
||||
return context.Orders
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.EmployeeId.HasValue)
|
||||
return context.Orders
|
||||
.Where(x => x.EmployeeId == model.EmployeeId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.Date.HasValue)
|
||||
return context.Orders
|
||||
.Where(x => x.Date == model.Date)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
return context.Orders
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.SearchModels;
|
||||
using BeautySaloonContracts.StoragesContracts;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
public class PositionStorage : IPositionStorage
|
||||
{
|
||||
public PositionViewModel? Delete(PositionBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var element = context.Positions
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Positions.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PositionViewModel? GetElement(PositionSearchModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
if (model.Id.HasValue)
|
||||
return context.Positions
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
return context.Positions
|
||||
.FirstOrDefault(x => x.Name.Equals(model.Name))?
|
||||
.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<PositionViewModel> GetFilteredList(PositionSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
return context.Positions
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PositionViewModel> GetFullList()
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
return context.Positions
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public PositionViewModel? Insert(PositionBindingModel model)
|
||||
{
|
||||
var newPosition = Position.Create(model);
|
||||
if (newPosition == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
context.Positions.Add(newPosition);
|
||||
context.SaveChanges();
|
||||
return newPosition.GetViewModel;
|
||||
}
|
||||
|
||||
public PositionViewModel? Update(PositionBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var element = context.Positions
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
element.Update(model);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.SearchModels;
|
||||
using BeautySaloonContracts.StoragesContracts;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
public class ServiceStorage : IServiceStorage
|
||||
{
|
||||
public ServiceViewModel? Delete(ServiceBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var element = context.Services
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Services.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ServiceViewModel? GetElement(ServiceSearchModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
if (model.Id.HasValue)
|
||||
return context.Services
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
if (!string.IsNullOrEmpty(model.Name))
|
||||
return context.Services
|
||||
.FirstOrDefault(x => x.Name.Equals(model.Name))?
|
||||
.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ServiceViewModel> GetFilteredList(ServiceSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
return context.Services
|
||||
.Where(x => x.Name.Contains(model.Name))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ServiceViewModel> GetFullList()
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
return context.Services
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ServiceViewModel? Insert(ServiceBindingModel model)
|
||||
{
|
||||
var newService = Service.Create(model);
|
||||
if (newService == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new NewdbContext();
|
||||
context.Services.Add(newService);
|
||||
context.SaveChanges();
|
||||
return newService.GetViewModel;
|
||||
}
|
||||
|
||||
public ServiceViewModel? Update(ServiceBindingModel model)
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var service = context.Services
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (service == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
service.Update(model);
|
||||
context.SaveChanges();
|
||||
return service.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Surname { get; set; } = string.Empty;
|
||||
public string Patronymic { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Client Create(ClientBindingModel model)
|
||||
{
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Surname = model.Surname,
|
||||
Patronymic = model.Patronymic,
|
||||
Phone = model.Phone
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Surname = model.Surname;
|
||||
Patronymic = model.Patronymic;
|
||||
Phone = model.Phone;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Surname = Surname,
|
||||
Patronymic = Patronymic,
|
||||
Phone = Phone
|
||||
};
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Models
|
||||
{
|
||||
public class Employee : IEmployeeModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Surname { get; set; } = string.Empty;
|
||||
|
||||
public string Patronymic { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public int PositionId { get; set; }
|
||||
public Position Position { get; set; }
|
||||
|
||||
[ForeignKey("EmployeeId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
[ForeignKey("EmployeeId")]
|
||||
public virtual List<ServiceOrder> OrderServices { get; set; } = new();
|
||||
|
||||
public static Employee? Create(EmployeeBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Employee()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Surname = model.Surname,
|
||||
Patronymic = model.Patronymic,
|
||||
Phone = model.Phone,
|
||||
PositionId = model.PositionId
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(EmployeeBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Surname = model.Surname;
|
||||
Patronymic = model.Patronymic;
|
||||
Phone = model.Phone;
|
||||
PositionId = model.PositionId;
|
||||
}
|
||||
|
||||
public EmployeeViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Surname = Surname,
|
||||
Patronymic = Patronymic,
|
||||
Phone = Phone,
|
||||
PositionId = PositionId,
|
||||
PositionName = Position.Name,
|
||||
};
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
using BeautySaloonDataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public DateTime Date { get; set; }
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
[Required]
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
private Dictionary<int, (DateTime, IServiceModel, IEmployeeModel)>? _orderServices = null;
|
||||
[ForeignKey("OrderId")]
|
||||
public virtual List<ServiceOrder> Services { get; set; } = new();
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (DateTime, IServiceModel, IEmployeeModel)> OrderServices
|
||||
{
|
||||
get
|
||||
{
|
||||
/*if (_orderServices == null)
|
||||
{
|
||||
_orderServices = Services
|
||||
.ToDictionary(recPC => recPC.ServiceId,
|
||||
recPC => (recPC.Service as IServiceModel, recPC.Count));
|
||||
}*/
|
||||
return _orderServices;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Models
|
||||
{
|
||||
public class Position : IPositionModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[ForeignKey("PositionId")]
|
||||
public virtual List<Employee> Employees { get; set; } = new();
|
||||
|
||||
public static Position Create(PositionBindingModel model)
|
||||
{
|
||||
return new Position()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name
|
||||
};
|
||||
}
|
||||
public void Update(PositionBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
}
|
||||
|
||||
public PositionViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name
|
||||
};
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonDataModels;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Models
|
||||
{
|
||||
public class Service : IServiceModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
[ForeignKey("ServiceId")]
|
||||
public virtual List<ServiceOrder> OrderServices { get; set; } = new();
|
||||
|
||||
public static Service Create(ServiceBindingModel model)
|
||||
{
|
||||
return new Service()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price
|
||||
};
|
||||
}
|
||||
public void Update(ServiceBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public ServiceViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price
|
||||
};
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Models
|
||||
{
|
||||
public class ServiceOrder
|
||||
{
|
||||
[Required]
|
||||
public int ServiceId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int OrderId { get; set; }
|
||||
[Required]
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public virtual Service Service { get; set; } = new();
|
||||
|
||||
public virtual Order Order { get; set; } = new();
|
||||
|
||||
public virtual Employee Employee { get; set; } = new();
|
||||
}
|
||||
}
|
215
BeautySaloon/BeautySaloonDatabaseImplement/NewdbContext.cs
Normal file
215
BeautySaloon/BeautySaloonDatabaseImplement/NewdbContext.cs
Normal file
@ -0,0 +1,215 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement;
|
||||
|
||||
public partial class NewdbContext : DbContext
|
||||
{
|
||||
public NewdbContext()
|
||||
{
|
||||
}
|
||||
|
||||
public NewdbContext(DbContextOptions<NewdbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<Client> Clients { get; set; }
|
||||
|
||||
public virtual DbSet<Employee> Employees { get; set; }
|
||||
|
||||
public virtual DbSet<Order> Orders { get; set; }
|
||||
|
||||
public virtual DbSet<Position> Positions { get; set; }
|
||||
|
||||
public virtual DbSet<Service> Services { get; set; }
|
||||
|
||||
public virtual DbSet<ServiceOrder> ServiceOrders { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
|
||||
=> optionsBuilder.UseNpgsql("Host=192.168.0.103;Port=5432;Database=newdb;Username=username123;Password=12345");
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Client>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("client_pkey");
|
||||
|
||||
entity.ToTable("clients", tb => tb.HasComment("Сущность клиенты"));
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasComment("Уникальный идентификатор")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(40)
|
||||
.HasComment("Имя")
|
||||
.HasColumnName("name");
|
||||
entity.Property(e => e.Patronymic)
|
||||
.HasMaxLength(40)
|
||||
.HasDefaultValueSql("'Отсутствует'::character varying")
|
||||
.HasComment("Отчество")
|
||||
.HasColumnName("patronymic");
|
||||
entity.Property(e => e.Phone)
|
||||
.HasMaxLength(11)
|
||||
.HasComment("Номер телефона")
|
||||
.HasColumnName("phone");
|
||||
entity.Property(e => e.Surname)
|
||||
.HasMaxLength(40)
|
||||
.HasComment("Фамилия")
|
||||
.HasColumnName("surname");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Employee>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("employee_pkey");
|
||||
|
||||
entity.ToTable("employees", tb => tb.HasComment("Сущность сотрудники"));
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasComment("Уникальный идентификатор")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(40)
|
||||
.HasComment("Имя")
|
||||
.HasColumnName("name");
|
||||
entity.Property(e => e.Patronymic)
|
||||
.HasMaxLength(40)
|
||||
.HasDefaultValueSql("'Отсутствует'::character varying")
|
||||
.HasComment("Отчество")
|
||||
.HasColumnName("patronymic");
|
||||
entity.Property(e => e.Phone)
|
||||
.HasMaxLength(11)
|
||||
.HasComment("Номер телефона")
|
||||
.HasColumnName("phone");
|
||||
entity.Property(e => e.PositionId)
|
||||
.HasComment("Идентификатор позиции")
|
||||
.HasColumnName("position_id");
|
||||
entity.Property(e => e.Surname)
|
||||
.HasMaxLength(40)
|
||||
.HasComment("Фамилия")
|
||||
.HasColumnName("surname");
|
||||
|
||||
entity.HasOne(d => d.Position).WithMany(p => p.Employees)
|
||||
.HasForeignKey(d => d.PositionId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("position_fk");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Order>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("order_table_pkey");
|
||||
|
||||
entity.ToTable("orders", tb => tb.HasComment("Сущность заказы"));
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasComment("Уникальный идентификатор")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.ClientId)
|
||||
.HasComment("Идентификатор клиента")
|
||||
.HasColumnName("client_id");
|
||||
entity.Property(e => e.Date)
|
||||
.HasComment("Дата")
|
||||
.HasColumnName("date");
|
||||
entity.Property(e => e.EmployeeId)
|
||||
.HasComment("Идентификатор сотрудника")
|
||||
.HasColumnName("employee_id");
|
||||
entity.Property(e => e.Sum)
|
||||
.HasPrecision(6, 2)
|
||||
.HasComment("Сумма")
|
||||
.HasColumnName("sum");
|
||||
|
||||
entity.HasOne(d => d.Client).WithMany(p => p.Orders)
|
||||
.HasForeignKey(d => d.ClientId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("client_fk");
|
||||
|
||||
entity.HasOne(d => d.Employee).WithMany(p => p.Orders)
|
||||
.HasForeignKey(d => d.EmployeeId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("employee_fk");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Position>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("position_pkey");
|
||||
|
||||
entity.ToTable("positions", tb => tb.HasComment("Сущность позиции"));
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasComment("Идентификатор")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(40)
|
||||
.HasComment("Название")
|
||||
.HasColumnName("name");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Service>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Id).HasName("service_pkey");
|
||||
|
||||
entity.ToTable("services", tb => tb.HasComment("Сущность услуги"));
|
||||
|
||||
entity.Property(e => e.Id)
|
||||
.ValueGeneratedNever()
|
||||
.HasComment("Уникальный идентификатор")
|
||||
.HasColumnName("id");
|
||||
entity.Property(e => e.Name)
|
||||
.HasMaxLength(40)
|
||||
.HasComment("Название")
|
||||
.HasColumnName("name");
|
||||
entity.Property(e => e.Price)
|
||||
.HasPrecision(6, 2)
|
||||
.HasComment("Цена")
|
||||
.HasColumnName("price");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ServiceOrder>(entity =>
|
||||
{
|
||||
entity.HasKey(e => new { e.ServiceId, e.OrderId }).HasName("service_order_pkey");
|
||||
|
||||
entity.ToTable("service_order", tb => tb.HasComment("Сущность-связь услуги с заказом"));
|
||||
|
||||
entity.HasIndex(e => e.OrderId, "service_order_orderid_key").IsUnique();
|
||||
|
||||
entity.HasIndex(e => e.ServiceId, "service_order_serviceid_key").IsUnique();
|
||||
|
||||
entity.Property(e => e.ServiceId)
|
||||
.HasComment("Составной первичный ключ: идентификатор услуги")
|
||||
.HasColumnName("service_id");
|
||||
entity.Property(e => e.OrderId)
|
||||
.HasComment("Составной первичный ключ: идентификатор заказа")
|
||||
.HasColumnName("order_id");
|
||||
entity.Property(e => e.Date)
|
||||
.HasPrecision(6)
|
||||
.HasComment("Время")
|
||||
.HasColumnName("date");
|
||||
entity.Property(e => e.EmployeeId)
|
||||
.HasComment("Идентификатор сотрудника")
|
||||
.HasColumnName("employee_id");
|
||||
|
||||
entity.HasOne(d => d.Employee).WithMany(p => p.ServiceOrders)
|
||||
.HasForeignKey(d => d.EmployeeId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("employee_fk");
|
||||
|
||||
entity.HasOne(d => d.Order).WithOne(p => p.ServiceOrder)
|
||||
.HasForeignKey<ServiceOrder>(d => d.OrderId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("order_fk");
|
||||
|
||||
entity.HasOne(d => d.Service).WithOne(p => p.ServiceOrder)
|
||||
.HasForeignKey<ServiceOrder>(d => d.ServiceId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("service_fk");
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
93
BeautySaloon/BeautySaloonDatabaseImplement/Order.cs
Normal file
93
BeautySaloon/BeautySaloonDatabaseImplement/Order.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Numerics;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность заказы
|
||||
/// </summary>
|
||||
public partial class Order : IOrderModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Уникальный идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата
|
||||
/// </summary>
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Сумма
|
||||
/// </summary>
|
||||
public decimal Sum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор клиента
|
||||
/// </summary>
|
||||
public int ClientId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор сотрудника
|
||||
/// </summary>
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
public virtual Client Client { get; set; } = null!;
|
||||
|
||||
public virtual Employee Employee { get; set; } = null!;
|
||||
|
||||
public virtual ServiceOrder? ServiceOrder { get; set; }
|
||||
|
||||
|
||||
public Dictionary<int, (TimeOnly, IServiceModel, IEmployeeModel)> _orderServices = null;
|
||||
|
||||
public virtual List<ServiceOrder> Services { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (TimeOnly, IServiceModel, IEmployeeModel)> OrderServices
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ServiceOrder != null)
|
||||
{
|
||||
_orderServices = Services
|
||||
.ToDictionary(x => x.ServiceId,
|
||||
x => (x.Date, x.Service as IServiceModel, x.Employee as IEmployeeModel));
|
||||
}
|
||||
return _orderServices;
|
||||
}
|
||||
}
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
Date = model.Date,
|
||||
Sum = model.Sum,
|
||||
ClientId = model.ClientId,
|
||||
EmployeeId = model.EmployeeId
|
||||
};
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Date = Date,
|
||||
Sum = Sum,
|
||||
ClientId = ClientId,
|
||||
EmployeeId = EmployeeId,
|
||||
ClientName = Client.Name,
|
||||
EmployeeName = Employee.Name,
|
||||
ClientPhone = Client.Phone,
|
||||
EmployeePhone = Employee.Phone
|
||||
};
|
||||
}
|
42
BeautySaloon/BeautySaloonDatabaseImplement/Position.cs
Normal file
42
BeautySaloon/BeautySaloonDatabaseImplement/Position.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность позиции
|
||||
/// </summary>
|
||||
public partial class Position : IPositionModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public virtual ICollection<Employee> Employees { get; } = new List<Employee>();
|
||||
|
||||
public static Position Create(PositionBindingModel model)
|
||||
{
|
||||
return new Position()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name
|
||||
};
|
||||
}
|
||||
public void Update(PositionBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
}
|
||||
|
||||
public PositionViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name
|
||||
};
|
||||
}
|
52
BeautySaloon/BeautySaloonDatabaseImplement/Service.cs
Normal file
52
BeautySaloon/BeautySaloonDatabaseImplement/Service.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность услуги
|
||||
/// </summary>
|
||||
public partial class Service : IServiceModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Уникальный идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название
|
||||
/// </summary>
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Цена
|
||||
/// </summary>
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public virtual ServiceOrder? ServiceOrder { get; set; }
|
||||
|
||||
public static Service Create(ServiceBindingModel model)
|
||||
{
|
||||
return new Service()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price
|
||||
};
|
||||
}
|
||||
public void Update(ServiceBindingModel model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public ServiceViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Price = Price
|
||||
};
|
||||
}
|
36
BeautySaloon/BeautySaloonDatabaseImplement/ServiceOrder.cs
Normal file
36
BeautySaloon/BeautySaloonDatabaseImplement/ServiceOrder.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement;
|
||||
|
||||
/// <summary>
|
||||
/// Сущность-связь услуги с заказом
|
||||
/// </summary>
|
||||
public partial class ServiceOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Составной первичный ключ: идентификатор услуги
|
||||
/// </summary>
|
||||
public int ServiceId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Составной первичный ключ: идентификатор заказа
|
||||
/// </summary>
|
||||
public int OrderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Время
|
||||
/// </summary>
|
||||
public TimeOnly Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор сотрудника
|
||||
/// </summary>
|
||||
public int EmployeeId { get; set; }
|
||||
|
||||
public virtual Employee Employee { get; set; } = null!;
|
||||
|
||||
public virtual Order Order { get; set; } = null!;
|
||||
|
||||
public virtual Service Service { get; set; } = null!;
|
||||
}
|
@ -9,12 +9,17 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BeautySaloonBusinessLogic\BeautySaloonBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\BeautySaloonContracts\BeautySaloonContracts.csproj" />
|
||||
<ProjectReference Include="..\BeautySaloonDatabaseImplement\BeautySaloonDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\BeautySaloonDataModels\BeautySaloonDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
120
BeautySaloon/BeautySaloonView/FormMain.Designer.cs
generated
120
BeautySaloon/BeautySaloonView/FormMain.Designer.cs
generated
@ -28,12 +28,126 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.должностиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.услугиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.сотрудникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonCreateOrder = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 24);
|
||||
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new System.Drawing.Size(854, 515);
|
||||
this.dataGridView.TabIndex = 8;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.справочникиToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1037, 24);
|
||||
this.menuStrip1.TabIndex = 9;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// справочникиToolStripMenuItem
|
||||
//
|
||||
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.должностиToolStripMenuItem,
|
||||
this.услугиToolStripMenuItem,
|
||||
this.сотрудникиToolStripMenuItem,
|
||||
this.клиентыToolStripMenuItem});
|
||||
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
|
||||
this.справочникиToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// должностиToolStripMenuItem
|
||||
//
|
||||
this.должностиToolStripMenuItem.Name = "должностиToolStripMenuItem";
|
||||
this.должностиToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.должностиToolStripMenuItem.Text = "Должности";
|
||||
//
|
||||
// услугиToolStripMenuItem
|
||||
//
|
||||
this.услугиToolStripMenuItem.Name = "услугиToolStripMenuItem";
|
||||
this.услугиToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.услугиToolStripMenuItem.Text = "Услуги";
|
||||
//
|
||||
// сотрудникиToolStripMenuItem
|
||||
//
|
||||
this.сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem";
|
||||
this.сотрудникиToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.сотрудникиToolStripMenuItem.Text = "Сотрудники";
|
||||
//
|
||||
// клиентыToolStripMenuItem
|
||||
//
|
||||
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
|
||||
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.клиентыToolStripMenuItem.Text = "Клиенты";
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
this.buttonUpdate.Location = new System.Drawing.Point(885, 270);
|
||||
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUpdate.Name = "buttonUpdate";
|
||||
this.buttonUpdate.Size = new System.Drawing.Size(116, 58);
|
||||
this.buttonUpdate.TabIndex = 17;
|
||||
this.buttonUpdate.Text = "Обновить";
|
||||
this.buttonUpdate.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonCreateOrder
|
||||
//
|
||||
this.buttonCreateOrder.Location = new System.Drawing.Point(885, 208);
|
||||
this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCreateOrder.Name = "buttonCreateOrder";
|
||||
this.buttonCreateOrder.Size = new System.Drawing.Size(116, 58);
|
||||
this.buttonCreateOrder.TabIndex = 13;
|
||||
this.buttonCreateOrder.Text = "Создать заказ";
|
||||
this.buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
this.ClientSize = new System.Drawing.Size(1037, 539);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonCreateOrder);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.MainMenuStrip = this.menuStrip1;
|
||||
this.Name = "FormMain";
|
||||
this.Text = "Салон красоты";
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||
private ToolStripMenuItem должностиToolStripMenuItem;
|
||||
private ToolStripMenuItem услугиToolStripMenuItem;
|
||||
private ToolStripMenuItem сотрудникиToolStripMenuItem;
|
||||
private ToolStripMenuItem клиентыToolStripMenuItem;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonCreateOrder;
|
||||
}
|
||||
}
|
@ -1,64 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
@ -117,4 +57,7 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user