aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcinzelent <marcin@zelent.net>2017-05-23 17:27:26 +0200
committermarcinzelent <marcin@zelent.net>2017-05-23 17:27:26 +0200
commit4fb953b9df93be797201349d70cfb7a25ee0194f (patch)
tree7f0e4da963598087625a1ab26f5862d9df2b3b41
parent4bc22e5f3de02e4678c223333580578808977f8a (diff)
Reverted to using Imgur for storing images.
-rw-r--r--ApartmentManager/ApartmentManager/ApartmentManager.csproj2
-rw-r--r--ApartmentManager/ApartmentManager/Common/ByteArrayToImageConverter.cs45
-rw-r--r--ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs29
-rw-r--r--ApartmentManager/ApartmentManager/Model/Apartment.cs2
-rw-r--r--ApartmentManager/ApartmentManager/Model/Resident.cs2
-rw-r--r--ApartmentManager/ApartmentManager/Model/User.cs2
-rw-r--r--ApartmentManager/ApartmentManager/Persistency/ImgurPhotoUploader.cs48
-rw-r--r--ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml6
-rw-r--r--ApartmentManager/HousingWebApi/DataModel.cs24
-rw-r--r--ApartmentManager/HousingWebApi/HousingWebApi.csproj23
-rw-r--r--ApartmentManager/HousingWebApi/Models/Apartment.cs3
-rw-r--r--ApartmentManager/HousingWebApi/Models/ChangeDocument.cs3
-rw-r--r--ApartmentManager/HousingWebApi/Models/DefectPicture.cs3
-rw-r--r--ApartmentManager/HousingWebApi/Models/PastUser.cs3
-rw-r--r--ApartmentManager/HousingWebApi/Models/Resident.cs3
-rw-r--r--ApartmentManager/HousingWebApi/Models/User.cs3
16 files changed, 102 insertions, 99 deletions
diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj
index e628635..f267a50 100644
--- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj
+++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj
@@ -98,7 +98,6 @@
<Compile Include="AppShell.xaml.cs">
<DependentUpon>AppShell.xaml</DependentUpon>
</Compile>
- <Compile Include="Common\ByteArrayToImageConverter.cs" />
<Compile Include="Common\RelayCommand.cs" />
<Compile Include="Controls\NavMenuListView.cs" />
<Compile Include="Handler\BoardMemberHandler.cs" />
@@ -106,6 +105,7 @@
<Compile Include="Handler\LoginHandler.cs" />
<Compile Include="Handler\ApartmentHandler.cs" />
<Compile Include="Model\Apartment.cs" />
+ <Compile Include="Persistency\ImgurPhotoUploader.cs" />
<Compile Include="Singletons\BoardMemberCatalogSingleton.cs" />
<Compile Include="Model\Defect.cs" />
<Compile Include="Model\NavMenuItem.cs" />
diff --git a/ApartmentManager/ApartmentManager/Common/ByteArrayToImageConverter.cs b/ApartmentManager/ApartmentManager/Common/ByteArrayToImageConverter.cs
deleted file mode 100644
index 64526a1..0000000
--- a/ApartmentManager/ApartmentManager/Common/ByteArrayToImageConverter.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Windows.Storage;
-using Windows.Storage.Streams;
-using Windows.UI.Xaml.Data;
-using Windows.UI.Xaml.Media.Imaging;
-
-namespace ApartmentManager.Common
-{
- class ByteArrayToImageConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, string language)
- {
- if (value != null)
- {
- BitmapImage image = new BitmapImage();
- using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
- {
- stream.AsStreamForWrite().Write((byte[])value, 0, ((byte[])value).Length);
- image.SetSource(stream);
- }
- return image;
- }
- else return null;
- }
-
- public object ConvertBack(object value, Type targetType, object parameter, string language)
- {
- throw new NotImplementedException();
- }
-
- public async Task<object> ConvertToByte(object value, Type targetType, object parameter, string language)
- {
- IRandomAccessStream random = await RandomAccessStreamReference.CreateFromFile((StorageFile)value).OpenReadAsync();
- Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);
- Windows.Graphics.Imaging.PixelDataProvider pixelData = await decoder.GetPixelDataAsync();
- byte[] bytes = pixelData.DetachPixelData();
- return bytes;
- }
- }
-}
diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs
index 79b1682..c5dd6f0 100644
--- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs
+++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs
@@ -144,41 +144,14 @@ namespace ApartmentManager.Handler
{
try
{
- //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();
-
- ByteArrayToImageConverter converter = new ByteArrayToImageConverter();
- ApartmentViewModel.NewResident.Picture = (byte[]) await converter.ConvertToByte(file, typeof(System.Byte), null, "");
-
+ ApartmentViewModel.NewResident.Picture = await ImgurPhotoUploader.UploadPhotoAsync();
var tmp = ApartmentViewModel.NewResident;
ApartmentViewModel.NewResident = new Resident();
ApartmentViewModel.NewResident = tmp;
}
catch (Exception e)
{
-
-
}
-
}
}
}
diff --git a/ApartmentManager/ApartmentManager/Model/Apartment.cs b/ApartmentManager/ApartmentManager/Model/Apartment.cs
index 06b427d..74fe410 100644
--- a/ApartmentManager/ApartmentManager/Model/Apartment.cs
+++ b/ApartmentManager/ApartmentManager/Model/Apartment.cs
@@ -8,7 +8,7 @@
public double? MonthlyCharge { get; set; }
public int? Floor { get; set; }
public string Address { get; set; }
- public byte[] PlanPicture { get; set; }
+ public string PlanPicture { get; set; }
public Apartment() { }
diff --git a/ApartmentManager/ApartmentManager/Model/Resident.cs b/ApartmentManager/ApartmentManager/Model/Resident.cs
index d3d18d3..ac20ffa 100644
--- a/ApartmentManager/ApartmentManager/Model/Resident.cs
+++ b/ApartmentManager/ApartmentManager/Model/Resident.cs
@@ -11,7 +11,7 @@ namespace ApartmentManager.Model
public DateTime BirthDate { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
- public byte[] Picture { get; set; }
+ public string Picture { get; set; }
public Resident()
{
diff --git a/ApartmentManager/ApartmentManager/Model/User.cs b/ApartmentManager/ApartmentManager/Model/User.cs
index ea0e004..42964af 100644
--- a/ApartmentManager/ApartmentManager/Model/User.cs
+++ b/ApartmentManager/ApartmentManager/Model/User.cs
@@ -18,7 +18,7 @@ namespace ApartmentManager.Model
public DateTime BirthDate { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
- public byte[] Picture { get; set; }
+ public string Picture { get; set; }
public DateTime? MoveInDate { get; set; }
public DateTime? MoveOutDate { get; set; }
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/View/ApartmentResidentsPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml
index 3816b09..ca92dd2 100644
--- a/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml
+++ b/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml
@@ -9,10 +9,6 @@
x:Class="ApartmentManager.View.ApartmentResidentsPage"
mc:Ignorable="d">
- <Page.Resources>
- <Common:ByteArrayToImageConverter x:Key="ByteArrayToImageConverter"/>
- </Page.Resources>
-
<Page.DataContext>
<ViewModel:ApartmentViewModel/>
</Page.DataContext>
@@ -83,7 +79,7 @@
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Background="Gray" BorderThickness="0,0,2,0" BorderBrush="#CCFFFFFF" >
- <Image Stretch="Fill" Source="{Binding Picture, Converter={StaticResource ByteArrayToImageConverter}}"/>
+ <Image Stretch="Fill" Source="{Binding Picture}"/>
</Grid>
<Grid Grid.Column="1" Margin="3,3,3,3">
diff --git a/ApartmentManager/HousingWebApi/DataModel.cs b/ApartmentManager/HousingWebApi/DataModel.cs
index 485c697..26b2608 100644
--- a/ApartmentManager/HousingWebApi/DataModel.cs
+++ b/ApartmentManager/HousingWebApi/DataModel.cs
@@ -32,6 +32,10 @@ namespace HousingWebApi
.IsUnicode(false);
modelBuilder.Entity<Apartment>()
+ .Property(e => e.PlanPicture)
+ .IsUnicode(false);
+
+ modelBuilder.Entity<Apartment>()
.HasMany(e => e.ApartmentChanges)
.WithRequired(e => e.Apartment)
.WillCascadeOnDelete(false);
@@ -82,6 +86,10 @@ namespace HousingWebApi
.Property(e => e.Comment)
.IsUnicode(false);
+ modelBuilder.Entity<ChangeDocument>()
+ .Property(e => e.Document)
+ .IsUnicode(false);
+
modelBuilder.Entity<Defect>()
.Property(e => e.Name)
.IsUnicode(false);
@@ -108,6 +116,10 @@ namespace HousingWebApi
.Property(e => e.Picture)
.IsUnicode(false);
+ modelBuilder.Entity<DefectPicture>()
+ .Property(e => e.Picture)
+ .IsUnicode(false);
+
modelBuilder.Entity<PastUser>()
.Property(e => e.Username)
.IsUnicode(false);
@@ -132,6 +144,10 @@ namespace HousingWebApi
.Property(e => e.Email)
.IsUnicode(false);
+ modelBuilder.Entity<PastUser>()
+ .Property(e => e.Picture)
+ .IsUnicode(false);
+
modelBuilder.Entity<Resident>()
.Property(e => e.FirstName)
.IsUnicode(false);
@@ -148,6 +164,10 @@ namespace HousingWebApi
.Property(e => e.Email)
.IsUnicode(false);
+ modelBuilder.Entity<Resident>()
+ .Property(e => e.Picture)
+ .IsUnicode(false);
+
modelBuilder.Entity<User>()
.Property(e => e.Username)
.IsUnicode(false);
@@ -172,6 +192,10 @@ namespace HousingWebApi
.Property(e => e.Email)
.IsUnicode(false);
+ modelBuilder.Entity<User>()
+ .Property(e => e.Picture)
+ .IsUnicode(false);
+
modelBuilder.Entity<ApartmentResident>()
.Property(e => e.FirstName)
.IsUnicode(false);
diff --git a/ApartmentManager/HousingWebApi/HousingWebApi.csproj b/ApartmentManager/HousingWebApi/HousingWebApi.csproj
index b009a06..4d60cac 100644
--- a/ApartmentManager/HousingWebApi/HousingWebApi.csproj
+++ b/ApartmentManager/HousingWebApi/HousingWebApi.csproj
@@ -151,9 +151,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
- <Compile Include="Models\Apartment.cs" />
- <Compile Include="Models\ApartmentChange.cs" />
- <Compile Include="Models\ApartmentResident.cs" />
+ <Compile Include="Apartment.cs" />
+ <Compile Include="ApartmentChange.cs" />
+ <Compile Include="ApartmentResident.cs" />
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
@@ -186,8 +186,8 @@
<Compile Include="Areas\HelpPage\SampleGeneration\SampleDirection.cs" />
<Compile Include="Areas\HelpPage\SampleGeneration\TextSample.cs" />
<Compile Include="Areas\HelpPage\XmlDocumentationProvider.cs" />
- <Compile Include="Models\ChangeComment.cs" />
- <Compile Include="Models\ChangeDocument.cs" />
+ <Compile Include="ChangeComment.cs" />
+ <Compile Include="ChangeDocument.cs" />
<Compile Include="Controllers\ApartmentChangesController.cs" />
<Compile Include="Controllers\ApartmentsController.cs" />
<Compile Include="Controllers\ChangeCommentsController.cs" />
@@ -200,16 +200,16 @@
<Compile Include="Controllers\ResidentsController.cs" />
<Compile Include="Controllers\UsersController.cs" />
<Compile Include="DataModel.cs" />
- <Compile Include="Models\Defect.cs" />
- <Compile Include="Models\DefectComment.cs" />
- <Compile Include="Models\DefectPicture.cs" />
+ <Compile Include="Defect.cs" />
+ <Compile Include="DefectComment.cs" />
+ <Compile Include="DefectPicture.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
- <Compile Include="Models\PastUser.cs" />
+ <Compile Include="PastUser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Models\Resident.cs" />
- <Compile Include="Models\User.cs" />
+ <Compile Include="Resident.cs" />
+ <Compile Include="User.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Areas\HelpPage\HelpPage.css" />
@@ -267,6 +267,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
+ <Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<Content Include="fonts\glyphicons-halflings-regular.woff" />
diff --git a/ApartmentManager/HousingWebApi/Models/Apartment.cs b/ApartmentManager/HousingWebApi/Models/Apartment.cs
index d1ac1d5..94c9b11 100644
--- a/ApartmentManager/HousingWebApi/Models/Apartment.cs
+++ b/ApartmentManager/HousingWebApi/Models/Apartment.cs
@@ -33,7 +33,8 @@ namespace HousingWebApi
[StringLength(100)]
public string Address { get; set; }
- public byte[] PlanPicture { get; set; }
+ [StringLength(50)]
+ public string PlanPicture { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<ApartmentChange> ApartmentChanges { get; set; }
diff --git a/ApartmentManager/HousingWebApi/Models/ChangeDocument.cs b/ApartmentManager/HousingWebApi/Models/ChangeDocument.cs
index 9e910dc..7e869df 100644
--- a/ApartmentManager/HousingWebApi/Models/ChangeDocument.cs
+++ b/ApartmentManager/HousingWebApi/Models/ChangeDocument.cs
@@ -15,7 +15,8 @@ namespace HousingWebApi
public int ChangeId { get; set; }
- public byte[] Document { get; set; }
+ [StringLength(50)]
+ public string Document { get; set; }
public virtual ApartmentChange ApartmentChange { get; set; }
}
diff --git a/ApartmentManager/HousingWebApi/Models/DefectPicture.cs b/ApartmentManager/HousingWebApi/Models/DefectPicture.cs
index 6a83338..5d27ba3 100644
--- a/ApartmentManager/HousingWebApi/Models/DefectPicture.cs
+++ b/ApartmentManager/HousingWebApi/Models/DefectPicture.cs
@@ -15,7 +15,8 @@ namespace HousingWebApi
public int DefectId { get; set; }
- public byte[] Picture { get; set; }
+ [StringLength(50)]
+ public string Picture { get; set; }
public virtual Defect Defect { get; set; }
}
diff --git a/ApartmentManager/HousingWebApi/Models/PastUser.cs b/ApartmentManager/HousingWebApi/Models/PastUser.cs
index f258d34..d0bb504 100644
--- a/ApartmentManager/HousingWebApi/Models/PastUser.cs
+++ b/ApartmentManager/HousingWebApi/Models/PastUser.cs
@@ -36,7 +36,8 @@ namespace HousingWebApi
[StringLength(50)]
public string Email { get; set; }
- public byte[] Picture { get; set; }
+ [StringLength(50)]
+ public string Picture { get; set; }
[Column(TypeName = "date")]
public DateTime? MoveInDate { get; set; }
diff --git a/ApartmentManager/HousingWebApi/Models/Resident.cs b/ApartmentManager/HousingWebApi/Models/Resident.cs
index 0509d40..4d29f16 100644
--- a/ApartmentManager/HousingWebApi/Models/Resident.cs
+++ b/ApartmentManager/HousingWebApi/Models/Resident.cs
@@ -28,7 +28,8 @@ namespace HousingWebApi
[StringLength(50)]
public string Email { get; set; }
- public byte[] Picture { get; set; }
+ [StringLength(50)]
+ public string Picture { get; set; }
public virtual Apartment Apartment { get; set; }
}
diff --git a/ApartmentManager/HousingWebApi/Models/User.cs b/ApartmentManager/HousingWebApi/Models/User.cs
index 019e788..12438c6 100644
--- a/ApartmentManager/HousingWebApi/Models/User.cs
+++ b/ApartmentManager/HousingWebApi/Models/User.cs
@@ -36,7 +36,8 @@ namespace HousingWebApi
[StringLength(50)]
public string Email { get; set; }
- public byte[] Picture { get; set; }
+ [StringLength(50)]
+ public string Picture { get; set; }
[Column(TypeName = "date")]
public DateTime? MoveInDate { get; set; }