diff --git a/.gitignore b/.gitignore
index 3c4efe2..a476fbf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -258,4 +258,7 @@ paket-files/
# Python Tools for Visual Studio (PTVS)
__pycache__/
-*.pyc
\ No newline at end of file
+*.pyc
+
+# App_Data
+*/*/App_Data/*
\ No newline at end of file
diff --git a/API/API.Client.Test/App.config b/API/API.Client.Test/App.config
index 51bf85b..bf54cdd 100644
--- a/API/API.Client.Test/App.config
+++ b/API/API.Client.Test/App.config
@@ -1,8 +1,8 @@
-
-
+
+
\ No newline at end of file
diff --git a/API/API/API.csproj b/API/API/API.csproj
index 692b34b..ceb5fe8 100644
--- a/API/API/API.csproj
+++ b/API/API/API.csproj
@@ -94,6 +94,9 @@
True
True
+
+ ..\packages\Microsoft.AspNet.Cors.5.2.7\lib\net45\System.Web.Cors.dll
+
@@ -102,6 +105,9 @@
..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll
+
+ ..\packages\Microsoft.AspNet.WebApi.Cors.5.2.7\lib\net45\System.Web.Http.Cors.dll
+
..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.7\lib\net45\System.Web.Http.WebHost.dll
@@ -128,6 +134,7 @@
+
@@ -147,6 +154,7 @@
+
@@ -170,7 +178,7 @@
-
+
@@ -183,6 +191,9 @@
201903172028249_Log.cs
+
+
+
10.0
$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
diff --git a/API/API/App_Start/DependencyInjectionConfig.cs b/API/API/App_Start/DependencyInjectionConfig.cs
index 58fbdfd..cea1932 100644
--- a/API/API/App_Start/DependencyInjectionConfig.cs
+++ b/API/API/App_Start/DependencyInjectionConfig.cs
@@ -1,4 +1,5 @@
-using API.Database;
+using API.Controllers;
+using API.Database;
using API.Services;
using Autofac;
using Autofac.Integration.WebApi;
@@ -25,10 +26,13 @@ namespace API.App_Start {
private static void RegisterControllers(this ContainerBuilder builder) {
builder.RegisterType().InstancePerRequest();
+ builder.RegisterType().InstancePerRequest();
}
private static void RegisterServices(this ContainerBuilder builder) {
builder.RegisterType();
+
+ builder.RegisterType().As().SingleInstance();
}
private static void RegisterDataProvider(this ContainerBuilder builder) {
diff --git a/API/API/App_Start/WebApiConfig.cs b/API/API/App_Start/WebApiConfig.cs
index bcc57a9..dad0cb3 100644
--- a/API/API/App_Start/WebApiConfig.cs
+++ b/API/API/App_Start/WebApiConfig.cs
@@ -4,10 +4,17 @@ using Microsoft.AspNet.OData.Builder;
using Microsoft.AspNet.OData.Extensions;
using System.Net.Http.Headers;
using System.Web.Http;
+using System.Web.Http.Cors;
namespace API {
public static class WebApiConfig {
public static void Register(HttpConfiguration config) {
+
+ // CORS
+ var cors = new EnableCorsAttribute("http://localhost:4200", "*", "*");
+ cors.SupportsCredentials = true;
+ config.EnableCors(cors);
+
// Web API configuration and services
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
diff --git a/API/API/Controllers/FilesController.cs b/API/API/Controllers/FilesController.cs
new file mode 100644
index 0000000..0ac7387
--- /dev/null
+++ b/API/API/Controllers/FilesController.cs
@@ -0,0 +1,66 @@
+using API.Database;
+using API.Services;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Web;
+using System.Web.Http;
+
+namespace API.Controllers {
+ public class FilesController : ApiController {
+ private readonly DataContext dataContext;
+ private readonly IFileService fileService;
+
+ public FilesController(
+ DataContext dataContext,
+ IFileService fileService
+ ) {
+ this.dataContext = dataContext;
+ this.fileService = fileService;
+ }
+
+ // GET: api/Files/5
+ [Route("api/songs/{songId}/files/{fileId}")]
+ public string Get(int id) {
+ return "value";
+ }
+
+ // POST: api/Files
+ [Route("api/songs/{songId}/files")]
+ public async Task Post(long songId, CancellationToken c) {
+ // get file from network input
+ var files = HttpContext.Current.Request.Files;
+ if (files.Count != 1) return BadRequest();
+ var file = HttpContext.Current.Request.Files[0];
+
+ // find song in database
+ var song = dataContext.Songs.Find(songId);
+ if (song == null) return NotFound();
+
+ // save file in App_Data
+ var path = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data");
+ var filename = await fileService.Save(file, path, c);
+
+ // attach file reference to song
+ song.Files.Add(new Models.File {
+ Name = file.FileName,
+ ReferenceFile = filename
+ });
+ await dataContext.SaveChangesAsync(c);
+
+ return Ok();
+ }
+
+
+
+
+
+
+ //// PUT: api/Files/5
+ //public void Put(int id, [FromBody]string value) {
+ //}
+
+ //// DELETE: api/Files/5
+ //public void Delete(int id) {
+ //}
+ }
+}
diff --git a/API/API/Database/DataContext.cs b/API/API/Database/DataContext.cs
index 6b961cf..9dad195 100644
--- a/API/API/Database/DataContext.cs
+++ b/API/API/Database/DataContext.cs
@@ -1,5 +1,5 @@
-using API.Models;
-using API.Migrations;
+using API.Migrations;
+using API.Models;
using System.Data.Entity;
namespace API.Database {
diff --git a/API/API/Properties/PublishProfiles/CustomProfile.pubxml b/API/API/Properties/PublishProfiles/deploy to test.pubxml
similarity index 100%
rename from API/API/Properties/PublishProfiles/CustomProfile.pubxml
rename to API/API/Properties/PublishProfiles/deploy to test.pubxml
diff --git a/API/API/Services/FileService.cs b/API/API/Services/FileService.cs
new file mode 100644
index 0000000..24415bd
--- /dev/null
+++ b/API/API/Services/FileService.cs
@@ -0,0 +1,26 @@
+using System;
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Web;
+
+namespace API.Services {
+ public interface IFileService {
+ Task Save(HttpPostedFile file, string path, CancellationToken c);
+ }
+
+ public class FileService : IFileService {
+ private const int bufferSize = 4096;
+
+ public async Task Save(HttpPostedFile file, string path, CancellationToken c) {
+ var filename = Guid.NewGuid();
+ var fullPath = Path.Combine(path, filename.ToString());
+ using (var fs = new FileStream(fullPath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize, true)) {
+ await file.InputStream.CopyToAsync(fs, bufferSize, c);
+ }
+
+ return filename;
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/API/API/Web.config b/API/API/Web.config
index 0b9b72e..a569aec 100644
--- a/API/API/Web.config
+++ b/API/API/Web.config
@@ -1,4 +1,4 @@
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
-
+
+
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
\ No newline at end of file
+
diff --git a/API/API/packages.config b/API/API/packages.config
index cd44b51..2506503 100644
--- a/API/API/packages.config
+++ b/API/API/packages.config
@@ -4,10 +4,12 @@
+
+
diff --git a/API/Models/Song.cs b/API/Models/Song.cs
index d00b50d..c0b84d8 100644
--- a/API/Models/Song.cs
+++ b/API/Models/Song.cs
@@ -16,5 +16,7 @@ namespace API.Models {
public bool Final { get; set; }
public virtual ICollection Changes { get; set; }
+
+ public virtual ICollection Files { get; set; }
}
}
\ No newline at end of file