Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SergeevaAA
FileDesk
Commits
e0eeec0e
Commit
e0eeec0e
authored
Oct 23, 2020
by
SergeevaAA
Browse files
Merge branch 'feature/
#2
-AddDataAccessLibrary' into 'develop'
#2
- Реализована работа с БД See merge request
!5
parents
afb559d0
74022c73
Changes
12
Hide whitespace changes
Inline
Side-by-side
source/FileDesk.DataAccess/Class1.cs
deleted
100644 → 0
View file @
afb559d0
using
System
;
namespace
FileDesk.DataAccess
{
public
class
Class1
{
}
}
source/FileDesk.DataAccess/FileDesk.DataAccess.csproj
View file @
e0eeec0e
...
...
@@ -4,4 +4,22 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileDesk.Domain\FileDesk.Domain.csproj" />
</ItemGroup>
</Project>
source/FileDesk.DataAccess/Migrations/20201023144738_FilesAndDownloadsTablesCreate.Designer.cs
0 → 100644
View file @
e0eeec0e
// <auto-generated />
using
System
;
using
FileDesk.DataAccess.Repository
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Metadata
;
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
FileDesk.DataAccess.Migrations
{
[
DbContext
(
typeof
(
FileDeskContext
))]
[
Migration
(
"20201023144738_FilesAndDownloadsTablesCreate"
)]
partial
class
FilesAndDownloadsTablesCreate
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"3.1.9"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
128
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
modelBuilder
.
Entity
(
"FileDesk.Domain.Models.Download"
,
b
=>
{
b
.
Property
<
long
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"bigint"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b
.
Property
<
DateTime
>(
"DateTime"
)
.
HasColumnType
(
"datetime2"
);
b
.
Property
<
long
>(
"FileId"
)
.
HasColumnType
(
"bigint"
);
b
.
Property
<
string
>(
"IpAddress"
)
.
IsRequired
()
.
HasColumnType
(
"nvarchar(max)"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"FileId"
);
b
.
ToTable
(
"Downloads"
);
});
modelBuilder
.
Entity
(
"FileDesk.Domain.Models.File"
,
b
=>
{
b
.
Property
<
long
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"bigint"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b
.
Property
<
byte
[
]>
(
"Content"
)
.
IsRequired
()
.
HasColumnType
(
"varbinary(max)"
);
b
.
Property
<
string
>(
"Description"
)
.
IsRequired
()
.
HasColumnType
(
"nvarchar(max)"
);
b
.
Property
<
int
>(
"Format"
)
.
HasColumnType
(
"int"
);
b
.
Property
<
string
>(
"Name"
)
.
IsRequired
()
.
HasColumnType
(
"nvarchar(max)"
);
b
.
Property
<
DateTime
>(
"UploadDateTime"
)
.
HasColumnType
(
"datetime2"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Files"
);
});
modelBuilder
.
Entity
(
"FileDesk.Domain.Models.Download"
,
b
=>
{
b
.
HasOne
(
"FileDesk.Domain.Models.File"
,
"File"
)
.
WithMany
(
"Downloads"
)
.
HasForeignKey
(
"FileId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
#pragma warning restore 612, 618
}
}
}
source/FileDesk.DataAccess/Migrations/20201023144738_FilesAndDownloadsTablesCreate.cs
0 → 100644
View file @
e0eeec0e
using
System
;
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
FileDesk.DataAccess.Migrations
{
public
partial
class
FilesAndDownloadsTablesCreate
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"Files"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
long
>(
nullable
:
false
)
.
Annotation
(
"SqlServer:Identity"
,
"1, 1"
),
Name
=
table
.
Column
<
string
>(
nullable
:
false
),
Description
=
table
.
Column
<
string
>(
nullable
:
false
),
UploadDateTime
=
table
.
Column
<
DateTime
>(
nullable
:
false
),
Content
=
table
.
Column
<
byte
[
]>
(
nullable
:
false
),
Format
=
table
.
Column
<
int
>(
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_Files"
,
x
=>
x
.
Id
);
});
migrationBuilder
.
CreateTable
(
name
:
"Downloads"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
long
>(
nullable
:
false
)
.
Annotation
(
"SqlServer:Identity"
,
"1, 1"
),
FileId
=
table
.
Column
<
long
>(
nullable
:
false
),
DateTime
=
table
.
Column
<
DateTime
>(
nullable
:
false
),
IpAddress
=
table
.
Column
<
string
>(
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_Downloads"
,
x
=>
x
.
Id
);
table
.
ForeignKey
(
name
:
"FK_Downloads_Files_FileId"
,
column
:
x
=>
x
.
FileId
,
principalTable
:
"Files"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
});
migrationBuilder
.
CreateIndex
(
name
:
"IX_Downloads_FileId"
,
table
:
"Downloads"
,
column
:
"FileId"
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"Downloads"
);
migrationBuilder
.
DropTable
(
name
:
"Files"
);
}
}
}
\ No newline at end of file
source/FileDesk.DataAccess/Migrations/FileDeskContextModelSnapshot.cs
0 → 100644
View file @
e0eeec0e
// <auto-generated />
using
System
;
using
FileDesk.DataAccess.Repository
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Metadata
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
namespace
FileDesk.DataAccess.Migrations
{
[
DbContext
(
typeof
(
FileDeskContext
))]
partial
class
FileDeskContextModelSnapshot
:
ModelSnapshot
{
protected
override
void
BuildModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"3.1.9"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
128
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
modelBuilder
.
Entity
(
"FileDesk.Domain.Models.Download"
,
b
=>
{
b
.
Property
<
long
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"bigint"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b
.
Property
<
DateTime
>(
"DateTime"
)
.
HasColumnType
(
"datetime2"
);
b
.
Property
<
long
>(
"FileId"
)
.
HasColumnType
(
"bigint"
);
b
.
Property
<
string
>(
"IpAddress"
)
.
IsRequired
()
.
HasColumnType
(
"nvarchar(max)"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"FileId"
);
b
.
ToTable
(
"Downloads"
);
});
modelBuilder
.
Entity
(
"FileDesk.Domain.Models.File"
,
b
=>
{
b
.
Property
<
long
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"bigint"
)
.
HasAnnotation
(
"SqlServer:ValueGenerationStrategy"
,
SqlServerValueGenerationStrategy
.
IdentityColumn
);
b
.
Property
<
byte
[
]>
(
"Content"
)
.
IsRequired
()
.
HasColumnType
(
"varbinary(max)"
);
b
.
Property
<
string
>(
"Description"
)
.
IsRequired
()
.
HasColumnType
(
"nvarchar(max)"
);
b
.
Property
<
int
>(
"Format"
)
.
HasColumnType
(
"int"
);
b
.
Property
<
string
>(
"Name"
)
.
IsRequired
()
.
HasColumnType
(
"nvarchar(max)"
);
b
.
Property
<
DateTime
>(
"UploadDateTime"
)
.
HasColumnType
(
"datetime2"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Files"
);
});
modelBuilder
.
Entity
(
"FileDesk.Domain.Models.Download"
,
b
=>
{
b
.
HasOne
(
"FileDesk.Domain.Models.File"
,
"File"
)
.
WithMany
(
"Downloads"
)
.
HasForeignKey
(
"FileId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
#pragma warning restore 612, 618
}
}
}
source/FileDesk.DataAccess/Repository/FileDeskContext.cs
0 → 100644
View file @
e0eeec0e
namespace
FileDesk.DataAccess.Repository
{
using
FileDesk.Domain.Models
;
using
Microsoft.EntityFrameworkCore
;
using
System.Linq
;
using
System.Reflection
;
/// <summary>
/// Класс для работы с БД
/// </summary>
public
class
FileDeskContext
:
DbContext
{
/// <summary>
/// Создает новый экземпляр класса <see cref="FileDeskContext"/>
/// </summary>
public
FileDeskContext
()
{
}
/// <summary>
/// Создает новый экземпляр класса <see cref="FileDeskContext"/>
/// </summary>
/// <param name="options">Опции</param>
public
FileDeskContext
(
DbContextOptions
options
)
:
base
(
options
)
{
}
/// <summary>
/// Файлы
/// </summary>
public
DbSet
<
File
>
Files
{
get
;
set
;
}
/// <summary>
/// Скачивания файлов
/// </summary>
public
DbSet
<
Download
>
Downloads
{
get
;
set
;
}
/// <summary>
/// Метод при создании БД
/// </summary>
/// <param name="modelBuilder"></param>
protected
override
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
{
var
entityTypes
=
modelBuilder
.
Model
.
GetEntityTypes
().
Select
(
t
=>
t
.
ClrType
).
ToList
();
foreach
(
var
entityType
in
entityTypes
)
{
var
method
=
entityType
.
GetMethod
(
"OnModelCreating"
,
System
.
Reflection
.
BindingFlags
.
Static
|
BindingFlags
.
NonPublic
);
method
?.
Invoke
(
null
,
new
object
[]
{
modelBuilder
});
}
}
}
}
\ No newline at end of file
source/FileDesk.Domain/Models/AbstractEntity.cs
View file @
e0eeec0e
namespace
FileDesk.Domain.Models
{
using
System.ComponentModel.DataAnnotations
;
using
System.ComponentModel.DataAnnotations.Schema
;
/// <summary>
...
...
source/FileDesk.Domain/Models/Download.cs
View file @
e0eeec0e
namespace
FileDesk.Domain.Models
{
using
System
;
using
System.ComponentModel.DataAnnotations
;
using
System.ComponentModel.DataAnnotations.Schema
;
/// <summary>
/// Скачивание файла
/// </summary>
public
class
Download
public
class
Download
:
AbstractEntity
{
/// <summary>
/// Идентификатор файла
/// </summary>
[
Required
]
public
long
FileId
{
get
;
set
;
}
/// <summary>
...
...
@@ -20,11 +23,13 @@
/// <summary>
/// Дата и время скачивания
/// </summary>
[
Required
]
public
DateTime
DateTime
{
get
;
set
;
}
/// <summary>
/// IP-адрес компьютера, на который был скачан файл
/// </summary>
[
Required
]
public
string
IpAddress
{
get
;
set
;
}
}
}
\ No newline at end of file
source/FileDesk.Domain/Models/File.cs
View file @
e0eeec0e
...
...
@@ -2,7 +2,9 @@
{
using
FileDesk.Domain.Enums
;
using
System
;
using
System.Reflection.Metadata
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.ComponentModel.DataAnnotations.Schema
;
/// <summary>
/// Файл
...
...
@@ -12,26 +14,44 @@
/// <summary>
/// Название
/// </summary>
[
Required
]
public
string
Name
{
get
;
set
;
}
/// <summary>
/// Описание
/// </summary>
[
Required
]
public
string
Description
{
get
;
set
;
}
/// <summary>
/// Дата и время добавления
/// </summary>
[
Required
]
public
DateTime
UploadDateTime
{
get
;
set
;
}
/// <summary>
/// С
ам
файл
/// С
одержимое
файл
а
/// </summary>
public
Blob
Blob
{
get
;
set
;
}
[
Required
]
public
byte
[]
Content
{
get
;
set
;
}
/// <summary>
/// Формат
/// </summary>
[
Required
]
public
FileFormat
Format
{
get
;
set
;
}
/// <summary>
/// Список скачиваний
/// </summary>
public
List
<
Download
>
Downloads
{
get
;
set
;
}
/// <summary>
/// Создает новый экземпляр класса <see cref="File"/>
/// </summary>
public
File
()
{
Downloads
=
new
List
<
Download
>();
}
}
}
\ No newline at end of file
source/FileDesk.Web/FileDesk.Web.csproj
View file @
e0eeec0e
...
...
@@ -4,4 +4,16 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FileDesk.DataAccess\FileDesk.DataAccess.csproj" />
</ItemGroup>
</Project>
source/FileDesk.Web/Startup.cs
View file @
e0eeec0e
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.HttpsPolicy
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Hosting
;
namespace
FileDesk.Web
{
using
FileDesk.DataAccess.Repository
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Hosting
;
public
class
Startup
{
public
Startup
(
IConfiguration
configuration
)
...
...
@@ -23,6 +20,7 @@ namespace FileDesk.Web
// This method gets called by the runtime. Use this method to add services to the container.
public
void
ConfigureServices
(
IServiceCollection
services
)
{
services
.
AddDbContext
<
FileDeskContext
>(
options
=>
options
.
UseSqlServer
(
Configuration
.
GetConnectionString
(
"DefaultConnection"
)));
services
.
AddControllersWithViews
();
}
...
...
source/FileDesk.Web/appsettings.json
View file @
e0eeec0e
{
"ConnectionStrings"
:
{
"DefaultConnection"
:
"Server=ANASTASIYA
\\
SQLEXPRESS;Database=FileDesk;Trusted_Connection=True;"
},
"Logging"
:
{
"LogLevel"
:
{
"Default"
:
"Information"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment