надо сделать миграцию
This commit is contained in:
parent
a75923818e
commit
7eb1dcd63d
11
WinForm/AppView/AppView.csproj
Normal file
11
WinForm/AppView/AppView.csproj
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
39
WinForm/AppView/Form1.Designer.cs
generated
Normal file
39
WinForm/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
WinForm/AppView/Form1.cs
Normal file
10
WinForm/AppView/Form1.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace AppView
|
||||||
|
{
|
||||||
|
public partial class Form1 : Form
|
||||||
|
{
|
||||||
|
public Form1()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
WinForm/AppView/Form1.resx
Normal file
120
WinForm/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
WinForm/AppView/Program.cs
Normal file
17
WinForm/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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
WinForm/Contracts/BindingModels/ProviderBindingModel.cs
Normal file
26
WinForm/Contracts/BindingModels/ProviderBindingModel.cs
Normal file
@ -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 string Furniture { get; set; }
|
||||||
|
public DateTime? SupplyDate { get; set; }
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public ProviderBindingModel() { }
|
||||||
|
|
||||||
|
public ProviderBindingModel(IProviderModel provider)
|
||||||
|
{
|
||||||
|
Id = provider.Id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
WinForm/Contracts/BindingModels/TypeBindingModel.cs
Normal file
22
WinForm/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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
WinForm/Contracts/Contracts.csproj
Normal file
9
WinForm/Contracts/Contracts.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
WinForm/Contracts/SearchModels/ProviderSearchModel.cs
Normal file
13
WinForm/Contracts/SearchModels/ProviderSearchModel.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 ProviderSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
13
WinForm/Contracts/SearchModels/TypeSearchModel.cs
Normal file
13
WinForm/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; }
|
||||||
|
}
|
||||||
|
}
|
21
WinForm/Contracts/StoragesContracts/IProviderStorage.cs
Normal file
21
WinForm/Contracts/StoragesContracts/IProviderStorage.cs
Normal file
@ -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.StoragesContracts
|
||||||
|
{
|
||||||
|
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
WinForm/Contracts/StoragesContracts/ITypeStorage.cs
Normal file
20
WinForm/Contracts/StoragesContracts/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.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface ITypeStorage
|
||||||
|
{
|
||||||
|
List<TypeViewModel> GetFullList();
|
||||||
|
TypeViewModel? GetElement(TypeSearchModel model);
|
||||||
|
TypeViewModel? Insert(TypeBindingModel model);
|
||||||
|
TypeViewModel? Update(TypeBindingModel model);
|
||||||
|
TypeViewModel? Delete(TypeBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
19
WinForm/Contracts/ViewModels/ProviderViewModel.cs
Normal file
19
WinForm/Contracts/ViewModels/ProviderViewModel.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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 string Furniture { get; set; }
|
||||||
|
public DateTime? SupplyDate { get; set; }
|
||||||
|
public string? SupplyDateTime { get; set; }
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
15
WinForm/Contracts/ViewModels/TypeViewModel.cs
Normal file
15
WinForm/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; }
|
||||||
|
}
|
||||||
|
}
|
18
WinForm/DataBaseImplement/DBContext.cs
Normal file
18
WinForm/DataBaseImplement/DBContext.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using DatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace DatabaseImplement
|
||||||
|
{
|
||||||
|
public class DBContext:DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if(!optionsBuilder.IsConfigured)
|
||||||
|
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=COP;Username=courseuser;Password=courseuser");
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual DbSet<Provider> Providers { get; set; }
|
||||||
|
public virtual DbSet<Models.Type> Types { get; set; }
|
||||||
|
}
|
||||||
|
}
|
19
WinForm/DataBaseImplement/DataBaseImplement.csproj
Normal file
19
WinForm/DataBaseImplement/DataBaseImplement.csproj
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<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.13" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||||
|
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
89
WinForm/DataBaseImplement/Implements/ProviderStorage.cs
Normal file
89
WinForm/DataBaseImplement/Implements/ProviderStorage.cs
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
using Contracts.BindingModels;
|
||||||
|
using Contracts.SearchModels;
|
||||||
|
using Contracts.StoragesContracts;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using DatabaseImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ProviderStorage : IProviderStorage
|
||||||
|
{
|
||||||
|
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> 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProviderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new DBContext();
|
||||||
|
return context.Providers
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
79
WinForm/DataBaseImplement/Implements/TypeStorage.cs
Normal file
79
WinForm/DataBaseImplement/Implements/TypeStorage.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using Contracts.BindingModels;
|
||||||
|
using Contracts.SearchModels;
|
||||||
|
using Contracts.StoragesContracts;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class TypeStorage : ITypeStorage
|
||||||
|
{
|
||||||
|
public TypeViewModel? Delete(TypeBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new DBContext();
|
||||||
|
var element = context.Types.FirstOrDefault(x => x.Id == x.Id);
|
||||||
|
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.Types.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
WinForm/DataBaseImplement/Models/Provider.cs
Normal file
55
WinForm/DataBaseImplement/Models/Provider.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
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 DatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Provider : IProviderModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string Name { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string Type { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string Furniture { get; set; }
|
||||||
|
public DateTime? SupplyDate { get; set; } = DateTime.MinValue;
|
||||||
|
|
||||||
|
public static Provider? Create(ProviderBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null) return null;
|
||||||
|
return new Provider()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
Type = model.Type,
|
||||||
|
Furniture = model.Furniture,
|
||||||
|
SupplyDate = model.SupplyDate,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ProviderBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null) return;
|
||||||
|
Name = model.Name;
|
||||||
|
Type = model.Type;
|
||||||
|
Furniture = model.Furniture;
|
||||||
|
SupplyDate = model.SupplyDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProviderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
Type = Type,
|
||||||
|
Furniture = Furniture,
|
||||||
|
SupplyDate = SupplyDate,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
41
WinForm/DataBaseImplement/Models/Type.cs
Normal file
41
WinForm/DataBaseImplement/Models/Type.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
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 DatabaseImplement.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()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
Name = model.Name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(TypeBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null) return;
|
||||||
|
Name = model.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
Name = Name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
9
WinForm/DataModels/DataModels.csproj
Normal file
9
WinForm/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
WinForm/DataModels/IId.cs
Normal file
13
WinForm/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
WinForm/DataModels/Models/IProviderModel.cs
Normal file
16
WinForm/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; }
|
||||||
|
string Furniture { get; set; }
|
||||||
|
DateTime? SupplyDate { get; set; }
|
||||||
|
}
|
||||||
|
}
|
13
WinForm/DataModels/Models/ITypeModel.cs
Normal file
13
WinForm/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; }
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForm", "WinForm\WinForm.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{B617E65D-B482-4120-BC74-66B760D66FEF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsLibrary", "WinFormsLibrary\WinFormsLibrary.csproj", "{B617E65D-B482-4120-BC74-66B760D66FEF}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModels", "DataModels\DataModels.csproj", "{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -21,6 +25,14 @@ Global
|
|||||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B617E65D-B482-4120-BC74-66B760D66FEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B617E65D-B482-4120-BC74-66B760D66FEF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
Loading…
Reference in New Issue
Block a user