Пример #1
0
        public ContactsVM()
        {
            NewContactCommand = new NewContactCommand(this);

            Contacts = new ObservableCollection <Contact>();
            ReadContacts();
        }
Пример #2
0
        public ContactsVM()
        {
            Contactos = new ObservableCollection <Contact>();

            NewContactCommand    = new NewContactCommand(this);
            EditContactCommand   = new Command <Contact>(EditarContacto);
            DeleteContactCommand = new Command <Contact>(BorrarContacto);
        }
Пример #3
0
        public async Task <ServiceResponse <ContactViewModel> > Add(ContactViewModel model)
        {
            var newContactCommand = new NewContactCommand(model.FirstName, model.LastName, model.EmailAddress);
            var json     = JsonConvert.SerializeObject(newContactCommand);
            var response = await client.PostAsync("/contacts", new StringContent(json, Encoding.UTF8, "application/json"));

            var result = await response.ParseResponse <ContactViewModel>();

            return(result);
        }
        /// Handler is idempotent. Could be called multiple times due to try logic
        public async Task <Contact> Handle(NewContactCommand command)
        {
            var existingContact = await context.Contacts.FindAsync(command.EmailAddress);

            if (existingContact != null)
            {
                return(existingContact);
            }

            var contact = Contact.Create(command.FirstName, command.LastName, command.EmailAddress);

            var notifications = contact.DomainEvents.Select(x => x.ToNotification());

            context.Contacts.Add(contact);

            context.Notifications.AddRange(notifications);

            await context.SaveChangesAsync();

            return(contact);
        }
Пример #5
0
        public async Task <IActionResult> NewContact([FromBody] NewContactCommand command)
        {
            var response = await this.newContactCommandHandler.Handle(command);

            return(NoContent());
        }
 public ContactsVM()
 {
     NewContactCommand  = new NewContactCommand(this);
     EditContactCommand = new Command <Contact>(EditarContacto);
 }