示例#1
0
        public void DoneButtonClicked(object sender, EventArgs args)
        {
            var contact = new Contact();

            // Photo
            if (_profilePhoto != null)
            {
                contact.ImageName = Guid.NewGuid().ToString() + ".jpg";
                var directory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                var imagePath = System.IO.Path.Combine(directory, contact.ImageName);

                NSData  imgData = _profilePhoto.AsJPEG();
                NSError err     = null;
                if (!imgData.Save(imagePath, false, out err))
                {
                    throw new Exception(err.LocalizedDescription);
                }
            }

            // Name
            contact.FirstName    = ((EntryElement)_nameSection[0]).Value ?? null;
            contact.MiddleName   = ((EntryElement)_nameSection[1]).Value ?? null;
            contact.LastName     = ((EntryElement)_nameSection[2]).Value ?? null;
            contact.Organization = ((EntryElement)_nameSection[3]).Value ?? null;

            DatabaseManager.AddNewContact(contact);
            _rootContainerNavigationController.PopViewControllerAnimated(false);
            _rootContainerNavigationController.PushViewController(new AllContactsScreen(), false);
            NavigationController.DismissViewController(true, null);

            // Phone numbers
            for (int i = 0; i <= _phoneSection.Count - 1; i++)
            {
                if (_phoneSection[i].GetType() == typeof(EntryElement))
                {
                    if (i >= 1)
                    {
                        var phoneType   = (StyledStringElement)_phoneSection[i - 1];
                        var phoneNumber = (EntryElement)_phoneSection[i];

                        if (!string.IsNullOrEmpty(phoneNumber.Value))
                        {
                            Console.WriteLine("type:" + phoneType.Caption + " number:" + phoneNumber.Value);
                        }
                    }
                }
            }
        }