Done
This commit is contained in:
parent
4321d773e7
commit
32876640c2
@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleMainApp", "ConsoleMa
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarServiceDataBaseImplements", "CarServiceDataBaseImplements\CarServiceDataBaseImplements.csproj", "{48D159D4-7150-417E-BBE9-2B636E1EAFFB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarServiceDataModels", "CarServiceDataModels\CarServiceDataModels.csproj", "{7E6DC5DC-32CA-464C-884C-D949742DBF07}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -21,6 +23,10 @@ Global
|
||||
{48D159D4-7150-417E-BBE9-2B636E1EAFFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{48D159D4-7150-417E-BBE9-2B636E1EAFFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{48D159D4-7150-417E-BBE9-2B636E1EAFFB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7E6DC5DC-32CA-464C-884C-D949742DBF07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7E6DC5DC-32CA-464C-884C-D949742DBF07}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7E6DC5DC-32CA-464C-884C-D949742DBF07}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7E6DC5DC-32CA-464C-884C-D949742DBF07}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using CarServiceDataBaseImplements.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,16 +8,20 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataBaseImplements
|
||||
{
|
||||
public class CarServiceDataBase : DbContext
|
||||
public class CarServiceDataBase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if(optionsBuilder.IsConfigured == false)
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Database=CarServiceDataBase;Username=postgres;Password=postgres");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Car> Cars { get; set; }
|
||||
public virtual DbSet<Client> Clients { get; set; }
|
||||
public virtual DbSet<Receipt> Receipts { get; set; }
|
||||
public virtual DbSet<Service> Services { get; set; }
|
||||
public virtual DbSet<Staff> Staffs { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,15 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CarServiceDataModels\CarServiceDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
125
CarService/CarServiceDataBaseImplements/Migrations/20240505121028_InitMigration.Designer.cs
generated
Normal file
125
CarService/CarServiceDataBaseImplements/Migrations/20240505121028_InitMigration.Designer.cs
generated
Normal file
@ -0,0 +1,125 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarServiceDataBaseImplements;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarServiceDataBaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarServiceDataBase))]
|
||||
[Migration("20240505121028_InitMigration")]
|
||||
partial class InitMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Receipt", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateOfApplication")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Receipts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Service", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Staff", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PositionAtWork")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Staffs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarServiceDataBaseImplements.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Cars",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Brand = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Cars", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Clients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Email = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Clients", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Receipts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
DateOfApplication = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Receipts", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Services",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Services", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Staffs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
PositionAtWork = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Staffs", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Cars");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Receipts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Services");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Staffs");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using CarServiceDataBaseImplements;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace CarServiceDataBaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(CarServiceDataBase))]
|
||||
partial class CarServiceDataBaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Receipt", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DateOfApplication")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Receipts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Service", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Services");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("CarServiceDataBaseImplements.Models.Staff", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PositionAtWork")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Staffs");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
35
CarService/CarServiceDataBaseImplements/Models/Car.cs
Normal file
35
CarService/CarServiceDataBaseImplements/Models/Car.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using CarServiceDataModels.ModelsImplements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataBaseImplements.Models
|
||||
{
|
||||
public class Car : ICar
|
||||
{
|
||||
[Required]
|
||||
public string Brand {get; set;} = string.Empty;
|
||||
public int Id { get; set; }
|
||||
|
||||
public static Car? Create(CarModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Car()
|
||||
{
|
||||
Id = model.Id,
|
||||
Brand = model.Brand
|
||||
};
|
||||
}
|
||||
public void Update(CarModel? model) {
|
||||
if (model == null) { return; }
|
||||
Brand = model.Brand;
|
||||
}
|
||||
}
|
||||
}
|
41
CarService/CarServiceDataBaseImplements/Models/Client.cs
Normal file
41
CarService/CarServiceDataBaseImplements/Models/Client.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using CarServiceDataModels.ModelsImplements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataBaseImplements.Models
|
||||
{
|
||||
public class Client : IClient
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; } = String.Empty;
|
||||
[Required]
|
||||
public string Email { get; set; } = String.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public static Client? Create(ClientModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Email = model.Email
|
||||
};
|
||||
}
|
||||
public void Update(ClientModel? model)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
Name = model.Name;
|
||||
Email = model.Email;
|
||||
}
|
||||
}
|
||||
}
|
38
CarService/CarServiceDataBaseImplements/Models/Receipt.cs
Normal file
38
CarService/CarServiceDataBaseImplements/Models/Receipt.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using CarServiceDataModels.ModelsImplements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace CarServiceDataBaseImplements.Models
|
||||
{
|
||||
public class Receipt : IReceipt
|
||||
{
|
||||
[Required]
|
||||
public DateTime DateOfApplication { get; set; } = DateTime.Now;
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public static Receipt? Create(ReceiptModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Receipt()
|
||||
{
|
||||
Id = model.Id,
|
||||
DateOfApplication = model.DateOfApplication,
|
||||
};
|
||||
}
|
||||
public void Update(ReceiptModel? model)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
DateOfApplication = model.DateOfApplication;
|
||||
}
|
||||
}
|
||||
}
|
41
CarService/CarServiceDataBaseImplements/Models/Service.cs
Normal file
41
CarService/CarServiceDataBaseImplements/Models/Service.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using CarServiceDataModels.ModelsImplements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataBaseImplements.Models
|
||||
{
|
||||
public class Service : IService
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public static Service? Create(ServiceModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Service()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Price = model.Price
|
||||
};
|
||||
}
|
||||
public void Update(ServiceModel? model)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
Name = model.Name;
|
||||
Price = model.Price;
|
||||
}
|
||||
}
|
||||
}
|
42
CarService/CarServiceDataBaseImplements/Models/Staff.cs
Normal file
42
CarService/CarServiceDataBaseImplements/Models/Staff.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using CarServiceDataModels.ModelsImplements;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataBaseImplements.Models
|
||||
{
|
||||
public class Staff : IStaff
|
||||
{
|
||||
[Required]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string PositionAtWork { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public static Staff? Create(StaffModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Staff()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
PositionAtWork = model.PositionAtWork,
|
||||
};
|
||||
}
|
||||
public void Update(StaffModel? model)
|
||||
{
|
||||
if (model == null) { return; }
|
||||
Name = model.Name;
|
||||
PositionAtWork = model.PositionAtWork;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
13
CarService/CarServiceDataModels/Models/ICar.cs
Normal file
13
CarService/CarServiceDataModels/Models/ICar.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.Models
|
||||
{
|
||||
public interface ICar : Iid
|
||||
{
|
||||
string Brand { get; }
|
||||
}
|
||||
}
|
15
CarService/CarServiceDataModels/Models/IClient.cs
Normal file
15
CarService/CarServiceDataModels/Models/IClient.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.Models
|
||||
{
|
||||
public interface IClient : Iid
|
||||
{
|
||||
string Name { get; }
|
||||
string Email { get; }
|
||||
|
||||
}
|
||||
}
|
14
CarService/CarServiceDataModels/Models/IReceipt.cs
Normal file
14
CarService/CarServiceDataModels/Models/IReceipt.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.Models
|
||||
{
|
||||
public interface IReceipt : Iid
|
||||
{
|
||||
DateTime DateOfApplication { get; }
|
||||
|
||||
}
|
||||
}
|
14
CarService/CarServiceDataModels/Models/IService.cs
Normal file
14
CarService/CarServiceDataModels/Models/IService.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.Models
|
||||
{
|
||||
public interface IService : Iid
|
||||
{
|
||||
string Name { get; }
|
||||
double Price { get; }
|
||||
}
|
||||
}
|
14
CarService/CarServiceDataModels/Models/IStaff.cs
Normal file
14
CarService/CarServiceDataModels/Models/IStaff.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.Models
|
||||
{
|
||||
public interface IStaff : Iid
|
||||
{
|
||||
string Name { get; }
|
||||
string PositionAtWork { get; }
|
||||
}
|
||||
}
|
13
CarService/CarServiceDataModels/Models/Iid.cs
Normal file
13
CarService/CarServiceDataModels/Models/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 CarServiceDataModels.Models
|
||||
{
|
||||
public interface Iid
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
16
CarService/CarServiceDataModels/ModelsImplements/CarModel.cs
Normal file
16
CarService/CarServiceDataModels/ModelsImplements/CarModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.ModelsImplements
|
||||
{
|
||||
public class CarModel : ICar
|
||||
{
|
||||
public string Brand {get; set;} = string.Empty;
|
||||
|
||||
public int Id { get; set;}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.ModelsImplements
|
||||
{
|
||||
public class ClientModel : IClient
|
||||
{
|
||||
public string Name {get;set;} = string.Empty;
|
||||
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.ModelsImplements
|
||||
{
|
||||
public class ReceiptModel : IReceipt
|
||||
{
|
||||
public DateTime DateOfApplication { get; set; } = DateTime.Now;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.ModelsImplements
|
||||
{
|
||||
public class ServiceModel : IService
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using CarServiceDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarServiceDataModels.ModelsImplements
|
||||
{
|
||||
public class StaffModel : IStaff
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string PositionAtWork { get; set; } = string.Empty;
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
@ -8,6 +8,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql" Version="7.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -10,8 +10,19 @@ namespace ConsoleMainApp
|
||||
static void Main(string[] args)
|
||||
{
|
||||
using var context = new CarServiceDataBase();
|
||||
context.Database.OpenConnection();
|
||||
try
|
||||
{
|
||||
context.Database.OpenConnection();
|
||||
Console.WriteLine("Connect open");
|
||||
}
|
||||
catch {
|
||||
Console.WriteLine("Connect error");
|
||||
return;
|
||||
}
|
||||
context.Database.CloseConnection();
|
||||
if(context.Database.GetDbConnection().State == System.Data.ConnectionState.Open) {
|
||||
Console.WriteLine("Connect still open");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user