示例#1
0
        private async Task ExecuteOnEditContact()
        {
            var props = typeof(NewContact_Model).GetProperties();

            string[] required = { "lastname", "firsname", "business_type", "sector", "placement", "sex", "local_appearance", "prescription", "wilaya", "city", "address" };
            bool     valid    = true;

            foreach (var prop in props)
            {
                if (required.Contains(prop.Name))
                {
                    object value = prop.GetValue(NewContact, null);
                    if (string.IsNullOrWhiteSpace((string)value))
                    {
                        DependencyService.Get <IMessage>().ShortAlert("Vous devez remplir les champs obligatoires !");
                        valid = false;
                        break;
                    }
                }
            }
            if (string.IsNullOrWhiteSpace(NewContact.location.coordinates.lat) & valid)
            {
                valid = false;
                DependencyService.Get <IMessage>().ShortAlert("Impossible d'éditer un Contact sans sa position gps !");
            }
            if (valid)
            {
                if (await DependencyService.Get <IDialog>().AlertAsync("", "Voulez Vous Modifier le Contact " + Contact.Name + " ?", "Oui", "Non"))
                {
                    var json         = JsonConvert.SerializeObject(NewContact);
                    var contact_data = new EditContactToUpload_Model
                    {
                        Date        = DateTime.Now,
                        Json        = json,
                        Name        = NewContact.lastname + " " + NewContact.firstname,
                        PicturePath = PicturePath,
                        Contact_Id  = NewContact._id
                    };
                    DataStore.AddEditContactToUpload(contact_data);
                    MessagingCenter.Send(this, "UploadContactsTableModified");
                    await Navigation.PopModalAsync();
                }
            }
        }