示例#1
0
        public ContactDetailViewModel(ContactViewModel viewModel, IContactStore contactStore, IPageService pageService)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            _pageService  = pageService;
            _contactStore = contactStore;

            SaveCommand = new Command(async() => await Save());


            Contact = new Contact
            {
                ContactId = viewModel.ContactId,
                FirstName = viewModel.FirstName,
                LastName  = viewModel.LastName,
                Phone     = viewModel.Phone,
                Email     = viewModel.Email,
                IsBlocked = viewModel.IsBlocked,
            };
        }
示例#2
0
        private async Task SelectContact(ContactViewModel contact)
        {
            if (contact == null)
            {
                return;
            }

            SelectedContact = null;

            var viewModel = new ContactDetailViewModel(contact, _contactStore, _pageService);

            viewModel.ContactUpdated += (source, updatedContact) =>
            {
                contact.Id        = updatedContact.Id;
                contact.FirstName = updatedContact.FirstName;
                contact.LastName  = updatedContact.LastName;
                contact.Phone     = updatedContact.Phone;
                contact.Email     = updatedContact.Email;
                contact.IsBlocked = updatedContact.IsBlocked;
            };

            await _pageService.PushAsync(new ContactDetailPage(viewModel));
        }
示例#3
0
        public ContactsDetailViewModel(ContactViewModel contact, IPageService pageService, IContactStore contactStore)
        {
            if (contact == null)
            {
                throw new ArgumentNullException(nameof(contact));
            }

            Contact = new Contact
            {
                Id          = contact.Id,
                FirstName   = contact.FirstName,
                Surname     = contact.Surname,
                PhoneNumber = contact.PhoneNumber,
                Email       = contact.Email,
                IsBlocked   = contact.IsBlocked
            };

            Title = Contact.Id == 0 ? "New contact" : "Update contact";

            SaveContactCommand = new Command(SaveContact);

            _pageService  = pageService;
            _contactStore = contactStore;
        }