aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ApartmentManager/ApartmentManager/ApartmentManager.csproj4
-rw-r--r--ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs48
-rw-r--r--ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs5
3 files changed, 53 insertions, 4 deletions
diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj
index 89dcb5e..0bf5485 100644
--- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj
+++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj
@@ -104,6 +104,7 @@
<Compile Include="Handler\LoginHandler.cs" />
<Compile Include="Handler\ResidentsHandler.cs" />
<Compile Include="Model\Apartment.cs" />
+ <Compile Include="Persistency\ImgurPhotoUploader.cs" />
<Compile Include="Singletons\ApartmentsCatalogSingleton.cs" />
<Compile Include="Model\Defect.cs" />
<Compile Include="Model\NavMenuItem.cs" />
@@ -220,6 +221,9 @@
</Page>
</ItemGroup>
<ItemGroup>
+ <PackageReference Include="Imgur.API">
+ <Version>4.0.1</Version>
+ </PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.Client">
<Version>5.2.3</Version>
</PackageReference>
diff --git a/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs b/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs
new file mode 100644
index 0000000..7e9ebf2
--- /dev/null
+++ b/ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs
@@ -0,0 +1,48 @@
+using Imgur.API.Authentication.Impl;
+using Imgur.API.Endpoints.Impl;
+using Imgur.API.Models;
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using Windows.Storage;
+using Windows.Storage.Pickers;
+
+namespace ApartmentManager.Persistency
+{
+ public static class ImgurPhotoUploader
+ {
+ /// <summary>
+ /// Opens file picker, uploads chosen image and returns link to it.
+ /// </summary>
+ public async static Task<string> UploadPhotoAsync()
+ {
+ //Create new file picker
+ FileOpenPicker fp = new FileOpenPicker()
+ {
+ SuggestedStartLocation = PickerLocationId.PicturesLibrary,
+ ViewMode = PickerViewMode.Thumbnail,
+ CommitButtonText = "Upload"
+ };
+ fp.FileTypeFilter.Add(".jpg");
+ fp.FileTypeFilter.Add(".jpeg");
+ fp.FileTypeFilter.Add(".png");
+ fp.FileTypeFilter.Add(".gif");
+ fp.FileTypeFilter.Add(".apng");
+ fp.FileTypeFilter.Add(".tiff");
+ fp.FileTypeFilter.Add(".tif");
+ fp.FileTypeFilter.Add(".bmp");
+ fp.FileTypeFilter.Add(".pdf");
+ fp.FileTypeFilter.Add(".xcf");
+ fp.FileTypeFilter.Add(".webp");
+
+ //Get image file with picker
+ StorageFile file = await fp.PickSingleFileAsync();
+
+ //Upload to Imgur and return link
+ var client = new ImgurClient("7b05a61ed8df74f", "ade6f79163e19f92f852bc553bbe399d7d4218fe");
+ var endpoint = new ImageEndpoint(client);
+ IImage image = await endpoint.UploadImageStreamAsync(await file.OpenStreamForReadAsync());
+ return image.Link;
+ }
+ }
+} \ No newline at end of file
diff --git a/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs
index 9f1d7f7..0290053 100644
--- a/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs
+++ b/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs
@@ -1,11 +1,8 @@
-using ApartmentManager.Annotations;
-using ApartmentManager.Common;
+using ApartmentManager.Common;
using ApartmentManager.Handler;
using ApartmentManager.Model;
using ApartmentManager.View;
using System;
-using System.ComponentModel;
-using System.Runtime.CompilerServices;
using System.Windows.Input;
using Windows.UI.Popups;
using Windows.UI.Xaml;