Exemplo n.º 1
0
 public void Given_my_contact_book_is_filled_with_many_contacts()
 {
     for (var i = 0; i < 10000; ++i)
     {
         _contactBook.AddContact(i.ToString(CultureInfo.InvariantCulture), i.ToString(CultureInfo.InvariantCulture), i.ToString(CultureInfo.InvariantCulture));
     }
 }
        private void AddSomeContacts()
        {
            AddedContacts = new[]
            {
                new Contact("Jack", "123-456-789"),
                new Contact("Samantha", "321-654-987"),
                new Contact("Josh", "132-465-798")
            };

            foreach (var contact in AddedContacts)
            {
                ContactBook.AddContact(contact.Name, contact.PhoneNumber);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// If simple, see in Btnhowuse_Click
        /// (it read, check send to server Contact object)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (contactListBox.SelectedIndex == -1)
            {
                return;
            }

            if (contactListBox.SelectedIndex != viewModel.Contacts.Count() - 1)
            {
                MessageBox.Show("Please, click button HOW USE and read how add contact, thanks)))", "Instruction", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                if (viewModel.SelectedContact.Name == "" || viewModel.SelectedContact.Surname == "" || viewModel.SelectedContact.Telephone == "")
                {
                    MessageBox.Show("FullName and Telephone is important part! Please fill it!");
                }
                else
                {
                    Contact isexist;

                    int         age         = viewModel.SelectedContact.Age;
                    string      city        = viewModel.SelectedContact.City;
                    BitmapImage bitmapImage = viewModel.SelectedContact.ImageBitmap;
                    string      telephone   = viewModel.SelectedContact.Telephone;

                    viewModel.SelectedContact.Telephone = "";

                    try
                    {
                        isexist = viewModel.Contacts.FirstOrDefault(a => a.Telephone == telephone);
                    }
                    catch (Exception)
                    {
                        isexist = null;
                        viewModel.SelectedContact = new Contact()
                        {
                            Name = "Name", Age = 0, Surname = "LastName", City = "City", ImageBitmap = default_image, Telephone = "+1.. (telephone)"
                        };
                    }

                    if (isexist != null)
                    {
                        MessageBox.Show("This phone alredy used!");
                        viewModel.SelectedContact = new Contact()
                        {
                            Name = "Name", Age = 0, Surname = "LastName", City = "City", ImageBitmap = default_image, Telephone = "+1.. (telephone)"
                        };
                    }
                    else
                    {
                        viewModel.SelectedContact.Telephone = telephone;

                        if (age.ToString() == "")
                        {
                            age = 3;
                        }

                        if (city == "")
                        {
                            city = "none";
                        }

                        if (bitmapImage is null)
                        {
                            bitmapImage = default_image;
                        }

                        ContactByDB newcontact = new ContactByDB
                        {
                            Name      = viewModel.SelectedContact.Name,
                            SurName   = viewModel.SelectedContact.Surname,
                            Telephone = viewModel.SelectedContact.Telephone,

                            Age          = age,
                            City         = city,
                            ImageContact = ConvertBitmapToByteArray(bitmapImage),
                        };

                        var client = new TcpClient(Dns.GetHostName(), port);
                        using (var stream = client.GetStream())
                        {
                            var serializer_comand = new XmlSerializer(typeof(string));
                            serializer_comand.Serialize(stream, "add");
                        }

                        client = new TcpClient(Dns.GetHostName(), port);
                        using (var stream = client.GetStream())
                        {
                            var serializer = new XmlSerializer(typeof(ContactByDB));
                            serializer.Serialize(stream, newcontact);
                        }

                        viewModel.AddContact(new Contact()
                        {
                            Name = "Name", Age = 0, Surname = "LastName", City = "City", ImageBitmap = default_image, Telephone = "+1.. (telephone)"
                        });
                        foredit = false;
                        Refresh();
                    }
                }
            }
        }