Exemplo n.º 1
0
 public StreetArtDetailInfo(StreetArtDTO streetartdto)
 {
     InitializeComponent();
     Entry_Title.Text     = streetartdto.Title;
     Entry_Title.Text     = streetartdto.Title;
     Entry_Username.Text  = streetartdto.UserName;
     Entry_Time.Text      = streetartdto.Timestamp.ToLongDateString();
     Entry_Street.Text    = streetartdto.Street;
     Entry_Latitude.Text  = streetartdto.GpsLatitude.ToString();
     Entry_Longitude.Text = streetartdto.GpsLongitude.ToString();
 }
        public StreetArtDetailPage(StreetArtDTO streetartdto)
        {
            InitializeComponent();

            StreetArtDTO = streetartdto;


            img_Art.Source = (new UriImageSource {
                CachingEnabled = true, Uri = new Uri(Constants.PicsFolder + streetartdto.Image)
            });
        }
Exemplo n.º 3
0
        private async void btn_Upload_Clicked(object sender, EventArgs e)
        {
            try
            {
                if (pic == null || string.IsNullOrWhiteSpace(Entry_Title.Text) || string.IsNullOrWhiteSpace(Entry_Street.Text))
                {
                    await DisplayAlert("Error", "title or street values empty", "OK");
                }
                else if (location == null)
                {
                    await DisplayAlert("Error", "Location is empty", "OK");
                }
                else
                {
                    var user = App.UserDatabase.GetUser();
                    (sender as Button).IsEnabled = false;
                    UserDialogs.Instance.ShowLoading("Please Wait...");
                    var Imagepath = $"A_{user.Id}";


                    var streetart = new StreetArtDTO();
                    streetart.GpsLatitude   = (float)location.Latitude;
                    streetart.GpsLongitude  = (float)location.Longitude;
                    streetart.Title         = Entry_Title.Text;
                    streetart.Street        = Entry_Street.Text;
                    streetart.Image         = Imagepath;
                    streetart.UserAccountId = user.Id;
                    streetart.Timestamp     = picDate;

                    var content = new MultipartFormDataContent();

                    content.Add(new StreamContent(pic.GetStream()),
                                "\"file_art\"",
                                Imagepath);

                    content.Add(new StringContent(JsonConvert.SerializeObject(streetart), Encoding.UTF8, "application/json"), "data");

                    var httpClient = new HttpClient();

                    var uploadServiceBaseAddress = Constants.APIURL + "streetart/upload";

                    var response = await httpClient.PostAsync(uploadServiceBaseAddress, content);

                    if (response.StatusCode == System.Net.HttpStatusCode.Created)
                    {
                        try
                        {
                            string jsonResult = await response.Content.ReadAsStringAsync();
                        }
                        catch (Exception eex)
                        {
                        }
                        UserDialogs.Instance.HideLoading();
                        await DisplayAlert("Success", "Picture added", "OK");

                        var test = this.Parent;
                        var tab  = this.Parent as TabbedPage;
                        tab.CurrentPage = tab.Children[0];
                    }
                    else
                    {
                        string jsonResult = await response.Content.ReadAsStringAsync();

                        var aaa = JsonConvert.DeserializeObject <Exception>(jsonResult);
                        UserDialogs.Instance.HideLoading();

                        await DisplayAlert("Error", "upload failed", "OK");
                    }
                }
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.HideLoading();
                if (ex.GetType() == typeof(FeatureNotEnabledException))
                {
                    await App.Current.MainPage.DisplayAlert("Location", "Kindly Turn On Location In Setting Of Your Phone and try again", "OK");
                }
                else
                if (ex.GetType() == typeof(FeatureNotSupportedException))
                {
                    await App.Current.MainPage.DisplayAlert("Error", "FeatureNotSupported", "OK");
                }
                else
                if (ex.GetType() == typeof(PermissionException))
                {
                    await App.Current.MainPage.DisplayAlert("Location", "Kindly Give The App ThePermision Of Locaiton and try again", "OK");

                    await Xamarin.Essentials.Permissions.RequestAsync <Permissions.LocationWhenInUse>();
                }
                else
                {
                    await DisplayAlert("Error", "upload failed", "OK");
                }
            }
            location = null;
            (sender as Button).IsEnabled = true;
        }