Skip to content

Commit 00bcd91

Browse files
committed
Add project files.
1 parent 44f9170 commit 00bcd91

11 files changed

+614
-0
lines changed

EF_CRM.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.11.35327.3
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EF_CRM", "EF_CRM\EF_CRM.csproj", "{DD0F18AE-B5F4-45A1-A943-5BE714015286}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{DD0F18AE-B5F4-45A1-A943-5BE714015286}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{DD0F18AE-B5F4-45A1-A943-5BE714015286}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{DD0F18AE-B5F4-45A1-A943-5BE714015286}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{DD0F18AE-B5F4-45A1-A943-5BE714015286}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {F717DB0E-677B-4A2E-8910-3C3EEC04ADE2}
24+
EndGlobalSection
25+
EndGlobal

EF_CRM/CRMContext.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace EF_CRM
4+
{
5+
public class CRMContext : DbContext
6+
{
7+
public DbSet<Customer> Customers { get; set; }
8+
public DbSet<Order> Orders { get; set; }
9+
public DbSet<Product> Products { get; set; }
10+
11+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
12+
{
13+
//optionsBuilder.UseSqlServer("Data Source = localhost; Initial Catalog = EF_CRM; " +
14+
//"Integrated Security = true; Encrypt=false");
15+
16+
optionsBuilder.UseSqlServer("Data Source = 192.168.1.48; Initial Catalog = EF_CRM; " +
17+
"User = 'sa'; Password = '!Abc123456'; Encrypt=false");
18+
base.OnConfiguring(optionsBuilder);
19+
}
20+
}
21+
}

EF_CRM/Customer.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EF_CRM
8+
{
9+
public class Customer
10+
{
11+
public int Id { get; set; }
12+
public required string FirstName { get; set; }
13+
public required string LastName { get; set; }
14+
public string? Email { get; set; }
15+
public string? Telephone { get; set; }
16+
public List<Order> Orders { get; set; } = new();
17+
18+
public void CreateCustomer(string first, string last, string tel, string email)
19+
{
20+
Customer cust = new Customer()
21+
{
22+
FirstName = first,
23+
LastName = last,
24+
Email = email,
25+
Telephone = tel
26+
};
27+
}
28+
}
29+
}

EF_CRM/CustomerOrder.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EF_CRM
8+
{
9+
public class CustomerOrder
10+
{
11+
public DateTime OrderDate { get; set; }
12+
public required string CustomerName { get; set; }
13+
public required string ProductName { get; set; }
14+
}
15+
}

EF_CRM/EF_CRM.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
16+
</ItemGroup>
17+
18+
</Project>

EF_CRM/Migrations/20241219124453_initial.Designer.cs

Lines changed: 135 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace EF_CRM.Migrations
7+
{
8+
/// <inheritdoc />
9+
public partial class initial : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.CreateTable(
15+
name: "Customers",
16+
columns: table => new
17+
{
18+
Id = table.Column<int>(type: "int", nullable: false)
19+
.Annotation("SqlServer:Identity", "1, 1"),
20+
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: false),
21+
LastName = table.Column<string>(type: "nvarchar(max)", nullable: false),
22+
Email = table.Column<string>(type: "nvarchar(max)", nullable: true),
23+
Telephone = table.Column<string>(type: "nvarchar(max)", nullable: true)
24+
},
25+
constraints: table =>
26+
{
27+
table.PrimaryKey("PK_Customers", x => x.Id);
28+
});
29+
30+
migrationBuilder.CreateTable(
31+
name: "Products",
32+
columns: table => new
33+
{
34+
Id = table.Column<int>(type: "int", nullable: false)
35+
.Annotation("SqlServer:Identity", "1, 1"),
36+
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
37+
Price = table.Column<float>(type: "real", nullable: false),
38+
Color = table.Column<string>(type: "nvarchar(max)", nullable: true)
39+
},
40+
constraints: table =>
41+
{
42+
table.PrimaryKey("PK_Products", x => x.Id);
43+
});
44+
45+
migrationBuilder.CreateTable(
46+
name: "Orders",
47+
columns: table => new
48+
{
49+
Id = table.Column<int>(type: "int", nullable: false)
50+
.Annotation("SqlServer:Identity", "1, 1"),
51+
OrderDate = table.Column<DateTime>(type: "datetime2", nullable: false),
52+
CustomerId = table.Column<int>(type: "int", nullable: false),
53+
ProductId = table.Column<int>(type: "int", nullable: false)
54+
},
55+
constraints: table =>
56+
{
57+
table.PrimaryKey("PK_Orders", x => x.Id);
58+
table.ForeignKey(
59+
name: "FK_Orders_Customers_CustomerId",
60+
column: x => x.CustomerId,
61+
principalTable: "Customers",
62+
principalColumn: "Id",
63+
onDelete: ReferentialAction.Cascade);
64+
table.ForeignKey(
65+
name: "FK_Orders_Products_ProductId",
66+
column: x => x.ProductId,
67+
principalTable: "Products",
68+
principalColumn: "Id",
69+
onDelete: ReferentialAction.Cascade);
70+
});
71+
72+
migrationBuilder.CreateIndex(
73+
name: "IX_Orders_CustomerId",
74+
table: "Orders",
75+
column: "CustomerId");
76+
77+
migrationBuilder.CreateIndex(
78+
name: "IX_Orders_ProductId",
79+
table: "Orders",
80+
column: "ProductId");
81+
}
82+
83+
/// <inheritdoc />
84+
protected override void Down(MigrationBuilder migrationBuilder)
85+
{
86+
migrationBuilder.DropTable(
87+
name: "Orders");
88+
89+
migrationBuilder.DropTable(
90+
name: "Customers");
91+
92+
migrationBuilder.DropTable(
93+
name: "Products");
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)