Пример #1
0
        public void AddToAndGetFromDBTest()
        {
            using (ContactTypeDBDataContext Context = new ContactTypeDBDataContext())
            {
                ContactType newContact = new ContactType
                {
                    Name         = "New contact name",
                    ModifiedDate = DateTime.Now
                };

                Context.ContactType.InsertOnSubmit(newContact);
                Context.SubmitChanges();
            }

            using (ContactTypeDBDataContext Context = new ContactTypeDBDataContext())
            {
                ContactType readContact        = Context.ContactType.FirstOrDefault(c => c.Name == "New contact name");
                ContactType anotherReadContact = Context.ContactType.FirstOrDefault(c => c.Name == "A name that does not appear");

                Assert.AreEqual("New contact name", readContact.Name);
                Assert.IsNull(anotherReadContact);

                Context.ContactType.DeleteOnSubmit(readContact);
                Context.SubmitChanges();

                ContactType yetAnotherReadContact = Context.ContactType.FirstOrDefault(c => c.Name == "New contact name");

                Assert.IsNull(yetAnotherReadContact);
            }
        }
Пример #2
0
 public void RemoveContactType(int contactID)
 {
     using (ContactTypeDBDataContext Context = new ContactTypeDBDataContext())
     {
         ContactType contactType = Context.ContactType.Where(ct => ct.ContactTypeID == contactID).FirstOrDefault();
         Context.ContactType.DeleteOnSubmit(contactType);
         Context.SubmitChanges();
     }
 }
Пример #3
0
        public ContactTypeWrapper GetContactType(int id)
        {
            ContactType contact = new ContactType();

            using (ContactTypeDBDataContext Context = new ContactTypeDBDataContext())
            {
                contact = Context.ContactType.Where(ct => ct.ContactTypeID == id).FirstOrDefault();
            }
            return(new ContactTypeWrapper(contact));
        }
Пример #4
0
        public int GetContactIDByName(string name)
        {
            ContactType contact = new ContactType();

            using (ContactTypeDBDataContext Context = new ContactTypeDBDataContext())
            {
                contact = Context.ContactType.Where(ct => ct.Name == name).FirstOrDefault();
            }
            return(contact.ContactTypeID);
        }
Пример #5
0
        public void UpdateContactType(int contactID, string name)
        {
            using (ContactTypeDBDataContext Context = new ContactTypeDBDataContext())
            {
                ContactType contact = Context.ContactType.Where(ct => ct.ContactTypeID == contactID).FirstOrDefault();
                contact.Name         = name;
                contact.ModifiedDate = DateTime.Now;

                Context.SubmitChanges();
            }
        }
Пример #6
0
        public void AddContactType(string name)
        {
            ContactType newContact = new ContactType
            {
                Name         = name,
                ModifiedDate = DateTime.Now
            };

            using (ContactTypeDBDataContext Context = new ContactTypeDBDataContext())
            {
                Context.ContactType.InsertOnSubmit(newContact);
                Context.SubmitChanges();
            }
        }
Пример #7
0
        public List <ContactTypeWrapper> GetContactTypes()
        {
            List <ContactType> contacts = new List <ContactType>();

            using (ContactTypeDBDataContext Context = new ContactTypeDBDataContext())
            {
                contacts = Context.ContactType.ToList();
            }
            List <ContactTypeWrapper> contactTypeWrappers = new List <ContactTypeWrapper>();

            foreach (ContactType contact in contacts)
            {
                contactTypeWrappers.Add(new ContactTypeWrapper(contact));
            }

            return(contactTypeWrappers);
        }