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; } }
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; } }
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")); } }
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")); } }
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")); } }
public List <PersonModel> ListPersons() { try { using (var db = new AccelaEntities()) { var people = db.PersonModels; return(people.ToList()); } } catch (Exception e) { throw e.InnerException; } }
public string CountPerson() { try { using (var db = new AccelaEntities()) { var count = db.PersonModels .Count(); return(count.ToString()); } } catch (Exception e) { throw e.InnerException; } }
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; } }
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; } }