Esempio n. 1
0
        private void OnContactEdit(object sender, EventArgs e)
        {
            var form = new ContactForm();

            var contact = GetSelectedContact();

            if (contact == null)
            {
                return;
            }

            //contact to edit

            form.Contact = contact;

            while (true)
            {
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    _contacts.Update(contact.Id, form.Contact);
                    break;
                } catch (Exception ex)
                {
                    DisplayError(ex);
                };
            }
            ;

            BindList();
        }
Esempio n. 2
0
        public IActionResult Update(int id, ContactUpdateViewModel contact)
        {
            Contact domainContact = new Contact()
            {
                Id            = id,
                Naam          = contact.Naam,
                Voornaam      = contact.Voornaam,
                Geslacht      = contact.Geslacht,
                GeboorteDatum = contact.GeboorteDatum,
                Email         = contact.Email,
                TelefoonNr    = contact.TelefoonNr,
                Adres         = contact.Adres,
                Beschrijving  = contact.Beschrijving,
                Category      = contact.Category
            };

            if (contact.Avatar != null)
            {
                var bytes = GetBytesFromFile(contact.Avatar);
                domainContact.Avatar = bytes;
            }
            else
            {
                domainContact.Avatar = contact.FileBytes;
            }

            _contactDatabase.Update(id, domainContact);

            return(RedirectToAction("Details", new { Id = id }));
        }
Esempio n. 3
0
        public IActionResult Edit(int id, ContactEditModel contact)
        {
            if (!TryValidateModel(contact))
            {
                return(View(contact));
            }

            var contactToDb = new Contact()
            {
                FirstName   = contact.FirstName,
                LastName    = contact.LastName,
                PhoneNumber = contact.PhoneNumber,
                Addres      = contact.Address,
                Email       = contact.Email,
                Description = contact.Description,
                BirthDate   = contact.BirthDate
            };

            //if (contact.Avatar != null)
            //{
            //    var bytes = GetBytesFromFile(contact.Avatar);
            //    contactToDb.Avatar = bytes;
            //}

            if (contact.Avatar != null)
            {
                var     uniqueFileName = Guid.NewGuid().ToString() + Path.GetExtension(contact.Avatar.FileName);
                var     path           = Path.Combine(_hostEnvironment.WebRootPath, "photos", uniqueFileName);
                Contact contactFromDb  = _contactDatabase.GetContact(id);

                if (!string.IsNullOrEmpty(contactFromDb.PhotoUrl))
                {
                    var prevPath = Path.Combine(_hostEnvironment.WebRootPath, "photos", contactFromDb.PhotoUrl.Substring(8));
                    System.IO.File.Delete(prevPath);
                }

                using (var stream = new FileStream(path, FileMode.Create))
                {
                    contact.Avatar.CopyTo(stream);
                }

                contactToDb.PhotoUrl = "/photos/" + uniqueFileName;
            }
            else
            {
                Contact contactFromDb = _contactDatabase.GetContact(id);

                if (!string.IsNullOrEmpty(contactFromDb.PhotoUrl))
                {
                    contactToDb.PhotoUrl = contactFromDb.PhotoUrl;
                }
            }

            _contactDatabase.Update(id, contactToDb);

            return(RedirectToAction("Detail", new { Id = id }));
        }
Esempio n. 4
0
        public IActionResult Update([FromForm] ContactEditViewModel vm, [FromRoute] int id)
        {
            if (!TryValidateModel(vm))
            {
                return(View(vm));
            }

            _contactDatabase.Update(id, new Contact
            {
                Name       = vm.Name,
                Surname    = vm.Surname,
                Email      = vm.Email,
                BirthDate  = vm.BirthDate,
                TelNr      = vm.TelNr,
                Address    = vm.Address,
                Annotation = vm.Annotation
            });

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 5
0
        private void OnContactsEdit(object sender, EventArgs e)
        {
            // display UI
            var form = new ContactForm();

            // change from title
            form.Text = "Edit Contact";

            // get selected contact, if any
            var contact = _listContacts.SelectedItem as Contact;

            if (contact == null)
            {
                return;
            }

            form.Contact = contact;

            while (true)
            {
                if (form.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    _contacts.Update(contact.Id, form.Contact);
                    break;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Name must be unique.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            BindContactList();
        }
Esempio n. 6
0
        public IActionResult Update(int id, ContactUpdateViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(View());
            }

            Contact contactToUpdate = new Contact()
            {
                Id            = id,
                Voornaam      = model.Voornaam,
                Naam          = model.Naam,
                Geslacht      = model.Geslacht,
                Geboortedatum = model.Geboortedatum,
                TelefoonNr    = model.TelefoonNr,
                Email         = model.Email,
                Beschrijving  = model.Beschrijving,
                Adres         = model.Adres
            };

            _contactDabase.Update(id, contactToUpdate);

            return(RedirectToAction("Detail", new { Id = id }));
        }