еще правки

This commit is contained in:
Milana Ievlewa 2024-04-30 15:21:40 +03:00 committed by Allllen4a
parent 34e2825c61
commit 586ad5562a
5 changed files with 14 additions and 10 deletions

View File

@ -12,6 +12,6 @@ namespace BeautySalonContracts.BusinessLogicContracts
bool Create(OrderBindingModel model);
bool Delete(OrderBindingModel model);
bool Update(OrderBindingModel model);
int GetNumberOfPages(int userId, int pageSize = 10);
}
}

View File

@ -17,7 +17,6 @@ namespace BeautySalonContracts.StoragesContracts
OrderViewModel? Insert(OrderBindingModel model);
OrderViewModel? Update(OrderBindingModel model);
OrderViewModel? Delete(OrderBindingModel model);
int GetNumberOfPages(int userId, int pageSize);
}
}

View File

@ -19,5 +19,6 @@ namespace BeautySalonContracts.ViewModels
public int Id { get; set; }
public List<OrderServiceViewModel> OrderServices { get; set; } = new();
public List<OrderProcedureViewModel> OrderProcedures { get; set; } = new();
public List<OrderCosmeticViewModel> OrderCosmetics { get; set; } = new();
}
}

View File

@ -8,6 +8,7 @@ using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BeautySalonContracts.ViewModels;
namespace BeautySalonDatabaseImplement
{
@ -21,6 +22,8 @@ namespace BeautySalonDatabaseImplement
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Order_> Orders { set; get; }
public virtual DbSet<LaborCosts> LaborCosts { set; get; }
public virtual DbSet<Cosmetic> Cosmetics { set; get; }

View File

@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
@ -20,6 +21,7 @@ namespace BeautySalonDatabaseImplement.Implements
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)
{
@ -42,16 +44,12 @@ namespace BeautySalonDatabaseImplement.Implements
.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 int GetNumberOfPages(int userId, int pageSize)
{
using var context = new BeautySalonDatabase();
int carsCount = context.Orders.Where(c => c.ClientId == userId).Count();
int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize);
return numberOfpages != 0 ? numberOfpages : 1;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (model == null)
@ -66,7 +64,8 @@ namespace BeautySalonDatabaseImplement.Implements
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.ThenInclude(x => x.Evaluations)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Where(x => x.ClientId == model.ClientId &&
x.OrderDate == model.OrderDate).ToList()
.Select(x => x.GetViewModel)
@ -92,6 +91,8 @@ namespace BeautySalonDatabaseImplement.Implements
.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();