diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ClientLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ClientLogic.cs index 9cf9f74..1cb6b8f 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -108,10 +108,10 @@ namespace ComputerShopBusinessLogic.BusinessLogics { throw new Exception($"В качестве логина должна быть указана почта"); } - if (!Regex.IsMatch(model.Password, @"^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$")) - { - throw new Exception($"Пароль должен состоять из цифр, букв и небуквенных символов"); - } + //if (!Regex.IsMatch(model.Password, @"^[\w\.]{1,30}@{1}[^\d\W]+\.{1}[^\d\W]{2,4}$")) + //{ + // throw new Exception($"Пароль должен состоять из цифр, букв и небуквенных символов"); + //} _logger.LogInformation("Client. Id: {Id}, FIO: {fio}, email: {email}", model.Id, model.ClientFIO, model.Email); var element = _clientStorage.GetElement(new ClientSearchModel { diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs index 29b19e8..e77ebae 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/EquipmentReceivingLogic.cs @@ -52,12 +52,19 @@ namespace ComputerShopBusinessLogic.BusinessLogics return true; } - public bool TakeInWork(EquipmentReceivingBindingModel model) - { - return StatusUpdate(model, EquipmentReceivingStatus.Ожидается); - } + public bool Delete(EquipmentReceivingBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_receivingStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } - public bool Finish(EquipmentReceivingBindingModel model) + public bool Finish(EquipmentReceivingBindingModel model) { return StatusUpdate(model, EquipmentReceivingStatus.Получено); } diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs index a1b4325..453972a 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -141,25 +141,25 @@ namespace ComputerShopBusinessLogic.BusinessLogics } _logger.LogInformation("AddAssemblyToOrder. AssemblyName:{AssemblyName}.Id:{ Id}", assemblymodel.AssemblyName, model.Id); - var element = _orderStorage.GetElement(model); + var order = _orderStorage.GetElement(model); var assembly = _assemblyStorage.GetElement(assemblymodel); - if (element == null || assembly == null) + if (order == null || assembly == null) { return false; } - _logger.LogInformation("AddAssemblyToOrder find. Id:{Id}", element.Id); + _logger.LogInformation("AddAssemblyToOrder find. Id:{Id}", order.Id); - element.AssemblyOrders[assembly.Id] = (assembly, amount); + order.OrderAssemblies[assembly.Id] = (assembly, amount); _orderStorage.Update(new() { - Id = element.Id, - Status = element.Status, - Sum = element.Sum + assembly.Price * amount, - ClientId = element.ClientId, - AssemblyOrders = element.AssemblyOrders + Id = order.Id, + Status = order.Status, + Sum = order.Sum + assembly.Price * amount, + ClientId = order.ClientId, + AssemblyOrders = order.OrderAssemblies }); return true; diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs index 6b3f7c8..19ab6d2 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/SupplyLogic.cs @@ -18,12 +18,14 @@ namespace ComputerShopBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly ISupplyStorage _supplyStorage; private readonly IOrderStorage _orderStorage; + private readonly IComponentStorage _componentStorage; - public SupplyLogic(ILogger logger, ISupplyStorage supplyStorage, IOrderStorage orderStorage) + public SupplyLogic(ILogger logger, ISupplyStorage supplyStorage, IOrderStorage orderStorage, IComponentStorage componentStorage) { _logger = logger; _supplyStorage = supplyStorage; _orderStorage = orderStorage; + _componentStorage = componentStorage; } public bool Create(SupplyBindingModel model) { @@ -71,7 +73,7 @@ namespace ComputerShopBusinessLogic.BusinessLogics } public bool Finish(SupplyBindingModel model) { - return StatusUpdate(model, SupplyStatus.Отправлено); + return StatusUpdate(model, SupplyStatus.Поставлено); } public bool Update(SupplyBindingModel model) { @@ -101,7 +103,7 @@ namespace ComputerShopBusinessLogic.BusinessLogics return false; } model.Status = _newStatus; - if (model.Status == SupplyStatus.Отправлено) model.DateImplement = DateTime.Now; + if (model.Status == SupplyStatus.Поставлено) model.DateImplement = DateTime.Now; else { model.DateImplement = viewModel.DateImplement; @@ -131,7 +133,32 @@ namespace ComputerShopBusinessLogic.BusinessLogics return false; } - order.SupplyOrders[order.Id] = order; + supply.SupplyOrders[supply.Id] = order; + + _supplyStorage.Update(new() + { + Id = supply.Id, + SupplyOrders = supply.SupplyOrders, + }); + + return true; + } + public bool AddComponent(SupplySearchModel supplymodel, ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var component = _componentStorage.GetElement(model); + var supply = _supplyStorage.GetElement(supplymodel); + + if (component == null || supply == null) + { + return false; + } + + supply.SupplyComponents[supply.Id] = component; _supplyStorage.Update(new() { diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs index 2df7b64..9a104b4 100644 --- a/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/SupplyBindingModel.cs @@ -12,8 +12,8 @@ namespace ComputerShopContracts.BindingModels { public int Id { get; set; } public int ClientId { get; set; } - public int? ReceivingId { get; set; } + public int? ComponentId { get; set; } public SupplyStatus Status { get; set; } = SupplyStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; @@ -25,11 +25,5 @@ namespace ComputerShopContracts.BindingModels get; set; } = new(); - - public Dictionary SupplyComponents - { - get; - set; - } = new(); } } diff --git a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IEquipmentReceivingLogic.cs b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IEquipmentReceivingLogic.cs index 7c17b96..3b1f3d1 100644 --- a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IEquipmentReceivingLogic.cs +++ b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IEquipmentReceivingLogic.cs @@ -12,8 +12,8 @@ namespace ComputerShopContracts.BusinessLogicContracts public interface IEquipmentReceivingLogic { List? ReadList(EquipmentReceivingSearchModel? model); - bool Create(EquipmentReceivingBindingModel model); - bool TakeInWork(EquipmentReceivingBindingModel model); + bool Delete(EquipmentReceivingBindingModel model); + bool Create(EquipmentReceivingBindingModel model); bool Finish(EquipmentReceivingBindingModel model); } } diff --git a/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs b/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs index 27d729d..773e409 100644 --- a/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs @@ -11,8 +11,7 @@ namespace ComputerShopContracts.SearchModels { public int? Id { get; set; } public int? ClientId { get; set; } - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } - public SupplySearchModel? Supply { get; set; } + public DateTime? DateImplement { get; set; } + public int? Status { get; set; } } } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/AssemblyViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/AssemblyViewModel.cs index bdf1af4..239fc2a 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/AssemblyViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/AssemblyViewModel.cs @@ -21,11 +21,6 @@ namespace ComputerShopContracts.ViewModels get; set; } = new(); - public Dictionary AssemblyOrders - { - get; - set; - } = new(); public int ClientId { get; set; } [DisplayName("ФИО клиента")] diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs index dd71aa4..89c2630 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/OrderViewModel.cs @@ -19,17 +19,11 @@ namespace ComputerShopContracts.ViewModels [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; - public Dictionary AssemblyOrders + public Dictionary OrderAssemblies { get; set; } = new(); - public Dictionary SupplyOrders - { - get; - set; - } = new(); - [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } diff --git a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs index 0656c0f..0c69370 100644 --- a/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/SupplyViewModel.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace ComputerShopContracts.ViewModels @@ -27,16 +28,28 @@ namespace ComputerShopContracts.ViewModels public int ClientId { get; set; } [DisplayName("Номер получения")] public int? ReceivingId { get; set; } + [DisplayName("Номер комплектующего")] + public int? ComponentId { get; set; } public Dictionary SupplyOrders { get; set; } = new(); + public Dictionary SupplyComponents { get; set; } = new(); + [JsonConstructor] + public SupplyViewModel(Dictionary SupplyOrders) + { + this.SupplyOrders = SupplyOrders; + } + + public SupplyViewModel() + { + } } } diff --git a/ComputerShopProvider/ComputerShopDataModels/Enums/SupplyStatus.cs b/ComputerShopProvider/ComputerShopDataModels/Enums/SupplyStatus.cs index bed7258..31544c9 100644 --- a/ComputerShopProvider/ComputerShopDataModels/Enums/SupplyStatus.cs +++ b/ComputerShopProvider/ComputerShopDataModels/Enums/SupplyStatus.cs @@ -4,6 +4,6 @@ { Неизвестен = -1, Отправляется = 0, - Отправлено = 1 + Поставлено = 1 } } diff --git a/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs b/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs index cf958e3..944bbb3 100644 --- a/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs +++ b/ComputerShopProvider/ComputerShopDataModels/Models/ISupplyModel.cs @@ -8,6 +8,7 @@ namespace ComputerShopDataModels.Models DateTime DateCreate { get; } DateTime? DateImplement { get; } int? ReceivingId { get; } + int? ComponentId { get; } Dictionary SupplyOrders { get; } } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs index 856646a..5542817 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs @@ -15,7 +15,7 @@ namespace ComputerShopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-IRUVF5S\SQLEXPRESS;Initial Catalog=ComputerShopDatabaseCWW;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-QA8P9OJ;Initial Catalog=ComputerShopDatabaseCWW;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } @@ -28,7 +28,7 @@ namespace ComputerShopDatabaseImplement public virtual DbSet SupplyOrders { set; get; } public virtual DbSet EquipmentReceivings { set; get; } public virtual DbSet ComponentSupplies { set; get; } - public virtual DbSet AssemblyOrders { set; get; } + public virtual DbSet AssemblyOrders { set; get; } public virtual DbSet Clients { set; get; } } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/EquipmentReceivingStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/EquipmentReceivingStorage.cs index badef8d..5f885cb 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/EquipmentReceivingStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/EquipmentReceivingStorage.cs @@ -35,21 +35,35 @@ namespace ComputerShopDatabaseImplement.Implements } using var context = new ComputerShopDatabase(); return context.EquipmentReceivings - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? - .GetViewModel; - } + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } public List GetFilteredList(EquipmentReceivingSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ClientId.HasValue && !model.DateImplement.HasValue && !model.Status.HasValue) { return new(); } using var context = new ComputerShopDatabase(); + + if (model.DateImplement.HasValue) + return context.EquipmentReceivings + .Where(x => x.DateImplement == model.DateImplement) + .Select(x => x.GetViewModel) + .ToList(); + if (model.ClientId.HasValue) + { + return context.EquipmentReceivings + .Include(x => x.Client) + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } return context.EquipmentReceivings - .Where(x => x.Id == model.Supply.Component.Id) + .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); + } public List GetFullList() diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/OrderStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/OrderStorage.cs index 5f5807c..3dbafdc 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/OrderStorage.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace ComputerShopDatabaseImplement.Implements { - internal class OrderStorage : IOrderStorage + public class OrderStorage : IOrderStorage { public OrderViewModel? Delete(OrderBindingModel model) { diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20231007140302_fix2.Designer.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20231007140302_fix2.Designer.cs new file mode 100644 index 0000000..f0b6b63 --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20231007140302_fix2.Designer.cs @@ -0,0 +1,546 @@ +// +using System; +using ComputerShopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerShopDatabase))] + [Migration("20231007140302_fix2")] + partial class fix2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Assemblies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("ComponentId"); + + b.ToTable("AssemblyComponents"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("SupplyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("SupplyId"); + + b.ToTable("ComponentSupplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("EquipmentReceivings"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.OrderAssembly", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("OrderId"); + + b.ToTable("AssemblyOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ComponentId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ReceivingId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ReceivingId"); + + b.ToTable("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("SupplyId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("SupplyId"); + + b.ToTable("SupplyOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client") + .WithMany("Assemblies") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") + .WithMany("Components") + .HasForeignKey("AssemblyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("AssemblyComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assembly"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("Components") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ComponentSupply", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("Supplies") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply") + .WithMany("Components") + .HasForeignKey("SupplyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Supply"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("EquipmentReceivings") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.OrderAssembly", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") + .WithMany("Orders") + .HasForeignKey("AssemblyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order") + .WithMany("Assemblies") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assembly"); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client") + .WithMany("Purchases") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("Purchases") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) + .WithMany("Supplies") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany() + .HasForeignKey("ComponentId"); + + b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", "Receiving") + .WithMany("Supplies") + .HasForeignKey("ReceivingId"); + + b.Navigation("Component"); + + b.Navigation("Receiving"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.SupplyOrder", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order") + .WithMany("SupplyOrders") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply") + .WithMany("Orders") + .HasForeignKey("SupplyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Supply"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Assemblies"); + + b.Navigation("Components"); + + b.Navigation("EquipmentReceivings"); + + b.Navigation("Orders"); + + b.Navigation("Purchases"); + + b.Navigation("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Navigation("AssemblyComponents"); + + b.Navigation("Purchases"); + + b.Navigation("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.EquipmentReceiving", b => + { + b.Navigation("Supplies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.Navigation("Assemblies"); + + b.Navigation("SupplyOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20231007140302_fix2.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20231007140302_fix2.cs new file mode 100644 index 0000000..a348e01 --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/20231007140302_fix2.cs @@ -0,0 +1,89 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + /// + public partial class fix2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Supplies_EquipmentReceivings_ReceivingId", + table: "Supplies"); + + migrationBuilder.AlterColumn( + name: "ReceivingId", + table: "Supplies", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddColumn( + name: "ComponentId", + table: "Supplies", + type: "int", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Supplies_ComponentId", + table: "Supplies", + column: "ComponentId"); + + migrationBuilder.AddForeignKey( + name: "FK_Supplies_Components_ComponentId", + table: "Supplies", + column: "ComponentId", + principalTable: "Components", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Supplies_EquipmentReceivings_ReceivingId", + table: "Supplies", + column: "ReceivingId", + principalTable: "EquipmentReceivings", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Supplies_Components_ComponentId", + table: "Supplies"); + + migrationBuilder.DropForeignKey( + name: "FK_Supplies_EquipmentReceivings_ReceivingId", + table: "Supplies"); + + migrationBuilder.DropIndex( + name: "IX_Supplies_ComponentId", + table: "Supplies"); + + migrationBuilder.DropColumn( + name: "ComponentId", + table: "Supplies"); + + migrationBuilder.AlterColumn( + name: "ReceivingId", + table: "Supplies", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Supplies_EquipmentReceivings_ReceivingId", + table: "Supplies", + column: "ReceivingId", + principalTable: "EquipmentReceivings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs index 2ad85ee..cf6d49c 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs @@ -73,32 +73,6 @@ namespace ComputerShopDatabaseImplement.Migrations b.ToTable("AssemblyComponents"); }); - modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AssemblyId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("OrderId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("AssemblyId"); - - b.HasIndex("OrderId"); - - b.ToTable("AssemblyOrders"); - }); - modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Client", b => { b.Property("Id") @@ -229,6 +203,32 @@ namespace ComputerShopDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.OrderAssembly", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("OrderId"); + + b.ToTable("AssemblyOrders"); + }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b => { b.Property("Id") @@ -282,6 +282,9 @@ namespace ComputerShopDatabaseImplement.Migrations b.Property("ClientId") .HasColumnType("int"); + b.Property("ComponentId") + .HasColumnType("int"); + b.Property("DateCreate") .HasColumnType("datetime2"); @@ -289,7 +292,6 @@ namespace ComputerShopDatabaseImplement.Migrations .HasColumnType("datetime2"); b.Property("ReceivingId") - .IsRequired() .HasColumnType("int"); b.Property("Status") @@ -299,6 +301,8 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ComponentId"); + b.HasIndex("ReceivingId"); b.ToTable("Supplies"); @@ -360,25 +364,6 @@ namespace ComputerShopDatabaseImplement.Migrations b.Navigation("Component"); }); - modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyOrder", b => - { - b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") - .WithMany("Orders") - .HasForeignKey("AssemblyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order") - .WithMany("Assemblies") - .HasForeignKey("OrderId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Assembly"); - - b.Navigation("Order"); - }); - modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => { b.HasOne("ComputerShopDatabaseImplement.Models.Client", null) @@ -397,7 +382,7 @@ namespace ComputerShopDatabaseImplement.Migrations .IsRequired(); b.HasOne("ComputerShopDatabaseImplement.Models.Supply", "Supply") - .WithMany("ComponentSupplies") + .WithMany("Components") .HasForeignKey("SupplyId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -425,6 +410,25 @@ namespace ComputerShopDatabaseImplement.Migrations .IsRequired(); }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.OrderAssembly", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") + .WithMany("Orders") + .HasForeignKey("AssemblyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order") + .WithMany("Assemblies") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assembly"); + + b.Navigation("Order"); + }); + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Purchase", b => { b.HasOne("ComputerShopDatabaseImplement.Models.Client", "Client") @@ -452,11 +456,15 @@ namespace ComputerShopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany() + .HasForeignKey("ComponentId"); + b.HasOne("ComputerShopDatabaseImplement.Models.EquipmentReceiving", "Receiving") .WithMany("Supplies") - .HasForeignKey("ReceivingId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("ReceivingId"); + + b.Navigation("Component"); b.Navigation("Receiving"); }); @@ -525,7 +533,7 @@ namespace ComputerShopDatabaseImplement.Migrations modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Supply", b => { - b.Navigation("ComponentSupplies"); + b.Navigation("Components"); b.Navigation("Orders"); }); diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs index e7b6217..d2af51f 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Assembly.cs @@ -37,11 +37,9 @@ namespace ComputerShopDatabaseImplement.Models } } - private Dictionary? _assemblyOrders = null; - [ForeignKey("AssemblyId")] public virtual List Components { get; set; } = new(); [ForeignKey("AssemblyId")] - public virtual List Orders { get; set; } = new(); + public virtual List Orders { get; set; } = new(); public virtual Client Client { get; set; } public static Assembly Create(ComputerShopDatabase context, AssemblyBindingModel model) { @@ -58,7 +56,7 @@ namespace ComputerShopDatabaseImplement.Models Count = x.Value.Item2 }).ToList(), Orders = model.AssemblyOrders.Select(x => new - AssemblyOrder + OrderAssembly { Order = context.Orders.First(y => y.Id == x.Key), Count = x.Value.Item2 diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs index e5149bf..264f802 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/EquipmentReceiving.cs @@ -15,7 +15,7 @@ namespace ComputerShopDatabaseImplement.Models internal class EquipmentReceiving : IEquipmentReceivingModel { - public DateTime? DateImplement { get; private set; } + public DateTime? DateImplement { get; set; } public int Id { get; set; } public EquipmentReceivingStatus Status { get; private set; } = EquipmentReceivingStatus.Неизвестен; @@ -25,6 +25,7 @@ namespace ComputerShopDatabaseImplement.Models [Required] public int ClientId { get; set; } + public virtual Client Client { get; set; } public static EquipmentReceiving? Create(EquipmentReceivingBindingModel? model) { if (model == null) @@ -51,11 +52,11 @@ namespace ComputerShopDatabaseImplement.Models } public EquipmentReceivingViewModel GetViewModel => new() - { - DateImplement = DateImplement, - Id = Id, - Status = Status, - ClientId = ClientId + { + Id = Id, + Status = Status, + DateImplement = DateImplement, + ClientId = ClientId }; } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs index f9a0295..e375370 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Order.cs @@ -27,7 +27,7 @@ namespace ComputerShopDatabaseImplement.Models public virtual List SupplyOrders { get; set; } = new(); [ForeignKey("OrderId")] - public virtual List Assemblies { get; set; } = new(); + public virtual List Assemblies { get; set; } = new(); private Dictionary? _assemblyOrders = null; [NotMapped] diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/AssemblyOrder.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/OrderAssembly.cs similarity index 94% rename from ComputerShopProvider/ComputerShopDatabaseImplement/Models/AssemblyOrder.cs rename to ComputerShopProvider/ComputerShopDatabaseImplement/Models/OrderAssembly.cs index d084da4..1a15340 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/AssemblyOrder.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/OrderAssembly.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace ComputerShopDatabaseImplement.Models { - internal class AssemblyOrder + internal class OrderAssembly { public int Id { get; set; } [Required] diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs index 61920d2..856242b 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Supply.cs @@ -25,11 +25,12 @@ namespace ComputerShopDatabaseImplement.Models public int ClientId { get; set; } public int? ReceivingId { get; set; } - public virtual EquipmentReceiving Receiving { get; set; } + public virtual EquipmentReceiving? Receiving { get; set; } + public int? ComponentId { get; set; } + public virtual Component? Component { get; set; } private Dictionary? _supplyOrders = null; - private Dictionary? _supplyComponents = null; [NotMapped] public Dictionary SupplyOrders { @@ -43,19 +44,6 @@ namespace ComputerShopDatabaseImplement.Models return _supplyOrders; } } - [NotMapped] - public Dictionary SupplyComponents - { - get - { - if (_supplyComponents == null) - { - _supplyComponents = Components - .ToDictionary(recPC => recPC.SupplyId, recPC => recPC.Component as IComponentModel); - } - return _supplyComponents; - } - } [ForeignKey("SupplyId")] public virtual List Orders { get; set; } = new(); [ForeignKey("SupplyId")] @@ -71,16 +59,12 @@ namespace ComputerShopDatabaseImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, ReceivingId = model.ReceivingId, + ComponentId = model.ComponentId, Orders = model.SupplyOrders.Select(x => new SupplyOrder { Order = context.Orders.First(y => y.Id == x.Key), }).ToList(), - Components = model.SupplyComponents.Select(x => new - ComponentSupply - { - Component = context.Components.First(y => y.Id == x.Key), - }).ToList() }; } public void Update(SupplyBindingModel model) @@ -99,9 +83,9 @@ namespace ComputerShopDatabaseImplement.Models DateCreate = DateCreate, DateImplement = DateImplement, SupplyOrders = SupplyOrders, - SupplyComponents = SupplyComponents, ReceivingId = ReceivingId, - ClientId = ClientId + ClientId = ClientId, + ComponentId = ComponentId, }; public void UpdateOrders(ComputerShopDatabase context, SupplyBindingModel model) { diff --git a/ComputerShopProvider/ComputerShopRestApi/ComputerShopRestApi.csproj b/ComputerShopProvider/ComputerShopRestApi/ComputerShopRestApi.csproj index 1f0e345..cd8c422 100644 --- a/ComputerShopProvider/ComputerShopRestApi/ComputerShopRestApi.csproj +++ b/ComputerShopProvider/ComputerShopRestApi/ComputerShopRestApi.csproj @@ -13,8 +13,10 @@ + + diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs index 8d03fc5..0f69dff 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/EquipmentReceivingController.cs @@ -1,7 +1,10 @@ using ComputerShopContracts.BindingModels; using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; +using ComputerShopContracts.StorageContracts; using ComputerShopContracts.ViewModels; +using ComputerShopDatabaseImplement.Implements; +using DocumentFormat.OpenXml.Office2010.Excel; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -13,24 +16,14 @@ namespace ComputerShopRestApi.Controllers { private readonly ILogger _logger; private readonly IEquipmentReceivingLogic _equipmentReceiving; - public EquipmentReceivingController(ILogger logger, IEquipmentReceivingLogic equipmentReceiving) + private readonly IEquipmentReceivingStorage _equipmentReceivingStorage; + public EquipmentReceivingController(ILogger logger, IEquipmentReceivingLogic equipmentReceiving, IEquipmentReceivingStorage equipmentReceivingStorage) { _logger = logger; _equipmentReceiving = equipmentReceiving; - } - [HttpGet] - public List? GetReceivingList() - { - try - { - return _equipmentReceiving.ReadList(null); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка компонентов"); - throw; - } - } + _equipmentReceivingStorage = equipmentReceivingStorage; + + } [HttpGet] public List? GetReceivings(int clientId) @@ -48,7 +41,30 @@ namespace ComputerShopRestApi.Controllers throw; } } - [HttpPost] + + [HttpPost] + public void SetFinish(int id) + { + try + { + var receiving = _equipmentReceivingStorage.GetElement(new() { Id = id }); + EquipmentReceivingBindingModel model = new EquipmentReceivingBindingModel() + { + Id = id, + ClientId = receiving.ClientId, + DateImplement = receiving.DateImplement, + Status = receiving.Status + }; + _equipmentReceiving.Finish(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка изменения закупки"); + throw; + } + } + + [HttpPost] public void CreateReceiving(EquipmentReceivingBindingModel model) { try @@ -61,5 +77,26 @@ namespace ComputerShopRestApi.Controllers throw; } } - } + + [HttpPost] + public void DeleteReceiving(int id) + { + try + { + var receiving = _equipmentReceivingStorage.GetElement(new() { Id = id }); + _equipmentReceiving.Delete(new() + { + Id = id, + ClientId = receiving.ClientId, + DateImplement = receiving.DateImplement, + Status = receiving.Status + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления"); + throw; + } + } + } } diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs index 5e7e4e0..9e4e1f9 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/SupplyController.cs @@ -14,30 +14,30 @@ namespace ComputerShopRestApi.Controllers private readonly ILogger _logger; private readonly ISupplyLogic _supply; private readonly IOrderLogic _order; - private readonly IEquipmentReceivingLogic _equipmentReceiving; + private readonly IComponentLogic _component; - public SupplyController(ILogger logger, ISupplyLogic supply, IOrderLogic order, IEquipmentReceivingLogic equipmentReceiving) + public SupplyController(ILogger logger, ISupplyLogic supply, IOrderLogic order, IComponentLogic component) { _logger = logger; _supply = supply; _order = order; - _equipmentReceiving = equipmentReceiving; + _component = component; } [HttpGet] - public List? GetReceivingList(int clientId) + public List? GetReceivingList(int clientId) { try { - return _equipmentReceiving.ReadList(new EquipmentReceivingSearchModel + return _component.ReadList(new ComponentSearchModel { ClientId = clientId }); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения списка поставок клиента id ={ Id}", clientId); + _logger.LogError(ex, "Ошибка получения списка комплектующих клиента id ={ Id}", clientId); throw; } } @@ -55,7 +55,7 @@ namespace ComputerShopRestApi.Controllers throw; } } - + [HttpGet] public List? GetOrderList() { diff --git a/ComputerShopProvider/ComputerShopRestApi/Program.cs b/ComputerShopProvider/ComputerShopRestApi/Program.cs index fefd536..c42d32e 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Program.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Program.cs @@ -21,6 +21,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -28,6 +29,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/ComputerShopProvider/OrdererClientApp/Controllers/HomeController.cs b/ComputerShopProvider/OrdererClientApp/Controllers/HomeController.cs index 7160e6c..8d7f271 100644 --- a/ComputerShopProvider/OrdererClientApp/Controllers/HomeController.cs +++ b/ComputerShopProvider/OrdererClientApp/Controllers/HomeController.cs @@ -1,7 +1,9 @@ using ComputerShopContracts.BindingModels; using ComputerShopContracts.ViewModels; +using DocumentFormat.OpenXml.Office2010.Excel; using Microsoft.AspNetCore.Mvc; using OrdererClientApp.Models; +using System.ComponentModel; using System.Diagnostics; namespace OrdererClientApp.Controllers @@ -21,16 +23,16 @@ namespace OrdererClientApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/main/getreceivings?clientId={APIClient.Client.Id}")); + return View(APIClient.GetRequest>($"api/equipmentreceiving/getreceivings?clientId={APIClient.Client.Id}")); } - public IActionResult Order() + public IActionResult Order() { if (APIClient.Client == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/component/getorderlist")); + return View(APIClient.GetRequest>($"api/component/order")); } public IActionResult Supply() { @@ -38,7 +40,7 @@ namespace OrdererClientApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/assembly/getsupplylist")); + return View(APIClient.GetRequest>($"api/supply/getsupplylist")); } [HttpGet] @@ -127,29 +129,46 @@ namespace OrdererClientApp.Controllers } [HttpGet] - public IActionResult CreateEquipmentReceiving() - { - ViewBag.EquipmentReceivings = APIClient.GetRequest>("api/main/getreceivingslist"); - return View(); + public IActionResult CreateReceiving() + + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + APIClient.PostRequest("api/equipmentreceiving/createreceiving", new EquipmentReceivingBindingModel + { + ClientId = APIClient.Client.Id + }); + Response.Redirect("Index"); + return View(); } - [HttpPost] - public void CreateSupply(int receiving) - { - if (APIClient.Client == null) - { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - } + [HttpPost] + public void SetFinish(int id) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest($"api/equipmentreceiving/setfinish?id={id}", id); + Response.Redirect("Index"); + } - APIClient.PostRequest("api/main/createreceiving", new SupplyBindingModel - { - ClientId = APIClient.Client.Id, - ReceivingId = receiving, - }); - Response.Redirect("Index"); - } + [HttpPost] + public void DeleteReceiving(int receiving) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest($"api/equipmentreceiving/deletereceiving?id={receiving}", receiving); + Response.Redirect("Index"); - [HttpGet] + } + + [HttpGet] public IActionResult CreateOrder() { return View(); @@ -182,7 +201,7 @@ namespace OrdererClientApp.Controllers { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - APIClient.PostRequest("api/component/deleteorder", new ComponentBindingModel + APIClient.PostRequest("api/order/deleteorder", new ComponentBindingModel { Id = order }); diff --git a/ComputerShopProvider/OrdererClientApp/OrdererClientApp.csproj b/ComputerShopProvider/OrdererClientApp/OrdererClientApp.csproj index cd0392b..9562c11 100644 --- a/ComputerShopProvider/OrdererClientApp/OrdererClientApp.csproj +++ b/ComputerShopProvider/OrdererClientApp/OrdererClientApp.csproj @@ -11,7 +11,9 @@ + + diff --git a/ComputerShopProvider/OrdererClientApp/Program.cs b/ComputerShopProvider/OrdererClientApp/Program.cs index 0727468..5bf31e7 100644 --- a/ComputerShopProvider/OrdererClientApp/Program.cs +++ b/ComputerShopProvider/OrdererClientApp/Program.cs @@ -1,10 +1,32 @@ +using ComputerShopBusinessLogic.BusinessLogics; +using ComputerShopBusinessLogic.OfficePackage; +using ComputerShopBusinessLogic.OfficePackage.Implements; +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.StorageContracts; +using ComputerShopDatabaseImplement.Implements; +using OrdererClientApp; + var builder = WebApplication.CreateBuilder(args); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { diff --git a/ComputerShopProvider/OrdererClientApp/Views/Home/CreateReceiving.cshtml b/ComputerShopProvider/OrdererClientApp/Views/Home/CreateReceiving.cshtml new file mode 100644 index 0000000..e1dd794 --- /dev/null +++ b/ComputerShopProvider/OrdererClientApp/Views/Home/CreateReceiving.cshtml @@ -0,0 +1,5 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +} diff --git a/ComputerShopProvider/OrdererClientApp/Views/Home/Index.cshtml b/ComputerShopProvider/OrdererClientApp/Views/Home/Index.cshtml index d2d19bd..0658bc1 100644 --- a/ComputerShopProvider/OrdererClientApp/Views/Home/Index.cshtml +++ b/ComputerShopProvider/OrdererClientApp/Views/Home/Index.cshtml @@ -1,8 +1,74 @@ -@{ - ViewData["Title"] = "Home Page"; +@using ComputerShopContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Home Page"; }
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Список получений техники

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + +

+ Создать новое получение +

+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Номер + + ID клиента + + Дата получения + + Статус +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.ClientId) + + @Html.DisplayFor(modelItem => item.DateImplement) + + @Html.DisplayFor(modelItem => item.Status) + +
+ + +
+
+
+ + +
+
+
+ }
diff --git a/ComputerShopProvider/OrdererClientApp/Views/Shared/_Layout.cshtml b/ComputerShopProvider/OrdererClientApp/Views/Shared/_Layout.cshtml index 7453157..3ce7dc1 100644 --- a/ComputerShopProvider/OrdererClientApp/Views/Shared/_Layout.cshtml +++ b/ComputerShopProvider/OrdererClientApp/Views/Shared/_Layout.cshtml @@ -12,7 +12,7 @@