diff --git a/FIT5032-Assignment/App_Data/upload_images/5a6a3b14-129b-4c7a-b47f-700089530d4c.jpg b/FIT5032-Assignment/App_Data/upload_images/5a6a3b14-129b-4c7a-b47f-700089530d4c.jpg new file mode 100644 index 0000000..ffc20e4 Binary files /dev/null and b/FIT5032-Assignment/App_Data/upload_images/5a6a3b14-129b-4c7a-b47f-700089530d4c.jpg differ diff --git a/FIT5032-Assignment/App_Data/upload_images/681746da-ed7c-456a-8410-635c434c61eb.jpg b/FIT5032-Assignment/App_Data/upload_images/681746da-ed7c-456a-8410-635c434c61eb.jpg new file mode 100644 index 0000000..ffc20e4 Binary files /dev/null and b/FIT5032-Assignment/App_Data/upload_images/681746da-ed7c-456a-8410-635c434c61eb.jpg differ diff --git a/FIT5032-Assignment/App_Data/upload_images/786352fc-1903-451c-93ec-8b57419176bc.jpg b/FIT5032-Assignment/App_Data/upload_images/786352fc-1903-451c-93ec-8b57419176bc.jpg new file mode 100644 index 0000000..ffc20e4 Binary files /dev/null and b/FIT5032-Assignment/App_Data/upload_images/786352fc-1903-451c-93ec-8b57419176bc.jpg differ diff --git a/FIT5032-Assignment/App_Data/upload_images/9b70f4cf-9a58-42fd-a3ec-15cd01c1a58a.jpg b/FIT5032-Assignment/App_Data/upload_images/9b70f4cf-9a58-42fd-a3ec-15cd01c1a58a.jpg new file mode 100644 index 0000000..ffc20e4 Binary files /dev/null and b/FIT5032-Assignment/App_Data/upload_images/9b70f4cf-9a58-42fd-a3ec-15cd01c1a58a.jpg differ diff --git a/FIT5032-Assignment/App_Data/upload_images/e6880e20-4342-4d6e-9ec5-45f645638f49.jpg b/FIT5032-Assignment/App_Data/upload_images/e6880e20-4342-4d6e-9ec5-45f645638f49.jpg new file mode 100644 index 0000000..ffc20e4 Binary files /dev/null and b/FIT5032-Assignment/App_Data/upload_images/e6880e20-4342-4d6e-9ec5-45f645638f49.jpg differ diff --git a/FIT5032-Assignment/App_Data/upload_images/e836b97c-2a31-4ab4-93cc-aff336d92831.jpg b/FIT5032-Assignment/App_Data/upload_images/e836b97c-2a31-4ab4-93cc-aff336d92831.jpg new file mode 100644 index 0000000..ffc20e4 Binary files /dev/null and b/FIT5032-Assignment/App_Data/upload_images/e836b97c-2a31-4ab4-93cc-aff336d92831.jpg differ diff --git a/FIT5032-Assignment/Controllers/HomeController.cs b/FIT5032-Assignment/Controllers/HomeController.cs index 5cddd30..1959c03 100644 --- a/FIT5032-Assignment/Controllers/HomeController.cs +++ b/FIT5032-Assignment/Controllers/HomeController.cs @@ -21,6 +21,8 @@ using System.Threading.Tasks; using Newtonsoft.Json; using System.Net.Http.Headers; using System.Dynamic; +using RestSharp; +using RestSharp.Authenticators; namespace FIT5032_Assignment.Controllers { @@ -301,7 +303,7 @@ namespace FIT5032_Assignment.Controllers { } [HttpPost] - public ActionResult ImageUpload(Models.ImageUploadForm model) { + public async Task ImageUpload(Models.ImageUploadForm model) { try { if (Request.Cookies["psg_auth_token"] == null) { // Return 401 error @@ -353,7 +355,51 @@ namespace FIT5032_Assignment.Controllers { ModelState.AddModelError("patientEmail", "No patient found"); 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 "); + 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(); } catch (Exception e) { Trace.WriteLine(e); diff --git a/FIT5032-Assignment/FIT5032-Assignment.csproj b/FIT5032-Assignment/FIT5032-Assignment.csproj index f10d1c9..4b3897b 100644 --- a/FIT5032-Assignment/FIT5032-Assignment.csproj +++ b/FIT5032-Assignment/FIT5032-Assignment.csproj @@ -61,8 +61,8 @@ ..\packages\JWT.10.1.0\lib\net462\JWT.dll - - ..\packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll @@ -80,6 +80,9 @@ ..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\RestSharp.110.2.0\lib\net471\RestSharp.dll + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll @@ -101,11 +104,11 @@ - - ..\packages\System.Text.Encodings.Web.6.0.0\lib\net461\System.Text.Encodings.Web.dll + + ..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll - - ..\packages\System.Text.Json.6.0.7\lib\net461\System.Text.Json.dll + + ..\packages\System.Text.Json.7.0.2\lib\net462\System.Text.Json.dll ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll diff --git a/FIT5032-Assignment/Web.config b/FIT5032-Assignment/Web.config index 6bf3907..38b605f 100644 --- a/FIT5032-Assignment/Web.config +++ b/FIT5032-Assignment/Web.config @@ -62,11 +62,11 @@ - + - + diff --git a/FIT5032-Assignment/packages.config b/FIT5032-Assignment/packages.config index b586359..6029dad 100644 --- a/FIT5032-Assignment/packages.config +++ b/FIT5032-Assignment/packages.config @@ -12,7 +12,7 @@ - + @@ -22,13 +22,14 @@ + - - + +