Обновлённый order для FileIm, ListIm, DatabaseIm
This commit is contained in:
parent
48efcf07e8
commit
123cdecc96
@ -74,25 +74,38 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
||||
}
|
||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
CheckModel(model);
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (viewModel == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (model.Status + 1 != newStatus)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = newStatus;
|
||||
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
|
||||
model.DateCreate = viewModel.DateCreate;
|
||||
model.Sum = viewModel.Sum;
|
||||
model.Count = viewModel.Count;
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
model.WorkId = viewModel.WorkId;
|
||||
if (viewModel.ImplementerId.HasValue)
|
||||
{
|
||||
model.ImplementerId = viewModel.ImplementerId;
|
||||
}
|
||||
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
else
|
||||
{
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
}
|
||||
CheckModel(model);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
@ -102,12 +115,12 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Готов);
|
||||
return StatusUpdate(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выдан);
|
||||
return StatusUpdate(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using PlumbingRepairDataModels.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -12,5 +13,7 @@ namespace PlumbingRepairContracts.SearchModels
|
||||
public int? ClientId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public OrderStatus? Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,9 @@ namespace PlumbingRepairContracts.ViewModels
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("ФИО клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public int? ImplementerId { get; set; }
|
||||
[DisplayName("Исполнитель")]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
|
@ -20,7 +20,8 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
|
||||
return context.Orders.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -32,7 +33,8 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -41,7 +43,8 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -50,13 +53,29 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
else if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => x.ImplementerId == model.ImplementerId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => model.Status == x.Status)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
@ -70,7 +89,8 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
@ -91,7 +111,8 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
@ -112,7 +133,8 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
return context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
@ -127,6 +149,7 @@ namespace PlumbingRepairDataBaseImplement.Implements
|
||||
var deletedElement = context.Orders
|
||||
.Include(x => x.Work)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
context.Orders.Remove(element);
|
||||
|
@ -17,6 +17,7 @@ namespace PlumbingRepairDataBaseImplement.Models
|
||||
|
||||
public int WorkId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
public string WorkName { get; private set; } = string.Empty;
|
||||
|
||||
@ -36,8 +37,9 @@ namespace PlumbingRepairDataBaseImplement.Models
|
||||
|
||||
public virtual Work Work { get; set; }
|
||||
public virtual Client Client { get; set; }
|
||||
public virtual Implementer? Implementer { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -50,7 +52,8 @@ namespace PlumbingRepairDataBaseImplement.Models
|
||||
WorkId = model.WorkId,
|
||||
WorkName = model.WorkName,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
@ -67,6 +70,7 @@ namespace PlumbingRepairDataBaseImplement.Models
|
||||
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
@ -76,6 +80,8 @@ namespace PlumbingRepairDataBaseImplement.Models
|
||||
WorkName = Work.WorkName,
|
||||
ClientId = ClientId,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
ImplementerId = ImplementerId,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -24,5 +24,6 @@ namespace PlumbingRepairDataBaseImplement
|
||||
public virtual DbSet<WorkComponent> WorkComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ namespace PlumbingRepairDataModels.Models
|
||||
int ClientId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
int? ImplementerId { get; }
|
||||
string WorkName { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
|
@ -27,11 +27,36 @@ namespace PlumbingRepairFileImplement.Implements
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue)
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||
else if (model.DateFrom != null && model.DateTo != null)
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.ClientId.HasValue)
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.ImplementerId.HasValue)
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => x.ImplementerId == model.ImplementerId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return new();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
|
@ -16,6 +16,7 @@ namespace PlumbingRepairFileImplement.Models
|
||||
public int Id { get; private set; }
|
||||
public int WorkId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int? ImplementerId { get; private set; }
|
||||
public String WorkName { get; private set; } = string.Empty;
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
@ -35,7 +36,8 @@ namespace PlumbingRepairFileImplement.Models
|
||||
WorkId = model.WorkId,
|
||||
WorkName = model.WorkName,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
@ -54,7 +56,8 @@ namespace PlumbingRepairFileImplement.Models
|
||||
WorkId = Convert.ToInt32(element.Element("WorkId")!.Value),
|
||||
WorkName = element.Element("WorkName")!.Value,
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
@ -73,6 +76,7 @@ namespace PlumbingRepairFileImplement.Models
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
@ -80,7 +84,8 @@ namespace PlumbingRepairFileImplement.Models
|
||||
WorkId = WorkId,
|
||||
WorkName = WorkName,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
ImplementerId = ImplementerId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
@ -91,7 +96,8 @@ namespace PlumbingRepairFileImplement.Models
|
||||
new XElement("WorkName", WorkName),
|
||||
new XElement("WorkId", WorkId.ToString()),
|
||||
new XElement("ClientId", ClientId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("ImplementerId", ImplementerId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
|
@ -30,15 +30,41 @@ namespace PlumbingRepairListImplement.Implements
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (model.DateFrom.HasValue)
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (model.Id.HasValue && order.Id == model.Id)
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (model.DateFrom != null && model.DateTo != null)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (model.ClientId.HasValue)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (model.ImplementerId.HasValue)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.ImplementerId == model.ImplementerId)
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace PlumbingRepairListImplement.Models
|
||||
public int Id { get; private set; }
|
||||
public int WorkId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int? ImplementerId { get; private set; }
|
||||
public String WorkName { get; private set; } = string.Empty;
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
@ -33,7 +34,8 @@ namespace PlumbingRepairListImplement.Models
|
||||
WorkId = model.WorkId,
|
||||
WorkName = model.WorkName,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
ImplementerId = model.ImplementerId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
@ -51,6 +53,7 @@ namespace PlumbingRepairListImplement.Models
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
@ -58,7 +61,8 @@ namespace PlumbingRepairListImplement.Models
|
||||
WorkId = WorkId,
|
||||
WorkName = WorkName,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
ImplementerId = ImplementerId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
|
Loading…
Reference in New Issue
Block a user