Оттолкнулся от дна
This commit is contained in:
parent
c3424531c1
commit
462e8f8bb4
22
WinFormsProject/AppView/AppView.csproj
Normal file
22
WinFormsProject/AppView/AppView.csproj
Normal file
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DateBaseImplement\DateBaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
39
WinFormsProject/AppView/Form1.Designer.cs
generated
Normal file
39
WinFormsProject/AppView/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
||||
namespace AppView
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
10
WinFormsProject/AppView/Form1.cs
Normal file
10
WinFormsProject/AppView/Form1.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace AppView
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
120
WinFormsProject/AppView/Form1.resx
Normal file
120
WinFormsProject/AppView/Form1.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
17
WinFormsProject/AppView/Program.cs
Normal file
17
WinFormsProject/AppView/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace AppView
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.BindingModels
|
||||
{
|
||||
public class ProviderBindingModel : IProviderModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
public byte[] Logo { get; set; }
|
||||
public string Number { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public ProviderBindingModel() { }
|
||||
|
||||
public ProviderBindingModel(IProviderModel provider)
|
||||
{
|
||||
Id = provider.Id;
|
||||
}
|
||||
}
|
||||
}
|
22
WinFormsProject/Contracts/BindingModels/TypeBindingModel.cs
Normal file
22
WinFormsProject/Contracts/BindingModels/TypeBindingModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.BindingModels
|
||||
{
|
||||
public class TypeBindingModel : ITypeModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public TypeBindingModel() { }
|
||||
|
||||
public TypeBindingModel(ITypeModel type)
|
||||
{
|
||||
Id = type.Id;
|
||||
}
|
||||
}
|
||||
}
|
13
WinFormsProject/Contracts/Contracts.csproj
Normal file
13
WinFormsProject/Contracts/Contracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class ProviderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
13
WinFormsProject/Contracts/SearchModels/TypeSearchModel.cs
Normal file
13
WinFormsProject/Contracts/SearchModels/TypeSearchModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class TypeSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.StorageContracts
|
||||
{
|
||||
public interface IProviderStorage
|
||||
{
|
||||
List<ProviderViewModel> GetFullList();
|
||||
ProviderViewModel? GetElement(ProviderSearchModel model);
|
||||
List<ProviderViewModel> GetFilteredList(ProviderSearchModel model);
|
||||
ProviderViewModel? Insert(ProviderBindingModel model);
|
||||
ProviderViewModel? Update(ProviderBindingModel model);
|
||||
ProviderViewModel? Delete(ProviderBindingModel model);
|
||||
}
|
||||
}
|
20
WinFormsProject/Contracts/StorageContracts/ITypeStorage.cs
Normal file
20
WinFormsProject/Contracts/StorageContracts/ITypeStorage.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.StorageContracts
|
||||
{
|
||||
public interface ITypeStorage
|
||||
{
|
||||
List<TypeViewModel> GetFullList();
|
||||
TypeViewModel? GetElement(TypeSearchModel model);
|
||||
TypeViewModel? Insert(TypeBindingModel model);
|
||||
TypeViewModel? Update(TypeBindingModel model);
|
||||
TypeViewModel? Delete(TypeBindingModel model);
|
||||
}
|
||||
}
|
18
WinFormsProject/Contracts/ViewModels/ProviderViewModel.cs
Normal file
18
WinFormsProject/Contracts/ViewModels/ProviderViewModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class ProviderViewModel : IProviderModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
public byte[] Logo { get; set; }
|
||||
public string Number { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
15
WinFormsProject/Contracts/ViewModels/TypeViewModel.cs
Normal file
15
WinFormsProject/Contracts/ViewModels/TypeViewModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class TypeViewModel : ITypeModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
9
WinFormsProject/DataModels/DataModels.csproj
Normal file
9
WinFormsProject/DataModels/DataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
13
WinFormsProject/DataModels/IId.cs
Normal file
13
WinFormsProject/DataModels/IId.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
16
WinFormsProject/DataModels/Models/IProviderModel.cs
Normal file
16
WinFormsProject/DataModels/Models/IProviderModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels.Models
|
||||
{
|
||||
public interface IProviderModel : IId
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Type { get; set; }
|
||||
byte[] Logo { get; set; }
|
||||
string Number { get; set; }
|
||||
}
|
||||
}
|
13
WinFormsProject/DataModels/Models/ITypeModel.cs
Normal file
13
WinFormsProject/DataModels/Models/ITypeModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels.Models
|
||||
{
|
||||
public interface ITypeModel : IId
|
||||
{
|
||||
string Name { get; set; }
|
||||
}
|
||||
}
|
24
WinFormsProject/DateBaseImplement/DBContext.cs
Normal file
24
WinFormsProject/DateBaseImplement/DBContext.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using DateBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DateBaseImplement
|
||||
{
|
||||
public class DBContext : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=COP;Username=postgres;Password=postgres");
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Provider> Providers { get; set; }
|
||||
public virtual DbSet<Models.Type> Types { get; set; }
|
||||
}
|
||||
}
|
22
WinFormsProject/DateBaseImplement/DateBaseImplement.csproj
Normal file
22
WinFormsProject/DateBaseImplement/DateBaseImplement.csproj
Normal file
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,73 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModels;
|
||||
using DateBaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DateBaseImplement.Implements
|
||||
{
|
||||
public class ProviderStorage : IProviderStorage
|
||||
{
|
||||
public ProviderViewModel? Insert(ProviderBindingModel model)
|
||||
{
|
||||
var newProvider = Provider.Create(model);
|
||||
if (newProvider == null) return null;
|
||||
|
||||
using var context = new DBContext();
|
||||
context.Providers.Add(newProvider);
|
||||
context.SaveChanges();
|
||||
return newProvider.GetViewModel;
|
||||
}
|
||||
|
||||
public ProviderViewModel? Update(ProviderBindingModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
var provider = context.Providers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (provider == null) return null;
|
||||
provider.Update(model);
|
||||
context.SaveChanges();
|
||||
return provider.GetViewModel;
|
||||
}
|
||||
|
||||
public ProviderViewModel? Delete(ProviderBindingModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
var element = context.Providers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element == null) return null;
|
||||
context.Providers.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public ProviderViewModel? GetElement(ProviderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue) return null;
|
||||
using var context = new DBContext();
|
||||
return context.Providers
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ProviderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new DBContext();
|
||||
return context.Providers
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ProviderViewModel> GetFilteredList(ProviderSearchModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
return context.Providers
|
||||
.Where(x => model.Id.HasValue && x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
62
WinFormsProject/DateBaseImplement/Implements/TypeStorage.cs
Normal file
62
WinFormsProject/DateBaseImplement/Implements/TypeStorage.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DateBaseImplement.Implements
|
||||
{
|
||||
public class TypeStorage : ITypeStorage
|
||||
{
|
||||
public TypeViewModel? Insert(TypeBindingModel model)
|
||||
{
|
||||
var newType = Models.Type.Create(model);
|
||||
if (newType == null) return null;
|
||||
using var context = new DBContext();
|
||||
context.Types.Add(newType);
|
||||
context.SaveChanges();
|
||||
return newType.GetViewModel;
|
||||
}
|
||||
|
||||
public TypeViewModel? Update(TypeBindingModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
var type = context.Types.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (type == null) return null;
|
||||
type.Update(model);
|
||||
context.SaveChanges();
|
||||
return type.GetViewModel;
|
||||
}
|
||||
|
||||
public TypeViewModel? Delete(TypeBindingModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
var type = context.Types.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (type == null) return null;
|
||||
context.Types.Remove(type);
|
||||
context.SaveChanges();
|
||||
return type.GetViewModel;
|
||||
}
|
||||
|
||||
public TypeViewModel? GetElement(TypeSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue) return null;
|
||||
using var context = new DBContext();
|
||||
return context.Types
|
||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<TypeViewModel> GetFullList()
|
||||
{
|
||||
using var context = new DBContext();
|
||||
return context.Types
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
75
WinFormsProject/DateBaseImplement/Migrations/20231115184705_initMigration.Designer.cs
generated
Normal file
75
WinFormsProject/DateBaseImplement/Migrations/20231115184705_initMigration.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using DateBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DateBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(DBContext))]
|
||||
[Migration("20231115184705_initMigration")]
|
||||
partial class initMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.14")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DateBaseImplement.Models.Provider", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<byte[]>("Logo")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Number")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Providers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DateBaseImplement.Models.Type", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Types");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DateBaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class initMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Providers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Logo = table.Column<byte[]>(type: "bytea", nullable: false),
|
||||
Type = table.Column<string>(type: "text", nullable: false),
|
||||
Number = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Providers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Types",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Types", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Providers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Types");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
// <auto-generated />
|
||||
using DateBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DateBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(DBContext))]
|
||||
partial class DBContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.14")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DateBaseImplement.Models.Provider", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<byte[]>("Logo")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Number")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Providers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DateBaseImplement.Models.Type", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Types");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
62
WinFormsProject/DateBaseImplement/Models/Provider.cs
Normal file
62
WinFormsProject/DateBaseImplement/Models/Provider.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.ViewModels;
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DateBaseImplement.Models
|
||||
{
|
||||
public class Provider : IProviderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Required]
|
||||
public byte[] Logo { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Type { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Number { get; set; }
|
||||
|
||||
public static Provider? Create(ProviderBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new Provider()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Type = model.Type,
|
||||
Logo = model.Logo,
|
||||
Number = model.Number,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ProviderBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
|
||||
Name = model.Name;
|
||||
Type = model.Type;
|
||||
Logo = model.Logo;
|
||||
Number = model.Number;
|
||||
}
|
||||
|
||||
public ProviderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Type = Type,
|
||||
Logo = Logo,
|
||||
Number = Number,
|
||||
};
|
||||
}
|
||||
}
|
42
WinFormsProject/DateBaseImplement/Models/Type.cs
Normal file
42
WinFormsProject/DateBaseImplement/Models/Type.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.ViewModels;
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DateBaseImplement.Models
|
||||
{
|
||||
public class Type : ITypeModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
public static Type? Create(TypeBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new Type()
|
||||
{
|
||||
Name = model.Name,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(TypeBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
model.Name = Name;
|
||||
}
|
||||
|
||||
public TypeViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
};
|
||||
}
|
||||
}
|
@ -3,9 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32819.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsProject", "WinFormsProject\WinFormsProject.csproj", "{1FC6ABE3-DF27-453A-B2EE-FA17C71C9CF0}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsProject", "WinFormsProject\WinFormsProject.csproj", "{1FC6ABE3-DF27-453A-B2EE-FA17C71C9CF0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModels", "DataModels\DataModels.csproj", "{23F0E442-0283-4192-A17B-D13D0C01C10D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{6A196E6B-91D9-4873-9E5F-0D96D18A74F5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DateBaseImplement", "DateBaseImplement\DateBaseImplement.csproj", "{F53D2EB4-F1EB-4C24-987C-CCC6BFC5FAD7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppView", "AppView\AppView.csproj", "{294B81DD-546F-40AD-9BCE-0F51F1D17D1A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -21,6 +29,22 @@ Global
|
||||
{CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CF6B5601-DC60-48A2-8BDC-1CE32E3F6F15}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{23F0E442-0283-4192-A17B-D13D0C01C10D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{23F0E442-0283-4192-A17B-D13D0C01C10D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{23F0E442-0283-4192-A17B-D13D0C01C10D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{23F0E442-0283-4192-A17B-D13D0C01C10D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6A196E6B-91D9-4873-9E5F-0D96D18A74F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6A196E6B-91D9-4873-9E5F-0D96D18A74F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6A196E6B-91D9-4873-9E5F-0D96D18A74F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6A196E6B-91D9-4873-9E5F-0D96D18A74F5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F53D2EB4-F1EB-4C24-987C-CCC6BFC5FAD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F53D2EB4-F1EB-4C24-987C-CCC6BFC5FAD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F53D2EB4-F1EB-4C24-987C-CCC6BFC5FAD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F53D2EB4-F1EB-4C24-987C-CCC6BFC5FAD7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{294B81DD-546F-40AD-9BCE-0F51F1D17D1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{294B81DD-546F-40AD-9BCE-0F51F1D17D1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{294B81DD-546F-40AD-9BCE-0F51F1D17D1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{294B81DD-546F-40AD-9BCE-0F51F1D17D1A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user