......
This commit is contained in:
parent
2c7f9bc6de
commit
40cb4fc70d
@ -11,6 +11,8 @@ namespace BeautySalonContracts.BindingModels
|
||||
public double ProcedurePrice { get; set; }
|
||||
public double ProcedureDuration { get; set; }
|
||||
public int WorkerId { get; set; }
|
||||
|
||||
public int EvaluationId { get; set; }
|
||||
//public List<CosmeticProcedureViewModel> ProcedureCosmetics { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (ICosmeticModel, int)> ProcedureCosmetics
|
||||
|
@ -4,6 +4,7 @@
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ProcedureName { get; set; }
|
||||
public int? EvaluationId { get; set; }
|
||||
public int? WorkerId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ namespace BeautySalonContracts.StoragesContracts
|
||||
ProcedureViewModel? Insert(ProcedureBindingModel model);
|
||||
ProcedureViewModel? Update(ProcedureBindingModel model);
|
||||
ProcedureViewModel? Delete(ProcedureBindingModel model);
|
||||
|
||||
List<CosmeticViewModel> GetProcedureCosmetics(ProcedureSearchModel model);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautySalonContracts.ViewModels
|
||||
{
|
||||
|
||||
public class ProcedureCosmeticViewModel
|
||||
{
|
||||
public CosmeticViewModel Cosmetic { get; set; } = null!;
|
||||
public ProcedureViewModel Procedure { get; set; } = null!;
|
||||
public int Count { get; set; }
|
||||
|
||||
public ProcedureCosmeticViewModel() { }
|
||||
|
||||
public ProcedureCosmeticViewModel(CosmeticViewModel cosmetic, ProcedureViewModel procedure, int count)
|
||||
{
|
||||
Cosmetic = cosmetic;
|
||||
Procedure = procedure;
|
||||
Count = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ namespace BeautySalonContracts.ViewModels
|
||||
public int WorkerId { get; set; }
|
||||
public string WorkerName { get; set; } = string.Empty;
|
||||
|
||||
public int EvaluationId { get; set; }
|
||||
|
||||
public Dictionary<int, (ICosmeticModel, int)> ProcedureCosmetics
|
||||
{
|
||||
get;
|
||||
|
@ -8,6 +8,7 @@ namespace BeautySalonDataModels.Models
|
||||
double ProcedurePrice { get; }
|
||||
double ProcedureDuration { get; }
|
||||
int WorkerId { get; }
|
||||
int EvaluationId { get; }
|
||||
Dictionary<int, (ICosmeticModel, int)> ProcedureCosmetics { get; } //список косметики "участвующей" в заказе
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ namespace BeautySalonDatabaseImplement
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=ALYONA\;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
@ -37,6 +37,7 @@ namespace BeautySalonDatabaseImplement
|
||||
public virtual DbSet<OrderService> OrderServices { set; get; }
|
||||
public virtual DbSet<OrderProcedure> OrderProcedures { set; get; }
|
||||
public virtual DbSet<CosmeticProcedure> CosmeticProcedures { set; get; }
|
||||
public virtual DbSet<ProcedureCosmetic> ProcedureCosmetics { set; get; }
|
||||
public virtual DbSet<MessageInfo> MessageInfos { set; get; }
|
||||
|
||||
}
|
||||
|
@ -14,38 +14,17 @@ namespace BeautySalonDatabaseImplement.Implements
|
||||
{
|
||||
public class ProcedureStorage : IProcedureStorage
|
||||
{
|
||||
public ProcedureViewModel? Delete(ProcedureBindingModel model)
|
||||
public List<ProcedureViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
var element = context.Procedures
|
||||
.Include(x => x.Cosmetics)
|
||||
.Include(x => x.Worker)
|
||||
.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 BeautySalonDatabase();
|
||||
return context.Procedures
|
||||
.Include(x => x.Worker)
|
||||
.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;
|
||||
.Include(x => x.Worker)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
public List<ProcedureViewModel> GetFilteredList(ProcedureSearchModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
@ -65,18 +44,24 @@ namespace BeautySalonDatabaseImplement.Implements
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
public List<ProcedureViewModel> GetFullList()
|
||||
|
||||
public ProcedureViewModel? GetElement(ProcedureSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ProcedureName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.Procedures
|
||||
.Include(x => x.Worker)
|
||||
.Include(x => x.Cosmetics)
|
||||
.ThenInclude(x => x.Cosmetic)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.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 ProcedureViewModel? Insert(ProcedureBindingModel model)
|
||||
@ -87,33 +72,42 @@ namespace BeautySalonDatabaseImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Procedures.Add(newProcedure);
|
||||
context.SaveChanges();
|
||||
return newProcedure.GetViewModel;
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Update(ProcedureBindingModel model)
|
||||
|
||||
public ProcedureViewModel? Update(BeautySalonDatabase context, ProcedureBindingModel model)
|
||||
{
|
||||
|
||||
var element = context.Procedures
|
||||
.Include(x => x.Evaluation)
|
||||
.FirstOrDefault(x => x.Id.Equals(model.Id));
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
element.Update(context, model);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public ProcedureViewModel? Delete(ProcedureBindingModel model)
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
var element = context.Procedures
|
||||
.Include(x => x.EvaluationId)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
var procedure = context.Procedures.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (procedure == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
procedure.Update(model);
|
||||
context.Procedures.Remove(element);
|
||||
context.SaveChanges();
|
||||
procedure.UpdateCosmetics(context, model);
|
||||
transaction.Commit();
|
||||
return procedure.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<CosmeticViewModel> GetProcedureCosmetics(ProcedureSearchModel model)
|
||||
@ -123,11 +117,12 @@ namespace BeautySalonDatabaseImplement.Implements
|
||||
return new();
|
||||
}
|
||||
using var context = new BeautySalonDatabase();
|
||||
var cosmetics = context.CosmeticProcedures
|
||||
var cosmetics = context.ProcedureCosmetics
|
||||
.Where(x => x.ProcedureId == model.Id)
|
||||
.Select(x => x.Cosmetic.GetViewModel)
|
||||
.ToList();
|
||||
return cosmetics;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ namespace BeautySalonDatabaseImplement.Models
|
||||
public int WorkerId { get; set; }
|
||||
public virtual Worker Worker { get; set; }
|
||||
|
||||
public int EvaluationId { get; set; }
|
||||
|
||||
public virtual Evaluation Evaluation { get; set; } = new();
|
||||
|
||||
#region
|
||||
//// связь процедуры и оценок один - ко - многим
|
||||
//[ForeignKey("ProcedureId")]
|
||||
@ -95,6 +99,7 @@ namespace BeautySalonDatabaseImplement.Models
|
||||
ProcedurePrice = model.ProcedurePrice,
|
||||
ProcedureDuration = model.ProcedureDuration,
|
||||
WorkerId = model.WorkerId,
|
||||
EvaluationId = model.EvaluationId,
|
||||
Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure
|
||||
{
|
||||
Cosmetic = context.Cosmetics.First(y => y.Id == x.Key)
|
||||
@ -109,6 +114,7 @@ namespace BeautySalonDatabaseImplement.Models
|
||||
ProcedureName = model.ProcedureName;
|
||||
ProcedurePrice = model.ProcedurePrice;
|
||||
ProcedureDuration = model.ProcedureDuration;
|
||||
EvaluationId = model.EvaluationId;
|
||||
}
|
||||
|
||||
public ProcedureViewModel GetViewModel => new()
|
||||
@ -119,7 +125,8 @@ namespace BeautySalonDatabaseImplement.Models
|
||||
ProcedureDuration = ProcedureDuration,
|
||||
ProcedureCosmetics = ProcedureCosmetics,
|
||||
WorkerId = WorkerId,
|
||||
WorkerName = Worker.FullName
|
||||
WorkerName = Worker.FullName,
|
||||
EvaluationId = EvaluationId,
|
||||
};
|
||||
|
||||
public void UpdateCosmetics(BeautySalonDatabase context, ProcedureBindingModel model)
|
||||
|
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BeautySalonDatabaseImplement.Models
|
||||
{
|
||||
public class ProcedureCosmetic
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int CosmeticId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ProcedureId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Procedure Procedure { get; set; } = new();
|
||||
public virtual Cosmetic Cosmetic { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user