Esempio n. 1
0
        public static void Post(Image newImage)
        {
            if (ServerService.instance.isOffline())
            {
                OfflineFileLoader.post(newImage);
                ((MainWindow)Application.Current.MainWindow).LoadImage(newImage.id);
                return;
            }

            var request = new RestRequest(Settings.API_VERSION + Settings.IMAGES_PATH, Method.POST);

            request.AddJsonBody(newImage);
            ServerService.instance.server.ExecuteAsync(request, response =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    if (response.StatusCode == HttpStatusCode.Created)
                    {
                        dynamic data = JObject.Parse(response.Content);
                        ((MainWindow)Application.Current.MainWindow).LoadImage((string)data["id"]);

                        newImage.id = (string)data["id"];

                        ImageDao.Put(newImage);
                    }
                    else
                    {
                        MessageBox.Show("Could not create the image", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                });
            });
        }
        public GalleryCard(Image image)
        {
            InitializeComponent();
            Image       = image;
            DataContext = this;
            ConfigIcon();

            Uri         imageUri    = new Uri(image.fullImageUrl);
            BitmapImage imageBitmap = new BitmapImage();

            imageBitmap.BeginInit();
            imageBitmap.UriSource   = imageUri;
            imageBitmap.CacheOption = BitmapCacheOption.OnLoad;
            imageBitmap.EndInit();

            this.ImagePlaceholder.Source = imageBitmap;
        }
Esempio n. 3
0
        public static void Put(Image imageToUpdate)
        {
            if (ServerService.instance.isOffline())
            {
                OfflineFileLoader.put(imageToUpdate);
                return;
            }

            imageToUpdate.fullImageUrl = Settings.URL_TO_GALLERY_IMAGES + imageToUpdate.id + ".png";
            imageToUpdate.thumbnailUrl = Settings.URL_TO_GALLERY_IMAGES + imageToUpdate.id + ".png";
            var request = new RestRequest(Settings.API_VERSION + Settings.IMAGES_PATH + "/" + imageToUpdate.id, Method.PUT);

            request.AddJsonBody(imageToUpdate);
            ServerService.instance.server.ExecuteAsync(request, response =>
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    MessageBox.Show("Could not update the image", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            });
        }