public void Add(Home home) { home.HomeID = getLastId() + 1; var h1 = _homes.SingleOrDefault(h => h.HomeID == home.HomeID); if (h1 == null) { _homes.Add(home); using (HomeTrackerModel1 db = new HomeTrackerModel1()) { try { home.OwnerID = home.Owner.OwnerID; db.Homes.Add(home); db.SaveChanges(); //tried to add home with out owner and had this exception thrown. Owner can't be an option? } catch (Exception ex) { int i = 0; } } } }
public bool Remove(Home removeMe) { bool removed = false; if (_homes.Remove(removeMe)) { removed = true; using (HomeTrackerModel1 db = new HomeTrackerModel1()) { var homeSalesToRemove = from hs in db.HomeSales where hs.HomeID == removeMe.HomeID select hs; try { foreach (var hs in homeSalesToRemove)//could have used single or default { db.Entry(hs).State = EntityState.Deleted; } db.Entry(removeMe).State = EntityState.Deleted; db.SaveChanges(); } catch (Exception ex) { //notify user } } } return(removed); }
public void Add(Home home) { home.HomeID = getLastId() + 1; var h1 = _homes.SingleOrDefault(h => h.HomeID == home.HomeID); if (h1 == null) { _homes.Add(home); using (HomeTrackerModel1 db = new HomeTrackerModel1()) { try { home.OwnerID = home.Owner.OwnerID; home.Owner = null; db.Homes.Add(home); db.SaveChanges(); } catch (Exception) { int i = 0; } } } }
public void Update(HomeSale homeSale) { if (homeSale == null) { return; } using (HomeTrackerModel1 db = new HomeTrackerModel1()) { try { db.Entry(homeSale).State = EntityState.Modified; db.SaveChanges(); } catch (Exception ex) { //Todo: notify user int i = 0; } } }
public void Add(Person person) { person.PersonID = getLastId() + 1; var p1 = _peopleList.SingleOrDefault(p => p.PersonID == person.PersonID); if (p1 == null) { _peopleList.Add(person); using (HomeTrackerModel1 db = new HomeTrackerModel1()) { try { db.Entry(person).State = EntityState.Added; if (person.Owner != null) { person.Owner.OwnerID = person.PersonID; db.Entry(person.Owner).State = EntityState.Added; } if (person.Agent != null) { person.Agent.AgentID = person.PersonID; db.Entry(person.Agent).State = EntityState.Added; } if (person.Buyer != null) { person.Buyer.BuyerID = person.PersonID; db.Entry(person.Buyer).State = EntityState.Added; } db.SaveChanges(); } catch (Exception ex) { int i = 0; } } } }
public void Add(HomeSale homeSale) { homeSale.SaleID = getLastId() + 1; var homeS = _homeSales.SingleOrDefault(hs => hs.SaleID == homeSale.SaleID); if (homeS == null) { _homeSales.Add(homeSale); using (HomeTrackerModel1 db = new HomeTrackerModel1()) { try { db.HomeSales.Add(homeSale); db.SaveChanges(); } catch (Exception ex) { //Todo: notify user int i = 0; } } } }