Exemple #1
0
        public async Task <SingleDocumentResponse> GetSingleDocument(int docid)
        {
            var uri = new Uri(string.Format(_keys.SafeHavenAPI + "/document/getsingle/" + docid, string.Empty));

            try
            {
                HttpResponseMessage response = await _client.GetAsync(uri);

                var JSONstring = await response.Content.ReadAsStringAsync();

                SingleDocumentResponse result = JsonConvert.DeserializeObject <SingleDocumentResponse>(JSONstring);
                return(result);
            }
            catch
            {
                throw new NotImplementedException();
            }
        }
        public async void SetDocument(int docid)
        {
            SingleDocumentResponse response = await App.APIService.GetSingleDocument(docid);

            if (response.Document == null)
            {
                await DisplayAlert("Error", response.Message, "Okay");
            }
            BindingContext = response.Document;
            StackLayout ParentStack = new StackLayout();

            if (response.Document.DocumentImages != null)
            {
                foreach (DocumentImage img in response.Document.DocumentImages)
                {
                    StackLayout stack = new StackLayout();
                    Image       image = new Image()
                    {
                        Aspect = Aspect.AspectFit,
                    };
                    IFile file = await FileSystem.Current.GetFileFromPathAsync(img.FilePath);

                    if (file != null)
                    {
                        Stream stream = await file.OpenAsync(PCLStorage.FileAccess.Read);

                        image.Source = ImageSource.FromStream(() => stream);
                        stack.Children.Add(image);
                        ParentStack.Children.Add(stack);
                    }
                }
                ImageScroller.Content = ParentStack;
            }
            if (response.Document.DocumentImages == null)
            {
                StackLayout stack = new StackLayout();
                Label       label = new Label {
                    Text = "This user hasn't taken any pictures yet", HorizontalTextAlignment = TextAlignment.Center
                };
            }
        }
Exemple #3
0
        public async Task <SingleDocumentResponse> GetSingle([FromRoute] int docid)
        {
            SingleDocumentResponse response = new SingleDocumentResponse();

            if (!ModelState.IsValid)
            {
                response.Success = false;
                response.Message = "Bad Request.";
                return(response);
            }
            var document = await _context.Document.Include("DocumentType").Include("DocumentImages").SingleOrDefaultAsync(m => m.DocumentID == docid);

            if (document == null)
            {
                response.Success = false;
                response.Message = "Item not found.";
                return(response);
            }
            response.Document = document;
            response.Success  = true;
            response.Message  = "Item found.";
            return(response);
        }