ISEbd-22 Alimova M.S. Lab Work 05 base #6

Closed
malimova wants to merge 26 commits from Lab5_base into Lab4_base
6 changed files with 20 additions and 1 deletions
Showing only changes of commit ba39674377 - Show all commits

View File

@ -12,6 +12,7 @@ namespace ConfectioneryContracts.BindingModels
{
public int Id { get; set; }
public int PastryId { get; set; }
public int ClientId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -9,6 +9,7 @@ namespace ConfectioneryContracts.SearchModels
public class OrderSearchModel
{
public int? Id { get; set; }
public int? ClientId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}

View File

@ -13,6 +13,10 @@ namespace ConfectioneryContracts.ViewModels
{
[DisplayName("Номер")]
public int Id { get; set; }
public int ClientId { get; set; }
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
public int PastryId { get; set; }
[DisplayName("Изделие")]
public string PastryName { get; set; } = string.Empty;

View File

@ -10,6 +10,7 @@ namespace ConfectioneryDataModels.Models
public interface IOrderModel : IId
{
int PastryId { get; }
int ClientId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }

View File

@ -14,6 +14,10 @@ namespace ConfectioneryDatabaseImplement.Models
public class Order : IOrderModel
{
public int Id { get; private set; }
[Required]
public int ClientId { get; private set; }
public virtual Client Client { get; private set; } = new();
[Required]
public int PastryId { get; private set; }
@ -39,6 +43,8 @@ namespace ConfectioneryDatabaseImplement.Models
return new Order()
{
Id = model.Id,
ClientId = model.ClientId,
Client = context.Clients.First(x => x.Id == model.ClientId),
PastryId = model.PastryId,
Pastry = context.Pastrys.First(x => x.Id == model.PastryId),
Count = model.Count,
@ -62,6 +68,8 @@ namespace ConfectioneryDatabaseImplement.Models
public OrderViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
PastryId = PastryId,
PastryName = Pastry.PastryName,
Count = Count,

View File

@ -17,7 +17,7 @@ namespace ConfectioneryDatabaseImplement.Implements
public List<OrderViewModel> GetFullList()
{
using var context = new ConfectioneryDatabase();
return context.Orders.Include(x => x.Pastry).Select(x => x.GetViewModel).ToList();
return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Select(x => x.GetViewModel).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -27,6 +27,10 @@ namespace ConfectioneryDatabaseImplement.Implements
{
return context.Orders.Include(x => x.Pastry).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
}
if (model.ClientId.HasValue)
{
return context.Orders.Include(x => x.Pastry).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
}
return context.Orders.Include(x => x.Pastry).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
}