Ejemplo n.º 1
0
        private async Task PhotoFromCamera()
        {
            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                await Diag.AlertAsync(new AlertConfig()
                {
                    Message = "No hay camara", OkText = "Ok"
                });

                return;
            }
            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                Directory          = "Test",
                SaveToAlbum        = true,
                CompressionQuality = 75,
                CustomPhotoSize    = 50,
                PhotoSize          = PhotoSize.MaxWidthHeight,
                MaxWidthHeight     = 2000,
                DefaultCamera      = CameraDevice.Front
            });

            if (file == null)
            {
                return;
            }
            contact.Photo = Base64Photo(file.GetStream());
            sourceuserpic = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                file.Dispose();
                return(stream);
            });
            OnPropertyChanged("sourceuserpic");
        }
Ejemplo n.º 2
0
        private async Task PhotoFromGallery()
        {
            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await Diag.AlertAsync(new AlertConfig()
                {
                    Message = "No se puede accesar la galeria", OkText = "Ok"
                });

                return;
            }
            var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions
            {
                PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium,
            });

            if (file == null)
            {
                return;
            }
            contact.Photo = Base64Photo(file.GetStream());
            sourceuserpic = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                file.Dispose();
                return(stream);
            });
            OnPropertyChanged("sourceuserpic");
        }
        private async Task SaveApi()
        {
            try
            {
                if (Settings.LstContacts.Count == 0)
                {
                    await Diag.AlertAsync(new AlertConfig()
                    {
                        Message = "Agregue al menos un contacto", OkText = "Ok"
                    });

                    return;
                }
                var request = new ContactsRequest()
                {
                    Contacts = Settings.LstContacts,
                    Location = Position != null ? new Location {
                        Latitude = Position.latitude, Longitude = Position.longitud
                    } : new Location {
                        Latitude = 15.0, Longitude = 15.0
                    },
                    RegisteredBy = new RegisteredBy {
                        Name = "Jazmine Aline Villegas Brena"
                    },
                    Type = 1,
                };
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(request);

                var api = RestService.For <IContactsApi>("https://contactmanager.banlinea.com");
                MsgBusy = "Guardando Contactos. Espere por favor ...";
                Busy    = true;
                var response = await api.SaveContacts(request);

                Busy = false;
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    await Diag.AlertAsync(new AlertConfig()
                    {
                        Message = "Contactos Guardados", OkText = "Ok"
                    });
                }
                else
                {
                    await Diag.AlertAsync(new AlertConfig()
                    {
                        Message = "Error en la API", OkText = "Ok"
                    });
                }
            }
            catch (Refit.ApiException ex)
            {
                Busy = false;
                await Diag.AlertAsync(new AlertConfig()
                {
                    Message = "Error en la API", OkText = "Ok"
                });
            }
        }
Ejemplo n.º 4
0
        public async Task Init()
        {
            try
            {
                var api = RestService.For <IContactsApi>("https://contactmanager.banlinea.com");
                MsgBusy = "Cargando Paises. Espere por favor ...";
                Busy    = true;
                var tmp = await api.GetCountries();

                lstCountries = new ObservableCollection <Countries>(tmp);
                Busy         = false;
            }
            catch (Refit.ApiException ex)
            {
                Busy = false;
                await Diag.AlertAsync(new AlertConfig()
                {
                    Message = "Error en la API", OkText = "Ok"
                });

                lstCountries = new ObservableCollection <Countries>()
                {
                    new Countries {
                        Code = 52, Name = "México", Enabled = true
                    }
                };
            }
            finally
            {
                contact = new Contact
                {
                    Company = String.Empty,
                    Emails  = new ObservableCollection <Email>()
                    {
                        new Email {
                            EmailAddr = String.Empty, IsValid = false
                        }
                    },
                    EmailsAddress = new List <string>()
                    {
                        String.Empty
                    },
                    Name         = String.Empty,
                    LastName     = String.Empty,
                    PhoneNumbers = new ObservableCollection <PhoneNumber>()
                    {
                        new PhoneNumber {
                            Country = null, Number = String.Empty, IsValid = false, lstCountries = lstCountries
                        }
                    },
                    Photo = String.Empty
                };
                OnPropertyChanged("contact");
            }
        }
Ejemplo n.º 5
0
        private async Task DelNumber()
        {
            var cfg = new AlertConfig();

            cfg.Message = "Debe existir al menos un numero";
            cfg.OkText  = "Ok";
            if (contact.PhoneNumbers.Count <= 1)
            {
                await Diag.AlertAsync(cfg);
            }
            if (contact.PhoneNumbers.Count > 1)
            {
                contact.PhoneNumbers.Remove(contact.PhoneNumbers.LastOrDefault());
            }
        }
Ejemplo n.º 6
0
        private async Task SaveContact()
        {
            int errs = 0; int emailerrs = 0; int numberrs = 0;
            var cfg = new AlertConfig();

            cfg.Message = "Faltan algunos campos, revise por favor. ";
            cfg.OkText  = "Ok";

            if (String.IsNullOrEmpty(contact.Company))
            {
                errs++;
                cfg.Message += $"{Environment.NewLine}Falta la compañia";
            }
            foreach (Email e in contact.Emails)
            {
                if (!e.IsValid)
                {
                    emailerrs++;
                }
            }
            if (emailerrs > 0)
            {
                errs++;
                cfg.Message += $"{Environment.NewLine}Falta algun email o no es valido";
            }
            if (String.IsNullOrEmpty(contact.LastName))
            {
                errs++;
                cfg.Message += $"{Environment.NewLine}Falta el apellido";
            }
            if (String.IsNullOrEmpty(contact.Name))
            {
                errs++;
                cfg.Message += $"{Environment.NewLine}Falta el nombre";
            }
            foreach (PhoneNumber n in contact.PhoneNumbers)
            {
                if (!n.IsValid)
                {
                    numberrs++;
                }
            }
            if (numberrs > 0)
            {
                errs++;
                cfg.Message += $"{Environment.NewLine}Falta algun numero o no es valido";
            }
            if (String.IsNullOrEmpty(contact.Photo))
            {
                errs++;
                cfg.Message += $"{Environment.NewLine}Falta la fotografia";
            }

            if (errs > 0)
            {
                await Diag.AlertAsync(cfg);
            }
            else
            {
                var tmp = Settings.LstContacts;
                contact.EmailsAddress = contact.Emails.Select(x => x.EmailAddr).ToList();
                tmp.Add(contact);
                Settings.LstContacts = tmp;
                await Nav.PopAsync();
            }
        }