Ejemplo n.º 1
0
        public void CreateNewContact(Contact contact, AddressModel address, string contactType)
        {
            using (var dataContext = new DataContext.AdressbookDataContext())
            {
                var newContact = new DataContext.Contact();
                newContact.Name      = contact.Name;
                newContact.Email     = contact.Email;
                newContact.Telephone = contact.Telephone;

                var newAddress = new DataContext.Address();
                newAddress.StreetAddress = address.StreetAddress;
                newAddress.City          = address.City;
                newAddress.PostalCode    = address.PostalCode;

                var contactId      = newContact.Id;
                var newContactType = new DataContext.ContactType();
                newContactType.ContactType1 = contactType;
                newContactType.ContactId    = contactId;

                var newAddressContactLink = new DataContext.AddressContactLink();
                newAddressContactLink.ContactId = newContact.Id;
                newAddressContactLink.AddressId = newAddress.Id;

                dataContext.Contact.Add(newContact);
                dataContext.Address.Add(newAddress);
                dataContext.ContactType.Add(newContactType);
                dataContext.AddressContactLink.Add(newAddressContactLink);
                dataContext.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        public BindingList <View_Models.AddressModel> GetAddress()
        {
            BindingList <AddressModel> addresses;

            using (var dataContext = new DataContext.AdressbookDataContext())
            {
                var addressQuery = from address in dataContext.Address
                                   select new View_Models.AddressModel()
                {
                    Id            = address.Id,
                    StreetAddress = address.StreetAddress,
                    PostalCode    = address.PostalCode,
                    City          = address.City
                };
                addresses = new BindingList <AddressModel>(addressQuery.ToList());
            }
            return(addresses);
        }
Ejemplo n.º 3
0
        public BindingList <View_Models.Contact> GetContacts()
        {
            BindingList <Contact> contacts;


            using (var dataContext = new DataContext.AdressbookDataContext())
            {
                var contactQuery = from contact in dataContext.Contact
                                   join contactType in dataContext.ContactType on contact.Id equals contactType.ContactId

                                   select new View_Models.Contact()
                {
                    Id           = contact.Id,
                    Name         = contact.Name,
                    Email        = contact.Email,
                    Telephone    = contact.Telephone,
                    Contact_Type = contactType.ContactType1
                };
                contacts = new BindingList <Contact>(contactQuery.ToList());
            }
            return(contacts);
        }
Ejemplo n.º 4
0
        public BindingList <View_Models.Contact> GetContacts(int addressId)
        {
            BindingList <Contact> contacts;


            using (var dataContext = new DataContext.AdressbookDataContext())
            {
                var result = from link in dataContext.AddressContactLink
                             join address in dataContext.Address on link.AddressId equals addressId
                             join typeOfContact in dataContext.ContactType on link.ContactId equals typeOfContact.ContactId
                             where address.Id == addressId

                             select new View_Models.Contact()
                {
                    Id           = link.Id,
                    Name         = link.Contact.Name,
                    Email        = link.Contact.Email,
                    Telephone    = link.Contact.Telephone,
                    Contact_Type = typeOfContact.ContactType1
                };
                contacts = new BindingList <Contact>(result.ToList());
            }
            return(contacts);
        }