жестко наисправляла

This commit is contained in:
Allllen4a 2024-04-30 14:02:28 +04:00
parent fecdbe8d69
commit 86c536ecc7
4 changed files with 37 additions and 20 deletions

View File

@ -0,0 +1,16 @@
namespace BeautySalonContracts.ViewModels
{
public class CosmeticProcedureViewModel
{
public CosmeticViewModel Cosmetic { get; set; } = null!;
public int Count { get; set; }
public CosmeticProcedureViewModel() { }
public CosmeticProcedureViewModel(CosmeticViewModel cosmetic, int count)
{
Cosmetic = cosmetic;
Count = count;
}
}
}

View File

@ -19,8 +19,8 @@ namespace BeautySalonContracts.ViewModels
public int ClientId { get; set; }
public int Id { get; set; }
public List<ProcedureEvaluationViewModel> ProcedureCosmetics { get; set; } = new();
public List<EvaluationViewModel> ProcedureRatings { get; set; } = new();
public List<CosmeticProcedureViewModel> CosmeticProcedures { get; set; } = new();
public List<EvaluationViewModel> ProcedureEvaluations{ get; set; } = new();
}
}

View File

@ -32,6 +32,7 @@ namespace BeautySalonDatabaseImplement
public virtual DbSet<OrderCosmetic> OrderCosmetics { set; get; }
public virtual DbSet<OrderService> OrderServices { set; get; }
public virtual DbSet<OrderProcedure> OrderProcedures { set; get; }
public virtual DbSet<CosmeticProcedure> CosmeticProcedures { set; get; }
}

View File

@ -25,39 +25,39 @@ namespace BeautySalonDatabaseImplement.Models
public virtual Client Client { get; set; } = null!;
private List<CosmeticProcedureViewModel>? _procedureCosmetics = null;
private List<CosmeticProcedureViewModel>? _cosmeticProcedures = null;
[NotMapped]
public List<ProcedureCosmeticViewModel> ProcedureCosmetics
public List<CosmeticProcedureViewModel> CosmeticProcedures
{
get
{
_procedureCosmetics ??= Cosmetics
.Select(pc => new ProcedureCosmeticViewModel(pc.Cosmetic.GetViewModel, pc.ProcedureCosmeticCount))
_cosmeticProcedures ??= Cosmetics
.Select(pc => new CosmeticProcedureViewModel(pc.Cosmetic.GetViewModel, pc.ProcedureCosmeticCount))
.ToList();
return _procedureCosmetics;
return _cosmeticProcedures;
}
}
// связь процедуры и оценок один - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<Evaluation> Ratings { get; set; } = new();
public virtual List<Evaluation> Evaluations { get; set; } = new();
private List<EvaluationViewModel>? _procedureRatings = null;
private List<EvaluationViewModel>? _procedureEvaluations = null;
[NotMapped]
public List<EvaluationViewModel> ProcedureRatings
public List<EvaluationViewModel> ProcedureEvaluations
{
get
{
_procedureRatings ??= Ratings
_procedureEvaluations ??= Evaluations
.Select(x => x.GetViewModel)
.ToList();
return _procedureRatings;
return _procedureEvaluations;
}
}
// связь процедур и косметки многие - ко - многим
[ForeignKey("ProcedureId")]
public virtual List<ProcedureCosmetic> Cosmetics { get; set; } = new();
public virtual List<CosmeticProcedure> Cosmetics { get; set; } = new();
// связь процедур и заказов многие - ко - многим
[ForeignKey("ProcedureId")]
@ -71,7 +71,7 @@ namespace BeautySalonDatabaseImplement.Models
Id = model.Id,
ProcedureName = model.ProcedureName,
ProcedurePrice = model.ProcedurePrice,
Cosmetics = model.ProcedureCosmetics.Select(x => new ProcedureCosmetic()
Cosmetics = model.ProcedureCosmetics.Select(x => new CosmeticProcedure()
{
Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id),
ProcedureCosmeticCount = x.Count
@ -91,22 +91,22 @@ namespace BeautySalonDatabaseImplement.Models
Id = Id,
ProcedureName = ProcedureName,
ProcedurePrice = ProcedurePrice,
ProcedureCosmetics = ProcedureCosmetics,
ProcedureRatings = ProcedureRatings,
CosmeticProcedures = CosmeticProcedures,
ProcedureEvaluations = ProcedureEvaluations,
ClientId = ClientId
};
public void UpdateCosmetics(BeautySalonDatabase context, ProcedureBindingModel model)
{
var procedureCosmetics = context.ProcedureCosmetics
var procedureCosmetics = context.CosmeticProcedures
.Where(x => x.ProcedureId == model.Id)
.ToList();
context.ProcedureCosmetics
context.CosmeticProcedures
.RemoveRange(procedureCosmetics);
var procedure = context.Procedures.First(x => x.Id == Id);
foreach (var record in model.ProcedureCosmetics)
{
context.ProcedureCosmetics.Add(new ProcedureCosmetic
context.CosmeticProcedures.Add(new CosmeticProcedure
{
Procedure = procedure,
Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id),
@ -114,7 +114,7 @@ namespace BeautySalonDatabaseImplement.Models
});
context.SaveChanges();
}
_procedureCosmetics = null;
_cosmeticProcedures = null;
}
}