private async void GetImages(AppPreferences ap)
        {
            if (!String.IsNullOrEmpty(imageNames[0]))
            {
                Bitmap bit = ap.SetImageBitmap(_dir + "/" + imageNames[0]);
                if (bit != null)
                {
                    facilityPhoto.SetImageBitmap(bit);
                }
                else if (bit == null && !String.IsNullOrEmpty(imageNames[0]))
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(imageNames[0]);

                    if (picture != null)
                    {
                        var _bit = ap.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            ap.SaveImage(_bit, imageNames[0]);
                        }
                        facilityPhoto.SetImageBitmap(_bit);
                    }
                }
            }
            if (imageNames.Count > 1)
            {
                Bitmap bit = ap.SetImageBitmap(_dir + "/" + imageNames[1]);
                if (bit != null)
                {
                    secondFacilityPhoto.SetImageBitmap(bit);
                }
                else if (bit == null && !String.IsNullOrEmpty(imageNames[1]))
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(imageNames[1]);

                    if (picture != null)
                    {
                        var _bit = ap.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            ap.SaveImage(_bit, imageNames[1]);
                        }
                        secondFacilityPhoto.SetImageBitmap(_bit);
                    }
                }
            }
        }
        private async void GetImages(AppPreferences ap)
        {
            if (!String.IsNullOrEmpty(imageNames[0]))
            {
                Bitmap bit = ap.SetImageBitmap(ap.CreateDirectoryForPictures() + "/" + imageNames[0]);
                if (bit != null)
                {
                    pictureHolder.SetImageBitmap(bit);
                }
                else if (bit == null && !String.IsNullOrEmpty(imageNames[0]))
                {
                    PictureViewModel pictureViewModel = new PictureViewModel();
                    Models.Picture   picture          = await pictureViewModel.ExecuteGetPictureCommand(imageNames[0]);

                    if (picture != null)
                    {
                        var _bit = ap.StringToBitMap(picture.File);
                        if (_bit != null)
                        {
                            ap.SaveImage(_bit, imageNames[0]);
                        }
                        pictureHolder.SetImageBitmap(_bit);
                    }
                }
            }
        }
        private async void SaveFacility()
        {
            if (appPreferences.IsOnline(Application.Context))
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.ShowLoading();
                if (imageNames.Count() == 0)
                {
                    imageNames = new List <string>();
                }

                if (FirstPhotoIsChanged)
                {
                    string thisFileName = appPreferences.SaveImage(((BitmapDrawable)facilityPhoto.Drawable).Bitmap);
                    if (imageNames.Count() > 0)
                    {
                        imageNames[0] = thisFileName;
                    }
                    else
                    {
                        imageNames.Add(thisFileName);
                    }
                }
                if (SecondPhotoIsChanged)
                {
                    var _fileName = String.Format("facility_{0}", Guid.NewGuid());
                    appPreferences.SaveImage(((BitmapDrawable)secondFacilityPhoto.Drawable).Bitmap, _fileName);
                    if (imageNames.Count() > 1)
                    {
                        imageNames[1] = _fileName;
                    }
                    else
                    {
                        imageNames.Add(_fileName);
                    }
                }
                if (FirstPhotoIsChanged)
                {
                    facility.IDPicture = "";

                    foreach (var name in imageNames)
                    {
                        if (!String.IsNullOrEmpty(name))
                        {
                            if (String.IsNullOrEmpty(facility.IDPicture))
                            {
                                facility.IDPicture = name;
                            }
                            else
                            {
                                facility.IDPicture = facility.IDPicture + "," + name;
                            }
                        }
                    }
                }


                bool isUpdated = await ViewModel.ExecuteUpdateFacilityCommand(facility);

                if (isUpdated)
                {
                    PictureViewModel      pictureViewModel = new PictureViewModel();
                    List <Models.Picture> pictures         = new List <Models.Picture>();
                    if (FirstPhotoIsChanged)
                    {
                        Bitmap _bm  = ((BitmapDrawable)facilityPhoto.Drawable).Bitmap;
                        string file = "";
                        if (_bm != null)
                        {
                            MemoryStream stream = new MemoryStream();
                            _bm.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                            byte[] ba = stream.ToArray();
                            file = Base64.EncodeToString(ba, Base64.Default);
                        }

                        Models.Picture picture = new Models.Picture()
                        {
                            Name = imageNames[0],
                            File = file,
                        };
                        pictures.Add(picture);
                    }
                    if (SecondPhotoIsChanged && imageNames.Count() > 1)
                    {
                        Bitmap _bm  = ((BitmapDrawable)secondFacilityPhoto.Drawable).Bitmap;
                        string file = "";
                        if (_bm != null)
                        {
                            MemoryStream stream = new MemoryStream();
                            _bm.Compress(Bitmap.CompressFormat.Jpeg, 100, stream);
                            byte[] ba = stream.ToArray();
                            file = Base64.EncodeToString(ba, Base64.Default);
                        }

                        Models.Picture picture = new Models.Picture()
                        {
                            Name = imageNames[1],
                            File = file,
                        };
                        pictures.Add(picture);
                    }
                    bool isSuccess = await pictureViewModel.ExecuteSavePictureCommand(pictures);

                    messageDialog.HideLoading();
                    messageDialog.SendToast("Pictures are saved successful.");
                    var            intent   = new Intent(this, typeof(FacilityDetailActivity));
                    Context        mContext = Android.App.Application.Context;
                    AppPreferences ap       = new AppPreferences(mContext);
                    ap.SaveFacilityId(facility.Id.ToString());
                    intent.PutExtra("data", Newtonsoft.Json.JsonConvert.SerializeObject(facility));
                    this.StartActivity(intent);
                    Finish();
                }
                else
                {
                    messageDialog.HideLoading();
                    messageDialog.SendToast("Pictures are not saved successful.");
                }
            }
        }