Обновлена сущность заказа для связи с исполнителем
This commit is contained in:
parent
d0c2d6737f
commit
bb38b406ca
@ -14,6 +14,7 @@ namespace ConfectioneryFileImplement.Models
|
||||
|
||||
public int ClientId { get; set; }
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -40,6 +41,7 @@ namespace ConfectioneryFileImplement.Models
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Id = model.Id,
|
||||
};
|
||||
}
|
||||
@ -59,6 +61,7 @@ namespace ConfectioneryFileImplement.Models
|
||||
PastryId = Convert.ToInt32(element.Element("PastryId")!.Value),
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
|
||||
DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement),
|
||||
};
|
||||
}
|
||||
@ -79,6 +82,7 @@ namespace ConfectioneryFileImplement.Models
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
ImplementerFIO = DataFileSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty,
|
||||
PastryName = DataFileSingleton.GetInstance().Pastries.FirstOrDefault(x => x.Id == PastryId)?.PastryName ?? string.Empty,
|
||||
ClientFIO = DataFileSingleton.GetInstance().Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
|
||||
PastryId = PastryId,
|
||||
@ -88,6 +92,7 @@ namespace ConfectioneryFileImplement.Models
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ImplementerId = ImplementerId,
|
||||
Id = Id,
|
||||
};
|
||||
public XElement GetXElement => new("Order",
|
||||
@ -98,7 +103,8 @@ namespace ConfectioneryFileImplement.Models
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", (int)Status),
|
||||
new XElement("DateCreate", DateCreate),
|
||||
new XElement("DateImplement", DateImplement)
|
||||
new XElement("DateImplement", DateImplement),
|
||||
new XElement("ImplementerId", ImplementerId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ namespace ConfectioneryFileImplement
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
|
||||
}
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
@ -50,6 +54,13 @@ namespace ConfectioneryFileImplement
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (!model.Id.HasValue && model.Status.HasValue)
|
||||
{
|
||||
return _source.Orders
|
||||
.Where(x => x.Status == model.Status)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
var result = GetElement(model);
|
||||
return result != null ? new() { result } : new();
|
||||
|
@ -13,6 +13,8 @@ namespace ConfectioneryListImplement.Models
|
||||
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
@ -38,6 +40,7 @@ namespace ConfectioneryListImplement.Models
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Id = model.Id,
|
||||
};
|
||||
}
|
||||
@ -60,6 +63,8 @@ namespace ConfectioneryListImplement.Models
|
||||
PastryId = PastryId,
|
||||
ClientFIO = DataListSingleton.GetInstance().Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
ImplementerFIO = DataListSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -30,6 +30,10 @@ namespace ConfectioneryListImplement
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
|
||||
}
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
@ -61,6 +65,18 @@ namespace ConfectioneryListImplement
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (!model.Id.HasValue && model.Status.HasValue)
|
||||
{
|
||||
return _source.Orders
|
||||
.Where(x => x.Status == model.Status)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
var res = _source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId);
|
||||
return res != null ? new() { res.GetViewModel } : new();
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
|
@ -8,6 +8,7 @@ namespace ConfectioneryContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int PastryId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace ConfectioneryContracts.SearchModels
|
||||
using ConfectioneryDataModels.Enums;
|
||||
|
||||
namespace ConfectioneryContracts.SearchModels
|
||||
{
|
||||
public class OrderSearchModel
|
||||
{
|
||||
@ -9,5 +11,9 @@
|
||||
public DateTime? DateTo { get; set; }
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
public OrderStatus? Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,14 @@ namespace ConfectioneryContracts.ViewModels
|
||||
|
||||
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 PastryName { get; set; } = string.Empty;
|
||||
|
||||
|
@ -6,6 +6,7 @@ namespace ConfectioneryDataModels.Models
|
||||
{
|
||||
int PastryId { get; }
|
||||
int ClientId { get; }
|
||||
int? ImplementerId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
@ -1,8 +1,9 @@
|
||||
using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using ConfectioneryDataModels;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ConfectioneryDatabaseImplement
|
||||
namespace ConfectioneryDatabaseImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
@ -16,6 +17,9 @@ namespace ConfectioneryDatabaseImplement
|
||||
|
||||
public int Qualification { get; private set; }
|
||||
|
||||
[ForeignKey("ImplementerId")]
|
||||
public virtual List<Order> Orders { get; private set; } = new();
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -3,37 +3,33 @@ using ConfectioneryContracts.SearchModels;
|
||||
using ConfectioneryContracts.StoragesContract;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
|
||||
namespace ConfectioneryListImplement
|
||||
namespace ConfectioneryDatabaseImplement
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ImplementerStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||
{
|
||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
using var context = new ConfectioneryDatabase();
|
||||
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (res != null)
|
||||
{
|
||||
_source.Implementers.Remove(res);
|
||||
context.Implementers.Remove(res);
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||
{
|
||||
using var context = new ConfectioneryDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
if (model.ImplementerFIO != null && model.Password != null)
|
||||
return _source.Implementers
|
||||
return context.Implementers
|
||||
.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)
|
||||
&& x.Password.Equals(model.Password))
|
||||
?.GetViewModel;
|
||||
if (model.ImplementerFIO != null)
|
||||
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||
return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -50,7 +46,8 @@ namespace ConfectioneryListImplement
|
||||
}
|
||||
if (model.ImplementerFIO != null) // На случай если фио не будет уникальным (по заданию оно уникально)
|
||||
{
|
||||
return _source.Implementers
|
||||
using var context = new ConfectioneryDatabase();
|
||||
return context.Implementers
|
||||
.Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -60,23 +57,25 @@ namespace ConfectioneryListImplement
|
||||
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
using var context = new ConfectioneryDatabase();
|
||||
return context.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||
{
|
||||
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
|
||||
using var context = new ConfectioneryDatabase();
|
||||
var res = Implementer.Create(model);
|
||||
if (res != null)
|
||||
{
|
||||
_source.Implementers.Add(res);
|
||||
context.Implementers.Add(res);
|
||||
}
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||
{
|
||||
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
using var context = new ConfectioneryDatabase();
|
||||
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||
res?.Update(model);
|
||||
return res?.GetViewModel;
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -40,9 +42,10 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
|
||||
public Pastry Pastry { get; private set; }
|
||||
|
||||
|
||||
public Client Client { get; private set; }
|
||||
|
||||
public Implementer? Implementer { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -57,6 +60,7 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
ImplementerId = model.ImplementerId,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id,
|
||||
};
|
||||
@ -86,12 +90,15 @@ namespace ConfectioneryDatabaseImplement.Models
|
||||
PastryName = context.Pastries.FirstOrDefault(x => x.Id == PastryId)?.PastryName ?? string.Empty,
|
||||
// ??????
|
||||
ClientFIO = Client?.ClientFIO ?? context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO ??
|
||||
context.Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty,
|
||||
PastryId = PastryId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ImplementerId = ImplementerId,
|
||||
Id = Id,
|
||||
};
|
||||
}
|
||||
|
@ -26,6 +26,10 @@ namespace ConfectioneryDatabaseImplement.Implements
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
using var context = new ConfectioneryDatabase();
|
||||
if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return context.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)?.GetViewModel;
|
||||
}
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
@ -51,6 +55,13 @@ namespace ConfectioneryDatabaseImplement.Implements
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.Status.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Where(x => x.Status == model.Status)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user