Пример #1
0
 public ContactWithAddressDto GetContactWithAddressDto(Guid id)
 {
     using (var context = new ContactAggregateContext()) {
     Contact c = context.Contacts.Find(id);
     return ContactWithAddressDto.Create(c.Id, c.Name, c.PrimaryAddress, c.Source);
       }
 }
        public bool PersistNewContact(Contact contact)
        {
            using (var context = new ContactAggregateContext()) {
            context.Contacts.Add(contact);
            contact.SetModifiedDate();

            try {
              int response = context.SaveChanges();
              if (response > 0) {
            PublishContactPersistedEvent(contact, true);
              }
              return true;
            }
            catch (Exception ex) {
              throw ex;
            }
              }
        }
        public bool PersistNewContact(Contact contact)
        {
            using (var context = new ContactAggregateContext()) {
                context.Contacts.Add(contact);
                contact.SetModifiedDate();

                try {
                    int response = context.SaveChanges();
                    if (response > 0)
                    {
                        PublishContactPersistedEvent(contact, true);
                    }
                    return(true);
                }
                catch (Exception ex) {
                    throw ex;
                }
            }
        }
 public bool PersistChangeToContact(Contact contact)
 {
     using (var context = new ContactAggregateContext()) {
     context.Contacts.Attach(contact);
     contact.SetModifiedDate();
     context.Entry(contact).State = EntityState.Modified;
     try {
       int response = context.SaveChanges();
       if (response > 0) {
     if (contact.Events.OfType<ContactNameFixedEvent>().Any()) {
       PublishContactPersistedEvent(contact, false);
     }
     return true;
       }
       return false;
     }
     catch (Exception ex) {
       throw ex;
     }
       }
 }
 public bool PersistChangeToContact(Contact contact)
 {
     using (var context = new ContactAggregateContext()) {
         context.Contacts.Attach(contact);
         contact.SetModifiedDate();
         context.Entry(contact).State = EntityState.Modified;
         try {
             int response = context.SaveChanges();
             if (response > 0)
             {
                 if (contact.Events.OfType <ContactNameFixedEvent>().Any())
                 {
                     PublishContactPersistedEvent(contact, false);
                 }
                 return(true);
             }
             return(false);
         }
         catch (Exception ex) {
             throw ex;
         }
     }
 }
Пример #6
0
 // GET api/<controller>/5
 public Address GetPrimaryAddressForContact(Guid id)
 {
     using (var context = new ContactAggregateContext()) {
     return context.Contacts.Find(id).PrimaryAddress;
       }
 }
Пример #7
0
 // GET api/<controller>
 public IEnumerable<Contact> Get()
 {
     using (var context = new ContactAggregateContext()) {
     return context.Contacts.ToList();
       }
 }