сохраненка
This commit is contained in:
parent
0fe51306ed
commit
f6c9596f47
@ -3,17 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.9.34622.214
|
VisualStudioVersion = 17.9.34622.214
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryView", "GarmentFactoryView\GarmentFactoryView.csproj", "{65042CBB-618A-473F-BA40-C698EFD4850E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryView", "GarmentFactoryView\GarmentFactoryView.csproj", "{65042CBB-618A-473F-BA40-C698EFD4850E}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryBusinessLogic", "GarmentFactoryBusinessLogic\GarmentFactoryBusinessLogic.csproj", "{62F1E4D7-57A6-461E-90A3-92E41AB90207}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryBusinessLogic", "GarmentFactoryBusinessLogic\GarmentFactoryBusinessLogic.csproj", "{62F1E4D7-57A6-461E-90A3-92E41AB90207}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryContracts", "GarmentFactoryContracts\GarmentFactoryContracts.csproj", "{35B381E5-7C62-43F4-B1B0-608542B71E73}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryContracts", "GarmentFactoryContracts\GarmentFactoryContracts.csproj", "{35B381E5-7C62-43F4-B1B0-608542B71E73}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryDataModels", "GarmentFactoryDataModels\GarmentFactoryDataModels.csproj", "{40AF2900-9319-4957-AEE3-8FB3738805D4}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryDataModels", "GarmentFactoryDataModels\GarmentFactoryDataModels.csproj", "{40AF2900-9319-4957-AEE3-8FB3738805D4}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryListImplement", "GarmentFactoryListImplement\GarmentFactoryListImplement.csproj", "{AA691567-80A9-45EF-9916-C55FA3B53C47}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryListImplement", "GarmentFactoryListImplement\GarmentFactoryListImplement.csproj", "{AA691567-80A9-45EF-9916-C55FA3B53C47}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryFileImplement", "GarmentFactoryFileImplement\GarmentFactoryFileImplement.csproj", "{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GarmentFactoryFileImplement", "GarmentFactoryFileImplement\GarmentFactoryFileImplement.csproj", "{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GarmentFactoryDatabaseImplement", "GarmentFactoryDatabaseImplement\GarmentFactoryDatabaseImplement.csproj", "{0AD8F2A6-9B14-411A-A454-D1A33B170C27}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -45,6 +47,10 @@ Global
|
|||||||
{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{281A8DE2-A45A-4B4B-B4A6-DC13ECC0144E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0AD8F2A6-9B14-411A-A454-D1A33B170C27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0AD8F2A6-9B14-411A-A454-D1A33B170C27}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0AD8F2A6-9B14-411A-A454-D1A33B170C27}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0AD8F2A6-9B14-411A-A454-D1A33B170C27}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using GarmentFactoryDatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryDatabaseImplement
|
||||||
|
{
|
||||||
|
public class GarmentFactoryDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (optionsBuilder.IsConfigured == false)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=Alexandr\SQLEXPRESS;Initial Catalog=GarmentFactoryDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Component> Components { set; get; }
|
||||||
|
public virtual DbSet<Textile> Textiles { set; get; }
|
||||||
|
public virtual DbSet<TextileComponent> TextileComponents { set; get; }
|
||||||
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\GarmentFactoryContracts\GarmentFactoryContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\GarmentFactoryDataModels\GarmentFactoryDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,59 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
|
||||||
|
namespace GarmentFactoryDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Component : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
[Required]
|
||||||
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public double Cost { get; set; }
|
||||||
|
[ForeignKey("ComponentId")]
|
||||||
|
public virtual List<TextileComponent> TextileComponents { get; set; } =
|
||||||
|
new();
|
||||||
|
public static Component? Create(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Component()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComponentName = model.ComponentName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Component Create(ComponentViewModel model)
|
||||||
|
{
|
||||||
|
return new Component
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ComponentName = model.ComponentName,
|
||||||
|
Cost = model.Cost
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ComponentName = model.ComponentName;
|
||||||
|
Cost = model.Cost;
|
||||||
|
}
|
||||||
|
public ComponentViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ComponentName = ComponentName,
|
||||||
|
Cost = Cost
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryDataModels.Enums;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace GarmentFactoryDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int TextileId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public double Sum { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public OrderStatus Status { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public DateTime DateCreate { get; set; }
|
||||||
|
|
||||||
|
public DateTime? DateImplement { get; set; }
|
||||||
|
|
||||||
|
public virtual Textile Textile { get; set; }
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
TextileId = model.TextileId,
|
||||||
|
Count = model.Count,
|
||||||
|
Sum = model.Sum,
|
||||||
|
Status = model.Status,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
TextileId = TextileId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement,
|
||||||
|
TextileName = Textile.TextileName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,99 @@
|
|||||||
|
using GarmentFactoryContracts.BindingModels;
|
||||||
|
using GarmentFactoryContracts.ViewModels;
|
||||||
|
using GarmentFactoryDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
|
||||||
|
namespace GarmentFactoryDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Textile : ITextileModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string TextileName { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public double Price { get; set; }
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _textileComponents =
|
||||||
|
null;
|
||||||
|
[NotMapped]
|
||||||
|
public Dictionary<int, (IComponentModel, int)> TextileComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_textileComponents == null)
|
||||||
|
{
|
||||||
|
_textileComponents = Components
|
||||||
|
.ToDictionary(recPC => recPC.ComponentId, recPC =>
|
||||||
|
(recPC.Component as IComponentModel, recPC.Count));
|
||||||
|
}
|
||||||
|
return _textileComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[ForeignKey("TextileId")]
|
||||||
|
public virtual List<TextileComponent> Components { get; set; } = new();
|
||||||
|
[ForeignKey("TextileId")]
|
||||||
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
public static Textile Create(GarmentFactoryDatabase context,
|
||||||
|
TextileBindingModel model)
|
||||||
|
{
|
||||||
|
return new Textile()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
TextileName = model.TextileName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.TextileComponents.Select(x => new
|
||||||
|
TextileComponent
|
||||||
|
{
|
||||||
|
Component = context.Components.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(TextileBindingModel model)
|
||||||
|
{
|
||||||
|
TextileName = model.TextileName;
|
||||||
|
Price = model.Price;
|
||||||
|
}
|
||||||
|
public TextileViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
TextileName = TextileName,
|
||||||
|
Price = Price,
|
||||||
|
TextileComponents = TextileComponents
|
||||||
|
};
|
||||||
|
public void UpdateComponents(GarmentFactoryDatabase context,
|
||||||
|
TextileBindingModel model)
|
||||||
|
{
|
||||||
|
var textileComponents = context.TextileComponents.Where(rec =>
|
||||||
|
rec.TextileId == model.Id).ToList();
|
||||||
|
if (textileComponents != null && textileComponents.Count > 0)
|
||||||
|
{ // удалили те, которых нет в модели
|
||||||
|
context.TextileComponents.RemoveRange(textileComponents.Where(rec
|
||||||
|
=> !model.TextileComponents.ContainsKey(rec.ComponentId)));
|
||||||
|
context.SaveChanges();
|
||||||
|
// обновили количество у существующих записей
|
||||||
|
foreach (var updateComponent in textileComponents)
|
||||||
|
{
|
||||||
|
updateComponent.Count =
|
||||||
|
model.TextileComponents[updateComponent.ComponentId].Item2;
|
||||||
|
model.TextileComponents.Remove(updateComponent.ComponentId);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
var textile = context.Textiles.First(x => x.Id == Id);
|
||||||
|
foreach (var tt in model.TextileComponents)
|
||||||
|
{
|
||||||
|
context.TextileComponents.Add(new TextileComponent
|
||||||
|
{
|
||||||
|
Textile = textile,
|
||||||
|
Component = context.Components.First(x => x.Id == tt.Key),
|
||||||
|
Count = tt.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_textileComponents = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
|
||||||
|
namespace GarmentFactoryDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class TextileComponent
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int TextileId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int ComponentId { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int Count { get; set; }
|
||||||
|
public virtual Component Component { get; set; } = new();
|
||||||
|
public virtual Textile Textile { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.16">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||||
|
Loading…
Reference in New Issue
Block a user