изменила классы с заказами для работы с исполнителем

This commit is contained in:
Елена Бакальская 2024-04-20 20:00:18 +04:00
parent a9ea7f8522
commit bdc14267d0
8 changed files with 75 additions and 14 deletions

View File

@ -12,6 +12,7 @@ namespace SushiBarBusinessLogic.BusinessLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
static readonly object blocking = new object();
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
{ {
@ -19,6 +20,23 @@ namespace SushiBarBusinessLogic.BusinessLogic
_orderStorage = orderStorage; _orderStorage = orderStorage;
} }
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var elem = _orderStorage.GetElement(model);
if (elem == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement found. Id:{Id}", elem.Id);
return elem;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model) public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{ {
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id); _logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
@ -46,9 +64,12 @@ namespace SushiBarBusinessLogic.BusinessLogic
} }
public bool TakeOrderInWork(OrderBindingModel model) public bool TakeOrderInWork(OrderBindingModel model)
{
lock (blocking)
{ {
return ChangeStatus(model, OrderStatus.Выполняется); return ChangeStatus(model, OrderStatus.Выполняется);
} }
}
public bool FinishOrder(OrderBindingModel model) public bool FinishOrder(OrderBindingModel model)
{ {
@ -76,10 +97,6 @@ namespace SushiBarBusinessLogic.BusinessLogic
return false; return false;
} }
model.SushiId = order.SushiId;
model.Count = order.Count;
model.Sum = order.Sum;
model.DateCreate = order.DateCreate;
model.Status = orderStatus; model.Status = orderStatus;
if (model.Status == OrderStatus.Готов) if (model.Status == OrderStatus.Готов)

View File

@ -13,7 +13,9 @@ namespace SushiBarContracts.BindingModel
public int Id { get; set; } public int Id { get; set; }
public int SushiId { get; set; } public int SushiId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int? ImplementerId { get; set; }
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
public string ImplementerFIO { get; set; } = string.Empty;
public int Count { get; set; } public int Count { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -6,6 +6,7 @@ namespace SushiBarContracts.BusinessLogicsContracts
{ {
public interface IOrderLogic public interface IOrderLogic
{ {
OrderViewModel? ReadElement(OrderSearchModel model);
List<OrderViewModel>? ReadList(OrderSearchModel? model); List<OrderViewModel>? ReadList(OrderSearchModel? model);
bool CreateOrder(OrderBindingModel model); bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model);

View File

@ -1,4 +1,5 @@
using System; using SushiBarDataModels.Enums;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -10,8 +11,10 @@ namespace SushiBarContracts.SearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? ClientId { get; set; } public int? ClientId { get; set; }
public int? ImplementerId { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public OrderStatus? Status { get; set; }
} }
} }

View File

@ -11,11 +11,15 @@ namespace SushiBarContracts.ViewModels
public int Id { get; set; } public int Id { get; set; }
public int SushiId { get; set; } public int SushiId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int? ImplementerId { get; set; }
[DisplayName("Имя клиента")] [DisplayName("Имя клиента")]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Имя исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Суши")] [DisplayName("Суши")]
public string SushiName { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty;

View File

@ -6,6 +6,7 @@ namespace SushiBarDataModels
{ {
int SushiId { get; } int SushiId { get; }
int ClientId { get; } int ClientId { get; }
int? ImplementerId { get; }
int Count { get; } int Count { get; }
double Sum { get; } double Sum { get; }
OrderStatus Status { get; } OrderStatus Status { get; }

View File

@ -13,20 +13,29 @@ namespace SushiBarDatabaseImplement.Implements
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();
return context.Orders.Include(x => x.Sushi).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); return context.Orders
.Include(x => x.Sushi)
.Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel).ToList();
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null)
{ {
return new(); return new();
} }
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();
return context.Orders return context.Orders
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId) .Where(x =>
x.Id == model.Id ||
model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo ||
x.ClientId == model.ClientId ||
model.Status.Equals(x.Status))
.Include(x => x.Sushi) .Include(x => x.Sushi)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -37,7 +46,15 @@ namespace SushiBarDatabaseImplement.Implements
return null; return null;
} }
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();
return context.Orders.Include(x => x.Sushi).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; return context.Orders
.Include(x => x.Sushi)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x =>
(model.Status == null || model.Status != null && model.Status.Equals(x.Status)) &&
(model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId) ||
(model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)
{ {
@ -49,7 +66,11 @@ namespace SushiBarDatabaseImplement.Implements
} }
context.Orders.Add(newOrder); context.Orders.Add(newOrder);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Sushi).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; return context.Orders
.Include(x => x.Sushi)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
{ {
@ -61,7 +82,11 @@ namespace SushiBarDatabaseImplement.Implements
} }
order.Update(model); order.Update(model);
context.SaveChanges(); context.SaveChanges();
return context.Orders.Include(x => x.Sushi).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; return context.Orders
.Include(x => x.Sushi)
.Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
} }
public OrderViewModel? Delete(OrderBindingModel model) public OrderViewModel? Delete(OrderBindingModel model)
{ {

View File

@ -16,6 +16,9 @@ namespace SushiBarDatabaseImplement.Models
[Required] [Required]
public int ClientId { get; set; } public int ClientId { get; set; }
[Required]
public int? ImplementerId { get; set; }
[Required] [Required]
public int Count { get; set; } public int Count { get; set; }
@ -30,6 +33,7 @@ namespace SushiBarDatabaseImplement.Models
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
public virtual Client Client { get; set; } public virtual Client Client { get; set; }
public virtual Implementer? Implementer { get; set; }
public virtual Sushi Sushi { get; set; } public virtual Sushi Sushi { get; set; }
@ -48,7 +52,8 @@ namespace SushiBarDatabaseImplement.Models
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
DateImplement = model.DateImplement, DateImplement = model.DateImplement,
ClientId = model.ClientId ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
}; };
} }
@ -60,6 +65,7 @@ namespace SushiBarDatabaseImplement.Models
} }
Status = model.Status; Status = model.Status;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
ImplementerId = model.ImplementerId;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
@ -72,7 +78,9 @@ namespace SushiBarDatabaseImplement.Models
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement, DateImplement = DateImplement,
ClientId = ClientId, ClientId = ClientId,
ClientFIO = Client.ClientFIO ImplementerId =ImplementerId,
ClientFIO = Client?.ClientFIO ?? string.Empty,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
}; };
} }
} }