изменила классы с заказами для работы с исполнителем
This commit is contained in:
parent
a9ea7f8522
commit
bdc14267d0
@ -12,6 +12,7 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
static readonly object blocking = new object();
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
@ -19,6 +20,23 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
_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)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||
@ -47,7 +65,10 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
lock (blocking)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
@ -76,10 +97,6 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
model.SushiId = order.SushiId;
|
||||
model.Count = order.Count;
|
||||
model.Sum = order.Sum;
|
||||
model.DateCreate = order.DateCreate;
|
||||
model.Status = orderStatus;
|
||||
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
|
@ -13,7 +13,9 @@ namespace SushiBarContracts.BindingModel
|
||||
public int Id { get; set; }
|
||||
public int SushiId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
@ -6,6 +6,7 @@ namespace SushiBarContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IOrderLogic
|
||||
{
|
||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
bool CreateOrder(OrderBindingModel model);
|
||||
bool TakeOrderInWork(OrderBindingModel model);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SushiBarDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -10,8 +11,10 @@ namespace SushiBarContracts.SearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public OrderStatus? Status { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,14 @@ namespace SushiBarContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
public int SushiId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
|
||||
[DisplayName("Имя клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Имя исполнителя")]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Суши")]
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
|
@ -6,6 +6,7 @@ namespace SushiBarDataModels
|
||||
{
|
||||
int SushiId { get; }
|
||||
int ClientId { get; }
|
||||
int? ImplementerId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
@ -13,20 +13,29 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
using var context = new SushiBarDatabase();
|
||||
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.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -37,7 +46,15 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
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)
|
||||
{
|
||||
@ -49,7 +66,11 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
}
|
||||
context.Orders.Add(newOrder);
|
||||
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)
|
||||
{
|
||||
@ -61,7 +82,11 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
}
|
||||
order.Update(model);
|
||||
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)
|
||||
{
|
||||
|
@ -15,6 +15,9 @@ namespace SushiBarDatabaseImplement.Models
|
||||
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
@ -30,6 +33,7 @@ namespace SushiBarDatabaseImplement.Models
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
public virtual Implementer? Implementer { get; set; }
|
||||
|
||||
public virtual Sushi Sushi { get; set; }
|
||||
|
||||
@ -48,7 +52,8 @@ namespace SushiBarDatabaseImplement.Models
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
ClientId = model.ClientId,
|
||||
ImplementerId = model.ImplementerId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -60,6 +65,7 @@ namespace SushiBarDatabaseImplement.Models
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
@ -72,7 +78,9 @@ namespace SushiBarDatabaseImplement.Models
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId,
|
||||
ClientFIO = Client.ClientFIO
|
||||
ImplementerId =ImplementerId,
|
||||
ClientFIO = Client?.ClientFIO ?? string.Empty,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user