Exemple #1
0
        public ContactAdd(Entities.Contact selectedContact, int userId)
        {
            this.userId = userId;
            _service    = new ApplicationService();
            InitializeComponent();

            if (selectedContact != null)
            {
                FirstName.Text          = selectedContact.Firstname;
                Surname.Text            = selectedContact.Surname;
                Phone.Text              = selectedContact.Phone;
                Email.Text              = selectedContact.Email;
                Street.Text             = selectedContact.Street;
                City.Text               = selectedContact.City;
                Postalcode.Text         = selectedContact.Postalcode;
                contactId               = selectedContact.Id;
                titleForAddEdit.Content = "Kontakt bearbeiten";
                if (selectedContact.PicturePath != string.Empty && File.Exists(selectedContact.PicturePath))
                {
                    ContactPicture.Source = new BitmapImage(new Uri(selectedContact.PicturePath));
                }
            }
            else
            {
                titleForAddEdit.Content = "Kontakt hinzufügen";
            }
        }
Exemple #2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            if (FirstName.Text == string.Empty && Surname.Text == string.Empty)
            {
                errorMessageContact.Content = "Es müssen Vor- oder Nachname gegeben werden.";
            }
            else
            {
                string databasePath = string.Empty;
                string data         = programmPath + picturename;
                int    number       = 1;
                int    picterNumber = 0;
                if (path != string.Empty && picturename != null)
                {
                    if (!Directory.Exists(programmPath))
                    {
                        Directory.CreateDirectory(programmPath);
                    }

                    if (!File.Exists(data))
                    {
                        File.Copy(path, data);
                    }
                    else
                    {
                        var picturesearch = picturename.Substring(0, picturename.LastIndexOf('.')) + "*.*";
                        var list          = Directory.GetFiles(programmPath, picturesearch);
                        if (list.Length == 1)
                        {
                            number = 1;
                        }
                        else
                        {
                            foreach (var item in list)
                            {
                                string pictureCopyName = item;
                                if (pictureCopyName.Contains("_"))
                                {
                                    pictureCopyName = pictureCopyName.Substring(pictureCopyName.LastIndexOf('_'));
                                    var pictureCopyNameNumber = pictureCopyName.Remove(0, 1);
                                    pictureCopyNameNumber = pictureCopyNameNumber.Remove(1);
                                    if (int.TryParse(pictureCopyNameNumber, out picterNumber))
                                    {
                                        if (picterNumber >= number)
                                        {
                                            number = picterNumber + 1;
                                        }
                                    }
                                }
                            }
                        }
                        data         = data.Substring(0, data.LastIndexOf('.')) + "_" + number + data.Substring(data.LastIndexOf('.'));
                        databasePath = data;
                        File.Copy(path, databasePath);
                    }
                }


                Entities.Contact newContact = new Entities.Contact()
                {
                    Firstname   = FirstName.Text,
                    Surname     = Surname.Text,
                    Phone       = Phone.Text,
                    Street      = Street.Text,
                    City        = City.Text,
                    Email       = Email.Text,
                    Postalcode  = Postalcode.Text,
                    PicturePath = databasePath,
                    UserId      = this.userId,
                    Id          = contactId
                };
                _service.CreateOrUpdateContact(newContact);
                Back_Click(sender, e);
            }
        }