Database (recovery...)
This commit is contained in:
parent
108a80020c
commit
2d19c33ad3
@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautyStudioContracts", "Be
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautyStudioBusinessLogic", "BeautyStudioBusinessLogic\BeautyStudioBusinessLogic.csproj", "{25B40F20-807F-4A09-80E5-4A94EE480FB6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautyStudioDatabaseImplement", "BeautyStudioDatabaseImplement\BeautyStudioDatabaseImplement.csproj", "{8BEBC76F-F7B5-46CB-A42B-28E133452D52}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{25B40F20-807F-4A09-80E5-4A94EE480FB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{25B40F20-807F-4A09-80E5-4A94EE480FB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{25B40F20-807F-4A09-80E5-4A94EE480FB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8BEBC76F-F7B5-46CB-A42B-28E133452D52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8BEBC76F-F7B5-46CB-A42B-28E133452D52}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8BEBC76F-F7B5-46CB-A42B-28E133452D52}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8BEBC76F-F7B5-46CB-A42B-28E133452D52}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using BeautyStudioDatabaseImplement.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement
|
||||
{
|
||||
public class BeautyStudioDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=BeautyStudioDatabase;Username=postgres;Password=postgres");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<OrderService> OrderService { set; get; }
|
||||
public virtual DbSet<LaborCost> LaborCost { set; get; }
|
||||
public virtual DbSet<Cosmetic> Cosmetics { set; get; }
|
||||
public virtual DbSet<Service> Services { set; get; }
|
||||
public virtual DbSet<ServiceProcedure> ServiceProcedures { set; get; }
|
||||
public virtual DbSet<Procedure> Procedures { set; get; }
|
||||
public virtual DbSet <ProcedureCosmetics> ProcedureCosmetics { set; get; }
|
||||
public virtual DbSet<Staff> Staffs { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BeautyStudioBusinessLogic\BeautyStudioBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\BeautyStudioContracts\BeautyStudioContracts.csproj" />
|
||||
<ProjectReference Include="..\BeautyStudioDataModels\BeautyStudioDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,97 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.SearchModels;
|
||||
using BeautyStudioContracts.StoragesContracts;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
|
||||
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 BeautyStudioDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
|
||||
if (!string.IsNullOrEmpty(model.ClientLogin) &&
|
||||
!string.IsNullOrEmpty(model.ClientPassword))
|
||||
return context.Clients
|
||||
.FirstOrDefault(x =>
|
||||
x.ClientLogin.Equals(model.ClientLogin) &&
|
||||
x.ClientPassword.Equals(model.ClientPassword))?
|
||||
.GetViewModel;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Clients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
|
||||
var newClient = Client.Create(model);
|
||||
|
||||
if (newClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
|
||||
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,111 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.SearchModels;
|
||||
using BeautyStudioContracts.StoragesContracts;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Implements
|
||||
{
|
||||
public class CosmeticStorage : ICosmeticStorage
|
||||
{
|
||||
public List<CosmeticViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Cosmetics
|
||||
//.Include(x => x.Procedures)
|
||||
//.ThenInclude(x => x.Procedure)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<CosmeticViewModel> GetFilteredList(CosmeticSearchModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Cosmetics
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.LaborCostId.HasValue)
|
||||
{
|
||||
return context.Cosmetics
|
||||
.Where(x => x.LaborCostId == model.LaborCostId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
public CosmeticViewModel? GetElement(CosmeticSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.CosmeticName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Cosmetics
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CosmeticName) && x.CosmeticName == model.CosmeticName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public CosmeticViewModel? Insert(CosmeticBindingModel model)
|
||||
{
|
||||
var newCosmetic = Cosmetic.Create(model);
|
||||
if (newCosmetic == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
context.Cosmetics.Add(newCosmetic);
|
||||
context.SaveChanges();
|
||||
return newCosmetic.GetViewModel;
|
||||
}
|
||||
|
||||
public CosmeticViewModel? Update(CosmeticBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var сosmetic = context.Cosmetics.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (сosmetic == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
сosmetic.Update(model);
|
||||
context.SaveChanges();
|
||||
return сosmetic.GetViewModel;
|
||||
}
|
||||
|
||||
public CosmeticViewModel? Delete(CosmeticBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var element = context.Cosmetics.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Cosmetics.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ProcedureViewModel> GetCosmeticProcedures(CosmeticSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var procedures = context.CosmeticProcedures
|
||||
.Where(x => x.CosmeticId == model.Id)
|
||||
.Select(x => x.Procedure.GetViewModel)
|
||||
.ToList();
|
||||
return procedures;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.SearchModels;
|
||||
using BeautyStudioContracts.StoragesContracts;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Implements
|
||||
{
|
||||
public class LaborCostStorage : ILaborCostStorage
|
||||
{
|
||||
public LaborCostViewModel? Delete(LaborCostBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var element = context.LaborCost.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.LaborCost.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public LaborCostViewModel? GetElement(LaborCostSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.LaborCost
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<LaborCostViewModel> GetFilteredList(LaborCostSearchModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.LaborCost
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.StaffId.HasValue)
|
||||
{
|
||||
return context.LaborCost
|
||||
.Where(x => x.StaffId == model.StaffId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<LaborCostViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.LaborCost
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public LaborCostViewModel? Insert(LaborCostBindingModel model)
|
||||
{
|
||||
var newLaborCost = LaborCost.Create(model);
|
||||
if (newLaborCost == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
context.LaborCost.Add(newLaborCost);
|
||||
context.SaveChanges();
|
||||
return newLaborCost.GetViewModel;
|
||||
}
|
||||
|
||||
public LaborCostViewModel? Update(LaborCostBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var laborCosts = context.LaborCost.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (laborCosts == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
laborCosts.Update(model);
|
||||
context.SaveChanges();
|
||||
return laborCosts.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,140 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.SearchModels;
|
||||
using BeautyStudioContracts.StoragesContracts;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var element = context.Orders
|
||||
.Include(x => x.Services)
|
||||
.Include(x => x.Procedures)
|
||||
.Include(x => x.Cosmetics)
|
||||
.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)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
if (model.ClientId.HasValue && model.OrderDate.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.Where(x => x.ClientId == model.ClientId &&
|
||||
x.OrderDate == model.OrderDate).ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Services)
|
||||
.ThenInclude(x => x.Service)
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var newOrder = Order_.Create(context, model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
order.UpdateServices(context, model);
|
||||
order.UpdateProcedures(context, model);
|
||||
order.UpdateCosmetics(context, model);
|
||||
transaction.Commit();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.SearchModels;
|
||||
using BeautyStudioContracts.StoragesContracts;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Implements
|
||||
{
|
||||
public class ProcedureStorage : IProcedureStorage
|
||||
{
|
||||
public ProcedureViewModel? Delete(ProcedureBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var element = context.Procedures
|
||||
.Include(x => x.Cosmetics)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Procedures.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProcedureViewModel? GetElement(ProcedureSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ProcedureName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Procedures
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProcedureName) && x.ProcedureName == model.ProcedureName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ProcedureViewModel> GetFilteredList(ProcedureSearchModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Procedures
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Procedures
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<ProcedureViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Procedures
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Insert(ProcedureBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var newProcedure = Procedure.Create(context, model);
|
||||
if (newProcedure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Procedures.Add(newProcedure);
|
||||
context.SaveChanges();
|
||||
return newProcedure.GetViewModel;
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Update(ProcedureBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var procedure = context.Procedures.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (procedure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
procedure.Update(model);
|
||||
context.SaveChanges();
|
||||
procedure.UpdateCosmetics(context, model);
|
||||
transaction.Commit();
|
||||
return procedure.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public List<CosmeticViewModel> GetProcedureCosmetics(ProcedureSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var cosmetics = context.CosmeticProcedures
|
||||
.Where(x => x.ProcedureId == model.Id)
|
||||
.Select(x => x.Cosmetic.GetViewModel)
|
||||
.ToList();
|
||||
return cosmetics;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.SearchModels;
|
||||
using BeautyStudioContracts.StoragesContracts;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Implements
|
||||
{
|
||||
public class ServiceStorage : IServiceStorage
|
||||
{
|
||||
public ServiceViewModel? Delete(ServiceBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var element = context.Services
|
||||
.Include(x => x.Procedures)
|
||||
.Include(x => x.Cosmetics)
|
||||
.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)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ServiceName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Services
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ServiceName) && x.ServiceName == model.ServiceName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ServiceViewModel> GetFilteredList(ServiceSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BeautyStudioDatabase();
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return context.Services
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.StaffId.HasValue)
|
||||
{
|
||||
return context.Services
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.Where(x => x.StaffId == model.StaffId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<ServiceViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Services
|
||||
.Include(x => x.Procedures)
|
||||
.ThenInclude(x => x.Procedure)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ServiceViewModel? Insert(ServiceBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
var newService = Service.Create(context, model);
|
||||
if (newService == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Services.Add(newService);
|
||||
context.SaveChanges();
|
||||
return newService.GetViewModel;
|
||||
}
|
||||
|
||||
public ServiceViewModel? Update(ServiceBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var service = context.Services.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (service == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
service.Update(model);
|
||||
context.SaveChanges();
|
||||
service.UpdateCosmetics(context, model);
|
||||
service.UpdateProcedures(context, model);
|
||||
transaction.Commit();
|
||||
return service.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.SearchModels;
|
||||
using BeautyStudioContracts.StoragesContracts;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Implements
|
||||
{
|
||||
public class StaffStorage : IStaffStorage
|
||||
{
|
||||
public StaffViewModel? Delete(StaffBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
|
||||
var element = context.Staffs.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Staffs.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public StaffViewModel? GetElement(StaffSearchModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Staffs
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
|
||||
if (!string.IsNullOrEmpty(model.StaffPassword) &&
|
||||
!string.IsNullOrEmpty(model.StaffLogin))
|
||||
return context.Staffs
|
||||
.FirstOrDefault(x =>
|
||||
x.StaffPassword.Equals(model.StaffPassword) &&
|
||||
x.StaffLogin.Equals(model.StaffLogin))?
|
||||
.GetViewModel;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<StaffViewModel> GetFilteredList(StaffSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<StaffViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
return context.Staffs
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public StaffViewModel? Insert(StaffBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
|
||||
var newStaffs = Staff.Create(model);
|
||||
|
||||
if (newStaffs == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Staffs.Add(newStaffs);
|
||||
context.SaveChanges();
|
||||
|
||||
return newStaffs.GetViewModel;
|
||||
}
|
||||
|
||||
public StaffViewModel? Update(StaffBindingModel model)
|
||||
{
|
||||
using var context = new BeautyStudioDatabase();
|
||||
|
||||
var Staffs = context.Staffs.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (Staffs == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Staffs.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return Staffs.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
68
BeautyStudio/BeautyStudioDatabaseImplement/Models/Client.cs
Normal file
68
BeautyStudio/BeautyStudioDatabaseImplement/Models/Client.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ClientLogin { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string ClientEmail { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string ClientPhone { get; set; } = string.Empty;
|
||||
[Required]
|
||||
|
||||
public string ClientPassword { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientLogin = model.ClientLogin,
|
||||
ClientFIO = model.ClientFIO,
|
||||
ClientEmail = model.ClientEmail,
|
||||
ClientPassword = model.ClientPassword,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientLogin = model.ClientLogin;
|
||||
ClientFIO = model.ClientFIO;
|
||||
ClientEmail = model.ClientEmail;
|
||||
ClientPassword = model.ClientPassword;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientLogin = ClientLogin,
|
||||
ClientFIO = ClientFIO,
|
||||
ClientEmail = ClientEmail,
|
||||
ClientPassword = ClientPassword
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class Cosmetic : ICosmeticModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string CosmeticName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double CosmeticPrice { get; set; }
|
||||
|
||||
[Required]
|
||||
public int StoreKeeperId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int LaborCostId { get; set; }
|
||||
public virtual LaborCost LaborCost { get; set; } = new();
|
||||
|
||||
public static Cosmetic Create(CosmeticBindingModel model)
|
||||
{
|
||||
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Cosmetic()
|
||||
{
|
||||
Id = model.Id,
|
||||
CosmeticName = model.CosmeticName,
|
||||
CosmeticPrice = model.CosmeticPrice,
|
||||
StoreKeeperId = model.StoreKeeperId,
|
||||
LaborCostId = model.LaborCostId
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CosmeticBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
CosmeticName = model.CosmeticName;
|
||||
CosmeticPrice = model.CosmeticPrice;
|
||||
StoreKeeperId = model.StoreKeeperId;
|
||||
LaborCostId = model.LaborCostId;
|
||||
}
|
||||
|
||||
public CosmeticViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CosmeticName = CosmeticName,
|
||||
CosmeticPrice = CosmeticPrice,
|
||||
StoreKeeperId = StoreKeeperId,
|
||||
LaborCostId = LaborCostId
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDataModels.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class LaborCost : ILaborCostModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int TimeSpent { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Difficulty { get; set; } = string.Empty;
|
||||
|
||||
public int StaffId { get; set; }
|
||||
|
||||
public virtual Staff Staff { get; set; }
|
||||
|
||||
public virtual List<Cosmetic> Cosmetics { get; set; } = new();
|
||||
|
||||
public static LaborCost? Create(LaborCostBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new LaborCost()
|
||||
{
|
||||
Id = model.Id,
|
||||
StaffId = model.StaffId,
|
||||
TimeSpent = model.TimeSpent
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(LaborCostBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
TimeSpent = model.TimeSpent;
|
||||
|
||||
}
|
||||
|
||||
public LaborCostViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
TimeSpent = TimeSpent
|
||||
};
|
||||
}
|
||||
|
||||
}
|
69
BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs
Normal file
69
BeautyStudio/BeautyStudioDatabaseImplement/Models/Order.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDataModels.Enums;
|
||||
using BeautyStudioDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
public DateTime? DateComplete { get; set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int? StaffId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ServiceId { get; set; }
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual Client? Client { get; set; }
|
||||
public virtual Staff? Staff { get; set; }
|
||||
|
||||
public static Order Create(BeautyStudioDatabase context, OrderBindingModel model)
|
||||
{
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
DateCreate = model.DateCreate,
|
||||
DateComplete = model.DateComplete,
|
||||
ClientId = model.ClientId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
StaffId = model.StaffId;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DateCreate = DateCreate,
|
||||
ClientId = ClientId
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class OrderService
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int OrderId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ServiceId { get; set; }
|
||||
|
||||
public virtual Order Order { get; set; } = new();
|
||||
public virtual Service Service { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
108
BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs
Normal file
108
BeautyStudio/BeautyStudioDatabaseImplement/Models/Procedure.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class Procedure : IProcedureModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ProcedureName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double ProcedurePrice { get; set; }
|
||||
|
||||
[Required]
|
||||
public double ProcedureDuration { get; set; }
|
||||
|
||||
public int ClientId { get; set; }
|
||||
public virtual Client Client { get; set; } = null!;
|
||||
|
||||
// связь процедуры и оценок один - ко - многим
|
||||
[ForeignKey("ProcedureId")]
|
||||
public virtual List<Evaluation> Evaluations { get; set; } = new();
|
||||
private List<EvaluationViewModel>? _procedureEvaluations = null;
|
||||
[NotMapped]
|
||||
public List<EvaluationViewModel> ProcedureEvaluations
|
||||
{
|
||||
get
|
||||
{
|
||||
_procedureEvaluations ??= Evaluations
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
return _procedureEvaluations;
|
||||
}
|
||||
}
|
||||
|
||||
// связь процедур и косметки многие - ко - многим
|
||||
[ForeignKey("ProcedureId")]
|
||||
public virtual List<CosmeticProcedure> Cosmetics { get; set; } = new();
|
||||
|
||||
private List<CosmeticProcedureViewModel>? _cosmeticProcedures = null;
|
||||
|
||||
[NotMapped]
|
||||
public List<CosmeticProcedureViewModel> CosmeticProcedures
|
||||
{
|
||||
get
|
||||
{
|
||||
_cosmeticProcedures ??= Cosmetics
|
||||
.Select(pc => new CosmeticProcedureViewModel(pc.Cosmetic.GetViewModel, pc.Procedure.GetViewModel, pc.ProcedureCosmeticCount))
|
||||
.ToList();
|
||||
return _cosmeticProcedures;
|
||||
}
|
||||
}
|
||||
|
||||
// связь процедур и заказов многие - ко - многим
|
||||
[ForeignKey("ProcedureId")]
|
||||
public virtual List<OrderCosmetic> Orders { get; set; } = new();
|
||||
|
||||
// связь процедур и заказов многие - ко - многим
|
||||
[ForeignKey("ProcedureId")]
|
||||
public virtual List<ServiceProcedure> Services { get; set; } = new();
|
||||
|
||||
|
||||
public static Procedure Create(BeautyStudioDatabase context, ProcedureBindingModel model)
|
||||
{
|
||||
return new Procedure()
|
||||
{
|
||||
Id = model.Id,
|
||||
ProcedureName = model.ProcedureName,
|
||||
ProcedurePrice = model.ProcedurePrice,
|
||||
ProcedureDuration = model.ProcedureDuration,
|
||||
Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure()
|
||||
{
|
||||
Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id),
|
||||
ProcedureCosmeticCount = x.Count
|
||||
}).ToList(),
|
||||
ClientId = model.ClientId,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ProcedureBindingModel model)
|
||||
{
|
||||
ProcedureName = model.ProcedureName;
|
||||
ProcedurePrice = model.ProcedurePrice;
|
||||
ProcedureDuration = model.ProcedureDuration;
|
||||
}
|
||||
|
||||
public ProcedureViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ProcedureName = ProcedureName,
|
||||
ProcedurePrice = ProcedurePrice,
|
||||
ProcedureDuration = ProcedureDuration,
|
||||
CosmeticProcedures = CosmeticProcedures,
|
||||
ClientId = ClientId
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class ProcedureCosmetics
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ProcedureId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int CosmeticId { get; set; }
|
||||
|
||||
public virtual Procedure Procedure { get; set; } = new();
|
||||
|
||||
public virtual Cosmetic Cosmetic { get; set; } = new();
|
||||
}
|
||||
}
|
53
BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs
Normal file
53
BeautyStudio/BeautyStudioDatabaseImplement/Models/Service.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class Service : IServiceModel
|
||||
{
|
||||
public int Id {get; set; }
|
||||
|
||||
[Required]
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
|
||||
public int StaffId { get; set; }
|
||||
public virtual Staff Staff { get; set; }
|
||||
|
||||
public static Service Create(BeautyStudioDatabase context, ServiceBindingModel model)
|
||||
{
|
||||
return new Service()
|
||||
{
|
||||
Id = model.Id,
|
||||
ServiceName = model.ServiceName,
|
||||
StaffId = model.StaffId
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ServiceBindingModel model)
|
||||
{
|
||||
ServiceName = model.ServiceName;
|
||||
StaffId = model.StaffId;
|
||||
}
|
||||
|
||||
public ServiceViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ServiceName = ServiceName,
|
||||
StaffId = StaffId
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class ServiceProcedure
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ServiceId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ProcedureId { get; set; }
|
||||
|
||||
public virtual Service Service { get; set; } = new();
|
||||
|
||||
public virtual Procedure Procedure { get; set; } = new();
|
||||
}
|
||||
}
|
75
BeautyStudio/BeautyStudioDatabaseImplement/Models/Staff.cs
Normal file
75
BeautyStudio/BeautyStudioDatabaseImplement/Models/Staff.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using BeautyStudioContracts.BindingModels;
|
||||
using BeautyStudioContracts.ViewModels;
|
||||
using BeautyStudioDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BeautyStudioDatabaseImplement.Models
|
||||
{
|
||||
public class Staff : IStaffModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string StaffFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string StaffEmail { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string StaffLogin { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string StaffPassword { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string StaffPhone { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("StaffId")]
|
||||
public virtual List<LaborCost> LaborCost { get; set; } = new();
|
||||
|
||||
[ForeignKey("StaffId")]
|
||||
public virtual List<Service> Services { get; set; } = new();
|
||||
|
||||
public static Staff? Create(StaffBindingModel model)
|
||||
{
|
||||
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Staff()
|
||||
{
|
||||
Id = model.Id,
|
||||
StaffFIO = model.StaffFIO,
|
||||
StaffLogin = model.StaffLogin,
|
||||
StaffEmail = model.StaffEmail,
|
||||
StaffPassword = model.StaffPassword,
|
||||
StaffPhone = model.StaffPhone,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(StaffBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StaffFIO = model.StaffFIO;
|
||||
StaffLogin = model.StaffLogin;
|
||||
StaffEmail = model.StaffEmail;
|
||||
StaffPassword = model.StaffPassword;
|
||||
StaffPhone = model.StaffPhone;
|
||||
}
|
||||
|
||||
public StaffViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
StaffFIO = StaffFIO,
|
||||
StaffLogin = StaffLogin,
|
||||
StaffEmail = StaffEmail,
|
||||
StaffPassword = StaffPassword,
|
||||
StaffPhone = StaffPhone,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user