diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
index 665e281..f0f1b72 100644
--- a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -93,7 +93,7 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics
public bool DeliveryOrder(OrderBindingModel model)
{
- model.DateImplement = DateTime.Now;
+ model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
return StatusUpdate(model, OrderStatus.Готов);
}
diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs
similarity index 83%
rename from CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.Designer.cs
rename to CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs
index 7f314d6..1024bdf 100644
--- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.Designer.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs
@@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace CarpentryWorkshopDatabaseImplement.Migrations
{
[DbContext(typeof(CarpentryWorkshopDatabase))]
- [Migration("20240416072714_InitialCreate")]
+ [Migration("20240427190111_InitialCreate")]
partial class InitialCreate
{
///
@@ -70,6 +70,33 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
{
b.Property("Id")
@@ -90,6 +117,9 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("timestamp with time zone");
+ b.Property("ImplementerId")
+ .HasColumnType("integer");
+
b.Property("Status")
.HasColumnType("integer");
@@ -99,14 +129,12 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.Property("WoodId")
.HasColumnType("integer");
- b.Property("WoodName")
- .IsRequired()
- .HasColumnType("text");
-
b.HasKey("Id");
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.HasIndex("WoodId");
b.ToTable("Orders");
@@ -166,6 +194,10 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Order")
+ .HasForeignKey("ImplementerId");
+
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood")
.WithMany("Orders")
.HasForeignKey("WoodId")
@@ -174,6 +206,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.Navigation("Client");
+ b.Navigation("Implementer");
+
b.Navigation("Wood");
});
@@ -206,6 +240,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.Navigation("WoodComponents");
});
+ modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Order");
+ });
+
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b =>
{
b.Navigation("Components");
diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.cs
similarity index 82%
rename from CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.cs
rename to CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.cs
index 4feb6c9..9c8122e 100644
--- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.cs
@@ -41,6 +41,22 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
table.PrimaryKey("PK_Components", x => x.Id);
});
+ migrationBuilder.CreateTable(
+ name: "Implementers",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ ImplementerFIO = table.Column(type: "text", nullable: false),
+ Password = table.Column(type: "text", nullable: false),
+ WorkExperience = table.Column(type: "integer", nullable: false),
+ Qualification = table.Column(type: "integer", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Implementers", x => x.Id);
+ });
+
migrationBuilder.CreateTable(
name: "Woods",
columns: table => new
@@ -62,8 +78,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
Id = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
WoodId = table.Column(type: "integer", nullable: false),
+ ImplementerId = table.Column(type: "integer", nullable: true),
ClientId = table.Column(type: "integer", nullable: false),
- WoodName = table.Column(type: "text", nullable: false),
Count = table.Column(type: "integer", nullable: false),
Sum = table.Column(type: "double precision", nullable: false),
Status = table.Column(type: "integer", nullable: false),
@@ -79,6 +95,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_Orders_Implementers_ImplementerId",
+ column: x => x.ImplementerId,
+ principalTable: "Implementers",
+ principalColumn: "Id");
table.ForeignKey(
name: "FK_Orders_Woods_WoodId",
column: x => x.WoodId,
@@ -119,6 +140,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
table: "Orders",
column: "ClientId");
+ migrationBuilder.CreateIndex(
+ name: "IX_Orders_ImplementerId",
+ table: "Orders",
+ column: "ImplementerId");
+
migrationBuilder.CreateIndex(
name: "IX_Orders_WoodId",
table: "Orders",
@@ -147,6 +173,9 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Clients");
+ migrationBuilder.DropTable(
+ name: "Implementers");
+
migrationBuilder.DropTable(
name: "Components");
diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs
index 6e88e54..6300d49 100644
--- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs
@@ -67,6 +67,33 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.ToTable("Components");
});
+ modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("ImplementerFIO")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Qualification")
+ .HasColumnType("integer");
+
+ b.Property("WorkExperience")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("Implementers");
+ });
+
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b =>
{
b.Property("Id")
@@ -87,6 +114,9 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.Property("DateImplement")
.HasColumnType("timestamp with time zone");
+ b.Property("ImplementerId")
+ .HasColumnType("integer");
+
b.Property("Status")
.HasColumnType("integer");
@@ -96,14 +126,12 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.Property("WoodId")
.HasColumnType("integer");
- b.Property("WoodName")
- .IsRequired()
- .HasColumnType("text");
-
b.HasKey("Id");
b.HasIndex("ClientId");
+ b.HasIndex("ImplementerId");
+
b.HasIndex("WoodId");
b.ToTable("Orders");
@@ -163,6 +191,10 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
+ b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Implementer", "Implementer")
+ .WithMany("Order")
+ .HasForeignKey("ImplementerId");
+
b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood")
.WithMany("Orders")
.HasForeignKey("WoodId")
@@ -171,6 +203,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.Navigation("Client");
+ b.Navigation("Implementer");
+
b.Navigation("Wood");
});
@@ -203,6 +237,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations
b.Navigation("WoodComponents");
});
+ modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b =>
+ {
+ b.Navigation("Order");
+ });
+
modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b =>
{
b.Navigation("Components");
diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/DataFileSingleton.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/DataFileSingleton.cs
index 09b1a3b..26101b1 100644
--- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/DataFileSingleton.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/DataFileSingleton.cs
@@ -10,10 +10,12 @@ namespace CarpentryWorkshopFileImplement
private readonly string OrderFileName = "Order.xml";
private readonly string WoodFileName = "Wood.xml";
private readonly string ClientFileName = "Client.xml";
+ private readonly string ImplementerFileName = "Implementer.xml";
public List Components { get; private set; }
public List Orders { get; private set; }
public List Woods { get; private set; }
public List Clients { get; private set; }
+ public List Implementers { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@@ -25,12 +27,16 @@ namespace CarpentryWorkshopFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveWoods() => SaveData(Woods, WoodFileName, "Woods", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
- public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
+ public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
+
+ public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Woods = LoadData(WoodFileName, "Wood", x => Wood.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
+ Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
+ Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
}
private static List? LoadData(string filename, string xmlNodeName, Func selectFunction)
{
diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/ImplementerStorage.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..22eeb7e
--- /dev/null
+++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,92 @@
+using CarpentryWorkshopContracts.BindingModels;
+using CarpentryWorkshopContracts.SearchModels;
+using CarpentryWorkshopContracts.StoragesContracts;
+using CarpentryWorkshopContracts.ViewModels;
+using CarpentryWorkshopFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CarpentryWorkshopFileImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataFileSingleton source;
+
+ public ImplementerStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+
+ public List GetFullList()
+ {
+ return source.Implementers
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ImplementerFIO))
+ {
+ return new();
+ }
+ return source.Implementers
+ .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password))
+ {
+ return null;
+ }
+ return source.Implementers
+ .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
+ (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO &&
+ !string.IsNullOrEmpty(model.Password) && x.Password == model.Password))
+ ?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
+ var newImplementer = Implementer.Create(model);
+ if (newImplementer == null)
+ {
+ return null;
+ }
+ source.Implementers.Add(newImplementer);
+ source.SaveImplementers();
+ return newImplementer.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (implementer == null)
+ {
+ return null;
+ }
+ implementer.Update(model);
+ source.SaveImplementers();
+ return implementer.GetViewModel;
+ }
+
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ source.Implementers.Remove(element);
+ source.SaveImplementers();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/OrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/OrderStorage.cs
index f27f914..edc59b8 100644
--- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/OrderStorage.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/OrderStorage.cs
@@ -14,99 +14,128 @@ namespace CarpentryWorkshopFileImplement.Implements
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
+
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
- public List GetFullList()
- {
- return source.Orders.Select(x => GetViewModel(x)).ToList();
- }
- public List GetFilteredList(OrderSearchModel model)
- {
- if (!model.Id.HasValue && !model.DateFrom.HasValue)
- {
- return source.Orders
- .Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo)
- .Select(x => GetViewModel(x))
- .ToList();
- }
- if (model.DateFrom.HasValue)
- {
- return source.Orders
- .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
- .Select(x => x.GetViewModel)
- .ToList();
- }
- return source.Orders
- .Where(x => x.Id == model.Id)
- .Select(x => x.GetViewModel)
- .ToList();
- }
- public OrderViewModel? GetElement(OrderSearchModel model)
- {
- if (model.Id == null && !model.Id.HasValue)
- {
- return null;
- }
- return source.Orders
- .FirstOrDefault(x => (model.Id != null && x.Id == model.Id) ||
- (model.Id.HasValue && x.Id == model.Id))
- ?.GetViewModel;
- }
- public OrderViewModel? Insert(OrderBindingModel model)
- {
- model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
- var newOrder = Order.Create(model); if (newOrder == null)
- {
- return null;
- }
- source.Orders.Add(newOrder);
- source.SaveOrders();
- return newOrder.GetViewModel;
- }
- public OrderViewModel? Update(OrderBindingModel model)
- {
- var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
- if (order == null)
- {
- return null;
- }
- order.Update(model);
- source.SaveOrders();
- return order.GetViewModel;
- }
+
public OrderViewModel? Delete(OrderBindingModel model)
{
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+
if (element != null)
{
source.Orders.Remove(element);
source.SaveOrders();
+
return element.GetViewModel;
}
+
return null;
}
+
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (model.ImplementerId.HasValue && model.Statuses != null)
+ {
+ return source.Orders
+ .FirstOrDefault(x => x.ImplementerId == model.ImplementerId &&
+ model.Statuses.Contains(x.Status))
+ ?.GetViewModel;
+ }
+
+ if (model.ImplementerId.HasValue)
+ {
+ return source.Orders
+ .FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
+ ?.GetViewModel;
+ }
+
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+
+ return source.Orders
+ .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
- foreach (var comp in source.Woods)
- {
- if (comp.Id == order.WoodId)
- {
- viewModel.WoodName = comp.WoodName;
- break;
- }
- }
- foreach (var client in source.Clients)
- {
- if (client.Id == order.ClientId)
- {
- viewModel.ClientFIO = client.ClientFIO;
- break;
- }
- }
+
+ var wood = source
+ .Woods.FirstOrDefault(x => x.Id == order.WoodId);
+
+ var client = source
+ .Clients.FirstOrDefault(x => x.Id == order.ClientId);
+
+ if (wood != null)
+ viewModel.WoodName = wood.WoodName;
+
+ if (client != null)
+ viewModel.ClientFIO = client.ClientFIO;
+
return viewModel;
}
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ if (model.DateFrom.HasValue)
+ return source.Orders
+ .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
+ .Select(x => GetViewModel(x))
+ .ToList();
+
+ if (model.ClientId.HasValue && !model.Id.HasValue)
+ return source.Orders
+ .Where(x => x.ClientId == model.ClientId)
+ .Select(x => x.GetViewModel)
+ .ToList();
+
+ if (model.Id.HasValue)
+ return source.Orders
+ .Where(x => x.Id.Equals(model.Id))
+ .Select(x => GetViewModel(x))
+ .ToList();
+
+ return new();
+ }
+
+ public List GetFullList()
+ {
+ return source.Orders.Select(x => x.GetViewModel).ToList();
+ }
+
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
+ var newOrder = Order.Create(model);
+
+ if (newOrder == null)
+ {
+ return null;
+ }
+
+ source.Orders.Add(newOrder);
+ source.SaveOrders();
+
+ return newOrder.GetViewModel;
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+
+ if (order == null)
+ {
+ return null;
+ }
+
+ order.Update(model);
+ source.SaveOrders();
+
+ return order.GetViewModel;
+ }
}
}
diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs
new file mode 100644
index 0000000..f72f531
--- /dev/null
+++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs
@@ -0,0 +1,85 @@
+using CarpentryWorkshopContracts.BindingModels;
+using CarpentryWorkshopContracts.ViewModels;
+using CarpentryWorkshopDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace CarpentryWorkshopFileImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public int Id { get; private set; }
+
+ public string ImplementerFIO { get; private set; } = string.Empty;
+
+ public string Password { get; private set; } = string.Empty;
+
+ public int WorkExperience { get; private set; }
+
+ public int Qualification { get; private set; }
+
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Implementer()
+ {
+ Id = model.Id,
+ ImplementerFIO = model.ImplementerFIO,
+ Password = model.Password,
+ WorkExperience = model.WorkExperience,
+ Qualification = model.Qualification,
+ };
+ }
+
+ public static Implementer? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Implementer()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ImplementerFIO = element.Element("ImplementerFIO")!.Value,
+ Password = element.Element("Password")!.Value,
+ WorkExperience = Convert.ToInt32(element.Element("Cost")!.Value),
+ Qualification = Convert.ToInt32(element.Element("Cost")!.Value)
+ };
+ }
+
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ImplementerFIO = model.ImplementerFIO;
+ Password = model.Password;
+ WorkExperience = model.WorkExperience;
+ Qualification = model.Qualification;
+ }
+
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ImplementerFIO = ImplementerFIO,
+ Password = Password,
+ WorkExperience = WorkExperience,
+ Qualification = Qualification
+ };
+
+ public XElement GetXElement => new("Implementer",
+ new XAttribute("Id", Id),
+ new XElement("ImplementerFIO", ImplementerFIO),
+ new XElement("Password", Password),
+ new XElement("WorkExperience", WorkExperience),
+ new XElement("Qualification", Qualification));
+ }
+}
diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs
index 510d85e..b572582 100644
--- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs
@@ -4,6 +4,8 @@ using CarpentryWorkshopDataModels.Enums;
using CarpentryWorkshopDataModels.Models;
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
using System.Text;
@@ -14,15 +16,24 @@ namespace CarpentryWorkshopFileImplement.Models
{
public class Order : IOrderModel
{
- public int Id { get; private set; }
public int WoodId { get; private set; }
- public int ClientId { get; set; }
- public string WoodName { get; private set; } = string.Empty;
+
+ public int? ImplementerId { get; set; }
+
+ public int ClientId { get; private set; }
+
public int Count { get; private set; }
+
public double Sum { get; private set; }
+
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
public DateTime DateCreate { get; private set; } = DateTime.Now;
+
public DateTime? DateImplement { get; private set; }
+
+ public int Id { get; private set; }
+
public static Order? Create(OrderBindingModel model)
{
if (model == null)
@@ -32,9 +43,9 @@ namespace CarpentryWorkshopFileImplement.Models
return new Order()
{
Id = model.Id,
+ ImplementerId = model.ImplementerId,
WoodId = model.WoodId,
ClientId = model.ClientId,
- WoodName = model.WoodName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@@ -42,26 +53,32 @@ namespace CarpentryWorkshopFileImplement.Models
DateImplement = model.DateImplement
};
}
+
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
- return new Order()
+
+ var order = new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
WoodId = Convert.ToInt32(element.Element("WoodId")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
- WoodName = element.Element("WoodName")!.Value,
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
- Status = (OrderStatus)Convert.ToInt32(element.Element("Status").Value),
- DateCreate = Convert.ToDateTime(element.Element("DateCreate").Value),
- DateImplement = String.IsNullOrEmpty(element.Element("DateImplement").Value) ? DateTime.MinValue : Convert.ToDateTime(element.Element("DateImplement").Value)
-
+ Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
+ DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null)
};
+
+ DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
+ order.DateImplement = dateImpl;
+
+ return order;
}
+
public void Update(OrderBindingModel model)
{
if (model == null)
@@ -71,27 +88,29 @@ namespace CarpentryWorkshopFileImplement.Models
Status = model.Status;
DateImplement = model.DateImplement;
}
+
public OrderViewModel GetViewModel => new()
{
Id = Id,
+ ImplementerId = ImplementerId,
WoodId = WoodId,
ClientId = ClientId,
- WoodName = WoodName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
- DateImplement = DateImplement,
+ DateImplement = DateImplement
};
+
public XElement GetXElement => new("Order",
- new XAttribute("Id", Id),
- new XElement("WoodId", WoodId),
- new XElement("ClientId", ClientId),
- new XElement("WoodName", WoodName),
- new XElement("Count", Count),
- new XElement("Sum", Sum.ToString()),
- new XElement("Status", (int)Status),
- new XElement("DateCreate", DateCreate),
- new XElement("DateImplement", DateImplement));
+ new XAttribute("Id", Id),
+ new XElement("WoodId", WoodId.ToString()),
+ new XElement("ClientId", ClientId.ToString()),
+ new XElement("ImplementerId", ImplementerId.ToString()),
+ new XElement("Count", Count.ToString()),
+ new XElement("Sum", Sum.ToString()),
+ new XElement("Status", Status.ToString()),
+ new XElement("DateCreate", DateCreate.ToString()),
+ new XElement("DateImplement", DateImplement.ToString()));
}
}
diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs
index 3d6e086..0958ead 100644
--- a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs
@@ -9,11 +9,14 @@ namespace CarpentryWorkshopListImplement
public List Orders { get; set; }
public List Woods { get; set; }
public List Clients { get; set; }
+ public List Implementers { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Woods = new List();
+ Clients = new List();
+ Implementers = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ImplementerStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ImplementerStorage.cs
new file mode 100644
index 0000000..088a269
--- /dev/null
+++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ImplementerStorage.cs
@@ -0,0 +1,126 @@
+using CarpentryWorkshopContracts.BindingModels;
+using CarpentryWorkshopContracts.SearchModels;
+using CarpentryWorkshopContracts.StoragesContracts;
+using CarpentryWorkshopContracts.ViewModels;
+using CarpentryWorkshopListImplement.Models;
+
+namespace CarpentryWorkshopListImplement.Implements
+{
+ public class ImplementerStorage : IImplementerStorage
+ {
+ private readonly DataListSingleton _source;
+ public ImplementerStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public ImplementerViewModel? Delete(ImplementerBindingModel model)
+ {
+ for (int i = 0; i < _source.Implementers.Count; ++i)
+ {
+ if (_source.Implementers[i].Id == model.Id)
+ {
+ var element = _source.Implementers[i];
+ _source.Implementers.RemoveAt(i);
+
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public ImplementerViewModel? GetElement(ImplementerSearchModel model)
+ {
+ foreach (var x in _source.Implementers)
+ {
+ if (model.Id.HasValue && x.Id == model.Id)
+ return x.GetViewModel;
+
+ if (model.ImplementerFIO != null && model.Password != null &&
+ x.ImplementerFIO.Equals(model.ImplementerFIO) &&
+ x.Password.Equals(model.Password))
+ return x.GetViewModel;
+
+ if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO))
+ return x.GetViewModel;
+ }
+ return null;
+ }
+
+ public List GetFilteredList(ImplementerSearchModel model)
+ {
+ if (model == null)
+ {
+ return new();
+ }
+
+ if (model.Id.HasValue)
+ {
+ var res = GetElement(model);
+
+ return res != null ? new() { res } : new();
+ }
+
+ List result = new();
+
+ if (model.ImplementerFIO != null)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.ImplementerFIO.Equals(model.ImplementerFIO))
+ {
+ result.Add(implementer.GetViewModel);
+ }
+ }
+ }
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach (var implementer in _source.Implementers)
+ {
+ result.Add(implementer.GetViewModel);
+ }
+
+ return result;
+ }
+
+ public ImplementerViewModel? Insert(ImplementerBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach (var implementer in _source.Implementers)
+ {
+ if (model.Id <= implementer.Id)
+ {
+ model.Id = implementer.Id + 1;
+ }
+ }
+
+ var res = Implementer.Create(model);
+
+ if (res != null)
+ {
+ _source.Implementers.Add(res);
+ }
+ return res?.GetViewModel;
+ }
+
+ public ImplementerViewModel? Update(ImplementerBindingModel model)
+ {
+ foreach (var implementer in _source.Implementers)
+ {
+ if (implementer.Id == model.Id)
+ {
+ implementer.Update(model);
+
+ return implementer.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs
index 16db565..bfed4aa 100644
--- a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs
@@ -18,80 +18,6 @@ namespace CarpentryWorkshopListImplement.Implements
{
_source = DataListSingleton.GetInstance();
}
- public List GetFullList()
- {
- var result = new List();
- foreach (var Order in _source.Orders)
- {
- result.Add(GetViewModel(Order));
- }
- return result;
- }
- public List GetFilteredList(OrderSearchModel model)
- {
- var result = new List();
- foreach (var order in _source.Orders)
- {
- if (order.Id == model.Id)
- {
- return new() { GetViewModel(order) };
- }
- else if (model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo)
- {
- result.Add(GetViewModel(order));
- }
- else if (model.ClientId.HasValue && order.ClientId == model.ClientId)
- {
- result.Add(GetViewModel(order));
- }
- }
- return result;
- }
- public OrderViewModel? GetElement(OrderSearchModel model)
- {
- if (!model.Id.HasValue)
- {
- return null;
- }
- foreach (var Order in _source.Orders)
- {
- if (model.Id.HasValue && Order.Id == model.Id)
- {
- return GetViewModel(Order);
- }
- }
- return null;
- }
- public OrderViewModel? Insert(OrderBindingModel model)
- {
- model.Id = 1;
- foreach (var Order in _source.Orders)
- {
- if (model.Id <= Order.Id)
- {
- model.Id = Order.Id + 1;
- }
- }
- var newOrder = Order.Create(model);
- if (newOrder == null)
- {
- return null;
- }
- _source.Orders.Add(newOrder);
- return GetViewModel(newOrder);
- }
- public OrderViewModel? Update(OrderBindingModel model)
- {
- foreach (var Order in _source.Orders)
- {
- if (Order.Id == model.Id)
- {
- Order.Update(model);
- return GetViewModel(Order);
- }
- }
- return null;
- }
public OrderViewModel? Delete(OrderBindingModel model)
{
for (int i = 0; i < _source.Orders.Count; ++i)
@@ -100,20 +26,100 @@ namespace CarpentryWorkshopListImplement.Implements
{
var element = _source.Orders[i];
_source.Orders.RemoveAt(i);
- return GetViewModel(element);
+ return element.GetViewModel;
}
}
+
return null;
}
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id.HasValue && order.Id == model.Id)
+ {
+ return order.GetViewModel;
+ }
+
+ else if (model.ImplementerId.HasValue && model.Statuses != null &&
+ order.ImplementerId == model.ImplementerId &&
+ model.Statuses.Contains(order.Status))
+ {
+ return GetViewModel(order);
+ }
+
+ else if (model.ImplementerId.HasValue &&
+ model.ImplementerId == order.ImplementerId)
+ {
+ return GetViewModel(order);
+ }
+ }
+
+ return null;
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ var result = new List();
+
+ if (model.DateFrom.HasValue)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
+ {
+ result.Add(GetViewModel(order));
+ }
+ }
+ }
+ else if (model.ClientId.HasValue && !model.Id.HasValue)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.ClientId == model.ClientId)
+ {
+ result.Add(GetViewModel(order));
+ }
+ }
+ }
+ else if (model.Id.HasValue)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ result.Add(GetViewModel(order));
+ }
+
+ else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId)
+ {
+ result.Add(GetViewModel(order));
+ }
+
+ else if (model.Statuses != null && model.Statuses.Contains(order.Status))
+ {
+ result.Add(GetViewModel(order));
+ }
+ }
+ }
+
+
+ return result;
+ }
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
- foreach (var comp in _source.Woods)
+ foreach (var wood in _source.Woods)
{
- if (comp.Id == order.WoodId)
+ if (wood.Id == order.WoodId)
{
- viewModel.WoodName = comp.WoodName;
+ viewModel.WoodName = wood.WoodName;
break;
}
}
@@ -127,5 +133,54 @@ namespace CarpentryWorkshopListImplement.Implements
}
return viewModel;
}
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach (var order in _source.Orders)
+ {
+ result.Add(order.GetViewModel);
+ }
+
+ return result;
+ }
+
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id <= order.Id)
+ {
+ model.Id = order.Id + 1;
+ }
+ }
+
+ var newOrder = Order.Create(model);
+
+ if (newOrder == null)
+ {
+ return null;
+ }
+
+ _source.Orders.Add(newOrder);
+
+ return newOrder.GetViewModel;
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ order.Update(model);
+ return order.GetViewModel;
+ }
+ }
+
+ return null;
+ }
}
}
diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Implementer.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Implementer.cs
new file mode 100644
index 0000000..9326f3a
--- /dev/null
+++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Implementer.cs
@@ -0,0 +1,56 @@
+using CarpentryWorkshopContracts.BindingModels;
+using CarpentryWorkshopContracts.ViewModels;
+using CarpentryWorkshopDataModels.Models;
+
+namespace CarpentryWorkshopListImplement.Models
+{
+ public class Implementer : IImplementerModel
+ {
+ public string ImplementerFIO { get; private set; } = string.Empty;
+
+ public string Password { get; private set; } = string.Empty;
+
+ public int WorkExperience { get; private set; }
+
+ public int Qualification { get; private set; }
+
+ public int Id { get; private set; }
+
+ public static Implementer? Create(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = model.Id,
+ Password = model.Password,
+ Qualification = model.Qualification,
+ ImplementerFIO = model.ImplementerFIO,
+ WorkExperience = model.WorkExperience,
+ };
+ }
+
+ public void Update(ImplementerBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ Password = model.Password;
+ Qualification = model.Qualification;
+ ImplementerFIO = model.ImplementerFIO;
+ WorkExperience = model.WorkExperience;
+ }
+
+ public ImplementerViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Password = Password,
+ Qualification = Qualification,
+ ImplementerFIO = ImplementerFIO,
+ WorkExperience = WorkExperience
+ };
+ }
+}
diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs
index 64f3b5f..7502dd0 100644
--- a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs
@@ -1,4 +1,5 @@
using CarpentryWorkshopContracts.BindingModels;
+using CarpentryWorkshopContracts.SearchModels;
using CarpentryWorkshopContracts.ViewModels;
using CarpentryWorkshopDataModels.Enums;
using CarpentryWorkshopDataModels.Models;
@@ -13,15 +14,22 @@ namespace CarpentryWorkshopListImplement.Models
{
public class Order : IOrderModel
{
- public int Id { get; private set; }
public int WoodId { get; private set; }
+
public int ClientId { get; private set; }
- public string WoodName { get; private set; }
+
public int Count { get; private set; }
+
public double Sum { get; private set; }
- public OrderStatus Status { get; private set; }
- public DateTime DateCreate { get; private set; }
+
+ public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+
public DateTime? DateImplement { get; private set; }
+
+ public int Id { get; private set; }
+
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
@@ -32,8 +40,8 @@ namespace CarpentryWorkshopListImplement.Models
{
Id = model.Id,
WoodId = model.WoodId,
+ ImplementerId = model.ImplementerId,
ClientId = model.ClientId,
- WoodName = model.WoodName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@@ -41,6 +49,7 @@ namespace CarpentryWorkshopListImplement.Models
DateImplement = model.DateImplement
};
}
+
public void Update(OrderBindingModel? model)
{
if (model == null)
@@ -50,17 +59,20 @@ namespace CarpentryWorkshopListImplement.Models
Status = model.Status;
DateImplement = model.DateImplement;
}
+
public OrderViewModel GetViewModel => new()
{
Id = Id,
WoodId = WoodId,
ClientId = ClientId,
- WoodName = WoodName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
- DateImplement = DateImplement
+ DateImplement = DateImplement,
+ ImplementerId = ImplementerId
};
+
+ public int? ImplementerId { get; private set; }
}
}
diff --git a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs
index 575c4e4..058d34d 100644
--- a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs
+++ b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs
@@ -40,12 +40,15 @@ namespace CarpentryWorkshopView
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -61,6 +64,8 @@ namespace CarpentryWorkshopView
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file