public static Section[] BuildDialogSections(Contact c)
        {
            // init to default values
            string fName = string.Empty;
            string lName = string.Empty;
            string phoneNumber = string.Empty;
            string emailAddress = string.Empty;
            string address = string.Empty;

            // update values if a contact was passed in
            if (c != null)
            {
                if (!string.IsNullOrEmpty(c.FirstName)) fName = c.FirstName;
                if (!string.IsNullOrEmpty(c.LastName)) lName = c.LastName;
                if (!string.IsNullOrEmpty(c.Phone)) phoneNumber = c.Phone;
                if (!string.IsNullOrEmpty(c.Email)) emailAddress = c.Email;
                if (!string.IsNullOrEmpty(c.Address)) address = c.Address;
            }

            // build dialog section
            List<Section> sections = new List<Section>();

            var name = new Section() { Caption = "Individual" };
            sections.Add(name);
            var ee = new EntryElement("First Name", null, fName);
            name.Add(new EntryElement("First Name", null, fName) { KeyboardType = UIKeyboardType.NamePhonePad });

            var phoneSec = new Section() { Caption = "Phone Numbers" };
            sections.Add(phoneSec);
            //TODO: Add a button which adds a new row
            phoneSec.Add(new EntryElement("Work", null, phoneNumber) { KeyboardType = UIKeyboardType.PhonePad });

            // email
            var emailSec = new Section() { Caption = "Email Addresses" };
            sections.Add(emailSec);
            emailSec.Add(new EntryElement("Work", null, emailAddress) { KeyboardType = UIKeyboardType.EmailAddress });

            // addresses
            var addressSec = new Section() { Caption = "Addresses" };
            sections.Add(addressSec);
            addressSec.Add(new MultilineEntryElement("Home", address));
            return sections.ToArray();
        }
        public static bool SaveDialogElementsToModel(Contact c, Section[] section)
        {
            if (section != null)
            {
                foreach (Section s in section)
                {
                    foreach (Element e in s)
                    {
                        if (e.Caption == "First Name") { c.FirstName = ((EntryElement)e).Value; }
                        else if (e.Caption == "Last Name") { c.LastName = ((EntryElement)e).Value; }
                        else if (s.Caption == "Phone Numbers" && e.Caption == "Work") { c.Phone = ((EntryElement)e).Value; }
                        else if (s.Caption == "Email Addresses" && e.Caption == "Work") { c.Email = ((EntryElement)e).Value; }
                        else if (s.Caption == "Addresses" && e.Caption == "Home") { c.Address = ((MultilineEntryElement)e).Value; }
                    }
                }
            }

            //TODO: Refactor method to void if it can't fail
            return true;
        }
Ejemplo n.º 3
0
        public static Section[] CreateContactDetailSections(Contact c)
        {
            List<Section> sections = new List<Section>();

            //TODO: awating a refactor of Phones/Emails/Address to being lists in Contact
            var Phones = new List<string>(new string[] { c.Phone });
            var emails = new List<string>(new string[] { c.Email });
            var addresses = new List<string>(new string[] { c.Address });

            var phoneSec = new Section() { Caption = "Phone Numbers" };
            sections.Add(phoneSec);
            if (Phones != null && Phones.Count > 0)
            {
                var cell = new StringElement("Cell", Phones[0]);
                phoneSec.Add(cell);
            }
            var work = new StringElement("Office", "651-555-1212");
            phoneSec.Add(work);
            var home = new StringElement("Home", "507-555-1212");
            phoneSec.Add(home);

            // email
            var emailSec = new Section() { Caption = "Email Addresses" };
            sections.Add(emailSec);
            if (emails != null && emails.Count > 0)
            {
                string emailAddress = emails[0];
                var email = new StringElement("Work", emailAddress);
                emailSec.Add(email);
            }
            var homeEmail = new StringElement("Home", "*****@*****.**");
            emailSec.Add(homeEmail);

            // addresses
            var addressSec = new Section() { Caption = "Addresses" };
            sections.Add(addressSec);
            if (addresses != null && addresses.Count > 0)
                addressSec.Add(new MultilineElement("Home", addresses[0]));
            return sections.ToArray();
        }
Ejemplo n.º 4
0
 public static bool Add(List<Contact> contacts, Contact c)
 {
     //TODO: Replace with a post to a server
     bool added = false;
     if (contacts != null)
     {
         contacts.Add(c);
         added = true;
     }
     else { throw new ArgumentNullException("tasks", "task cannot be added to a null list"); }
     return added;
 }
Ejemplo n.º 5
0
        public static bool Update(IEnumerable<Contact> contacts, Contact contact)
        {
            bool updated = false;
            if (contacts != null)
            {
                foreach(Contact c in contacts)
                {
                    if (c.Id == contact.Id)
                    {
                        c.Address = contact.Address;
                        c.Email = contact.Email;
                        c.FirstName = contact.FirstName;
                        c.LastName = contact.LastName;
                        c.Phone = contact.Phone;

                        updated = true;
                        break;
                    }
                }
            }
            else { throw new ArgumentNullException("tasks", "task cannot be updated in a null list"); }
            return updated;
        }