diff --git a/Library.Encyclopedia.API/Controllers/FilesController.cs b/Library.Encyclopedia.API/Controllers/FilesController.cs index 6eb1979..a98ffcb 100644 --- a/Library.Encyclopedia.API/Controllers/FilesController.cs +++ b/Library.Encyclopedia.API/Controllers/FilesController.cs @@ -2,11 +2,14 @@ using Library.Encyclopedia.DataAccess; using Library.Encyclopedia.DataAccess.DataAccess; using Library.Encyclopedia.Entity.Interfaces; +using Library.Encyclopedia.Entity.Models; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading.Tasks; namespace Library.Encyclopedia.API.Controllers @@ -16,11 +19,13 @@ namespace Library.Encyclopedia.API.Controllers public class FilesController : ControllerBase { private readonly ILogger _logger; + private readonly IFilesAdapter filesAdapter; private readonly IFilesDataAccess filesDataAccess; - public FilesController(ILogger logger, IApplicationDbContext dbContext) + public FilesController(ILogger logger, IApplicationDbContext dbContext, IFilesAdapter filesAdapter) { _logger = logger; + this.filesAdapter = filesAdapter; this.filesDataAccess = new FilesDataAccess(dbContext); } @@ -32,28 +37,70 @@ public FilesController(ILogger logger, IApplicationDbContext db /// /// /// - //[HttpPost("{id}")] - //[ApiKey] - //public async Task Get(Guid id, List files) - //{ - // try - // { - // ////var response = await filesDataAccess.AddFiles(id, files); - - // //if (response == null) - // //{ - // // return StatusCode(204); - // //} - // //else - // //{ - // // return Ok(response); - // //} - // } - // catch (Exception ex) - // { - // _logger.LogError(ex, $"an error has occured {ex.Message}"); - // throw; - // } - //} + [HttpPost("{id}")] + [ApiKey] + public async Task Post(Guid id, List files, [FromForm] Dictionary descriptions) + { + try + { + // Store files at remote location + var responses = filesAdapter.UploadFiles(id, files); + + List fileResponses = new List(); + + // filter out the failed uploads + for (int i = 0; i < responses.Count(); i++) + { + if (responses.ToList()[i]) + { + string fileNameWithoutExt = Path.GetFileNameWithoutExtension(files[i].FileName); + fileResponses.Add(new Files + { + Id = Guid.NewGuid(), + MainId = id, + FileName = files[i].FileName, + FilePath = $@"/encyclopedia-media/{id}/{files[i].FileName}", + FileType = files[i].ContentType, + FileDescription = descriptions.ContainsKey(fileNameWithoutExt) ? descriptions[fileNameWithoutExt] : null + }); + } + } + + // Save to database + await filesDataAccess.AddFiles(fileResponses); + + return Ok(fileResponses); + } + catch (Exception ex) + { + _logger.LogError(ex, $"an error has occured {ex.Message}"); + throw; + } + } + + /// + /// Upload Files + /// + /// + /// + /// + /// + /// + [HttpGet("{id}")] + [ApiKey] + public async Task Get(Guid id, string directory) + { + try + { + var files = await filesDataAccess.GetFiles(id); + var fileResponses = filesAdapter.DownloadFiles(files, directory); + return Ok(fileResponses); + } + catch (Exception ex) + { + _logger.LogError(ex, $"an error has occured {ex.Message}"); + throw; + } + } } } \ No newline at end of file diff --git a/Library.Encyclopedia.API/Startup.cs b/Library.Encyclopedia.API/Startup.cs index d0b4867..dff2820 100644 --- a/Library.Encyclopedia.API/Startup.cs +++ b/Library.Encyclopedia.API/Startup.cs @@ -1,4 +1,6 @@ using Library.Encyclopedia.DataAccess; +using Library.Encyclopedia.DataAccess.FileAccess; +using Library.Encyclopedia.Entity.Interfaces; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.SpaServices.AngularCli; @@ -27,7 +29,15 @@ public void ConfigureServices(IServiceCollection services) configuration.RootPath = "ClientApp/dist"; }); + string url = Configuration.GetValue("FTPSettings:url"); + string userName = Configuration.GetValue("FTPSettings:username"); + string password = Configuration.GetValue("FTPSettings:password"); + services.AddScoped(s => new ApplicationDbContext(Configuration.GetConnectionString("DefaultConnection"))); + services.AddScoped(s => + { + return new FTPAdapter(url, new System.Net.NetworkCredential(userName, password)); + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/Library.Encyclopedia.API/appsettings.json b/Library.Encyclopedia.API/appsettings.json index 0c4f199..8d02394 100644 --- a/Library.Encyclopedia.API/appsettings.json +++ b/Library.Encyclopedia.API/appsettings.json @@ -8,7 +8,12 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "DefaultConnection": "Server=localhost\\SQLEXPRESS01;Database=Encyclopedia;Trusted_Connection=True;" + "DefaultConnection": "Server=localhost;Database=Encyclopedia;User=root;Password=root" }, - "ApiKey": "5929b003-8895-4fb3-bbb0-2eb101c48f66" + "ApiKey": "5929b003-8895-4fb3-bbb0-2eb101c48f66", + "FTPSettings": { + "url": "10.161.100.82", + "username": "mazus01", + "password": "" + } } \ No newline at end of file diff --git a/Library.Encyclopedia.DataAccess/ApplicationDbContext.cs b/Library.Encyclopedia.DataAccess/ApplicationDbContext.cs index 41f6d96..574dc9d 100644 --- a/Library.Encyclopedia.DataAccess/ApplicationDbContext.cs +++ b/Library.Encyclopedia.DataAccess/ApplicationDbContext.cs @@ -1,5 +1,6 @@ using Library.Encyclopedia.Entity.Models; using Microsoft.EntityFrameworkCore; +using System; using System.Threading.Tasks; namespace Library.Encyclopedia.DataAccess @@ -14,7 +15,8 @@ public ApplicationDbContext(string connectionString) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer(connectionString); + var serverVersion = new MySqlServerVersion(new Version(8, 0, 18)); + optionsBuilder.UseMySql(connectionString, serverVersion); } public DbSet
Main { get; set; } diff --git a/Library.Encyclopedia.DataAccess/DataAccess/FilesDataAccess.cs b/Library.Encyclopedia.DataAccess/DataAccess/FilesDataAccess.cs index 5ac9236..c0edfb3 100644 --- a/Library.Encyclopedia.DataAccess/DataAccess/FilesDataAccess.cs +++ b/Library.Encyclopedia.DataAccess/DataAccess/FilesDataAccess.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading.Tasks; namespace Library.Encyclopedia.DataAccess.DataAccess @@ -17,9 +16,34 @@ public FilesDataAccess(IApplicationDbContext dbcontext) _dbcontext = dbcontext; } + public async Task> GetFiles(Guid id) + { + return await _dbcontext.Files.Where(s => s.MainId == id).ToListAsync(); + } + public async Task AddFiles(IEnumerable files) { - await _dbcontext.Files.AddRangeAsync(files); + var existingFiles = await _dbcontext.Files.Where(s => s.MainId == files.FirstOrDefault().MainId).ToListAsync(); + List newFiles = new List(); + List oldFiles = new List(); + + foreach (var file in files) + { + if (!existingFiles.Any(s => s.FileName == file.FileName)) + newFiles.Add(file); + else + { + var oldFile = existingFiles.FirstOrDefault(s => s.FileName == file.FileName); + oldFile.FileName = file.FileName; + oldFile.FileDescription = file.FileDescription; + oldFile.FilePath = file.FilePath; + oldFile.FileType = file.FileType; + oldFiles.Add(oldFile); + } + } + + await _dbcontext.Files.AddRangeAsync(newFiles); + _dbcontext.Files.UpdateRange(oldFiles); await _dbcontext.SaveChanges(); } diff --git a/Library.Encyclopedia.DataAccess/FileAccess/FTPAdapter.cs b/Library.Encyclopedia.DataAccess/FileAccess/FTPAdapter.cs new file mode 100644 index 0000000..1e1cae2 --- /dev/null +++ b/Library.Encyclopedia.DataAccess/FileAccess/FTPAdapter.cs @@ -0,0 +1,69 @@ +using Library.Encyclopedia.Entity.Interfaces; +using Library.Encyclopedia.Entity.Models; +using Microsoft.AspNetCore.Http; +using Renci.SshNet; +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Text; + +namespace Library.Encyclopedia.DataAccess.FileAccess +{ + public class FTPAdapter : IFilesAdapter + { + private readonly string url; + private readonly NetworkCredential networkCredential; + + public FTPAdapter(string url, NetworkCredential networkCredential) + { + this.url = url; + this.networkCredential = networkCredential; + } + + public IEnumerable DownloadFiles(IEnumerable files, string directory) + { + List responses = new List(); + var customUrl = $@"/home/{networkCredential.UserName}"; + + using (SftpClient client = new SftpClient(url, 22, networkCredential.UserName, networkCredential.Password)) + { + client.Connect(); + foreach (var file in files) + { + using (var stream = File.OpenWrite(Path.Combine(directory, file.FileName))) + { + client.DownloadFile(customUrl + file.FilePath, stream); + responses.Add(true); + } + } + } + + return responses; + } + + public IEnumerable UploadFiles(Guid id, List files) + { + List responses = new List(); + var customUrl = $@"/home/{networkCredential.UserName}/encyclopedia-media/{id}/"; + + using (SftpClient client = new SftpClient(url, 22, networkCredential.UserName, networkCredential.Password)) + { + client.Connect(); + if (!client.Exists(customUrl)) + client.CreateDirectory(customUrl); + + foreach (var file in files) + { + if (client.Exists(customUrl + file.FileName)) + client.DeleteFile(customUrl + file.FileName); + + client.UploadFile(file.OpenReadStream(), customUrl + file.FileName); + responses.Add(true); + } + } + + return responses; + } + } +} diff --git a/Library.Encyclopedia.DataAccess/Library.Encyclopedia.DataAccess.csproj b/Library.Encyclopedia.DataAccess/Library.Encyclopedia.DataAccess.csproj index 22ce5df..e53781f 100644 --- a/Library.Encyclopedia.DataAccess/Library.Encyclopedia.DataAccess.csproj +++ b/Library.Encyclopedia.DataAccess/Library.Encyclopedia.DataAccess.csproj @@ -5,6 +5,7 @@ + all @@ -15,6 +16,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.cs b/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.cs deleted file mode 100644 index eb10574..0000000 --- a/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace Library.Encyclopedia.DataAccess.Migrations -{ - public partial class Update_11302021 : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Main", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - Title = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: false), - Description = table.Column(type: "nvarchar(max)", nullable: true), - Category = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Main", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Files", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - MainId = table.Column(type: "uniqueidentifier", nullable: false), - FileName = table.Column(type: "nvarchar(max)", nullable: false), - FileType = table.Column(type: "nvarchar(max)", nullable: false), - FileDescription = table.Column(type: "nvarchar(max)", nullable: true), - FilePath = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Files", x => x.Id); - table.ForeignKey( - name: "FK_Files_Main_MainId", - column: x => x.MainId, - principalTable: "Main", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Links", - columns: table => new - { - Id = table.Column(type: "uniqueidentifier", nullable: false), - MainId = table.Column(type: "uniqueidentifier", nullable: false), - Link = table.Column(type: "nvarchar(max)", nullable: false), - Description = table.Column(type: "nvarchar(max)", nullable: true), - IsInternal = table.Column(type: "bit", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Links", x => x.Id); - table.ForeignKey( - name: "FK_Links_Main_MainId", - column: x => x.MainId, - principalTable: "Main", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Files_MainId", - table: "Files", - column: "MainId"); - - migrationBuilder.CreateIndex( - name: "IX_Links_MainId", - table: "Links", - column: "MainId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Files"); - - migrationBuilder.DropTable( - name: "Links"); - - migrationBuilder.DropTable( - name: "Main"); - } - } -} diff --git a/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.Designer.cs b/Library.Encyclopedia.DataAccess/Migrations/20211207163235_InitialCreate.Designer.cs similarity index 74% rename from Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.Designer.cs rename to Library.Encyclopedia.DataAccess/Migrations/20211207163235_InitialCreate.Designer.cs index 51d3f77..340d59f 100644 --- a/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.Designer.cs +++ b/Library.Encyclopedia.DataAccess/Migrations/20211207163235_InitialCreate.Designer.cs @@ -3,47 +3,45 @@ using Library.Encyclopedia.DataAccess; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Library.Encyclopedia.DataAccess.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20211130183310_Update_11302021")] - partial class Update_11302021 + [Migration("20211207163235_InitialCreate")] + partial class InitialCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("ProductVersion", "5.0.12") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.12"); modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Files", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.Property("FileDescription") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("FileName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("FilePath") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("FileType") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("MainId") - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -56,20 +54,20 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("IsInternal") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("Link") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("MainId") - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -82,19 +80,19 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.Property("Category") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("varchar(256)"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("Title") .IsRequired() .HasMaxLength(1024) - .HasColumnType("nvarchar(1024)"); + .HasColumnType("varchar(1024)"); b.HasKey("Id"); diff --git a/Library.Encyclopedia.DataAccess/Migrations/20211207163235_InitialCreate.cs b/Library.Encyclopedia.DataAccess/Migrations/20211207163235_InitialCreate.cs new file mode 100644 index 0000000..e2f9051 --- /dev/null +++ b/Library.Encyclopedia.DataAccess/Migrations/20211207163235_InitialCreate.cs @@ -0,0 +1,105 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Library.Encyclopedia.DataAccess.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Main", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Title = table.Column(type: "varchar(1024)", maxLength: 1024, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Category = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Main", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Files", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + MainId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + FileName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + FileType = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + FileDescription = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + FilePath = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Files", x => x.Id); + table.ForeignKey( + name: "FK_Files_Main_MainId", + column: x => x.MainId, + principalTable: "Main", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Links", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + MainId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Link = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + IsInternal = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Links", x => x.Id); + table.ForeignKey( + name: "FK_Links_Main_MainId", + column: x => x.MainId, + principalTable: "Main", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_Files_MainId", + table: "Files", + column: "MainId"); + + migrationBuilder.CreateIndex( + name: "IX_Links_MainId", + table: "Links", + column: "MainId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Files"); + + migrationBuilder.DropTable( + name: "Links"); + + migrationBuilder.DropTable( + name: "Main"); + } + } +} diff --git a/Library.Encyclopedia.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs b/Library.Encyclopedia.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs index 236dc44..a59c19f 100644 --- a/Library.Encyclopedia.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Library.Encyclopedia.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs @@ -3,7 +3,6 @@ using Library.Encyclopedia.DataAccess; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace Library.Encyclopedia.DataAccess.Migrations @@ -15,33 +14,32 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("ProductVersion", "5.0.12") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.12"); modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Files", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.Property("FileDescription") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("FileName") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("FilePath") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("FileType") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("MainId") - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -54,20 +52,20 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("IsInternal") - .HasColumnType("bit"); + .HasColumnType("tinyint(1)"); b.Property("Link") .IsRequired() - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("MainId") - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.HasKey("Id"); @@ -80,19 +78,19 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); + .HasColumnType("char(36)"); b.Property("Category") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("varchar(256)"); b.Property("Description") - .HasColumnType("nvarchar(max)"); + .HasColumnType("longtext"); b.Property("Title") .IsRequired() .HasMaxLength(1024) - .HasColumnType("nvarchar(1024)"); + .HasColumnType("varchar(1024)"); b.HasKey("Id"); diff --git a/Library.Encyclopedia.Entity/Interfaces/IFilesAdapter.cs b/Library.Encyclopedia.Entity/Interfaces/IFilesAdapter.cs new file mode 100644 index 0000000..95bfb79 --- /dev/null +++ b/Library.Encyclopedia.Entity/Interfaces/IFilesAdapter.cs @@ -0,0 +1,13 @@ +using Library.Encyclopedia.Entity.Models; +using Microsoft.AspNetCore.Http; +using System; +using System.Collections.Generic; + +namespace Library.Encyclopedia.Entity.Interfaces +{ + public interface IFilesAdapter + { + IEnumerable UploadFiles(Guid id, List files); + IEnumerable DownloadFiles(IEnumerable files, string directory); + } +} \ No newline at end of file diff --git a/Library.Encyclopedia.Entity/Interfaces/IFilesDataAccess.cs b/Library.Encyclopedia.Entity/Interfaces/IFilesDataAccess.cs index 061d2af..5b10c40 100644 --- a/Library.Encyclopedia.Entity/Interfaces/IFilesDataAccess.cs +++ b/Library.Encyclopedia.Entity/Interfaces/IFilesDataAccess.cs @@ -8,6 +8,7 @@ namespace Library.Encyclopedia.Entity.Interfaces { public interface IFilesDataAccess { + Task> GetFiles(Guid id); Task AddFiles(IEnumerable files); Task RemoveFiles(IEnumerable ids); } diff --git a/Library.Encyclopedia.Entity/Library.Encyclopedia.Entity.csproj b/Library.Encyclopedia.Entity/Library.Encyclopedia.Entity.csproj index 71cd50d..f6f8e6a 100644 --- a/Library.Encyclopedia.Entity/Library.Encyclopedia.Entity.csproj +++ b/Library.Encyclopedia.Entity/Library.Encyclopedia.Entity.csproj @@ -6,6 +6,7 @@ +