using System; using System.Linq; using System.Threading.Tasks; using InABox.Clients; using InABox.Core; using InABox.Mobile; using Xamarin.Forms.Xaml; using XF.Material.Forms.UI.Dialogs; namespace PRS.Mobile { public enum EmployeeQualificationImageType { Front, Back, Other } [XamlCompilation(XamlCompilationOptions.Compile)] public partial class EmployeeQualificationEditImagesView { public EmployeeQualificationEditImagesView() { InitializeComponent(); } public override void Refresh() { if (ViewModel == null) return; _otherImages.ParentID = ViewModel.Item.ID; _otherImages.ItemsSource = ViewModel.Documents; var front = ViewModel.Photos.FirstOrDefault(x => x.ID == ViewModel.Item.FrontPhotoID); var back = ViewModel.Photos.FirstOrDefault(x => x.ID == ViewModel.Item.BackPhotoID); _frontImage.Load(front?.FileName, front?.Data); _backImage.Load(back?.FileName, back?.Data); } public EmployeeQualificationImageType ImageType => _accordion.SelectedItem == _frontitem ? EmployeeQualificationImageType.Front : _accordion.SelectedItem == _backitem ? EmployeeQualificationImageType.Back : EmployeeQualificationImageType.Other; public async Task AddImage(TOptions options) where T : MobileImageSource where TOptions : MobileImageOptions, new() { if (_accordion.SelectedItem == _otheritem) { await _otherImages.AddImage(options); return; } MobileDocument file = null; try { file = await MobileDocument.From(options); } catch (Exception e) { await MaterialDialog.Instance.AlertAsync(e.Message, "ERROR"); } if (file != null) { using (await MaterialDialog.Instance.LoadingDialogAsync("Saving Image")) { Document doc = new Document() { FileName = file.FileName, Data = file.Data, CRC = CoreUtils.CalculateCRC(file.Data), TimeStamp = DateTime.Now }; new Client().Save(doc, "Created on Mobile Device"); if (_accordion.SelectedItem == _frontitem) { ViewModel.Item.FrontPhotoID = doc.ID; ViewModel.Item.Save("Front Image Loaded from Mobile Device"); _frontImage.Load(file.FileName,file.Data); } else if (_accordion.SelectedItem == _backitem) { ViewModel.Item.BackPhotoID = doc.ID; ViewModel.Item.Save("Back Image Loaded from Mobile Device"); _backImage.Load(file.FileName,file.Data); } } } } } }