подправила заказ

This commit is contained in:
Allllen4a 2024-04-30 13:31:58 +04:00
parent 8c62d730a8
commit dbd2b04c7d
4 changed files with 68 additions and 0 deletions

View File

@ -27,7 +27,11 @@ namespace BeautySalonDatabaseImplement.Models
public virtual LaborCosts LaborCost { get; set; }
[ForeignKey("CosmeticId")]
<<<<<<< HEAD
public virtual List<ProcedureCosmetic> Procedures { get; set; } = new();
=======
public virtual List<CosmeticProcedure> Procedures { get; set; } = new();
>>>>>>> подправила заказ
[ForeignKey("CosmeticId")]
public virtual List<ServiceCosmetic> Services { get; set; } = new();

View File

@ -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 CosmeticProcedure
{
public int Id { get; set; }
[Required]
public int CosmeticId { get; set; }
[Required]
public int ProcedureId { get; set; }
[Required]
public int ProcedureCosmeticCount { get; set; }
public virtual Cosmetic Cosmetic { get; set; } = new();
public virtual Procedure Procedure { get; set; } = new();
}
}

View File

@ -17,6 +17,12 @@ namespace BeautySalonDatabaseImplement.Models
[Required]
public int CosmeticId { get; set; }
<<<<<<< HEAD
=======
[Required]
public int OrderCosmeticCount { get; set; }
>>>>>>> подправила заказ
public virtual Order_ Order { get; set; } = new();
public virtual Cosmetic Cosmetic { get; set; } = new();

View File

@ -59,8 +59,13 @@ namespace BeautySalonDatabaseImplement.Models
{
get
{
<<<<<<< HEAD:BeautySalonView/BeautySalonDatabaseImplement/Models/Order_.cs
_orderCosmetics ??= Cosmetic
.Select(pc => new OrderCosmeticViewModel(pc.Cosmetic.GetViewModel))
=======
_orderCosmetics ??= Cosmetics
.Select(pc => new OrderCosmeticViewModel(pc.Cosmetic.GetViewModel, pc.OrderCosmeticCount))
>>>>>>> подправила заказ:BeautySalonView/BeautySalonDatabaseImplement/Models/Order.cs
.ToList();
return _orderCosmetics;
}
@ -93,6 +98,11 @@ namespace BeautySalonDatabaseImplement.Models
Procedure = context.Procedures.First(y => y.Id == x.Procedure.Id),
OrderProcedureCount = x.Count
}).ToList(),
Cosmetics= model.OrderCosmetics.Select(x => new OrderCosmetic()
{
Cosmetic = context.Cosmetics.First(y => y.Id == x.Cosmetic.Id),
OrderCosmeticCount = x.Count
}).ToList(),
ClientId = model.ClientId,
};
}
@ -154,5 +164,26 @@ namespace BeautySalonDatabaseImplement.Models
}
_orderProcedures = null;
}
public void UpdateCosmetics(BeautySalonDatabase context, OrderBindingModel model)
{
var orderCosmetic = context.OrderCosmetics
.Where(x => x.OrderId == model.Id)
.ToList();
context.OrderCosmetics
.RemoveRange(orderCosmetic);
var order = context.Orders.First(x => x.Id == Id);
foreach (var record in model.OrderCosmetics)
{
context.OrderCosmetics.Add(new OrderCosmetic
{
Order = order,
Cosmetic = context.Cosmetics.First(x => x.Id == record.Cosmetic.Id),
OrderCosmeticCount = record.Count
});
context.SaveChanges();
}
_orderCosmetics = null;
}
}
}