Exemplo n.º 1
0
 public bool EditPerson(int personId, string firstName, string lastName)
 {
     try
     {
         using (var db = new AccelaEntities())
         {
             var result = db.PersonModels.SingleOrDefault(b => b.PERSON_ID == personId);
             if (result != null)
             {
                 if (!firstName.Equals(""))
                 {
                     result.FIRST_NAME = firstName;
                 }
                 if (!lastName.Equals(""))
                 {
                     result.LAST_NAME = lastName;
                 }
                 db.SaveChanges();
                 MessageBox.Show("This record has been edited sucessfully");
                 return(true);
             }
             else
             {
                 MessageBox.Show("No value exists for the ID entered");
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         throw e.InnerException;
     }
 }
Exemplo n.º 2
0
        public bool AddPersonXML(string xmlPath)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(xmlPath);

                XmlNode firstNameNode = doc.DocumentElement.SelectSingleNode("FirstName");
                string  firstName     = firstNameNode.InnerText;
                XmlNode lastNameNode  = doc.DocumentElement.SelectSingleNode("LastName");
                string  lastName      = lastNameNode.InnerText;

                using (var db = new AccelaEntities())
                {
                    var person = new PersonModel {
                        FIRST_NAME = firstName, LAST_NAME = lastName
                    };
                    db.PersonModels.Add(person);
                    db.SaveChanges();
                    MessageBox.Show("Person has been added to the database through XML.");
                    return(true);
                }
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
Exemplo n.º 3
0
 public void EditAddressTest()
 {
     using (var db = new AccelaEntities())
     {
         var result = db.AddressModels.Select(b => b.ADDRESS_ID).FirstOrDefault();
         Assert.IsTrue(address.EditAddress(result, "street", "city", "state", "postcode"));
     }
 }
Exemplo n.º 4
0
 public void EditPersonTest()
 {
     using (var db = new AccelaEntities())
     {
         var result = db.PersonModels.Select(b => b.PERSON_ID).FirstOrDefault();
         Assert.IsTrue(person.EditPerson(result, "UnitTestFirstName", "UnitTestSecondName"));
     }
 }
Exemplo n.º 5
0
 public void AddAddressTest()
 {
     using (var db = new AccelaEntities())
     {
         var result = db.PersonModels.Select(b => b.PERSON_ID).FirstOrDefault();
         Assert.IsTrue(address.AddAddress(result.ToString(), "street", "city", "state", "postcode"));
     }
 }
Exemplo n.º 6
0
 public List <PersonModel> ListPersons()
 {
     try
     {
         using (var db = new AccelaEntities())
         {
             var people = db.PersonModels;
             return(people.ToList());
         }
     }
     catch (Exception e)
     {
         throw e.InnerException;
     }
 }
Exemplo n.º 7
0
 public string CountPerson()
 {
     try
     {
         using (var db = new AccelaEntities())
         {
             var count = db.PersonModels
                         .Count();
             return(count.ToString());
         }
     }
     catch (Exception e)
     {
         throw e.InnerException;
     }
 }
Exemplo n.º 8
0
 public bool AddPerson(string firstName, string lastName)
 {
     try
     {
         using (var db = new AccelaEntities())
         {
             var person = new PersonModel {
                 FIRST_NAME = firstName, LAST_NAME = lastName
             };
             db.PersonModels.Add(person);
             db.SaveChanges();
             MessageBox.Show("Person has been added to the database.");
             return(true);
         }
     }
     catch (Exception e)
     {
         throw e.InnerException;
     }
 }
Exemplo n.º 9
0
 public bool EditAddress(int addressId, string street, string city, string state, string postcode)
 {
     try
     {
         using (var db = new AccelaEntities())
         {
             var result = db.AddressModels.SingleOrDefault(b => b.ADDRESS_ID == addressId);
             if (result != null)
             {
                 if (!street.Equals(""))
                 {
                     result.STREET = street;
                 }
                 if (!city.Equals(""))
                 {
                     result.CITY = city;
                 }
                 if (!state.Equals(""))
                 {
                     result.STATE = state;
                 }
                 if (!postcode.Equals(""))
                 {
                     result.POSTAL_CODE = postcode;
                 }
                 db.SaveChanges();
                 MessageBox.Show("This record has been edited sucessfully");
                 return(true);
             }
             else
             {
                 MessageBox.Show("No value exists for the ID entered");
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         throw e.InnerException;
     }
 }