все само починилось :)
This commit is contained in:
parent
6cf5536154
commit
2f39bace9a
@ -54,7 +54,9 @@ namespace ComputersShop
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
|
@ -17,6 +17,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
static readonly object locker = new object();
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
@ -73,41 +74,42 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
}
|
||||
public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (viewModel == null)
|
||||
CheckModel(model, false);
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("Read operation failed");
|
||||
return false;
|
||||
}
|
||||
if (element.Status != newStatus - 1)
|
||||
{
|
||||
_logger.LogWarning("Status change operation failed");
|
||||
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
|
||||
}
|
||||
if (element.ImplementerId.HasValue)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(viewModel));
|
||||
model.ImplementerId = element.ImplementerId;
|
||||
}
|
||||
if (viewModel.Status + 1 != newStatus)
|
||||
{
|
||||
_logger.LogWarning("Status change operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = newStatus;
|
||||
model.ComputerId = viewModel.ComputerId;
|
||||
model.Count = viewModel.Count;
|
||||
model.Sum = viewModel.Sum;
|
||||
model.DateCreate = viewModel.DateCreate;
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
OrderStatus oldStatus = model.Status;
|
||||
model.Status = newStatus;
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
}
|
||||
CheckModel(model, false);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Status change operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status = oldStatus;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
lock (locker)
|
||||
{
|
||||
return ChangeStatus(model, OrderStatus.Выполняется);
|
||||
}
|
||||
}
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ namespace ComputersShopBusinessLogic.BusinessLogics
|
||||
_logger.LogDebug("DoWork. Worker {Id} finish order { Order}", implementer.Id, order.Id);
|
||||
_orderLogic.FinishOrder(new OrderBindingModel
|
||||
{
|
||||
Id = order.Id
|
||||
Id = order.Id,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,6 @@ namespace ComputersShopContracts.SearchModels
|
||||
public DateTime? DateTo { get; set;}
|
||||
public int? ClientId { get; set; }
|
||||
public int? ImplementerId { get; set; }
|
||||
public OrderStatus Status { get; set; }
|
||||
public OrderStatus? Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -21,30 +21,33 @@ namespace ComputersShopDatabaseImplements.Implements
|
||||
return null;
|
||||
}
|
||||
using var context = new ComputersShopDatabase();
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public List<OrderViewModel> GetFiltredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Id.HasValue)
|
||||
if (!model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Id.HasValue && !model.Status.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new ComputersShopDatabase();
|
||||
if (model.DateFrom.HasValue)
|
||||
{
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
return context.Orders.Where(x => x.Id == model.Id).Include(x => x.Computer).Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
if (model.Status.HasValue)
|
||||
{
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.Status.Equals(model.Status)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
return context.Orders.Where(x => x.Id == model.Id).Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new ComputersShopDatabase();
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Select(x => x.GetViewModel).ToList();
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
@ -56,7 +59,7 @@ namespace ComputersShopDatabaseImplements.Implements
|
||||
using var context = new ComputersShopDatabase();
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
@ -68,7 +71,7 @@ namespace ComputersShopDatabaseImplements.Implements
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Computer).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
|
@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace ComputersShopDatabaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(ComputersShopDatabase))]
|
||||
[Migration("20240418224044_Mig")]
|
||||
partial class Mig
|
||||
[Migration("20240420140804_one")]
|
||||
partial class one
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -167,7 +167,6 @@ namespace ComputersShopDatabaseImplements.Migrations
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
@ -222,9 +221,7 @@ namespace ComputersShopDatabaseImplements.Migrations
|
||||
|
||||
b.HasOne("ComputersShopDatabaseImplements.Models.Implementer", "Implementer")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
@ -1,11 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ComputersShopDatabaseImplements.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Mig : Migration
|
||||
public partial class one : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@ -104,7 +105,7 @@ namespace ComputersShopDatabaseImplements.Migrations
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComputerId = table.Column<int>(type: "int", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: false),
|
||||
ImplementerId = table.Column<int>(type: "int", nullable: false),
|
||||
ImplementerId = table.Column<int>(type: "int", nullable: true),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
@ -130,8 +131,7 @@ namespace ComputersShopDatabaseImplements.Migrations
|
||||
name: "FK_Orders_Implementers_ImplementerId",
|
||||
column: x => x.ImplementerId,
|
||||
principalTable: "Implementers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
@ -164,7 +164,6 @@ namespace ComputersShopDatabaseImplements.Migrations
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int?>("ImplementerId")
|
||||
.IsRequired()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
@ -219,9 +218,7 @@ namespace ComputersShopDatabaseImplements.Migrations
|
||||
|
||||
b.HasOne("ComputersShopDatabaseImplements.Models.Implementer", "Implementer")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ImplementerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
.HasForeignKey("ImplementerId");
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
|
@ -18,7 +18,6 @@ namespace ComputersShopDatabaseImplements.Models
|
||||
public int ComputerId { get; private set; }
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
[Required]
|
||||
public int? ImplementerId { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
@ -31,7 +30,7 @@ namespace ComputersShopDatabaseImplements.Models
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public virtual Computer Computer { get; private set; }
|
||||
public virtual Client Client { get; private set; }
|
||||
public virtual Implementer Implementer { get; private set; }
|
||||
public virtual Implementer? Implementer { get; private set; }
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -60,7 +59,6 @@ namespace ComputersShopDatabaseImplements.Models
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
ImplementerId = model.ImplementerId;
|
||||
|
||||
}
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
@ -73,9 +71,9 @@ namespace ComputersShopDatabaseImplements.Models
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
ComputerName = Computer.ComputerName,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
ImplementerFIO = Implementer.ImplementerFIO
|
||||
};
|
||||
ComputerName = Computer.ComputerName ?? string.Empty,
|
||||
ClientFIO = Client.ClientFIO ?? string.Empty,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user