File uploading & email sending
This commit is contained in:
parent
18fe6822d4
commit
8155446527
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
|
@ -21,6 +21,8 @@ using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
|
using RestSharp;
|
||||||
|
using RestSharp.Authenticators;
|
||||||
|
|
||||||
namespace FIT5032_Assignment.Controllers {
|
namespace FIT5032_Assignment.Controllers {
|
||||||
|
|
||||||
|
@ -301,7 +303,7 @@ namespace FIT5032_Assignment.Controllers {
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult ImageUpload(Models.ImageUploadForm model) {
|
public async Task<ActionResult> ImageUpload(Models.ImageUploadForm model) {
|
||||||
try {
|
try {
|
||||||
if (Request.Cookies["psg_auth_token"] == null) {
|
if (Request.Cookies["psg_auth_token"] == null) {
|
||||||
// Return 401 error
|
// Return 401 error
|
||||||
|
@ -354,6 +356,50 @@ namespace FIT5032_Assignment.Controllers {
|
||||||
return View(model);
|
return View(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store file to server
|
||||||
|
var fileId = Guid.NewGuid().ToString();
|
||||||
|
var fileName = fileId + Path.GetExtension(model.imageFile.FileName);
|
||||||
|
var filePath = Path.Combine(Server.MapPath("~/App_Data/upload_images"), fileName);
|
||||||
|
model.imageFile.SaveAs(filePath);
|
||||||
|
|
||||||
|
// Create image entity to database
|
||||||
|
var appointmentId = Guid.NewGuid().ToString();
|
||||||
|
var imageId = Guid.NewGuid().ToString();
|
||||||
|
var appointment = new Appointments {
|
||||||
|
uuid = appointmentId,
|
||||||
|
patient = patientUuid,
|
||||||
|
responsibleBy = user.uuid,
|
||||||
|
createdAt = DateTime.Now,
|
||||||
|
appointmentDate = DateTime.Now,
|
||||||
|
status = 0,
|
||||||
|
createdBy = 1
|
||||||
|
};
|
||||||
|
var image = new Images {
|
||||||
|
uuid = imageId,
|
||||||
|
appointment = appointmentId,
|
||||||
|
patient = patientUuid,
|
||||||
|
responsibleBy = user.uuid,
|
||||||
|
createdAt = DateTime.Now,
|
||||||
|
file = fileName,
|
||||||
|
status = 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send attached email with mailgun
|
||||||
|
var doctorName = user.displayName;
|
||||||
|
RestClient client = new RestClient(new RestClientOptions ("https://api.mailgun.net/v3/test.astrian.moe") {
|
||||||
|
Authenticator = new HttpBasicAuthenticator("api", "365900a7818241eafcbbf82e59cf99e8-5465e583-b4966e64"),
|
||||||
|
});
|
||||||
|
var request = new RestRequest("messages", Method.Post);
|
||||||
|
request.AddParameter("from", "Xpectrum <xpectrum@test.astrian.moe>");
|
||||||
|
request.AddParameter("to", model.patientEmail);
|
||||||
|
request.AddParameter("subject", "Xpectrum: New image available");
|
||||||
|
request.AddParameter("text", $"Hi {patient.First().displayName},\n\nDr. {doctorName} has uploaded a new image for you.\n\nPlease check the attachment.\n\nBest regards,\nXpectrum");
|
||||||
|
// request.AddFile("attachment", filePath);
|
||||||
|
|
||||||
|
// Send request
|
||||||
|
var response = await client.ExecuteAsync(request);
|
||||||
|
Trace.WriteLine(response.Content);
|
||||||
|
|
||||||
return View();
|
return View();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Trace.WriteLine(e);
|
Trace.WriteLine(e);
|
||||||
|
|
|
@ -61,8 +61,8 @@
|
||||||
<Reference Include="JWT, Version=10.0.0.0, Culture=neutral, PublicKeyToken=6f98bca0f40f2ecf, processorArchitecture=MSIL">
|
<Reference Include="JWT, Version=10.0.0.0, Culture=neutral, PublicKeyToken=6f98bca0f40f2ecf, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\JWT.10.1.0\lib\net462\JWT.dll</HintPath>
|
<HintPath>..\packages\JWT.10.1.0\lib\net462\JWT.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="Microsoft.IdentityModel.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.IdentityModel.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
@ -80,6 +80,9 @@
|
||||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="RestSharp, Version=110.2.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\RestSharp.110.2.0\lib\net471\RestSharp.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||||
|
@ -101,11 +104,11 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Runtime.Serialization" />
|
<Reference Include="System.Runtime.Serialization" />
|
||||||
<Reference Include="System.Security" />
|
<Reference Include="System.Security" />
|
||||||
<Reference Include="System.Text.Encodings.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Text.Encodings.Web, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.Text.Encodings.Web.6.0.0\lib\net461\System.Text.Encodings.Web.dll</HintPath>
|
<HintPath>..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Text.Json, Version=6.0.0.7, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Text.Json, Version=7.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.Text.Json.6.0.7\lib\net461\System.Text.Json.dll</HintPath>
|
<HintPath>..\packages\System.Text.Json.7.0.2\lib\net462\System.Text.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||||
|
|
|
@ -62,11 +62,11 @@
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.7" newVersion="6.0.0.7" />
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.2" newVersion="7.0.0.2" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
|
||||||
</dependentAssembly>
|
</dependentAssembly>
|
||||||
</assemblyBinding>
|
</assemblyBinding>
|
||||||
</runtime>
|
</runtime>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<package id="Microsoft.AspNet.Razor" version="3.2.9" targetFramework="net48" />
|
<package id="Microsoft.AspNet.Razor" version="3.2.9" targetFramework="net48" />
|
||||||
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net48" />
|
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net48" />
|
||||||
<package id="Microsoft.AspNet.WebPages" version="3.2.9" targetFramework="net48" />
|
<package id="Microsoft.AspNet.WebPages" version="3.2.9" targetFramework="net48" />
|
||||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="6.0.0" targetFramework="net48" />
|
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net48" />
|
||||||
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net48" />
|
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net48" />
|
||||||
<package id="Microsoft.IdentityModel.Abstractions" version="7.0.0" targetFramework="net48" />
|
<package id="Microsoft.IdentityModel.Abstractions" version="7.0.0" targetFramework="net48" />
|
||||||
<package id="Microsoft.IdentityModel.JsonWebTokens" version="7.0.0" targetFramework="net48" />
|
<package id="Microsoft.IdentityModel.JsonWebTokens" version="7.0.0" targetFramework="net48" />
|
||||||
|
@ -22,13 +22,14 @@
|
||||||
<package id="Microsoft.Web.Infrastructure" version="2.0.1" targetFramework="net48" />
|
<package id="Microsoft.Web.Infrastructure" version="2.0.1" targetFramework="net48" />
|
||||||
<package id="Modernizr" version="2.8.3" targetFramework="net48" />
|
<package id="Modernizr" version="2.8.3" targetFramework="net48" />
|
||||||
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="net48" />
|
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="net48" />
|
||||||
|
<package id="RestSharp" version="110.2.0" targetFramework="net48" />
|
||||||
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
|
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
|
||||||
<package id="System.IdentityModel.Tokens.Jwt" version="7.0.0" targetFramework="net48" />
|
<package id="System.IdentityModel.Tokens.Jwt" version="7.0.0" targetFramework="net48" />
|
||||||
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
|
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
|
||||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
|
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
|
||||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
|
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
|
||||||
<package id="System.Text.Encodings.Web" version="6.0.0" targetFramework="net48" />
|
<package id="System.Text.Encodings.Web" version="7.0.0" targetFramework="net48" />
|
||||||
<package id="System.Text.Json" version="6.0.7" targetFramework="net48" />
|
<package id="System.Text.Json" version="7.0.2" targetFramework="net48" />
|
||||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
|
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
|
||||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
|
||||||
<package id="WebGrease" version="1.6.0" targetFramework="net48" />
|
<package id="WebGrease" version="1.6.0" targetFramework="net48" />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user